RE: wish: allow a: in the function def
Sorry; it's located here: http://vim.sourceforge.net/scripts/script.php?script_id=353 > -Original Message- > From: Halim, Salman > Sent: Wednesday, April 25, 2007 10:28 AM > To: 'Marc Weber'; vim-dev@vim.org > Subject: RE: wish: allow a: in the function def > > I uploaded GetVar a long long time ago to vim.sf.net > (initially in 2002, updated for Vim 7 in 2006) that basically > is called with the name of a variable and an optional default > value. It checks w:, b:, t:, and finally g: before returning > the specified default value (default default value is -1). > > There is also a VarExists function in there that just returns > true/false (1/0) based on whether it was able to find any of those. > > I use these to override global plugin settings on a > per-buffer basis, among other things. > > Salman.
RE: wish: allow a: in the function def
I uploaded GetVar a long long time ago to vim.sf.net (initially in 2002, updated for Vim 7 in 2006) that basically is called with the name of a variable and an optional default value. It checks w:, b:, t:, and finally g: before returning the specified default value (default default value is -1). There is also a VarExists function in there that just returns true/false (1/0) based on whether it was able to find any of those. I use these to override global plugin settings on a per-buffer basis, among other things. Salman. > -Original Message- > From: Marc Weber [mailto:[EMAIL PROTECTED] > Sent: Wednesday, April 25, 2007 10:24 AM > To: vim-dev@vim.org > Subject: Re: wish: allow a: in the function def > > > So maybe one could make vimscript search a variable foo as l:foo, > > a:foo, (maybe also: w:foo, b:foo), s:foo, g:foo, and then throw an > > undefined variable name error if none exists. Or so. > > No. I don't want to go back to VB without using Option > Explicit ;) Don't let vim find some value somewhere. This > leads to failures not so easy to spot > > But you are right. This might be useful: > Use buffer setting if it exists, if not use global one.. > But you should be able to emulate this behaviour using the > function exists: > > function GetSetting(name) > if exists('b:'.a:name) > exec 'return b:'.a:name > elseif exists('g:'.a:name) > exec 'return g:'.a:name > else > echoe "Please define setting ".a:name > endif > endfunction > > perhaps even add a optional parameter for a default value.. > > I'm using this very often: > > function! vl#lib#brief#args#GetOptionalArg( name, default, ...) > if a:0 == 1 > let idx = a:1 > else > let idx = 1 > endif > if type( a:default) != 1 > throw "wrong type: default parameter of > vl#lib#brief#args#GetOptionalArg must be a string, use string(value)" > endif > let script = [ "if a:0 >= ". idx >\ , " let ".a:name." = a:".idx >\ , "else" >\ , " let ".a:name." = ".a:default >\ , "endif" >\ ] > return join( script, "\n") > endfunction > > function GetSetting(name, ...) > exec vl#lib#brief#args#GetOptionalArg('default', > string("option not given")) > if exists('b:'.a:name) > exec 'return b:'.a:name > elseif exists('g:'.a:name) > exec 'return g:'.a:name > else > return default > endif > endfunction > > Then you can use > let b = GetSetting('my_name','default value') or let b = > GetSetting('my_name') which will set b to "option not given" > if neither b:my_name nor g:my_name does exist > > HTH Marc >
RE: VIM doesn't need new features?!?!
I really didn't think Peter said anything that was a flame. Perhaps he didn't read the whole thing, but I, too, initially walked away with the same conclusion was he did, and I *have* been using Vim for a long time. (I just know better because I've been here longer.) Suresh, on the other hand, was pretty much out of line and actually took it to the level of personal attacks. Makes me wonder if he's really Sven Guckes in disguise. Salman. > -Original Message- > From: Milan Vancura [mailto:[EMAIL PROTECTED] > Sent: Monday, April 16, 2007 3:27 AM > To: Vim development list > Subject: Re: VIM doesn't need new features?!?! > > > > The preceding shows you have trouble reading -- that page has a > > > link to a "voting page", which page lists certain core features > > > that could be added to vim. If your investigation into > plugins was > > > as casual as your reading of the above link, then your > efforts at > > > finding and evaluating existing plugins in relation to > your notion > > > of a project are likely to have been botched! > > > > "Vim has many, many features. We don't really need more" > > Peter, don't start flames, please. vim-dev list is a very > valuable list exactly for the reason that people usualy don't > try flaming here. > > It's easy to take one sentence without any context and become > upset. Read more (as Suresh Govindachar already suggested) > and your life will be nicer again. > Please start with Suresh Govindachar's e-mail, the answer for > you is already there. The sentence you started a flame with > means that it seems we can add new features by some script > languages (most usualy the internal vim script) and don't > need to add every bell and whistle in the core vim code. > > And it's true for your problem too: core vim features are > strong enough to allow "project handling" - but the exact > implementation is up to your choice. > There are several plugins ready at vim.org which you can use > or modify. > > So again: please start reading at vim.org again with this > information in mind. > And stop the flame. If you have a concrete question, ask here > or at vim-users. > > Thank you and have a nice day, > > Milan Vancura > -- > Milan Vancura, Prague, Czech Republic, Europe >
RE: Two minor requests for the TODO list
I have a relatively simple function I use: function! GetVar( ... ) let varName=a:1 let retVal = exists( "a:2" ) ? a:2 : -1 if ( exists ( "w:" . varName ) ) let retVal=w:{varName} elseif ( exists ( "b:" . varName ) ) let retVal=b:{varName} elseif ( exists ( "t:" . varName ) ) let retVal=t:{varName} elseif ( exists ( "g:" . varName ) ) let retVal=g:{varName} endif return retVal endfunction Calling it with something like: :let test = GetVar( 'expandWindow', 'never' ) First checks to see if w:expandWindow exists (and returns that), then b:expandWindow, t:expandWindow and finally g:expandWindow; if none of them exist, it returns 'never' (or -1, if there was no second parameter). I use it in plugins to allow both global default values as well as window-, buffer- or tab-specific overrides. This could be easily rewritten as: :return exists( a:1 ) ? {a:1} : exists( a:2 ) ? a:2 : 0 To do what you're asking. Of course, an internal version would be much faster, which might be why you asked :) Salman. > -Original Message- > From: Eggum, DavidX S [mailto:[EMAIL PROTECTED] > Sent: Thursday, December 07, 2006 1:22 PM > To: vim developers list > Subject: RE: Two minor requests for the TODO list > > > > How about adding this: > > get({string} [, {default}]) > > Get value from variable {string}. > > When this variable does not > > exist, return {default}. > Return zero > > when {default} is > > omitted. > > > Hmmm we could follow the more succinct gmake way of doing > things and add a new operator instead (I like this solution better): > > :let {var} ?= {expr}This is a conditional > variable assignment operator, > it only has an effect > if the variable is not yet > defined. This statement: > > let foo ?= "bar" > > is exactly equivalent to this: > > if !exists("foo") > let foo = "bar" > endif > > Regards, > David > > --- > "Love is what's in the room with you at Christmas if you stop > opening presents and listen." > > Bobby - age 7 >
Vim 7.0d02
Hello, On Windows XP, the following line throws an error in my _vimrc: set sessionoptions-=options sessionoptions-=folds sessionoptions-=resize sessionoptions-=buffers sessionoptions+=slash,unix It's probably caused by the new tab page option added to sessionoptions (it isn't the first -= setting in my _vimrc). Thank you, Salman.