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

Re: folding refused, set filetype=c helps, why?

Expand Messages
  • Ben Fritz
    On Nov 30, 4:39 am, fka...@googlemail.com ... That does seem strange. Internally, setting filetype=c will re-apply the syntax
    Message 1 of 12 , Dec 1, 2010
    • 0 Attachment
      On Nov 30, 4:39 am, "fka...@..." <fka...@...>
      wrote:
      > Hi,
      >
      > I use syntax based folding in C code (vim 7.3.50). Sometimes when code
      > is changed folding is refused completely, e.g. zc does not fold
      > anymore. I found out that resetting the filetype helps (set
      > filetype=c), although a previous check (set filetype? and set
      > foldmethod?) shows that is was already c / syntax.
      >
      > So I wonder what 'set foldtype=c' internally does to reenable folding.
      > Maybe this is a hint to solve this misbehaviour...
      >

      That does seem strange.

      Internally, setting filetype=c will re-apply the syntax highlighting,
      which will re-calculate all the folds.

      You can try using zx, zX, or :syn sync fromstart to see if those have
      any effect. The first two will have the additional effect of closing
      any manually opened folds, the third will make syntax highlighting
      slower.

      Do existing folds stay as they were, and just a new fold refuses to
      show up, or are all folds removed?

      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • fkater@googlemail.com
      ... Thank You for the information. ... I was not aware of the first two and I will try. Regarding :syn sync fromstart -- This does not always help and that is
      Message 2 of 12 , Dec 2, 2010
      • 0 Attachment
        > > So I wonder what 'set foldtype=c' internally does to reenable folding.

        > Internally, setting filetype=c will re-apply the syntax highlighting,
        > which will re-calculate all the folds.

        Thank You for the information.


        > You can try using zx, zX, or :syn sync fromstart to see if those have
        > any effect.

        I was not aware of the first two and I will try. Regarding :syn sync
        fromstart -- This does not always help and that is the point here. In
        some situations only the above mentioned command (:set filetype=c)
        helps.

        > The first two will have the additional effect of closing
        > any manually opened folds, the third will make syntax highlighting
        > slower.

        What do you mean by "make ... slower"? You mean permanently?
        Unfortunatelly I need to launch this third command quite often since
        the syntax folding gets confused too easily.

        > Do existing folds stay as they were, and just a new fold refuses to
        > show up, or are all folds removed?

        In the addressed situtation ALL folds refuse to fold. And, I think,
        all folds are open in that case (not 100% sure).

        Felix

        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • fkater@googlemail.com
        ... No, non of the three things help. All folds are open and can not be closed. Only the mentioned way helps (set filetype=c). Additional note: I am working
        Message 3 of 12 , Dec 6, 2010
        • 0 Attachment
          > > You can try using zx, zX, or :syn sync fromstart to see if those have
          > > any effect.

          No, non of the three things help. All folds are open and can not be
          closed. Only the mentioned way helps (set filetype=c).

          Additional note: I am working with vertically split window. Mostly
          (not always) the situation occures like this:

          (1) vim opened by session, with two windows (vertically split) and two
          different C files loaded.

          (2) Then in one window the *same* buffer/file is opened by :b
          <filename>CR.

          (3) Now the folds in the newly loaded window are all open and cannot
          be closed. In the original window (same file/buffer) folding remains
          functional.

          Note: This does *not* always reproduce the case. Only sometimes.

          Felix

          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        • Ben Fritz
          On Dec 6, 5:00 am, fka...@googlemail.com ... Set the foldcolumn to some value (8 is usually enough for me). Do your folds exist but
          Message 4 of 12 , Dec 6, 2010
          • 0 Attachment
            On Dec 6, 5:00 am, "fka...@..." <fka...@...>
            wrote:
            > > > You can try using zx, zX, or :syn sync fromstart to see if those have
            > > > any effect.
            >
            > No, non of the three things help. All folds are open and can not be
            > closed. Only the mentioned way helps (set filetype=c).
            >
            > Additional note: I am working with vertically split window. Mostly
            > (not always) the situation occures like this:
            >
            > (1) vim opened by session, with two windows (vertically split) and two
            > different C files loaded.
            >
            > (2) Then in one window the *same* buffer/file is opened by :b
            > <filename>CR.
            >
            > (3) Now the folds in the newly loaded window are all open and cannot
            > be closed. In the original window (same file/buffer) folding remains
            > functional.
            >

            Set the foldcolumn to some value (8 is usually enough for me). Do your
            folds exist but refuse to close? Or are they gone entirely? Is ft
            still set to c when the folds are gone? Is 'foldenable' set?

            I would also try starting with no .vimrc and no plugins, then manually
            enabling filetype and syntax. I haven't needed to do this before, so
            I'm not 100% sure I'm not missing anything, but I think this will do
            it:

            gvim -N -u NONE
            :filetype indent plugin on
            :syntax on

            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
          • Ben Fritz
            On Dec 2, 3:12 am, fka...@googlemail.com ... One more thing, this effect of zx and zX is fairly new, introduced in 7.2.421. Check
            Message 5 of 12 , Dec 6, 2010
            • 0 Attachment
              On Dec 2, 3:12 am, "fka...@..." <fka...@...>
              wrote:
              > > > So I wonder what 'set foldtype=c' internally does to reenable folding.
              > > Internally, setting filetype=c will re-apply the syntax highlighting,
              > > which will re-calculate all the folds.
              >
              > Thank You for the information.
              >
              > > You can try using zx, zX, or :syn sync fromstart to see if those have
              > > any effect.
              >
              > I was not aware of the first two and I will try. Regarding :syn sync
              > fromstart -- This does not always help and that is the point here. In
              > some situations only the above mentioned command (:set filetype=c)
              > helps.
              >

              One more thing, this effect of zx and zX is fairly new, introduced in
              7.2.421. Check your version, since they don't have the desired effect.

              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php
            • fkater@googlemail.com
              ... I work without foldcolumn -- so next time it occurs I ll try to enable it on the fly and see if they are gone or just refuse to work. (I believe somehow
              Message 6 of 12 , Dec 7, 2010
              • 0 Attachment
                > Set the foldcolumn to some value (8 is usually enough for me). Do your
                > folds exist but refuse to close?
                > Or are they gone entirely?

                I work without foldcolumn -- so next time it occurs I'll try to enable
                it on the fly and see if they are gone or just refuse to work. (I
                believe somehow the filetype changed and therefore all syntax based
                folding does not apply, that's probably why set filetype=c helps.)

                > Is ft still set to c when the folds are gone?

                Yes: set filetype? shows =c in that situation, however, it does not
                seem to be really set, because when I then do set filetype=c it
                reenables folding.

                > Is 'foldenable' set?

                I will check when it occurs.

                > I would also try starting with no .vimrc and no plugins, then manually
                > enabling filetype and syntax. I haven't needed to do this before, so
                > I'm not 100% sure I'm not missing anything, but I think this will do
                > it:
                >
                > gvim -N -u NONE
                > :filetype indent plugin on
                > :syntax on

                Thanks a lot... sigh.... I cannot really work without my settings and
                the bug occurs only some times per day... I will check that last.

                Felix


                --
                You received this message from the "vim_use" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php
              • fkater@googlemail.com
                ... The problem occured again. FYI: When foldcolumn is displayed in this case: There are NO folds in it anymore. But some breaking news: I have
                Message 7 of 12 , Dec 12, 2010
                • 0 Attachment
                  > > Do your folds exist but refuse to close?
                  > > Or are they gone entirely?
                  >
                  > I work without foldcolumn -- so next time it occurs I'll try to enable
                  > it on the fly and see if they are gone or just refuse to work.

                  The problem occured again.

                  FYI: When foldcolumn is displayed in this case: There are NO folds in
                  it anymore.

                  But some breaking news: I have foldmethod=marker by default, and
                  foldmethod=syntax in ~/.vim/ftplugin/c.vim. And I found out that the
                  whole c ftplugin is NOT EXECUTED in this sitution. In fact, when I do
                  set folmethod? it shows 'marker' instead of 'syntax'.

                  (a) So the question behind all this is: Why is ftplugin/c.vim not
                  executed (although set filetype? shows 'c').
                  (b) Why does this happen only sometimes?

                  ---- my ~/.vim/ftplugin.c basically contains this:------

                  if(&diff)
                  exit
                  endif
                  setlocal foldtext=repeat('\ ',indent(v:foldstart)-indent(v:foldstart)/
                  4).getline(v:foldstart)
                  setlocal foldmethod=syntax
                  setlocal foldnestmax=6
                  setlocal commentstring=/*%s*/
                  setlocal noet

                  ---- my ~/.vimrc has these options set (among others): -----
                  filetype on
                  filetype plugin on
                  set noet
                  set foldmethod=marker
                  set foldlevelstart=0

                  ---- my ~/.vim/filetype.vim ----

                  if exists("did_load_filetypes")
                  finish
                  endif
                  augroup filetypedetect
                  au! BufRead,BufNewFile *.txt setfiletype txt
                  augroup END


                  Felix

                  --
                  You received this message from the "vim_use" maillist.
                  Do not top-post! Type your reply below the text you are replying to.
                  For more information, visit http://www.vim.org/maillist.php
                • Jürgen Krämer
                  Hi, ... is this really the name of your filetype plugin. It should be ~/.vim/ftplugin/c.vim Regards, Jürgen -- Sometimes I think the surest sign that
                  Message 8 of 12 , Dec 12, 2010
                  • 0 Attachment
                    Hi,

                    fkater@... wrote:
                    >>> Do your folds exist but refuse to close?
                    >>> Or are they gone entirely?
                    >>
                    >> I work without foldcolumn -- so next time it occurs I'll try to enable
                    >> it on the fly and see if they are gone or just refuse to work.
                    >
                    > The problem occured again.
                    >
                    > FYI: When foldcolumn is displayed in this case: There are NO folds in
                    > it anymore.
                    >
                    > But some breaking news: I have foldmethod=marker by default, and
                    > foldmethod=syntax in ~/.vim/ftplugin/c.vim. And I found out that the
                    > whole c ftplugin is NOT EXECUTED in this sitution. In fact, when I do
                    > set folmethod? it shows 'marker' instead of 'syntax'.
                    >
                    > (a) So the question behind all this is: Why is ftplugin/c.vim not
                    > executed (although set filetype? shows 'c').
                    > (b) Why does this happen only sometimes?
                    >
                    > ---- my ~/.vim/ftplugin.c basically contains this:------

                    is this really the name of your filetype plugin. It should be

                    ~/.vim/ftplugin/c.vim

                    Regards,
                    Jürgen

                    --
                    Sometimes I think the surest sign that intelligent life exists elsewhere
                    in the universe is that none of it has tried to contact us. (Calvin)

                    --
                    You received this message from the "vim_use" maillist.
                    Do not top-post! Type your reply below the text you are replying to.
                    For more information, visit http://www.vim.org/maillist.php
                  • fkater@googlemail.com
                    ... Thanks, yes, my file is named like this. This was a typo in my posting. Felix -- You received this message from the vim_use maillist. Do not top-post!
                    Message 9 of 12 , Dec 13, 2010
                    • 0 Attachment
                      > > ---- my ~/.vim/ftplugin.c basically contains this:------
                      >
                      > is this really the name of your filetype plugin. It should be
                      >
                      >   ~/.vim/ftplugin/c.vim

                      Thanks, yes, my file is named like this. This was a typo in my
                      posting.

                      Felix

                      --
                      You received this message from the "vim_use" maillist.
                      Do not top-post! Type your reply below the text you are replying to.
                      For more information, visit http://www.vim.org/maillist.php
                    • Ben Fritz
                      On Dec 12, 5:32 am, fka...@googlemail.com ... You say it basically contains the text given. Does something like this also show up?
                      Message 10 of 12 , Dec 13, 2010
                      • 0 Attachment
                        On Dec 12, 5:32 am, "fka...@..." <fka...@...>
                        wrote:
                        > > > Do your folds exist but refuse to close?
                        > > > Or are they gone entirely?
                        >
                        > > I work without foldcolumn -- so next time it occurs I'll try to enable
                        > > it on the fly and see if they are gone or just refuse to work.
                        >
                        > The problem occured again.
                        >
                        > FYI: When foldcolumn is displayed in this case: There are NO folds in
                        > it anymore.
                        >
                        > But some breaking news: I have foldmethod=marker by default, and
                        > foldmethod=syntax in ~/.vim/ftplugin/c.vim. And I found out that the
                        > whole c ftplugin is NOT EXECUTED in this sitution. In fact, when I do
                        > set folmethod? it shows 'marker' instead of 'syntax'.
                        >
                        > (a) So the question behind all this is: Why is ftplugin/c.vim not
                        > executed (although set filetype? shows 'c').
                        > (b) Why does this happen only sometimes?
                        >
                        > ---- my ~/.vim/ftplugin.c basically contains this:------
                        >
                        > if(&diff)
                        >         exit
                        > endif
                        > ...

                        You say it "basically" contains the text given. Does something like
                        this also show up?

                        " Only do this when not done yet for this buffer
                        if exists("b:did_ftplugin")
                        finish
                        endif

                        If so, try removing it.

                        As a side note, are you sure you want "exit" in your "if(&diff)"
                        block? This will save and close the buffer. Maybe you want "finish"
                        instead?

                        --
                        You received this message from the "vim_use" maillist.
                        Do not top-post! Type your reply below the text you are replying to.
                        For more information, visit http://www.vim.org/maillist.php
                      • fkater@googlemail.com
                        ... Yes, in .vim/ftplugin.vim, however, after removing, no change. ... Thanks, now change, though. Anyway, I am glad to say I have got a test case now. This
                        Message 11 of 12 , Dec 15, 2010
                        • 0 Attachment
                          > You say it "basically" contains the text given. Does something like
                          > this also show up?
                          >
                          > " Only do this when not done yet for this buffer
                          > if exists("b:did_ftplugin")
                          >   finish
                          > endif

                          Yes, in .vim/ftplugin.vim, however, after removing, no change.

                          > As a side note, are you sure you want "exit" in your "if(&diff)"
                          > block? This will save and close the buffer. Maybe you want "finish"
                          > instead?

                          Thanks, now change, though.

                          Anyway, I am glad to say I have got a test case now. This case is
                          based on txt files and foldmethod 'marker' and not on C files and
                          syntax folding, however seems to address the same issue like in my
                          original posting.

                          Since I do not know the policies here if attachements are possible/
                          allowed, I just paste the files.

                          (1) Create this new minimal file structure in ~/.

                          .vim/filetype.vim
                          .vim/ftplugin/txt.vim
                          vimrc
                          demo.txt

                          (2) filetype.vim contains:

                          augroup filetypedetect
                          "au! BufRead,BufNewFile *.txt setfiletype txt
                          au BufRead,BufNewFile *.txt setfiletype txt
                          augroup END

                          (3) txt.vim contains:

                          setlocal foldmarker={,}
                          setlocal foldmethod=marker

                          (4) vimrc:

                          filetype on
                          filetype plugin on
                          set foldmethod=marker

                          (5) demo.txt

                          normal text

                          begin of fold{

                          content of fold

                          }

                          (6) Steps to reproduce:

                          cd ~
                          vim -u vimrc
                          :vsp (vertical split)
                          :ed demo.txt (file loaded with everything folded = ok)
                          :Ctrl-W l (switch to right window)
                          :ed demo.txt (file loaded but folding INACTIVE = not expected)


                          (7) Additional note:

                          :set ft? shows nothing in both cases. This differs from the problem in
                          my original posting, however, the effect is quite similar: Folding
                          does not work in the other buffer.


                          If anyone could try tro reproduce, please?

                          Felix

                          --
                          You received this message from the "vim_use" maillist.
                          Do not top-post! Type your reply below the text you are replying to.
                          For more information, visit http://www.vim.org/maillist.php
                        Your message has been successfully submitted and would be delivered to recipients shortly.