change redisplay to handle some cases where the line consumes more than the number of physical screen lines; add regerror() error messages if regular expression compilation fails; make sure active region readline variables are displayed with bind -v; partial fix for bind -x and commands containing quoting characters

This commit is contained in:
Chet Ramey
2023-07-19 15:33:45 -04:00
parent 7f7ee0e9c6
commit ad39c5c3d7
23 changed files with 2269 additions and 1996 deletions
+42 -5
View File
@@ -2861,9 +2861,16 @@ _rl_macro_dumper_internal (int print_readably, Keymap map, char *prefix)
{
case ISMACR:
keyname = _rl_get_keyname (key);
out = _rl_untranslate_macro_value ((char *)map[key].function, 0);
if (print_readably < 0)
out = savestring ((char *)map[key].function);
else
out = _rl_untranslate_macro_value ((char *)map[key].function, 0);
if (print_readably)
if (print_readably < 0)
fprintf (rl_outstream, "\"%s%s\": %s\n", prefix ? prefix : "",
keyname,
out ? out : "");
else if (print_readably > 0)
fprintf (rl_outstream, "\"%s%s\": \"%s\"\n", prefix ? prefix : "",
keyname,
out ? out : "");
@@ -2926,10 +2933,40 @@ rl_dump_macros (int count, int key)
static char *
_rl_get_string_variable_value (const char *name)
{
static char numbuf[32];
static char numbuf[64];
char *ret;
if (_rl_stricmp (name, "bell-style") == 0)
if (_rl_stricmp (name, "active-region-start-color") == 0)
{
if (_rl_active_region_start_color == 0)
return 0;
ret = _rl_untranslate_macro_value (_rl_active_region_start_color, 0);
if (ret)
{
strncpy (numbuf, ret, sizeof (numbuf) - 1);
xfree (ret);
numbuf[sizeof(numbuf) - 1] = '\0';
}
else
numbuf[0] = '\0';
return numbuf;
}
else if (_rl_stricmp (name, "active-region-end-color") == 0)
{
if (_rl_active_region_end_color == 0)
return 0;
ret = _rl_untranslate_macro_value (_rl_active_region_end_color, 0);
if (ret)
{
strncpy (numbuf, ret, sizeof (numbuf) - 1);
xfree (ret);
numbuf[sizeof(numbuf) - 1] = '\0';
}
else
numbuf[0] = '\0';
return numbuf;
}
else if (_rl_stricmp (name, "bell-style") == 0)
{
switch (_rl_bell_preference)
{
@@ -2963,7 +3000,7 @@ _rl_get_string_variable_value (const char *name)
return (rl_get_keymap_name_from_edit_mode ());
else if (_rl_stricmp (name, "history-size") == 0)
{
sprintf (numbuf, "%d", history_is_stifled() ? history_max_entries : 0);
sprintf (numbuf, "%d", history_is_stifled() ? history_max_entries : -1);
return (numbuf);
}
else if (_rl_stricmp (name, "isearch-terminators") == 0)
+64 -4
View File
@@ -813,6 +813,7 @@ rl_redisplay (void)
char *prompt_this_line;
char cur_face;
int hl_begin, hl_end;
int short_circuit;
int mb_cur_max = MB_CUR_MAX;
#if defined (HANDLE_MULTIBYTE)
WCHAR_T wc;
@@ -1311,9 +1312,54 @@ rl_redisplay (void)
norm_face (INV_LINE_FACE(linenum), INV_LLEN (linenum));
}
/* XXX - experimental new code */
/* Now that _rl_last_v_pos is a logical count, not bounded by the
number of physical screen lines, this is a start at being able
to redisplay lines that consume more than the number of physical
screen lines in more than a simple `move-to-the-next-line' way.
If the new line has more lines than there are physical screen
lines, and the cursor would be off the top of the screen if we
displayed all the new lines, clear the screen without killing
the scrollback buffer, clear out the visible line so we do a
complete redraw, and make the loop break when we have displayed
a physical screen full of lines. Do the same if we are going to
move the cursor to a line that's greater than the number of
physical screen lines when we weren't before.
SHORT_CIRCUIT says where to break the loop. Pretty simple right now. */
short_circuit = -1;
if (inv_botlin >= _rl_screenheight)
{
int extra;
extra = inv_botlin - _rl_screenheight; /* lines off the top */
/* cursor in portion of line that would be off screen or in
the lines that exceed the number of physical screen lines. */
if (cursor_linenum <= extra ||
(cursor_linenum >= _rl_screenheight && _rl_vis_botlin <= _rl_screenheight))
{
if (cursor_linenum <= extra)
short_circuit = _rl_screenheight;
_rl_clear_screen (0);
if (visible_line)
memset (visible_line, 0, line_size);
rl_on_new_line ();
}
/* The cursor is beyond the number of lines that would be off
the top, but we still want to display only the first
_RL_SCREENHEIGHT lines starting at the beginning of the line. */
else if (cursor_linenum > extra && cursor_linenum <= _rl_screenheight &&
_rl_vis_botlin <= _rl_screenheight)
short_circuit = _rl_screenheight;
}
/* For each line in the buffer, do the updating display. */
for (linenum = 0; linenum <= inv_botlin; linenum++)
{
if (short_circuit >= 0 && linenum == short_circuit)
break;
/* This can lead us astray if we execute a program that changes
the locale from a non-multibyte to a multibyte one. */
o_cpos = _rl_last_c_pos;
@@ -1417,7 +1463,7 @@ rl_redisplay (void)
((linenum == _rl_vis_botlin) ? strlen (tt) : _rl_screenwidth);
}
}
_rl_vis_botlin = inv_botlin;
_rl_vis_botlin = (short_circuit >= 0) ? short_circuit : inv_botlin;
/* CHANGED_SCREEN_LINE is set to 1 if we have moved to a
different screen line during this redisplay. */
@@ -2748,8 +2794,6 @@ rl_on_new_line_with_prompt (void)
int
rl_forced_update_display (void)
{
register char *temp;
if (visible_line)
memset (visible_line, 0, line_size);
@@ -2934,9 +2978,25 @@ _rl_move_vert (int to)
{
register int delta, i;
if (_rl_last_v_pos == to || to > _rl_screenheight)
if (_rl_last_v_pos == to)
return;
#if 0
/* If we're being asked to move to a line beyond the screen height, and
we're currently at the last physical line, issue a newline and let the
terminal take care of scrolling the display. */
if (to >= _rl_screenheight)
{
if (_rl_last_v_pos == _rl_screenheight)
{
putc ('\n', rl_outstream);
_rl_cr ();
_rl_last_c_pos = 0;
}
return;
}
#endif
if ((delta = to - _rl_last_v_pos) > 0)
{
for (i = 0; i < delta; i++)
+7 -3
View File
@@ -6,9 +6,9 @@
.\" Case Western Reserve University
.\" chet.ramey@case.edu
.\"
.\" Last Change: Fri Feb 17 10:59:58 EST 2023
.\" Last Change: Mon Jul 17 16:46:23 EDT 2023
.\"
.TH READLINE 3 "2023 February 17" "GNU Readline 8.2"
.TH READLINE 3 "2023 July 17" "GNU Readline 8.3"
.\"
.\" File Name macro. This used to be `.PN', for Path Name,
.\" but Sun doesn't seem to like that very much.
@@ -371,8 +371,12 @@ If set to \fBaudible\fP, readline attempts to ring the terminal's bell.
.TP
.B bind\-tty\-special\-chars (On)
If set to \fBOn\fP (the default), readline attempts to bind the control
characters treated specially by the kernel's terminal driver to their
characters that are
treated specially by the kernel's terminal driver to their
readline equivalents.
These override the default readline bindings described here.
Type \f(CWstty -a\fP at a bash prompt to see your current terminal settings,
including the special control characters (usually \fBcchars\fP).
.TP
.B blink\-matching\-paren (Off)
If set to \fBOn\fP, readline attempts to briefly move the cursor to an
+7 -2
View File
@@ -1348,14 +1348,19 @@ If @var{c} is a number, return the value it represents.
Bind the key sequence @var{keyseq} to invoke the macro @var{macro}.
The binding is performed in @var{map}. When @var{keyseq} is invoked, the
@var{macro} will be inserted into the line. This function is deprecated;
use @code{rl_generic_bind()} instead.
use @code{rl_generic_bind} instead.
@end deftypefun
@deftypefun void rl_macro_dumper (int readable)
Print the key sequences bound to macros and their values, using
the current keymap, to @code{rl_outstream}.
If @var{readable} is non-zero, the list is formatted in such a way
If @var{readable} is greater than zero, the list is formatted in such a way
that it can be made part of an @code{inputrc} file and re-read.
If @var{readable} is less than zero, the list is printed in a
"translated" form that can be used by applications that wish to bind
key sequences directly without calling @code{rl_parse_and_bind}
(e.g., by calling @code{rl_generic_bind}).
@end deftypefun
@deftypefun int rl_variable_bind (const char *variable, const char *value)
+15 -9
View File
@@ -456,8 +456,12 @@ the terminal's bell.
@item bind-tty-special-chars
@vindex bind-tty-special-chars
If set to @samp{on} (the default), Readline attempts to bind the control
characters treated specially by the kernel's terminal driver to their
characters that are
treated specially by the kernel's terminal driver to their
Readline equivalents.
These override the default Readline bindings described here.
Type @samp{stty -a} at a Bash prompt to see your current terminal settings,
including the special control characters (usually @code{cchars}).
@item blink-matching-paren
@vindex blink-matching-paren
@@ -1464,6 +1468,16 @@ moving point past that word as well.
If the insertion point is at the end of the line, this transposes
the last two words on the line.
@ifset BashFeatures
@item shell-transpose-words (M-C-t)
Drag the word before point past the word after point,
moving point past that word as well.
If the insertion point is at the end of the line, this transposes
the last two words on the line.
Word boundaries are the same as @code{shell-forward-word} and
@code{shell-backward-word}.
@end ifset
@item upcase-word (M-u)
Uppercase the current (or following) word. With a negative argument,
uppercase the previous word, but do not move the cursor.
@@ -1534,14 +1548,6 @@ Kill the word behind point.
Word boundaries are the same as @code{shell-backward-word}.
@end ifset
@item shell-transpose-words (M-C-t)
Drag the word before point past the word after point,
moving point past that word as well.
If the insertion point is at the end of the line, this transposes
the last two words on the line.
Word boundaries are the same as @code{shell-forward-word} and
@code{shell-backward-word}.
@item unix-word-rubout (C-w)
Kill the word behind point, using white space as a word boundary.
The killed text is saved on the kill-ring.
+5 -5
View File
@@ -2,10 +2,10 @@
Copyright (C) 1988-2023 Free Software Foundation, Inc.
@end ignore
@set EDITION 8.2
@set VERSION 8.2
@set EDITION 8.3
@set VERSION 8.3
@set UPDATED 15 June 2023
@set UPDATED-MONTH June 2023
@set UPDATED 17 July 2023
@set UPDATED-MONTH July 2023
@set LASTCHANGE Thu Jun 15 14:37:40 EDT 2023
@set LASTCHANGE Mon Jul 17 16:47:01 EDT 2023
+24 -7
View File
@@ -39,24 +39,36 @@
#include "variables.h"
#include "externs.h"
extern int glob_ignore_case, match_ignore_case;
extern int match_ignore_case;
#if defined (ARRAY_VARS)
extern SHELL_VAR *builtin_find_indexed_array (char *, int);
#endif
static char *
strregerror (int err, const regex_t *regex_p)
{
char *str;
size_t size;
size = regerror (err, regex_p, (char *)0, 0);
str = xmalloc (size);
(void)regerror (err, regex_p, str, size);
return str;
}
int
sh_regmatch (const char *string, const char *pattern, int flags)
sh_regmatch (const char *string, const char *pattern, int flags, char **errbuf)
{
regex_t regex = { 0 };
regmatch_t *matches;
int rflags;
int rflags, reg_err;
#if defined (ARRAY_VARS)
SHELL_VAR *rematch;
ARRAY *amatch;
int subexp_ind;
size_t subexp_ind, subexp_len;
char *subexp_str;
int subexp_len;
#endif
int result;
@@ -71,8 +83,12 @@ sh_regmatch (const char *string, const char *pattern, int flags)
rflags |= REG_NOSUB;
#endif
if (regcomp (&regex, pattern, rflags))
return 2; /* flag for printing a warning here. */
if (reg_err = regcomp (&regex, pattern, rflags))
{
if (errbuf)
*errbuf = strregerror (reg_err, &regex);
return 2; /* flag for printing a warning here. */
}
#if defined (ARRAY_VARS)
matches = (regmatch_t *)malloc (sizeof (regmatch_t) * (regex.re_nsub + 1));
@@ -82,6 +98,7 @@ sh_regmatch (const char *string, const char *pattern, int flags)
/* man regexec: NULL PMATCH ignored if NMATCH == 0 */
if (regexec (&regex, string, matches ? regex.re_nsub + 1 : 0, matches, 0))
/* XXX - catch errors and fill in *errbuf here? */
result = EXECUTION_FAILURE;
else
result = EXECUTION_SUCCESS; /* match */