Yakov Lerner wrote:
On 9/25/06, Yakov Lerner <[EMAIL PROTECTED]> wrote:
On 9/25/06, Daniel Nogradi <[EMAIL PROTECTED]> wrote:
> > > 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.
Yakov
In filetype-plugins or syntax scripts like this one, you should use everywhere
":setlocal" rather than ":set" (:setlocal fdm=..., setlocal fde=..., etc.).
This will avoid clobbering the global defaults of the same options for future
windows.
Similarly, from the command-line, use ":setlocal ft=abc" and "setlocal
ft=abc-x". You can abbreviate ":setlocal" to ":setl" or anything in-between.
The global default for 'filetype' should always be empty (check it with
":verbose setglobal ft?"), so when you do ":new foobar" (creating an empty
file whose name doesn't imply a filetype) it shouldn't get one, and when you
do ":new foobar.c" "new foobar.cpp" ":new foobar.htm" etc., it should get the
proper default filetype (in these examples respectively c, cpp and html), not
whatever you last set with ":set ft=...". (In the case of the file with the
ambiguous name, you can either ":setlocal" the 'filetype' manually, or else
use ":e" with no arguments to re-read it and reassess the filetype once you've
entered the #!/bin/bash shebang line or whatever.)
Best regards,
Tony.