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

86168Re: Simple hiding all comments by folding

Expand Messages
  • A.Politz
    Jan 1, 2008
    • 0 Attachment
      A.Politz wrote:

      >A.Politz wrote:
      >
      >
      >
      >>arctgx wrote:
      >>
      >>
      >>
      >>
      >>
      >>>Is there a simple universal command which hides all comments in file
      >>>by current syntax? I would like, for example hide comments in my shell
      >>>scripts (syntax=sh) or xorg.conf (syntax=xf86conf). There is a lot
      >>>text about folding but I still can't find a good solution.
      >>>
      >>>I tried
      >>>set foldmarker=#,$ | set foldmethod=marker
      >>>
      >>>but it is not universal solution and... hides all lines of shell
      >>>script ;) ($ doesn't denote end of line?)
      >>>
      >>>
      >>>
      >>>
      >>>
      >>>
      >>>
      >>>
      >>The following will fold commented lines,including pre- and succeeding
      >>empty ones. All it needs is a correct syntax plugin.
      >>This can be slow, as noted at ':h synID'. It would maybe be faster to
      >>use 'comment*' options, but then it wouldn't be simple anymore ;-).
      >>
      >>...
      >>
      >
      >

      Ok, here is a working and faster version.


      -----------%<--------------
      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
      -----------%<--------------

      -ap


      --
      Ich hab geträumt, der Krieg wär vorbei.


      --~--~---------~--~----~------------~-------~--~----~
      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