Gary Johnson wrote:

> On 2017-12-15, Bram Moolenaar wrote:
> > Many plugins set options to a different value.  To be able to restore
> > the original value very often the old value needs to be saved.
> > 
> > Not only is this a bit of a hassle, especially for local options, it is
> > also incomplete, since the location where the option was originally set
> > can't be restored.
> > 
> > I have been thinking of adding two functions to make this work better:
> > 
> > option_save({list})                                 *option_save()*
> >             Saves the options named in {list}.  The returned value can be
> >             passed to option_restore().  Example: >
> >                     let s:saved_options = option_save([
> >                         \ 'ignorecase',
> >                         \ 'iskeyword',
> >                         \ ])
> >                      au <buffer> BufLeave *
> >                         \ call option_restore(s:saved_options)
> > <           The advantage over using `:let` is that global and local
> >             values are handled and the script ID is restored, so that
> >             `:verbose set` will show where the option was originally set,
> >             not where it was restored.
> > 
> > 
> > option_restore({list})                                      
> > *option_restore()*
> >             Restore options previously saved by option_save().
> >             When buffer-local options have been saved, this function must
> >             be called when the same buffer is the current buffer.
> >             When window-local options have been saved, this function must
> >             be called when the same window is the current window.
> >             When in the wrong buffer and/or window an error is given and
> >             the local options won't be restored.
> > 
> > Does that sound useful?
> 
> Almost.
> 
> I surveyed my plugins for places where I save and restore options
> and in almost all cases the function opens a new buffer, sometimes
> as the result of a :grep command.
> 
> So, this would not be useful to me unless option_save() also
> remembered the buffer/window it was in when executed and
> option_restore() just restored to that buffer/window, even if it
> wasn't the current buffer/window.

I wonder why you change a local option in another window/buffer than the
one your plugin works.

Restoring from another window/buffer can be problematic, e.g. when a
window is split the value needs to be restored in two windows.  And when
a new buffer is created it may use a mix of global values and
buffer-local values of the current buffer.  I don't think we can make
this work generally.  Only in specific cases.

-- 
To be rich is not the end, but only a change of worries.

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
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

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui