On May 13, 2:04 am, Jan Larres <[email protected]> wrote:
> Hi all,
>
> I've recently been trying to write a 'foldtext' setting that is specific
> to LaTeX and would include useful information like for a example the
> caption information for a folded environment. But then I discovered that
> the 'foldtext' setting is local to a window and not to a buffer, making
> filetype-specific foldtexts pretty much impossible. So if I were to for
> example edit my LaTeX file and a C file that I'm writing about in the
> same window I can't have foldtexts that are tuned for those files,
> respectively.
This indeed can be a problem with all folding options, not just with
&foldtext but also &foldmethod and &foldexpr. Fortunately, this is not
a frequent problem. Somehow, Vim usually preserves correct window-
local options for each buffer, so these options behave like they are
local to buffer.
A setting local to window can become wrong after displaying an
existing buffer in a new window for the first time. This requires
special effort -- create new window via :split or :vsplit, load
another existing buffer in it via :edit or :buffer. If you don't have
split windows there is nothing to worry about. And if there are split
windows, then you most likely keep different buffers in different
windows. Also note that you can restore default window-local settings
at any time with
:set ft=myfiletype
> I guess you could sort of work around that by defining buffer-local
> functions, but it probably wouldn't be pretty.
You could try BufEnter au like this:
au BufEnter *.myfiletype call CheckFoldOptions()
func! CheckFoldOptions()
if &foldtext !=# "MyFoldText()"
setl foldtext=MyFoldText()
endif
if &foldmethod !=# "expr"
setl foldmethod=expr
endif
if &foldexpr !=# "MyFoldExpr(v:lnum)"
setl foldexpr=MyFoldExpr(v:lnum)
endif
endfunc
The important thing is to avoid setting &foldexpr, etc., on **every**
BufEnter. That would be extremely wasteful because most of the time
fold settings will be correct.
--
You received this message from the "vim_dev" 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