Gary Johnson wrote:
On 2006-06-27, Jason Aeschilman <[EMAIL PROTECTED]> wrote:
I wanted to save the current setting for an option so I could change
that option temporarily then set it back to what it was. Specifically,
I'm using the Cfname.vim plugin and it hard sets the statusline option
then hard sets it back. I already improved it to work "on demand" by
creating a toggle to turn it on and off. I wanted to improve it further
by storing the user's current statusline setting when toggling it on
then restoring the statusline setting when toggling it off. I was going
to ask in this list how to do this but I ended up figuring it out on my
own. I'll go ahead and post my solution in case someone finds it
useful. This seems to work but if anyone can see any problems with this
or a better way to do it, please let me know.
"save user's current statusline option
let g:CF_statusline=escape(getbufvar(1, "&statusline"), " ")
"set statusline back to previous setting
execute 'set statusline=' . g:CF_statusline
Here's the "standard" way of doing that:
"save user's current statusline option
let g:CF_statusline=&statusline
"set statusline back to previous setting
let &statusline=g:CF_statusline
Further, if there is no need to access CF_statusline outside the
script in which 'statusline' is saved and restored, a script
variable is often used instead of a global variable to avoid
polluting the global name space. So you might consider using
s:CF_statusline instead of g:CF_statusline.
Gary
Well that looks like a much cleaner way to do it. I just did what I did
based on the only examples I could find online. As for scope, you're
right, the variable needn't be global, I was just being lazy while
getting it to work.
It actually turns out there is a 3.0a version of Cfname.vim that retains
the user's statusline and fixes the slowdown problems with the script so
I don't even need my toggle. The author didn't list it as the latest
version, I guess because he didn't make the changes. It performs much
better than the author's 3.0 version. Oh and it does save and restore
statusline just the way you mention. :-)
Jason Aeschilman