Excerpts from gabriel's message of Fri Jul 09 16:10:20 +0200 2010:
> I wrote this function that generates toggle functions:
>
> func! CreateToggle(name,oncode,offcode)
> exec
> \ "let g:" . a:name . "toggle = 0 \n" .
> \ "func! " . a:name . "()\n" .
> \ "if g:" . a:name . "toggle == 0\n" .
> \ a:oncode . "\n" .
> \ "echo \"" . a:name . " On\"\n" .
> \ "else\n" .
> \ a:offcode . "\n" .
> \ "echo \"" . a:name . " Off\"\n" .
> \ "endif\n" .
> \ "let g:" . a:name . "toggle = ! g:" . a:name . "toggle
> \n" .
> \ "endfunc\n"
> endfunc
>
> and I use it like so:
>
> call CreateToggle("SpellingToggle","setlocal spell
> spelllang=en_us","setlocal nospell")
>
> map ,z :call SpellingToggle()<CR>
Did you try:
option a)
map ,z :call Toggle("SpellingToggle", "setlocal spell spelllang=en_us",
"setlocal nospell")
fun Toggle(name, oncode, offcode)
if g:spell_{a:name}
echo 'switichig off'
exec a:offcode
else
" ..
endif
endfun
instead? I guess that your on/ off lines are one line scripts most of
the time?
option b)
Write it to a file and source that:
let t = tmpfile()
call writefile(t, your_func_as_string, 'b')
exec 'source '.t
or such
This should work - but is slower
option c) upgrade vim
Marc Weber
--
You received this message from the "vim_use" 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