aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDongdong Zhou <dzhou121@gmail.com>2017-04-28 06:51:16 +0100
committerBjörn Linse <bjorn.linse@gmail.com>2017-10-26 09:35:12 +0200
commit550651c130c014e6c668644273db31dd96be475e (patch)
treee3723a1101e6e1648e1d7fa526d92b9e7904458c /src
parentb7a8a76f6e3b2de1cfdf32e3ccc66d87ab8e5cad (diff)
downloadrneovim-550651c130c014e6c668644273db31dd96be475e.tar.gz
rneovim-550651c130c014e6c668644273db31dd96be475e.tar.bz2
rneovim-550651c130c014e6c668644273db31dd96be475e.zip
ext_cmdline: use standard external ui functions
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval.c15
-rw-r--r--src/nvim/ex_getln.c104
-rw-r--r--src/nvim/ui.c1
3 files changed, 54 insertions, 66 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 72b97cbab9..3c9614dfcd 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -11147,15 +11147,12 @@ void get_user_input(const typval_T *const argvars,
cmd_silent = false; // Want to see the prompt.
// Only the part of the message after the last NL is considered as
- // prompt for the command line.
- const char *p = strrchr(prompt, '\n');
- if (ui_is_external(kUICmdline)) {
- p = prompt;
- } else {
- if (p == NULL) {
- p = prompt;
- } else {
- p++;
+ // prompt for the command line, unlsess cmdline is externalized
+ const char *p = prompt;
+ if (!ui_is_external(kUICmdline)) {
+ const char *lastnl = strrchr(prompt, '\n');
+ if (lastnl != NULL) {
+ p = lastnl+1;
msg_start();
msg_clr_eos();
msg_puts_attr_len(prompt, p - prompt, echo_attr);
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 0fae6c9810..8c9e081c89 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -185,8 +185,6 @@ static int cmd_showtail; /* Only show path tail in lists ? */
static int new_cmdpos; /* position set by set_cmdline_pos() */
-static bool cmdline_external = false;
-
/*
* Type used by call_user_expand_func
*/
@@ -806,7 +804,7 @@ static int command_line_execute(VimState *state, int key)
}
if (!cmd_silent) {
- if (!cmdline_external) {
+ if (!ui_is_external(kUICmdline)) {
ui_cursor_goto(msg_row, 0);
}
ui_flush();
@@ -1832,12 +1830,12 @@ getcmdline (
int indent // indent for inside conditionals
)
{
- if (cmdline_external) {
+ if (ui_is_external(kUICmdline)) {
Array args = ARRAY_DICT_INIT;
ui_event("cmdline_enter", args);
}
char_u *p = command_line_enter(firstc, count, indent);
- if (cmdline_external) {
+ if (ui_is_external(kUICmdline)) {
Array args = ARRAY_DICT_INIT;
ui_event("cmdline_leave", args);
}
@@ -2602,11 +2600,8 @@ static void draw_cmdline(int start, int len)
return;
}
- if (cmdline_external) {
- Array args = ARRAY_DICT_INIT;
- ADD(args, STRING_OBJ(cstr_to_string((char *)(ccline.cmdbuff))));
- ADD(args, INTEGER_OBJ(ccline.cmdpos));
- ui_event("cmdline", args);
+ if (ui_is_external(kUICmdline)) {
+ ui_ext_cmdline_show();
return;
}
@@ -2725,6 +2720,32 @@ draw_cmdline_no_arabicshape:
}
}
+void ui_ext_cmdline_char(int c, int shift)
+{
+ Array args = ARRAY_DICT_INIT;
+ ADD(args, STRING_OBJ(cstr_to_string((char *)(&c))));
+ ADD(args, INTEGER_OBJ(shift));
+ ui_event("cmdline_char", args);
+}
+
+void ui_ext_cmdline_show(void)
+{
+ Array args = ARRAY_DICT_INIT;
+ ADD(args, STRING_OBJ(cstr_to_string((char *)(ccline.cmdbuff))));
+ ADD(args, INTEGER_OBJ(ccline.cmdpos));
+ if (ccline.cmdfirstc != NUL) {
+ ADD(args, STRING_OBJ(cstr_to_string((char *)(&ccline.cmdfirstc))));
+ } else {
+ ADD(args, STRING_OBJ(cstr_to_string("")));
+ }
+ if (ccline.cmdprompt != NULL) {
+ ADD(args, STRING_OBJ(cstr_to_string((char *)(ccline.cmdprompt))));
+ } else {
+ ADD(args, STRING_OBJ(cstr_to_string("")));
+ }
+ ui_event("cmdline_show", args);
+}
+
/*
* Put a character on the command line. Shifts the following text to the
* right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc.
@@ -2732,29 +2753,17 @@ draw_cmdline_no_arabicshape:
*/
void putcmdline(int c, int shift)
{
- if (cmd_silent)
+ if (cmd_silent) {
return;
- if (!cmdline_external) {
+ }
+ if (!ui_is_external(kUICmdline)) {
msg_no_more = TRUE;
msg_putchar(c);
if (shift)
draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos);
msg_no_more = FALSE;
} else {
- char_u *p;
- if (ccline.cmdpos == ccline.cmdlen || shift) {
- p = vim_strnsave(ccline.cmdbuff, ccline.cmdlen + 1);
- } else {
- p = vim_strsave(ccline.cmdbuff);
- }
- p[ccline.cmdpos] = c;
- if (shift)
- STRCPY(p + ccline.cmdpos + 1, ccline.cmdbuff + ccline.cmdpos);
- Array args = ARRAY_DICT_INIT;
- ADD(args, STRING_OBJ(cstr_to_string((char *)(p))));
- ADD(args, INTEGER_OBJ(ccline.cmdpos));
- ui_event("cmdline", args);
- xfree(p);
+ ui_ext_cmdline_char(c, shift);
}
cursorcmd();
ui_cursor_shape();
@@ -3104,27 +3113,19 @@ static void redrawcmdprompt(void)
if (cmd_silent)
return;
+ if (ui_is_external(kUICmdline)) {
+ ui_ext_cmdline_show();
+ return;
+ }
if (ccline.cmdfirstc != NUL) {
- if (cmdline_external) {
- Array args = ARRAY_DICT_INIT;
- ADD(args, STRING_OBJ(cstr_to_string((char *)(&ccline.cmdfirstc))));
- ui_event("cmdline_firstc", args);
- } else {
- msg_putchar(ccline.cmdfirstc);
- }
+ msg_putchar(ccline.cmdfirstc);
}
if (ccline.cmdprompt != NULL) {
- if (cmdline_external) {
- Array args = ARRAY_DICT_INIT;
- ADD(args, STRING_OBJ(cstr_to_string((char *)(ccline.cmdprompt))));
- ui_event("cmdline_prompt", args);
- } else {
- msg_puts_attr((const char *)ccline.cmdprompt, ccline.cmdattr);
- ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns;
- // do the reverse of set_cmdspos()
- if (ccline.cmdfirstc != NUL) {
- ccline.cmdindent--;
- }
+ msg_puts_attr((const char *)ccline.cmdprompt, ccline.cmdattr);
+ ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns;
+ // do the reverse of set_cmdspos()
+ if (ccline.cmdfirstc != NUL) {
+ ccline.cmdindent--;
}
} else {
for (i = ccline.cmdindent; i > 0; i--) {
@@ -3141,7 +3142,7 @@ void redrawcmd(void)
if (cmd_silent)
return;
- if (cmdline_external) {
+ if (ui_is_external(kUICmdline)) {
draw_cmdline(0, ccline.cmdlen);
return;
}
@@ -3189,7 +3190,7 @@ static void cursorcmd(void)
if (cmd_silent)
return;
- if (cmdline_external) {
+ if (ui_is_external(kUICmdline)) {
Array args = ARRAY_DICT_INIT;
ADD(args, INTEGER_OBJ(ccline.cmdpos));
ui_event("cmdline_pos", args);
@@ -3213,7 +3214,7 @@ static void cursorcmd(void)
void gotocmdline(int clr)
{
- if (cmdline_external) {
+ if (ui_is_external(kUICmdline)) {
return;
}
msg_start();
@@ -6044,12 +6045,3 @@ static void set_search_match(pos_T *t)
}
}
-void cmdline_set_external(bool external)
-{
- cmdline_external = external;
-}
-
-bool cmdline_get_external(void)
-{
- return cmdline_external;
-}
diff --git a/src/nvim/ui.c b/src/nvim/ui.c
index 0fa4034ff6..6b09f6e6db 100644
--- a/src/nvim/ui.c
+++ b/src/nvim/ui.c
@@ -281,7 +281,6 @@ void ui_refresh(void)
int save_p_lz = p_lz;
p_lz = false; // convince redrawing() to return true ...
- cmdline_set_external(cmdline_external);
screen_resize(width, height);
p_lz = save_p_lz;