Friday, May 25, 2012

Re: Folding on markdown headers

On Tue, May 22, 2012 at 09:14:03AM EDT, Eric Weir wrote:

> On May 20, 2012, at 12:20 AM, Chris Jones wrote:

> > On Sat, May 19, 2012 at 12:25:26PM EDT, Eric Weir wrote:

> >> When I create a file with markdown headers and save it, folding on
> >> the headers does not work.
> >>
> >> When I create a file with markdown headers, save it, close the
> >> window, and open the file in a new window, folding on the headers
> >> works.
> >>
> >> Why in the one case and not in the other?
> >
> > On a different line, now that you have found a workaround...
> >
> > What folding method are you using..?

> At first I didn't know how to answer. I didn't find anything related
> to fold method in my .vimrc. Fortunately, I keep copies of emails
> pertaining to problems I've encountered and solved with the help of
> people here and at vim_mac. Thank God!
>
> Turns out I'm using Vlad Irnov's markdown folding script.
> https://gist.github.com/1035030 I'd completely forgotten about it, but
> it is what takes care of it for me.

I meant the value of the 'foldmethod' Vim option. What does ':set fdm?'
tell you?

| :h fdm
| :h folding

The script sets the fdm option to 'expr' for the current buffer/window,
which amounts to running user-written code for each line in the buffer.

In this particular case, the user-written code is a function named
'Foldexpr_markdown()'. By the look of it, this function should create
a fold automatically wherever it sees a line that starts with an equal
sign in column one, followed by either an equal sign or white space.
A valid markdown header would be something such as '= a header'.. or
'=== another header'... etc.

So that if you if you add a line of the form: '= this is a header' and
hit <Enter>, the script should run automatically and create a fold
immediately. At least that's the way I understand it.

> Maybe this is something Vlad overlooked? Whatever, the workaround is
> pretty simple, so thanks again for that.

I use a one-line expression to fold Vim help files that is quite similar
to the script you referred me to and it updates the folding immediately
when for instance I duplicate the first couple of lines of an existing
fold by copying and pasting it - I never have to reload the file.

At a glance I cannot see any particular reason why the above-mentioned
script shouldn't work the same.

What exactly do you mean by 'when I create a file'..? How does it 'not
work'?

CJ

--
Mooo Canada!!!!

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

No comments:

Post a Comment