📄 text.c
字号:
curr_line = _rl_current_display_line (); _rl_move_vert (curr_line); _rl_move_cursor_relative (0, rl_line_buffer); /* XXX is this right */ _rl_clear_to_eol (0); /* arg of 0 means to not use spaces */ rl_forced_update_display (); rl_display_fixed = 1; return 0;}/* C-l typed to a line without quoting clears the screen, and then reprints the prompt and the current input line. Given a numeric arg, redraw only the current line. */intrl_clear_screen (count, key) int count, key;{ if (rl_explicit_arg) { rl_refresh_line (count, key); return 0; } _rl_clear_screen (); /* calls termcap function to clear screen */ rl_forced_update_display (); rl_display_fixed = 1; return 0;}intrl_arrow_keys (count, c) int count, c;{ int ch; RL_SETSTATE(RL_STATE_MOREINPUT); ch = rl_read_key (); RL_UNSETSTATE(RL_STATE_MOREINPUT); switch (_rl_to_upper (ch)) { case 'A': rl_get_previous_history (count, ch); break; case 'B': rl_get_next_history (count, ch); break; case 'C': if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) rl_forward_char (count, ch); else rl_forward_byte (count, ch); break; case 'D': if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) rl_backward_char (count, ch); else rl_backward_byte (count, ch); break; default: rl_ding (); } return 0;}/* **************************************************************** *//* *//* Text commands *//* *//* **************************************************************** */#ifdef HANDLE_MULTIBYTEstatic char pending_bytes[MB_LEN_MAX];static int pending_bytes_length = 0;static mbstate_t ps = {0};#endif/* Insert the character C at the current location, moving point forward. If C introduces a multibyte sequence, we read the whole sequence and then insert the multibyte char into the line buffer. */int_rl_insert_char (count, c) int count, c;{ register int i; char *string;#ifdef HANDLE_MULTIBYTE int string_size; char incoming[MB_LEN_MAX + 1]; int incoming_length = 0; mbstate_t ps_back; static int stored_count = 0;#endif if (count <= 0) return 0;#if defined (HANDLE_MULTIBYTE) if (MB_CUR_MAX == 1 || rl_byte_oriented) { incoming[0] = c; incoming[1] = '\0'; incoming_length = 1; } else { wchar_t wc; size_t ret; if (stored_count <= 0) stored_count = count; else count = stored_count; ps_back = ps; pending_bytes[pending_bytes_length++] = c; ret = mbrtowc (&wc, pending_bytes, pending_bytes_length, &ps); if (ret == (size_t)-2) { /* Bytes too short to compose character, try to wait for next byte. Restore the state of the byte sequence, because in this case the effect of mbstate is undefined. */ ps = ps_back; return 1; } else if (ret == (size_t)-1) { /* Invalid byte sequence for the current locale. Treat first byte as a single character. */ incoming[0] = pending_bytes[0]; incoming[1] = '\0'; incoming_length = 1; pending_bytes_length--; memmove (pending_bytes, pending_bytes + 1, pending_bytes_length); /* Clear the state of the byte sequence, because in this case the effect of mbstate is undefined. */ memset (&ps, 0, sizeof (mbstate_t)); } else if (ret == (size_t)0) { incoming[0] = '\0'; incoming_length = 0; pending_bytes_length--; /* Clear the state of the byte sequence, because in this case the effect of mbstate is undefined. */ memset (&ps, 0, sizeof (mbstate_t)); } else { /* We successfully read a single multibyte character. */ memcpy (incoming, pending_bytes, pending_bytes_length); incoming[pending_bytes_length] = '\0'; incoming_length = pending_bytes_length; pending_bytes_length = 0; } }#endif /* HANDLE_MULTIBYTE */ /* If we can optimize, then do it. But don't let people crash readline because of extra large arguments. */ if (count > 1 && count <= 1024) {#if defined (HANDLE_MULTIBYTE) string_size = count * incoming_length; string = (char *)xmalloc (1 + string_size); i = 0; while (i < string_size) { strncpy (string + i, incoming, incoming_length); i += incoming_length; } incoming_length = 0; stored_count = 0;#else /* !HANDLE_MULTIBYTE */ string = (char *)xmalloc (1 + count); for (i = 0; i < count; i++) string[i] = c;#endif /* !HANDLE_MULTIBYTE */ string[i] = '\0'; rl_insert_text (string); free (string); return 0; } if (count > 1024) { int decreaser;#if defined (HANDLE_MULTIBYTE) string_size = incoming_length * 1024; string = (char *)xmalloc (1 + string_size); i = 0; while (i < string_size) { strncpy (string + i, incoming, incoming_length); i += incoming_length; } while (count) { decreaser = (count > 1024) ? 1024 : count; string[decreaser*incoming_length] = '\0'; rl_insert_text (string); count -= decreaser; } free (string); incoming_length = 0; stored_count = 0;#else /* !HANDLE_MULTIBYTE */ char str[1024+1]; for (i = 0; i < 1024; i++) str[i] = c; while (count) { decreaser = (count > 1024 ? 1024 : count); str[decreaser] = '\0'; rl_insert_text (str); count -= decreaser; }#endif /* !HANDLE_MULTIBYTE */ return 0; }#if defined (HANDLE_MULTIBYTE) if (MB_CUR_MAX == 1 || rl_byte_oriented) {#endif /* We are inserting a single character. If there is pending input, then make a string of all of the pending characters that are bound to rl_insert, and insert them all. */ if (_rl_any_typein ()) _rl_insert_typein (c); else { /* Inserting a single character. */ char str[2]; str[1] = '\0'; str[0] = c; rl_insert_text (str); }#if defined (HANDLE_MULTIBYTE) } else { rl_insert_text (incoming); stored_count = 0; }#endif return 0;}/* Overwrite the character at point (or next COUNT characters) with C. If C introduces a multibyte character sequence, read the entire sequence before starting the overwrite loop. */int_rl_overwrite_char (count, c) int count, c;{ int i;#if defined (HANDLE_MULTIBYTE) char mbkey[MB_LEN_MAX]; int k; /* Read an entire multibyte character sequence to insert COUNT times. */ if (count > 0 && MB_CUR_MAX > 1 && rl_byte_oriented == 0) k = _rl_read_mbstring (c, mbkey, MB_LEN_MAX);#endif rl_begin_undo_group (); for (i = 0; i < count; i++) {#if defined (HANDLE_MULTIBYTE) if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) rl_insert_text (mbkey); else#endif _rl_insert_char (1, c); if (rl_point < rl_end) rl_delete (1, c); } rl_end_undo_group (); return 0;}intrl_insert (count, c) int count, c;{ return (rl_insert_mode == RL_IM_INSERT ? _rl_insert_char (count, c) : _rl_overwrite_char (count, c));}/* Insert the next typed character verbatim. */intrl_quoted_insert (count, key) int count, key;{ int c;#if defined (HANDLE_SIGNALS) _rl_disable_tty_signals ();#endif RL_SETSTATE(RL_STATE_MOREINPUT); c = rl_read_key (); RL_UNSETSTATE(RL_STATE_MOREINPUT);#if defined (HANDLE_SIGNALS) _rl_restore_tty_signals ();#endif return (_rl_insert_char (count, c)); }/* Insert a tab character. */intrl_tab_insert (count, key) int count, key;{ return (_rl_insert_char (count, '\t'));}/* What to do when a NEWLINE is pressed. We accept the whole line. KEY is the key that invoked this command. I guess it could have meaning in the future. */intrl_newline (count, key) int count, key;{ rl_done = 1; if (_rl_history_preserve_point) _rl_history_saved_point = (rl_point == rl_end) ? -1 : rl_point; RL_SETSTATE(RL_STATE_DONE);#if defined (VI_MODE) if (rl_editing_mode == vi_mode) { _rl_vi_done_inserting (); if (_rl_vi_textmod_command (_rl_vi_last_command) == 0) /* XXX */ _rl_vi_reset_last (); }#endif /* VI_MODE */ /* If we've been asked to erase empty lines, suppress the final update, since _rl_update_final calls rl_crlf(). */ if (rl_erase_empty_line && rl_point == 0 && rl_end == 0) return 0; if (readline_echoing_p) _rl_update_final (); return 0;}/* What to do for some uppercase characters, like meta characters, and some characters appearing in emacs_ctlx_keymap. This function is just a stub, you bind keys to it and the code in _rl_dispatch () is special cased. */intrl_do_lowercase_version (ignore1, ignore2) int ignore1, ignore2;{ return 0;}/* This is different from what vi does, so the code's not shared. Emacs rubout in overwrite mode has one oddity: it replaces a control character that's displayed as two characters (^X) with two spaces. */int_rl_overwrite_rubout (count, key) int count, key;{ int opoint; int i, l; if (rl_point == 0) { rl_ding (); return 1; } opoint = rl_point; /* L == number of spaces to insert */ for (i = l = 0; i < count; i++) { rl_backward_char (1, key); l += rl_character_len (rl_line_buffer[rl_point], rl_point); /* not exactly right */ } rl_begin_undo_group (); if (count > 1 || rl_explicit_arg) rl_kill_text (opoint, rl_point); else rl_delete_text (opoint, rl_point); /* Emacs puts point at the beginning of the sequence of spaces. */ if (rl_point < rl_end) { opoint = rl_point; _rl_insert_char (l, ' '); rl_point = opoint; } rl_end_undo_group (); return 0;} /* Rubout the character behind point. */intrl_rubout (count, key) int count, key;{ if (count < 0) return (rl_delete (-count, key)); if (!rl_point) { rl_ding (); return -1; } if (rl_insert_mode == RL_IM_OVERWRITE) return (_rl_overwrite_rubout (count, key)); return (_rl_rubout_char (count, key));}int_rl_rubout_char (count, key) int count, key;{ int orig_point; unsigned char c; /* Duplicated code because this is called from other parts of the library. */ if (count < 0) return (rl_delete (-count, key)); if (rl_point == 0) { rl_ding (); return -1; } if (count > 1 || rl_explicit_arg) { orig_point = rl_point;#if defined (HANDLE_MULTIBYTE) if (MB_CUR_MAX > 1 && rl_byte_oriented == 0) rl_backward_char (count, key); else#endif rl_backward_byte (count, key); rl_kill_text (orig_point, rl_point); } else {#if defined (HANDLE_MULTIBYTE) if (MB_CUR_MAX == 1 || rl_byte_oriented) {#endif c = rl_line_buffer[--rl_point]; rl_delete_text (rl_point, rl_point + 1);#if defined (HANDLE_MULTIBYTE) } else { int orig_point; orig_point = rl_point; rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_NONZERO); c = rl_line_buffer[rl_point]; rl_delete_text (rl_point, orig_point); }#endif /* HANDLE_MULTIBYTE */ /* I don't think that the hack for end of line is needed for multibyte chars. */#if defined (HANDLE_MULTIBYTE) if (MB_CUR_MAX == 1 || rl_byte_oriented)#endif if (rl_point == rl_end && ISPRINT (c) && _rl_last_c_pos) { int l; l = rl_character_len (c, rl_point); _rl_erase_at_end_of_line (l);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -