I'm asking about this code snippet:
:function TextwidthIsTooWide() : if &l:textwidth ># 80 : return 1 : endif :endfunction
This is what vim-help says on the
l (local) prefix:
Inside functions local variables are accessed without prepending anything. But you can also prepend "l:" if you like. However, without prepending "l:" you may run into reserved variable names. For example "count". By itself it refers to "v:count". Using "l:count" you can have a local variable with the same name.
Based on this, I would expect
l:textwidth to be something like
undefined, instead of taking the value of the global (?)
textwidth option. (C.f.
l:count in the documentation.)
Question: Why does it take on the value of the option, even though it is local?
I do realize it has the
& symbol prefixed, which refers to the option, so maybe it overrides local.
Question: In that case (i.e., if
local), what is the point of making the variable local?
I tried the following change (only difference: remove
l: prefix) and it seems to work too (even with
setlocal -- of course I realize this is a different kind of "localness" compared to function-local variables)
:function! TextwidthIsTooWide() : if &textwidth ># 80 : return 1 : endif :endfunction
:set textwidth=79 :echo TextwidthIsTooWide() 0 :set textwidth=81 :echo TextwidthIsTooWide() 1 :setlocal textwidth=79 :echo TextwidthIsTooWide() 0 :setlocal textwidth=81 :echo TextwidthIsTooWide() 1