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

Diff syntax folding

Expand Messages
  • Shaun Jackman
    I d like add syntax folding for diff files (note, not the vimdiff view). I haven t done any syntax file hacking though. In a multi-file diff, each individual
    Message 1 of 5 , Jun 24, 2003
      I'd like add syntax folding for diff files (note, not the vimdiff view).
      I haven't done any syntax file hacking though. In a multi-file diff,
      each individual diff starts with

      diff -ur old new
      --- old
      +++ new

      I'd like the fold to last from the line beginning with diff "^diff " to
      the line just before the next "^diff " or the end-of-file. Can this be
      done easily with a simple "syn region fold" command? Once I understand
      this a little better, I'd like to add regions of changes within the
      individual files.

      Cheers,
      Shaun
    • Shaun Jackman
      I thought I d mention how I m currently doing this: set foldcolumn=2 set foldmarker=+++ ,--- +++ to --- set foldmethod=marker This works, but is
      Message 2 of 5 , Jun 24, 2003
        I thought I'd mention how I'm currently doing this:

        set foldcolumn=2
        set foldmarker=+++\ ,---\ "+++ " to "--- "
        set foldmethod=marker

        This works, but is slightly imperfect. The fold goes from +++ to ---
        rather than from diff to diff. It does have more or less the desired
        effect though.

        Cheers,
        Shaun


        On Tue, 2003-06-24 at 13:06, Shaun Jackman wrote:
        > I'd like add syntax folding for diff files (note, not the vimdiff view).
        > I haven't done any syntax file hacking though. In a multi-file diff,
        > each individual diff starts with
        >
        > diff -ur old new
        > --- old
        > +++ new
        >
        > I'd like the fold to last from the line beginning with diff "^diff " to
        > the line just before the next "^diff " or the end-of-file. Can this be
        > done easily with a simple "syn region fold" command? Once I understand
        > this a little better, I'd like to add regions of changes within the
        > individual files.
        >
        > Cheers,
        > Shaun
        >
        >
        >
      • Gary Johnson
        ... I think you re saying that you want to fold everything but lines containing ^diff . If that s the case, then you could do this: set foldmethod=expr set
        Message 3 of 5 , Jun 24, 2003
          On 2003-06-24, Shaun Jackman <sjackman@...> wrote:
          > On Tue, 2003-06-24 at 13:06, Shaun Jackman wrote:
          > > I'd like add syntax folding for diff files (note, not the vimdiff view).
          > > I haven't done any syntax file hacking though. In a multi-file diff,
          > > each individual diff starts with
          > >
          > > diff -ur old new
          > > --- old
          > > +++ new
          > >
          > > I'd like the fold to last from the line beginning with diff "^diff " to
          > > the line just before the next "^diff " or the end-of-file. Can this be
          > > done easily with a simple "syn region fold" command? Once I understand
          > > this a little better, I'd like to add regions of changes within the
          > > individual files.

          > I thought I'd mention how I'm currently doing this:
          >
          > set foldcolumn=2
          > set foldmarker=+++\ ,---\ "+++ " to "--- "
          > set foldmethod=marker
          >
          > This works, but is slightly imperfect. The fold goes from +++ to ---
          > rather than from diff to diff. It does have more or less the desired
          > effect though.

          I think you're saying that you want to fold everything but lines
          containing "^diff ". If that's the case, then you could do this:

          set foldmethod=expr
          set foldexpr=getline(v:lnum)!~'^diff\ '

          It's not syntax folding, but it wasn't clear whether syntax folding
          was a requirement or just the approach you had taken so far.

          HTH,
          Gary

          --
          Gary Johnson | Agilent Technologies
          garyjohn@... | Wireless Division
          | Spokane, Washington, USA
        • Shaun Jackman
          Thanks, this works great! Syntax folding wasn t a requirement, so much as a curiosity. Using foldexpr, can the the line containing ^diff be included as the
          Message 4 of 5 , Jun 25, 2003
            Thanks, this works great! Syntax folding wasn't a requirement, so much
            as a curiosity. Using foldexpr, can the the line containing '^diff ' be
            included as the first line of the fold? In such a case, all lines would
            be at fold level 1, but each region would be it's own fold.

            Thanks,
            Shaun


            > I think you're saying that you want to fold everything but lines
            > containing "^diff ". If that's the case, then you could do this:
            >
            > set foldmethod=expr
            > set foldexpr=getline(v:lnum)!~'^diff\ '
            >
            > It's not syntax folding, but it wasn't clear whether syntax folding
            > was a requirement or just the approach you had taken so far.
            >
            > HTH,
            > Gary
          • Gary Johnson
            ... You re welcome. Yes; see :help fold-expr . I tried the following and it seemed to work. set foldexpr=(getline(v:lnum)=~ ^diff )?
            Message 5 of 5 , Jun 25, 2003
              On 2003-06-25, Shaun Jackman <sjackman@...> wrote:

              > > I think you're saying that you want to fold everything but lines
              > > containing "^diff ". If that's the case, then you could do this:
              > >
              > > set foldmethod=expr
              > > set foldexpr=getline(v:lnum)!~'^diff\ '
              > >
              > > It's not syntax folding, but it wasn't clear whether syntax folding
              > > was a requirement or just the approach you had taken so far.

              > Thanks, this works great! Syntax folding wasn't a requirement, so much
              > as a curiosity. Using foldexpr, can the the line containing '^diff ' be
              > included as the first line of the fold? In such a case, all lines would
              > be at fold level 1, but each region would be it's own fold.

              You're welcome. Yes; see ":help fold-expr". I tried the following
              and it seemed to work.

              set foldexpr=(getline(v:lnum)=~'^diff\ ')?'<1':'1'

              Gary

              --
              Gary Johnson | Agilent Technologies
              garyjohn@... | Wireless Division
              | Spokane, Washington, USA
            Your message has been successfully submitted and would be delivered to recipients shortly.