void _rl_vi_done_inserting(void) { if (_rl_vi_doing_insert) { /* The `C', `s', and `S' commands set this. */ rl_end_undo_group(); /* Now, the text between rl_undo_list->next->start and rl_undo_list->next->end is what was inserted while in insert mode. It gets copied to VI_INSERT_BUFFER because it depends on absolute indices into the line which may change (though they probably will not). */ _rl_vi_doing_insert = 0; _rl_vi_save_insert(rl_undo_list->next); vi_continued_command = 1; } else { if ((_rl_vi_last_key_before_insert == 'i') && rl_undo_list) _rl_vi_save_insert(rl_undo_list); /* XXX - Other keys probably need to be checked. */ else if (_rl_vi_last_key_before_insert == 'C') rl_end_undo_group(); while (_rl_undo_group_level > 0) rl_end_undo_group(); vi_continued_command = 0; } }
int rl_vi_yank_to (int count, int key) { int c, save = rl_point; if (uppercase_p (key)) rl_stuff_char ('$'); if (rl_vi_domove (key, &c)) { DING (); return -1; } /* These are the motion commands that do not require adjusting the mark. */ if ((strchr (" l|h^0%bB", c) == 0) && (rl_mark < rl_end)) rl_mark++; rl_begin_undo_group (); rl_kill_text (rl_point, rl_mark); rl_end_undo_group (); rl_do_undo (); rl_point = save; return (0); }
int rl_vi_overstrike_delete (int count, int ignore) { int i, s; for (i = 0; i < count; i++) { if (vi_replace_count == 0) { DING (); break; } s = rl_point; if (rl_do_undo ()) vi_replace_count--; if (rl_point == s) rl_backward (1, ignore); } if (vi_replace_count == 0 && _rl_vi_doing_insert) { rl_end_undo_group (); rl_do_undo (); _rl_vi_doing_insert = 0; } return (0); }
int rl_vi_overstrike (int count, int key) { int i; if (_rl_vi_doing_insert == 0) { _rl_vi_doing_insert = 1; rl_begin_undo_group (); } for (i = 0; i < count; i++) { vi_replace_count++; rl_begin_undo_group (); if (rl_point < rl_end) { rl_delete (1, key); rl_insert (1, key); } else rl_insert (1, key); rl_end_undo_group (); } return (0); }
int rl_vi_change_char (int count, int key) { int c; if (vi_redoing) c = _rl_vi_last_replacement; else _rl_vi_last_replacement = c = rl_getc (rl_instream); if (c == '\033' || c == CTRL ('C')) return -1; while (count-- && rl_point < rl_end) { rl_begin_undo_group (); rl_delete (1, c); rl_insert (1, c); if (count == 0) rl_backward (1, c); rl_end_undo_group (); } return (0); }
static void _rl_vi_stuff_insert(int count) { rl_begin_undo_group(); while (count--) rl_insert_text(vi_insert_buffer); rl_end_undo_group(); }
int rl_vi_change_to(int count, int key) { int c, start_pos; if (_rl_uppercase_p (key)) rl_stuff_char ('$'); else if (vi_redoing) rl_stuff_char (_rl_vi_last_motion); start_pos = rl_point; if (rl_vi_domove (key, &c)) { rl_ding (); return -1; } /* These are the motion commands that do not require adjusting the mark. c[wW] are handled by special-case code in rl_vi_domove(), and already leave the mark at the correct location. */ if ((strchr (" l|hwW^0bB", c) == 0) && (rl_mark < rl_end)) rl_mark++; /* The cursor never moves with c[wW]. */ if ((_rl_to_upper (c) == 'W') && rl_point < start_pos) rl_point = start_pos; if (vi_redoing) { if (vi_insert_buffer && *vi_insert_buffer) rl_begin_undo_group (); rl_delete_text (rl_point, rl_mark); if (vi_insert_buffer && *vi_insert_buffer) { rl_insert_text (vi_insert_buffer); rl_end_undo_group (); } } else { rl_begin_undo_group (); /* to make the `u' command work */ rl_kill_text (rl_point, rl_mark); /* `C' does not save the text inserted for undoing or redoing. */ if (_rl_uppercase_p (key) == 0) _rl_vi_doing_insert = 1; _rl_vi_set_last (key, count, rl_arg_sign); rl_vi_insertion_mode (1, key); } return (0); }
void _rl_vi_done_inserting (void) { if (_rl_vi_doing_insert) { rl_end_undo_group (); /* Now, the text between rl_undo_list->next->start and rl_undo_list->next->end is what was inserted while in insert mode. */ _rl_vi_doing_insert = 0; vi_continued_command = 1; } else vi_continued_command = 0; }
static int _rl_vi_change_mbchar_case(int count) { wchar_t wc; char mb[MB_LEN_MAX + 1]; int mb_len; mbstate_t ps; memset(&ps, 0, sizeof(mbstate_t)); if (_rl_adjust_point(rl_line_buffer, rl_point, &ps) > 0) count--; while (count-- && (rl_point < rl_end)) { mbrtowc(&wc, (rl_line_buffer + rl_point), (size_t)(rl_end - rl_point), &ps); if (iswupper(wc)) wc = towlower(wc); else if (iswlower(wc)) wc = towupper(wc); else { /* Just skip over chars neither upper nor lower case */ rl_forward_char(1, 0); continue; } /* Vi is kind of strange here. */ if (wc) { mb_len = wctomb(mb, wc); if (mb_len >= 0) mb[mb_len] = '\0'; rl_begin_undo_group(); rl_delete(1, 0); rl_insert_text(mb); rl_end_undo_group(); rl_vi_check(); } else rl_forward_char(1, 0); } return 0; }
//------------------------------------------------------------------------------ static int menu_completion_shim(int count, int invoking_key) { int ret; // rl_complete checks if it was called previously. if (rl_last_func == menu_completion_shim) { rl_last_func = rl_menu_complete; } rl_begin_undo_group(); ret = rl_menu_complete(count, invoking_key); suffix_translation(); rl_end_undo_group(); g_slash_translation = 0; return ret; }
//------------------------------------------------------------------------------ static int completion_shim_impl(int count, int invoking_key, int (*rl_func)(int, int)) { int ret; // rl complete functions checks if it was called previously, so restore it. if (rl_last_func == completion_shim || rl_last_func == menu_completion_shim) { rl_last_func = rl_func; } rl_begin_undo_group(); ret = rl_func(count, invoking_key); suffix_translation(); rl_end_undo_group(); g_slash_translation = 0; return ret; }
int rl_vi_change_case(int count, int ignore) { char c = 0; /* Do NOT try this on an empty line: */ if (rl_point >= rl_end) return (0); #if defined(HANDLE_MULTIBYTE) if ((MB_CUR_MAX > 1) && (rl_byte_oriented == 0)) return (_rl_vi_change_mbchar_case(count)); #endif while (count-- && (rl_point < rl_end)) { if (_rl_uppercase_p(rl_line_buffer[rl_point])) c = (char)_rl_to_lower(rl_line_buffer[rl_point]); else if (_rl_lowercase_p(rl_line_buffer[rl_point])) c = (char)_rl_to_upper(rl_line_buffer[rl_point]); else { /* Just skip over characters neither upper nor lower case. */ rl_forward_char (1, c); continue; } /* Vi is kind of strange here. */ if (c) { rl_begin_undo_group (); rl_delete (1, c); _rl_insert_char (1, c); rl_end_undo_group (); rl_vi_check (); } else rl_forward_char (1, c); } return (0); }
int rl_vi_subst (int count, int key) { rl_begin_undo_group (); if (uppercase_p (key)) { rl_beg_of_line (1, key); rl_kill_line (1, key); } else rl_delete_text (rl_point, rl_point+count); rl_end_undo_group (); _rl_vi_set_last (key, count, rl_arg_sign); rl_begin_undo_group (); _rl_vi_doing_insert = 1; rl_vi_insertion_mode (1, key); return (0); }
static int input_help(int arg, int key UNUSED) { int i, in_string, in_bracket; if (arg != 1) return rl_insert(arg, '?'); in_string = in_bracket = 0; for (i = 0; i < rl_point; i++) { if (rl_line_buffer[i] == '"') in_string = ! in_string; else if (! in_string) { if (rl_line_buffer[i] == '[') in_bracket++; else if (rl_line_buffer[i] == ']') in_bracket--; } } /* `?' inside string or path -> insert */ if (in_string || in_bracket) return rl_insert(1, '?'); rl_begin_undo_group(); /* HACK: We want to display `?' at point position */ rl_insert_text("?"); rl_redisplay(); rl_end_undo_group(); input_start_list(); cmd_help(rl_line_buffer, rl_point); rl_undo_command(1, 0); input_stop_list(); return 0; }
//------------------------------------------------------------------------------ static int completion_shim(int count, int invoking_key) { int ret; // rl_complete checks if it was called previously. if (rl_last_func == completion_shim) { rl_last_func = rl_complete; } rl_begin_undo_group(); ret = rl_complete(count, invoking_key); // readline's path completion may have appended a '/'. If so; flip it. if ((rl_point > 0) && (rl_line_buffer[rl_point - 1] == '/')) { rl_delete_text(rl_point - 1, rl_point); --rl_point; rl_insert_text("\\"); } rl_end_undo_group(); return ret; }
int rl_vi_change_case (int count, int ignore) { char c = 0; /* Don't try this on an empty line. */ if (rl_point >= rl_end) return (0); while (count-- && rl_point < rl_end) { if (uppercase_p (rl_line_buffer[rl_point])) c = to_lower (rl_line_buffer[rl_point]); else if (lowercase_p (rl_line_buffer[rl_point])) c = to_upper (rl_line_buffer[rl_point]); else { /* Just skip over characters neither upper nor lower case. */ rl_forward (1, c); continue; } /* Vi is kind of strange here. */ if (c) { rl_begin_undo_group (); rl_delete (1, c); rl_insert (1, c); rl_end_undo_group (); rl_vi_check (); } else rl_forward (1, c); } return (0); }