Loading ...
Sorry, an error occurred while loading the content.

86265Re: Simple hiding all comments by folding

Expand Messages
  • arctgx
    Jan 6, 2008
    • 0 Attachment
      I wouldn't like to insert into file any strings ({{{, 'token' etc.)
      that are deserve only to define fold range, especially as I open some
      files only for reading.

      Vince Negri's patch doesn't exists for 7.1 vim version. I tried to
      patch 7.1 but patching exited with fails. Charles, does your commands
      work only with this patch (E492: Not an editor command:
      cmmnt_toggle=1<bar>hi link shComment Ign)?

      A.Politz, I tested your functions on following text:

      *************************************
      # vim syntax=sh :
      # c1cccccccc
      # c2cccccccc
      nnn1nnnnnnnn
      nnn2nnnnnnnn
      nnn3nnnnnnnn
      # c3cccccccc
      # c4cccccccc
      # c5cccccccc
      # c6cccccccc
      nnn4nnnnnnnn
      nnn5nnnnnnnn
      nnn6nnnnnnnn
      # c7cccccccc
      # c8cccccccc
      # c9cccccccc
      nnn7nnnnnnnn
      # c10ccccccc
      nnn8nnnnnnnn
      # c11ccccccc
      nnn9nnnnnnnn
      *****************************************************


      Loading source with
      ******************
      set fdm=expr
      set fde=IsComment(v:lnum)?1:IsComment(prevnonblank(v:lnum-1))?
      1:IsComment(nextnonblank(v:lnum+1))?1:0
      func! FoldComments( lnum )
      if getline('.') =~ '\S'
      return IsComment(a:lnum)
      else
      return IsComment(prevnonblank(a:lnum)) ||
      IsComment(nextnonblank(a:lnum))
      endif
      endfun

      func! IsComment( lnum )
      return synIDattr(synID(a:lnum, match(getline(a:lnum),'\S')+1,
      1),"name") =~? 'comment'
      endfun

      ******************
      gives
      ******************
      +-- 4 lines: #
      c1cccccccc-----------------------------------------------------------------------------------
      nnn2nnnnnnnn
      +-- 6 lines:
      nnn3nnnnnnnn-----------------------------------------------------------------------------------
      nnn5nnnnnnnn
      +-- 9 lines:
      nnn6nnnnnnnn-----------------------------------------------------------------------------------
      ******************



      Loading source with
      ******************
      gives
      ******************
      +-- 4 lines: #
      c1cccccccc-----------------------------------------------------------------------------------
      nnn2nnnnnnnn
      +-- 6 lines:
      nnn3nnnnnnnn-----------------------------------------------------------------------------------
      nnn5nnnnnnnn
      +-- 9 lines:
      nnn6nnnnnnnn-----------------------------------------------------------------------------------
      ******************

      ******************
      set fdm=expr
      set fde=FoldComments(v:lnum)
      func! FoldComments( lnum )
      if getline('.') =~ '\S'
      return IsComment(a:lnum)
      else
      return IsComment(prevnonblank(a:lnum)) ||
      IsComment(nextnonblank(a:lnum))
      endif
      endfun

      func! IsComment( lnum )
      return synIDattr(synID(a:lnum, match(getline(a:lnum),'\S')+1,
      1),"name") =~? 'comment'
      endfun
      ******************
      gives
      ******************
      +-- 3 lines: #
      c1cccccccc-----------------------------------------------------------------------------------
      nnn1nnnnnnnn
      nnn2nnnnnnnn
      nnn3nnnnnnnn
      +-- 4 lines: #
      c3cccccccc-----------------------------------------------------------------------------------
      nnn4nnnnnnnn
      nnn5nnnnnnnn
      nnn6nnnnnnnn
      +-- 3 lines: #
      c7cccccccc-----------------------------------------------------------------------------------
      nnn7nnnnnnnn
      # c10ccccccc
      nnn8nnnnnnnn
      # c11ccccccc
      nnn9nnnnnnnn
      ******************
      but in practice those solutions may sometimes work fine after loading
      them into vim :)
      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Show all 17 messages in this topic