On Jul 9, 10:25 am, Marc Weber <[email protected]> wrote:
> 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
Marc, your a solution was perfect. This is what I came up with based
on your ideas:
fun Toggle(name, oncode, offcode)
if g:toggle_{a:name}
echo ' switichig off ' . a:name
exec a:offcode
else
echo ' switichig on ' . a:name
exec a:oncode
endif
let g:toggle_{a:name} = ! g:toggle_{a:name}
endfun
let g:toggle_SyntaxToggle = 1
map ,x :call Toggle("SyntaxToggle",":syntax enable",":syntax off")<CR>
and this all works on 6.3
Thanks for your help
Gabriel Russell
--
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