>From many discussions I've had in the past, and from my own limited first-hand experience, I have learned that one of the biggest hurdles to writing a robust vim script to distribute to other people is dealing with the hundreds of options that Vim has, many of which potentially cause your script to do unexpected things. Dr. Chip has even made a plugin that attempts to check these options in an effort to make things easier, but I have not heard it mentioned very often.
I propose two alternate methods to solving this problem, each of which add new functionality and should therefore break no backwards compatibility (though it will cause scripts utilizing the method to not work on older Vims without the functionality; I would think this is to be expected). Method 1: Script-local options We have the ability to "let" variables that are global, local to the tab, local to the window, local to the buffer, and even local to the script and the commands defined in the script. Why not add this final category to options as well? This method would add a command, :setscript, that behaves just like :setlocal, except that the option will only be read during script execution, or during execution of commands defined in the script. Typical use would be as follows: setscript all& setscript ignorecase " load the smartcase option from the local 'smartcase' option defined by the user setscript smartcase< ...more script-local options, as needed, to override the defaults... ...Commands that execute with a KNOWN configuration... At the end of the script, user settings will be unaffected. The script writer can choose on an option-by-option basis whether to use a user setting, or define their own. Commands defined in the script need not worry about saving and restoring relevant options, making them far less complex. This method would obviously require a LOT of effort to implement, and certainly cannot be implemented in vimscript, but would probably be the cleaner of the two. Method 2: create an "option stack" This method was already discussed here, briefly, in the middle of this thread: http://groups.google.com/group/vim_dev/browse_thread/thread/92bce4a37ae9858f/07cda2bd46fc62b4?lnk=gst&q=option+stack#07cda2bd46fc62b4 Typical use would be as follows: optionpush setlocal all& ... command foo optionpush | call s:Func() | optionpop ... optionpop Again, script writers would be able to easily execute their entire script in a know configuration, and easily restore all options at the end without setting each one individually. Commands defined within the script would need to set and restore the options during command execution, however. This method has the advantage that it could probably be implemented using vimscript, and as long as it was distributed with the official Vim runtime files, script writers could assume its presence. However, I believe it would be far better if it were made a built-in function. I imagine, since :set with no arguments currently displays all options set to non-default values, and there is an easy way to restore all options to default values, that this method would take fairly little effort to implement as well. What do people think? What are the advantages/disadvantages of each method? Is there any chance of either of these actually making it into Vim? How useful would something like this be? --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_dev" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---
