> > > > I guess it's a simple thing but couldn't find a definite answer yet.
> > > > Is there a way to make commands such as
> > > >
> > > > syn off
> > > > set foldmethod=expr
> > > >
> > > > local in a sense that they should only effect the window in which
they
> > > > are issued?
> > >
> > > 1. Frist, 'set foldmethod=' is already local to window, so there's no
> > > problem.
> > >
> > > 2. 'syn off' is global, but if you, instead of 'syn off' do 'set
filetype='
> > > (set filetype to empty), which is window-local, you'll get equivalent
> > > result.
> > > Does this work for you ?
> >
> > Thanks for the reply, actually these 2 commands are just examples from
> > what I really would like to do. In more detail, I have a function:
> >
> > function! ReFold()
> > syn off | syn on
> > set foldmethod=expr
> > set foldexpr=0
> > syn region myFold start='{' end='}' transparent fold
> > syntax sync fromstart
> > set foldmethod=syntax
> > echo
> > endfunction
> >
> > And whenever I call this function in a window it also effects the
> > other windows. So my real question (sorry if I should have explained
> > it better in the first email) is how to make the function ReFold act
> > locally.
The solution that I have in mind is this.
Let's say your language is abc (perl, c, cpp, etc). Let's denote is abc
for sake of this example.
1. Create file ~/.vim/after/synatx/abc-x.vim
2. Put this nito file abc-x.vim:
if exists("b:current_syntax") | finish | endif
runtime syntax/abc.vim
set foldmethod=expr
set foldexpr=0
syn region myFold start='{' end='}' transparent fold
syntax sync fromstart
set foldmethod=syntax
3. In the window where you want to turn own ReFold, you do
:set filetype=abc-x
To reset folsing & back:
:set filetype=abc
I expect this shall do it.
Note that this solution will trigger your custom additions
in all windows where filetype if abc-x, but leave intact windows
with different filetypes.
Explanation:
The thing in your ReFold that scrambles syntax of other
windows is 'syn off|syn on'. You need to avoid 'syn off|syn on' on
one hand, and still preserve your local syntax-related commands.
My solution above tries to to do exactly this.
The language is C. And my problem is that I frequently have several
source files open (all C) and would like to avoid the scrambling in
this situation (I don't care so much about other file types as I only
have C source files).
Anyway, your suggestion is still useful, I'll try to avoid the 'syn
off| syn on' part and all the rest then should be okay (if I
understand you correctly, they are window-local anyway).