Am 22.01.2010 15:13, schrieb Bram Moolenaar:
I haven't looked at all of this, but it seems the problem is that an
expression mapping is being evaluated, which then redefines that same
mapping. The solution would then be to make a copy of the mapping
before evaluating the expression. That's not efficient.
Why is efficiency important here?
... given the copying will only be done for <expr> maps?
Another solution is to disallow changing a mapping that is being used.
That is more difficult and disables some functionality.
From my experience, self-modifying mappings and commands (except
<expr>-mappings of course) work without problems, and I find them very
useful to auto-load scripts.
Yet another solution is to postpone setting the new mapping until it
has finished evaluation (we do something similar for autocommands).
That's even more complicated...
I risked a look ...
OLD (crashing) SCRIPT
" initially called:
function! s:vimim_chinese_mode_mapping_on()
inoremap<silent><expr><Plug>VimimChineseMode <SID>VimimChineseMode()
imap<silent><C-Bslash> <Plug>VimimChineseMode
user types i_CTRL-\
->
function! <SID>VimimChineseMode()
sil!call s:vimim_start_chinese_mode()
function! s:vimim_start_chinese_mode()
sil!call s:vimim_stop()
function! s:vimim_stop()
sil!call s:vimim_initialize_mapping()
function! s:vimim_initialize_mapping()
sil!call s:vimim_chinese_mode_mapping_on()
(!)
-> Bram, you're right, the <expr> map modifies itself
OR
function! <SID>VimimChineseMode()
sil!call s:vimim_stop_chinese_mode()
function! s:vimim_stop_chinese_mode()
sil!call s:vimim_stop()
... see above ...
(-> s:vimim_chinese_mode_flag doesn't matter)
NEW SCRIPT
function! s:vimim_chinese_mode_mapping_on()
if !hasmapto('<Plug>VimimChinesemode', 'i')
inoremap <unique> <expr> <Plug>VimimChinesemode <SID>Chinesemode()
endif
imap <C-Bslash> <Plug>VimimChinesemode
The hasmapto()-check prevents defining <Plug>VimimChinesemode again.
--
Andy
--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php