getchar() is useful for mapping dynamic key sequences, but the downside is that it moves the cursor to the command line when waiting for input. If the action depends on where the cursor is, you can lose the visual feedback on where you're about to make an edit. getchar(2) behaves just like getchar(), but bypasses the move of the cursor.
https://github.com/vim/vim/pull/10603
(2 files)
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@ii14 pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@ii14 commented on this pull request.
In src/testdir/test_vim9_builtin.vim:
> @@ -1683,8 +1683,7 @@ def Test_getchar()
endwhile
getchar(true)->assert_equal(0)
getchar(1)->assert_equal(0)
- v9.CheckDefAndScriptFailure(['getchar(2)'], ['E1013: Argument 1: type mismatch, expected bool but got number', 'E1212: Bool required for argument 1'])
- v9.CheckDefAndScriptFailure(['getchar("1")'], ['E1013: Argument 1: type mismatch, expected bool but got string', 'E1212: Bool required for argument 1'])
+ v9.CheckDefAndScriptFailure(['getchar("1")'], ['E1013: Argument 1: type mismatch, expected bool but got string', 'E1290: Bool or Number required for argument 1'])
These tests are probably wrong. I don't get how to change what types vim9script expects.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@ii14 commented on this pull request.
In src/getchar.c:
> @@ -2067,20 +2067,31 @@ getchar_common(typval_T *argvars, typval_T *rettv)
parse_queued_messages();
#endif
- // Position the cursor. Needed after a message that ends in a space.
- windgoto(msg_row, msg_col);
+ if (argvars[0].v_type != VAR_UNKNOWN) {
+ int error = FALSE;
+ arg = tv_get_number_chk(&argvars[0], &error);
note to self: vim9script throws Using a Bool as a Number here
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@brammool Hey, before I proceed, do you have any comments on this? Would you be okay with this feature? It works right now with the old vim script, vim9script is broken at the moment.
Here's an example script that adds a window pseudo-mode. CTRL-W to enter it, and then CTRL-{W,P,H,J,K,L} will sustain that mode until you escape, CTRL-C or press some other key.
let s:remap = { \ "\<c-w>": "\<c-w>w", \ "\<c-p>": "\<c-w>p", \ "\<c-h>": "\<c-w>h", \ "\<c-j>": "\<c-w>j", \ "\<c-k>": "\<c-w>k", \ "\<c-l>": "\<c-w>l", \ "w": "\<c-w>w", \ "p": "\<c-w>p", \ "h": "\<c-w>h", \ "j": "\<c-w>j", \ "k": "\<c-w>k", \ "l": "\<c-w>l", \ } function Getch(...) let ch = getcharstr(2) if has_key(s:remap, ch) call feedkeys(s:remap[ch], 'n') call timer_start(0, function('Getch')) else call feedkeys("\<C-W>"..ch, 'n') echo '' end endfunction nno <nowait> <C-W> <cmd>echo '-- WINDOW --'<bar>call timer_start(0, function('Getch'))<CR>
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
There is an entry in todo.txt:
https://github.com/vim/vim/blob/4e0fc8956649d3208aeaa1642c5efc44e385d77a/runtime/doc/todo.txt#L213
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
I would think that we need an extra argument for the flag to not
position the cursor. Then the first, existing argument can be used as
before.
@brammool The problem is that getchar() has the blocking behavior when the argument is skipped. I might be wrong, but I don't think you can skip the first argument (leaving it as VAR_UNKNOWN?) and just supply the second in vim script?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@brammool any decision on how you'd like arguments for getchar to work?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Looks like we can use -1 for the first argument to get the same behavior as when it is omitted (blocking wait).
One other option that can be useful is to always return a string. Currently it can return a number or a string, which can be clumsy to handle. Thus it's best to make the second argument a dictionary, with an entry for each flag: "move" for moving the cursor (default true), "number" for possibly returning a number (default true). How about that?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
So with number=false it would basically be getcharstr()?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Hmm, it might be better to also add the extra argument to getcharstr() and not have the "number" flag. More consistent.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
What about getchar() accepting either a number or a dictionary as the first argument? A number to be backwards compatible and a dictionary for all the potential new features.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Closed #10603.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
This seems to have stalled and the tests seems to be wrong. So I am closing this for now. If you have a working version, please consider opening a new PR. thanks!
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()