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>

I have a bunch of features that I toggle on and off this way. I like
it.

The only problem is that, here at work, we have two different versions
of vim, 7.2.330 and 6.3 ( from debian sarge ), and this function only
works under 7.2

I would like to make a version that works under 6.3 but I can't quite
figure it out. I can't actually figure out why it doesn't work in 6.3
short of the fact that I can't seam to define any functions a all via
execute under vim 6.3

I've boiled the issue down to this sample code:

execute "function Foo()\n echo \"foo\"\n endfunction"
call Foo()

which works fine under 7.3 but doesn't work under 6.3

So, can anyone shed any light on how I can't get this done on 6.3? Am
I missing an obvious way to dynamically create functions?

Thanks for your attention.

Gabriel Russell
[email protected]

-- 
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

Reply via email to