diff options
author | Chet Ramey <chet.ramey@case.edu> | 2021-01-18 13:42:55 -0500 |
---|---|---|
committer | Chet Ramey <chet.ramey@case.edu> | 2021-01-18 13:42:55 -0500 |
commit | cf3c762ecfff5b2f445647a0f1543693984a5540 (patch) | |
tree | e21eb36970a06b1d8a2df6a97a161da43410e136 /isearch.c | |
parent | c5ad6be530f5c1daf64a2d20df4baba9f6b57aa4 (diff) |
Readline-8.1 distribution sources and documentationreadline-8.1
Diffstat (limited to 'isearch.c')
-rw-r--r-- | isearch.c | 75 |
1 files changed, 68 insertions, 7 deletions
@@ -6,7 +6,7 @@ /* */ /* **************************************************************** */ -/* Copyright (C) 1987-2017 Free Software Foundation, Inc. +/* Copyright (C) 1987-2020 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. @@ -185,11 +185,13 @@ rl_display_search (char *search_string, int flags, int where) strcpy (message + msglen, "i-search)`"); msglen += 10; - if (search_string) + if (search_string && *search_string) { strcpy (message + msglen, search_string); msglen += searchlen; } + else + _rl_optimize_redisplay (); strcpy (message + msglen, "': "); @@ -255,6 +257,9 @@ _rl_isearch_init (int direction) _rl_iscxt = cxt; /* save globally */ + /* experimental right now */ + _rl_init_executing_keyseq (); + return cxt; } @@ -287,16 +292,22 @@ _rl_isearch_fini (_rl_search_cxt *cxt) else cxt->sline_index = strlen (rl_line_buffer); rl_mark = cxt->save_mark; + rl_deactivate_mark (); } rl_point = cxt->sline_index; /* Don't worry about where to put the mark here; rl_get_previous_history - and rl_get_next_history take care of it. */ + and rl_get_next_history take care of it. + If we want to highlight the search string, this is where to set the + point and mark to do it. */ _rl_fix_point (0); + rl_deactivate_mark (); +/* _rl_optimize_redisplay (); */ rl_clear_message (); } +/* XXX - we could use _rl_bracketed_read_mbstring () here. */ int _rl_search_getchar (_rl_search_cxt *cxt) { @@ -342,6 +353,24 @@ _rl_isearch_dispatch (_rl_search_cxt *cxt, int c) return -1; } + _rl_add_executing_keyseq (c); + + /* XXX - experimental code to allow users to bracketed-paste into the search + string even when ESC is one of the isearch-terminators. Not perfect yet. */ + if (_rl_enable_bracketed_paste && c == ESC && strchr (cxt->search_terminators, c) && (n = _rl_nchars_available ()) > (BRACK_PASTE_SLEN-1)) + { + j = _rl_read_bracketed_paste_prefix (c); + if (j == 1) + { + cxt->lastc = -7; /* bracketed paste, see below */ + goto opcode_dispatch; + } + else if (_rl_pushed_input_available ()) /* eat extra char we pushed back */ + c = cxt->lastc = rl_read_key (); + else + c = cxt->lastc; /* last ditch */ + } + /* If we are moving into a new keymap, modify cxt->keymap and go on. This can be a problem if c == ESC and we want to terminate the incremental search, so we check */ @@ -387,7 +416,18 @@ add_character: /* Translate the keys we do something with to opcodes. */ if (c >= 0 && cxt->keymap[c].type == ISFUNC) { - f = cxt->keymap[c].function; + /* If we have a multibyte character, see if it's bound to something that + affects the search. */ +#if defined (HANDLE_MULTIBYTE) + if (MB_CUR_MAX > 1 && rl_byte_oriented == 0 && cxt->mb[1]) + f = rl_function_of_keyseq (cxt->mb, cxt->keymap, (int *)NULL); + else +#endif + { + f = cxt->keymap[c].function; + if (f == rl_do_lowercase_version) + f = cxt->keymap[_rl_to_lower (c)].function; + } if (f == rl_reverse_search_history) cxt->lastc = (cxt->sflags & SF_REVERSE) ? -1 : -2; @@ -454,9 +494,14 @@ add_character: } else if (cxt->lastc > 0 && cxt->prevc > 0 && f && f != rl_insert) { - rl_stuff_char (cxt->lastc); - rl_execute_next (cxt->prevc); - /* XXX - do we insert everything in cxt->pmb? */ + _rl_term_executing_keyseq (); /* should this go in the caller? */ + + _rl_pending_command.map = cxt->keymap; + _rl_pending_command.count = 1; /* XXX */ + _rl_pending_command.key = cxt->lastc; + _rl_pending_command.func = f; + _rl_command_to_execute = &_rl_pending_command; + return (0); } } @@ -502,6 +547,9 @@ add_character: return (0); } + _rl_init_executing_keyseq (); + +opcode_dispatch: /* Now dispatch on the character. `Opcodes' affect the search string or state. Other characters are added to the string. */ switch (cxt->lastc) @@ -519,6 +567,7 @@ add_character: rl_display_search (cxt->search_string, cxt->sflags, -1); break; } + /* XXX - restore keymap here? */ return (1); } else if ((cxt->sflags & SF_REVERSE) && cxt->sline_index >= 0) @@ -566,9 +615,11 @@ add_character: rl_replace_line (cxt->lines[cxt->save_line], 0); rl_point = cxt->save_point; rl_mark = cxt->save_mark; + rl_deactivate_mark (); rl_restore_prompt(); rl_clear_message (); + _rl_fix_point (1); /* in case save_line and save_point are out of sync */ return -1; case -5: /* C-W */ @@ -632,6 +683,8 @@ add_character: free (paste); break; } + if (_rl_enable_active_region) + rl_activate_mark (); if (cxt->search_string_index + pastelen + 1 >= cxt->search_string_size) { cxt->search_string_size += pastelen + 2; @@ -736,11 +789,15 @@ add_character: cxt->sline_index = (cxt->sflags & SF_REVERSE) ? cxt->sline_len - cxt->search_string_index : 0; } + /* reset the keymaps for the next time through the loop */ + cxt->keymap = cxt->okeymap = _rl_keymap; + if (cxt->sflags & SF_FAILED) { /* We cannot find the search string. Ding the bell. */ rl_ding (); cxt->history_pos = cxt->last_found_line; + rl_deactivate_mark (); rl_display_search (cxt->search_string, cxt->sflags, (cxt->history_pos == cxt->save_line) ? -1 : cxt->history_pos); return 1; } @@ -752,7 +809,11 @@ add_character: { cxt->prev_line_found = cxt->lines[cxt->history_pos]; rl_replace_line (cxt->lines[cxt->history_pos], 0); + if (_rl_enable_active_region) + rl_activate_mark (); rl_point = cxt->sline_index; + if (rl_mark_active_p () && cxt->search_string_index > 0) + rl_mark = rl_point + cxt->search_string_index; cxt->last_found_line = cxt->history_pos; rl_display_search (cxt->search_string, cxt->sflags, (cxt->history_pos == cxt->save_line) ? -1 : cxt->history_pos); } |