aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/getchar.c
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2016-03-14 23:58:47 +0100
committerBjörn Linse <bjorn.linse@gmail.com>2018-03-23 14:01:49 +0100
commitd407a48665d8f8e1e42eb1060ea245d979419605 (patch)
treee9e69777347e92618603f3d0d8bc54f81486a663 /src/nvim/getchar.c
parentce3bc12e25f19d29c74e53a8a7f92079b1ccfcbf (diff)
downloadrneovim-d407a48665d8f8e1e42eb1060ea245d979419605.tar.gz
rneovim-d407a48665d8f8e1e42eb1060ea245d979419605.tar.bz2
rneovim-d407a48665d8f8e1e42eb1060ea245d979419605.zip
getchar: implement <Cmd> key to invoke command in any mode
Diffstat (limited to 'src/nvim/getchar.c')
-rw-r--r--src/nvim/getchar.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index 7df1bf8429..5d4e61d56a 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -4247,3 +4247,70 @@ mapblock_T *get_maphash(int index, buf_T *buf)
return (buf == NULL) ? maphash[index] : buf->b_maphash[index];
}
+
+/// Get command argument for <Cmd> key
+char_u * getcmdkeycmd(int promptc, void *cookie, int indent)
+{
+ garray_T line_ga;
+ int c1 = -1, c2;
+ int cmod = 0;
+ bool aborted = false;
+
+ ga_init(&line_ga, 1, 32);
+
+ no_mapping++;
+
+ got_int = false;
+ while (c1 != NUL && !aborted) {
+ ga_grow(&line_ga, 32);
+
+ if (vgetorpeek(false) == NUL) {
+ // incomplete <Cmd> is an error, because there is not much the user
+ // could do in this state.
+ EMSG(e_cmdmap_err);
+ aborted = true;
+ break;
+ }
+
+ // Get one character at a time.
+ c1 = vgetorpeek(true);
+ // Get two extra bytes for special keys
+ if (c1 == K_SPECIAL) {
+ c1 = vgetorpeek(true); // no mapping for these chars
+ c2 = vgetorpeek(true);
+ if (c1 == KS_MODIFIER) {
+ cmod = c2;
+ continue;
+ }
+ c1 = TO_SPECIAL(c1, c2);
+ }
+
+
+ if (got_int) {
+ aborted = true;
+ } else if (c1 == '\r' || c1 == '\n') {
+ c1 = NUL; // end the line
+ } else if (c1 == ESC) {
+ aborted = true;
+ } else if (c1 == K_COMMAND) {
+ // special case to give nicer error message
+ EMSG(e_cmdmap_repeated);
+ aborted = true;
+ } else if (IS_SPECIAL(c1)) {
+ EMSG2(e_cmdmap_key, get_special_key_name(c1, cmod));
+ aborted = true;
+ } else {
+ ga_append(&line_ga, (char)c1);
+ }
+
+ cmod = 0;
+ }
+
+ no_mapping--;
+
+ if (aborted) {
+ ga_clear(&line_ga);
+ }
+
+ return (char_u *)line_ga.ga_data;
+}