kana / vim-submode

Vim plugin: Create your own submodes
http://www.vim.org/scripts/script.php?script_id=2467
217 stars 24 forks source link

Little fix for bug in executing_on_action #9

Closed LFDM closed 10 years ago

LFDM commented 10 years ago

So far s:on_executing_action always returns an empty string. When the showmode is active, this however causes a bug for mappings that include a carriage return, in pseudocode:

   # a mapping created by submode definition function
   nmap xx :call HelperFunction()<cr>

While everything is executed correctly (i.e. the HelperFunction got called), the cursor will hang in showmode-line, right after the highlighted string, that indicates the current submode. There's no way to return the cursor to the buffer other than leaving the submode then.

If we don't return '' when the submode is echoed, everything's fine again.

kana commented 10 years ago

Would you mind creating complete steps to reproduce the problem?

Anyway, your patch has an unacceptable side effect. There is no void in Vim script. Every function always returns a value. When a function ends without an explicit :return, the number 0 is returned. Your patch changes s:on_executing_action to return 0. And this 0 is treated as if user types the key, because s:on_executing_action is called in an <expr> mapping. As a result, your patch forces redrawing screen by moving the cursor to the beginning of the line or inserting the character 0, depending on the base mode of a submode.

LFDM commented 10 years ago

Whoops, sorry, that was careless. Well, one should probably never try to fix something when the source of the problem is not really known. Would be great if you could help me out debugging this. Steps to reproduce:

call submode#enter_with('jump', 'n', '', ',j', '<nop>')
call submode#map('jump', 'n', '', 'j', ':call JumpDown()<cr>') 

function! JumpDown()
  normal! 5j
endfunction

You should see - when showmode is set - that you're jumping down as you should, but the cursor rests all the time in vim's last line, right behind the submode's message.

kana commented 10 years ago

Thank you. I succeeded to reproduce the problem.

But I wonder why I've never noticed problem for years. Since the problem is related to screen rendering, I guess that some options force redrawing screen.

kana commented 10 years ago

I found that 'showcmd' triggers a partial screen rendering. If showcmd is turned on, the problem doesn't happen. The cursor is always rendered at the right position. Otherwise the cursor is rendered at the right behind of the submode message.

But 'showcmd' has another screen rendering problem. See gh-3 for the details. Please try 'showcmd' as a workaround if you could accept the side effect.

LFDM commented 10 years ago

Hm I'd rather not turn showcmd on - not sure I like the constant flickering of commands down there - during the submode there's also some corrupted string to be seen there (the other issue you were referring to)

LFDM commented 10 years ago

Can confirm this is working now as it should! Thanks @kana!