diff options
Diffstat (limited to 'src/nvim/ex_getln.c')
-rw-r--r-- | src/nvim/ex_getln.c | 264 |
1 files changed, 2 insertions, 262 deletions
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 4ebd384ae0..855f71ca28 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2510,266 +2510,6 @@ getexline( return getcmdline(c, 1L, indent, do_concat); } -/* - * Get an Ex command line for Ex mode. - * In Ex mode we only use the OS supplied line editing features and no - * mappings or abbreviations. - * Returns a string in allocated memory or NULL. - */ -char_u * -getexmodeline( - int promptc, // normally ':', NUL for ":append" and '?' - // for :s prompt - void *cookie, - int indent, // indent for inside conditionals - bool do_concat -) -{ - garray_T line_ga; - char_u *pend; - int startcol = 0; - int c1 = 0; - int escaped = FALSE; /* CTRL-V typed */ - int vcol = 0; - char_u *p; - int prev_char; - int len; - - /* always start in column 0; write a newline if necessary */ - compute_cmdrow(); - if ((msg_col || msg_didout) && promptc != '?') - msg_putchar('\n'); - if (promptc == ':') { - /* indent that is only displayed, not in the line itself */ - if (p_prompt) - msg_putchar(':'); - while (indent-- > 0) - msg_putchar(' '); - startcol = msg_col; - } - - ga_init(&line_ga, 1, 30); - - /* autoindent for :insert and :append is in the line itself */ - if (promptc <= 0) { - vcol = indent; - while (indent >= 8) { - ga_append(&line_ga, TAB); - msg_puts(" "); - indent -= 8; - } - while (indent-- > 0) { - ga_append(&line_ga, ' '); - msg_putchar(' '); - } - } - no_mapping++; - - /* - * Get the line, one character at a time. - */ - got_int = FALSE; - while (!got_int) { - ga_grow(&line_ga, 40); - - /* Get one character at a time. Don't use inchar(), it can't handle - * special characters. */ - prev_char = c1; - - // Check for a ":normal" command and no more characters left. - if (ex_normal_busy > 0 && typebuf.tb_len == 0) { - c1 = '\n'; - } else { - c1 = vgetc(); - } - - /* - * Handle line editing. - * Previously this was left to the system, putting the terminal in - * cooked mode, but then CTRL-D and CTRL-T can't be used properly. - */ - if (got_int) { - msg_putchar('\n'); - break; - } - - if (!escaped) { - /* CR typed means "enter", which is NL */ - if (c1 == '\r') - c1 = '\n'; - - if (c1 == BS || c1 == K_BS || c1 == DEL || c1 == K_DEL || c1 == K_KDEL) { - if (!GA_EMPTY(&line_ga)) { - p = (char_u *)line_ga.ga_data; - p[line_ga.ga_len] = NUL; - len = utf_head_off(p, p + line_ga.ga_len - 1) + 1; - line_ga.ga_len -= len; - goto redraw; - } - continue; - } - - if (c1 == Ctrl_U) { - msg_col = startcol; - msg_clr_eos(); - line_ga.ga_len = 0; - goto redraw; - } - - int num_spaces; - if (c1 == Ctrl_T) { - int sw = get_sw_value(curbuf); - - p = (char_u *)line_ga.ga_data; - p[line_ga.ga_len] = NUL; - indent = get_indent_str(p, 8, FALSE); - num_spaces = sw - indent % sw; -add_indent: - if (num_spaces > 0) { - ga_grow(&line_ga, num_spaces + 1); - p = (char_u *)line_ga.ga_data; - char_u *s = skipwhite(p); - - // Insert spaces after leading whitespaces. - long move_len = line_ga.ga_len - (s - p) + 1; - assert(move_len >= 0); - memmove(s + num_spaces, s, (size_t)move_len); - memset(s, ' ', (size_t)num_spaces); - - line_ga.ga_len += num_spaces; - } -redraw: - /* redraw the line */ - msg_col = startcol; - vcol = 0; - p = (char_u *)line_ga.ga_data; - p[line_ga.ga_len] = NUL; - while (p < (char_u *)line_ga.ga_data + line_ga.ga_len) { - if (*p == TAB) { - do { - msg_putchar(' '); - } while (++vcol % 8); - p++; - } else { - len = utfc_ptr2len(p); - msg_outtrans_len(p, len); - vcol += ptr2cells(p); - p += len; - } - } - msg_clr_eos(); - cmd_cursor_goto(msg_row, msg_col); - continue; - } - - if (c1 == Ctrl_D) { - /* Delete one shiftwidth. */ - p = (char_u *)line_ga.ga_data; - if (prev_char == '0' || prev_char == '^') { - if (prev_char == '^') - ex_keep_indent = TRUE; - indent = 0; - p[--line_ga.ga_len] = NUL; - } else { - p[line_ga.ga_len] = NUL; - indent = get_indent_str(p, 8, FALSE); - if (indent == 0) { - continue; - } - --indent; - indent -= indent % get_sw_value(curbuf); - } - - // reduce the line's indentation - char_u *from = skipwhite(p); - char_u *to = from; - int old_indent; - while ((old_indent = get_indent_str(p, 8, FALSE)) > indent) { - *--to = NUL; - } - long move_len = line_ga.ga_len - (from - p) + 1; - assert(move_len > 0); - memmove(to, from, (size_t)move_len); - line_ga.ga_len -= (int)(from - to); - - // Removed to much indentation, fix it before redrawing. - num_spaces = indent - old_indent; - goto add_indent; - } - - if (c1 == Ctrl_V || c1 == Ctrl_Q) { - escaped = TRUE; - continue; - } - - if (IS_SPECIAL(c1)) { - // Ignore other special key codes - continue; - } - } - - if (IS_SPECIAL(c1)) { - c1 = '?'; - } - len = utf_char2bytes(c1, (char_u *)line_ga.ga_data + line_ga.ga_len); - if (c1 == '\n') { - msg_putchar('\n'); - } else if (c1 == TAB) { - // Don't use chartabsize(), 'ts' can be different. - do { - msg_putchar(' '); - } while (++vcol % 8); - } else { - msg_outtrans_len(((char_u *)line_ga.ga_data) + line_ga.ga_len, len); - vcol += char2cells(c1); - } - line_ga.ga_len += len; - escaped = FALSE; - - cmd_cursor_goto(msg_row, msg_col); - pend = (char_u *)(line_ga.ga_data) + line_ga.ga_len; - - /* We are done when a NL is entered, but not when it comes after an - * odd number of backslashes, that results in a NUL. */ - if (!GA_EMPTY(&line_ga) && pend[-1] == '\n') { - int bcount = 0; - - while (line_ga.ga_len - 2 >= bcount && pend[-2 - bcount] == '\\') - ++bcount; - - if (bcount > 0) { - /* Halve the number of backslashes: "\NL" -> "NUL", "\\NL" -> - * "\NL", etc. */ - line_ga.ga_len -= (bcount + 1) / 2; - pend -= (bcount + 1) / 2; - pend[-1] = '\n'; - } - - if ((bcount & 1) == 0) { - --line_ga.ga_len; - --pend; - *pend = NUL; - break; - } - } - } - - no_mapping--; - - /* make following messages go to the next line */ - msg_didout = FALSE; - msg_col = 0; - if (msg_row < Rows - 1) { - msg_row++; - } - emsg_on_display = false; // don't want os_delay() - - if (got_int) - ga_clear(&line_ga); - - return (char_u *)line_ga.ga_data; -} - bool cmdline_overstrike(void) { return ccline.overstrike; @@ -6469,7 +6209,7 @@ static int open_cmdwin(void) char_u typestr[2]; int save_restart_edit = restart_edit; int save_State = State; - int save_exmode = exmode_active; + bool save_exmode = exmode_active; int save_cmdmsg_rl = cmdmsg_rl; /* Can't do this recursively. Can't do it when typing a password. */ @@ -6563,7 +6303,7 @@ static int open_cmdwin(void) save_cmdline(&save_ccline); // No Ex mode here! - exmode_active = 0; + exmode_active = false; State = NORMAL; setmouse(); |