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

-- 
Gary Johnson                 | Agilent Technologies
[EMAIL PROTECTED]     | Wireless Division
                             | Spokane, Washington, USA

Reply via email to