From: Chet Ramey Date: Fri, 23 Aug 2024 19:19:54 +0000 (-0400) Subject: add bindable readline variable `force-meta-prefix' to allow users to tell readline... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=215d585e5df5faf214e857c26ac4d95d4e9bc8a5;p=thirdparty%2Freadline.git add bindable readline variable `force-meta-prefix' to allow users to tell readline how their Meta key works --- diff --git a/CHANGELOG b/CHANGELOG index 8fd9513..783a097 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1486,3 +1486,9 @@ configure.ac configure.ac - add ncursesw as a possible value for TERMCAP_PKG_CONFIG_LIB, with corresponding changes to aclocal.m4, which is shared with bash + + 7/24 + ---- +configure.ac,Makefile.in + - STYLE_CFLAGS: set like bash if we're using gcc or clang; add to + CCFLAGS so we can compile -Wno-parentheses by default diff --git a/Makefile.in b/Makefile.in index 6c9de8b..00de1df 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,6 +1,6 @@ ## -*- text -*- ## # Master Makefile for the GNU readline library. -# Copyright (C) 1994-2018 Free Software Foundation, Inc. +# Copyright (C) 1994-2024 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -78,6 +78,7 @@ CFLAGS = @CFLAGS@ LOCAL_CFLAGS = @LOCAL_CFLAGS@ -DRL_LIBRARY_VERSION='"$(RL_LIBRARY_VERSION)"' @BRACKETED_PASTE@ CPPFLAGS = @CPPFLAGS@ +STYLE_CFLAGS = @STYLE_CFLAGS@ DEFS = @DEFS@ @CROSS_COMPILE@ LOCAL_DEFS = @LOCAL_DEFS@ @@ -87,7 +88,7 @@ TERMCAP_LIB = @TERMCAP_LIB@ INCLUDES = -I. -I$(srcdir) XCCFLAGS = $(ASAN_CFLAGS) $(DEFS) $(LOCAL_DEFS) $(INCLUDES) $(CPPFLAGS) -CCFLAGS = $(XCCFLAGS) $(LOCAL_CFLAGS) $(CFLAGS) +CCFLAGS = $(XCCFLAGS) $(LOCAL_CFLAGS) $(CFLAGS) $(STYLE_CFLAGS) # could add -Werror here GCC_LINT_FLAGS = -ansi -Wall -Wshadow -Wpointer-arith -Wcast-qual \ @@ -98,6 +99,9 @@ GCC_LINT_CFLAGS = $(XCCFLAGS) $(GCC_LINT_FLAGS) @CFLAGS@ @LOCAL_CFLAGS@ ASAN_XCFLAGS = -fsanitize=address -fno-omit-frame-pointer ASAN_XLDFLAGS = -fsanitize=address +UBSAN_XCFLAGS = -fsanitize=undefined -fsanitize-recover -fstack-protector +UBSAN_XLDFLAGS = -fsanitize=undefined + install_examples = @EXAMPLES_INSTALL_TARGET@ .c.o: diff --git a/bind.c b/bind.c index b4f8004..21cfdf5 100644 --- a/bind.c +++ b/bind.c @@ -98,6 +98,15 @@ static int currently_reading_init_file; /* used only in this file */ static int _rl_prefer_visible_bell = 1; +/* Currently confined to this file for key bindings. If enabled (> 0), we + force meta key bindings to use the meta prefix (ESC). If unset (-1) or + disabled (0), we use the current value of _rl_convert_meta_chars_to_ascii + as in previous readline versions. */ +static int _rl_force_meta_prefix = 0; + +/* Do we want to force binding "\M-C" to the meta prefix (ESC-C)? */ +#define FORCE_META_PREFIX() (_rl_force_meta_prefix > 0 ? 1 : _rl_convert_meta_chars_to_ascii) + #define OP_EQ 1 #define OP_NE 2 #define OP_GT 3 @@ -137,7 +146,7 @@ rl_bind_key (int key, rl_command_func_t *function) return (key); /* Want to make this a multi-character key sequence with an ESC prefix */ - if (META_CHAR (key) && _rl_convert_meta_chars_to_ascii) + if (META_CHAR (key) && FORCE_META_PREFIX()) { if (_rl_keymap[ESC].type == ISKMAP) { @@ -418,19 +427,8 @@ rl_generic_bind (int type, const char *keyseq, char *data, Keymap map) return -1; } - /* We now rely on rl_translate_keyseq to do this conversion, so this - check is superfluous. */ -#if 0 - if (META_CHAR (ic) && _rl_convert_meta_chars_to_ascii) - { - ic = UNMETA (ic); - if (map[ESC].type == ISKMAP) - { - prevmap = map; - map = FUNCTION_TO_KEYMAP (map, ESC); - } - } -#endif + /* We rely on rl_translate_keyseq to do convert meta-chars to key + sequences with the meta prefix (ESC). */ if ((i + 1) < keys_len) { @@ -617,14 +615,13 @@ rl_translate_keyseq (const char *seq, char *array, int *len) c = (c == '?') ? RUBOUT : CTRL (_rl_to_upper (c)); has_control = 0; } + if (has_meta) - { - c = META (c); - has_meta = 0; - } + c = META (c); - /* If convert-meta is turned on, convert a meta char to a key sequence */ - if (META_CHAR (c) && _rl_convert_meta_chars_to_ascii) + /* If force-meta-prefix is turned on, convert a meta char to a key + sequence, but only if it uses the \M- syntax. */ + if (META_CHAR (c) && has_meta && FORCE_META_PREFIX()) { int x = UNMETA (c); if (x) @@ -638,6 +635,8 @@ rl_translate_keyseq (const char *seq, char *array, int *len) else array[l++] = (c); + has_meta = 0; + /* Null characters may be processed for incomplete prefixes at the end of sequence */ if (seq[i] == '\0') @@ -698,7 +697,7 @@ rl_untranslate_keyseq (int seq) c = UNMETA (c); } - if (c == ESC) + if (c == ESC) /* look at _rl_force_meta_prefix here? */ { kseq[i++] = '\\'; c = 'e'; @@ -805,7 +804,7 @@ _rl_function_of_keyseq_internal (const char *keyseq, size_t len, Keymap map, int { unsigned char ic = keyseq[i]; - if (META_CHAR (ic) && _rl_convert_meta_chars_to_ascii) + if (META_CHAR (ic) && FORCE_META_PREFIX()) /* XXX - might not want this */ { if (map[ESC].type == ISKMAP) { @@ -1888,6 +1887,7 @@ static const struct { { "enable-keypad", &_rl_enable_keypad, 0 }, { "enable-meta-key", &_rl_enable_meta, 0 }, { "expand-tilde", &rl_complete_with_tilde_expansion, 0 }, + { "force-meta-prefix", &_rl_force_meta_prefix, 0 }, { "history-preserve-point", &_rl_history_preserve_point, 0 }, { "horizontal-scroll-mode", &_rl_horizontal_scroll_mode, 0 }, { "input-meta", &_rl_meta_flag, 0 }, diff --git a/configure b/configure index 7b78382..eb2c1bf 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.ac for Readline 8.3, version 2.99. +# From configure.ac for Readline 8.3, version 2.101. # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.72 for readline 8.3. # @@ -649,6 +649,7 @@ TERMCAP_PKG_CONFIG_LIB TERMCAP_LIB LIBVERSION ARFLAGS +STYLE_CFLAGS LOCAL_DEFS LOCAL_LDFLAGS LOCAL_CFLAGS @@ -7281,14 +7282,14 @@ if test "x$ac_cv_lib_curses_tgetent" = xyes then : bash_cv_termcap_lib=libcurses else case e in #( - e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for tgetent in -lncurses" >&5 -printf %s "checking for tgetent in -lncurses... " >&6; } -if test ${ac_cv_lib_ncurses_tgetent+y} + e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for tgetent in -lncursesw" >&5 +printf %s "checking for tgetent in -lncursesw... " >&6; } +if test ${ac_cv_lib_ncursesw_tgetent+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_check_lib_save_LIBS=$LIBS -LIBS="-lncurses $LIBS" +LIBS="-lncursesw $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -7312,9 +7313,9 @@ return tgetent (); _ACEOF if ac_fn_c_try_link "$LINENO" then : - ac_cv_lib_ncurses_tgetent=yes + ac_cv_lib_ncursesw_tgetent=yes else case e in #( - e) ac_cv_lib_ncurses_tgetent=no ;; + e) ac_cv_lib_ncursesw_tgetent=no ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ @@ -7322,20 +7323,20 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam \ LIBS=$ac_check_lib_save_LIBS ;; esac fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ncurses_tgetent" >&5 -printf "%s\n" "$ac_cv_lib_ncurses_tgetent" >&6; } -if test "x$ac_cv_lib_ncurses_tgetent" = xyes +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ncursesw_tgetent" >&5 +printf "%s\n" "$ac_cv_lib_ncursesw_tgetent" >&6; } +if test "x$ac_cv_lib_ncursesw_tgetent" = xyes then : - bash_cv_termcap_lib=libncurses + bash_cv_termcap_lib=libncursesw else case e in #( - e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for tgetent in -lncursesw" >&5 -printf %s "checking for tgetent in -lncursesw... " >&6; } -if test ${ac_cv_lib_ncursesw_tgetent+y} + e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for tgetent in -lncurses" >&5 +printf %s "checking for tgetent in -lncurses... " >&6; } +if test ${ac_cv_lib_ncurses_tgetent+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_check_lib_save_LIBS=$LIBS -LIBS="-lncursesw $LIBS" +LIBS="-lncurses $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -7359,9 +7360,9 @@ return tgetent (); _ACEOF if ac_fn_c_try_link "$LINENO" then : - ac_cv_lib_ncursesw_tgetent=yes + ac_cv_lib_ncurses_tgetent=yes else case e in #( - e) ac_cv_lib_ncursesw_tgetent=no ;; + e) ac_cv_lib_ncurses_tgetent=no ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ @@ -7369,11 +7370,11 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam \ LIBS=$ac_check_lib_save_LIBS ;; esac fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ncursesw_tgetent" >&5 -printf "%s\n" "$ac_cv_lib_ncursesw_tgetent" >&6; } -if test "x$ac_cv_lib_ncursesw_tgetent" = xyes +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ncurses_tgetent" >&5 +printf "%s\n" "$ac_cv_lib_ncurses_tgetent" >&6; } +if test "x$ac_cv_lib_ncurses_tgetent" = xyes then : - bash_cv_termcap_lib=libncursesw + bash_cv_termcap_lib=libncurses else case e in #( e) bash_cv_termcap_lib=gnutermcap ;; esac @@ -7413,6 +7414,9 @@ TERMCAP_DEP= elif test $bash_cv_termcap_lib = libtinfo; then TERMCAP_LIB=-ltinfo TERMCAP_DEP= +elif test $bash_cv_termcap_lib = libncursesw; then +TERMCAP_LIB=-lncursesw +TERMCAP_DEP= elif test $bash_cv_termcap_lib = libncurses; then TERMCAP_LIB=-lncurses TERMCAP_DEP= @@ -7453,6 +7457,7 @@ esac case "$TERMCAP_LIB" in -ltinfo) TERMCAP_PKG_CONFIG_LIB=tinfo ;; -lcurses) TERMCAP_PKG_CONFIG_LIB=ncurses ;; +-lncursesw) TERMCAP_PKG_CONFIG_LIB=ncursesw ;; -lncurses) TERMCAP_PKG_CONFIG_LIB=ncurses ;; -ltermcap) TERMCAP_PKG_CONFIG_LIB=termcap ;; *) TERMCAP_PKG_CONFIG_LIB=termcap ;; @@ -8065,6 +8070,7 @@ CFLAGS="$CFLAGS $STYLE_CFLAGS" + ac_config_files="$ac_config_files Makefile doc/Makefile examples/Makefile shlib/Makefile readline.pc history.pc" diff --git a/configure.ac b/configure.ac index 295e13c..1783dae 100644 --- a/configure.ac +++ b/configure.ac @@ -20,7 +20,7 @@ dnl Process this file with autoconf to produce a configure script. # You should have received a copy of the GNU General Public License # along with this program. If not, see . -AC_REVISION([for Readline 8.3, version 2.100]) +AC_REVISION([for Readline 8.3, version 2.101]) AC_INIT(readline, 8.3, bug-readline@gnu.org) @@ -328,6 +328,7 @@ AC_SUBST(CFLAGS) AC_SUBST(LOCAL_CFLAGS) AC_SUBST(LOCAL_LDFLAGS) AC_SUBST(LOCAL_DEFS) +AC_SUBST(STYLE_CFLAGS) AC_SUBST(AR) AC_SUBST(ARFLAGS) diff --git a/doc/history.0 b/doc/history.0 index 7abcb7d..71b0a00 100644 --- a/doc/history.0 +++ b/doc/history.0 @@ -88,7 +88,9 @@ HHIISSTTOORRYY EEXXPPAANNSSIIOONN pand to the zeroth word if there is only one word in the line. %% The first word matched by the most recent "?_s_t_r_i_n_g?" search, if the search string begins with a character that is part of a - word. + word. By default, searches begin at the end of each line and + proceed to the beginning, so the first word matched is the one + closest to the end of the line. _x--_y A range of words; "-_y" abbreviates "0-_y". ** All of the words but the zeroth. This is a synonym for "_1_-_$". It is not an error to use ** if there is just one word in the @@ -513,4 +515,4 @@ BBUUGG RREEPPOORRTTSS Comments and bug reports concerning this manual page should be directed to _c_h_e_t_._r_a_m_e_y_@_c_a_s_e_._e_d_u. -GNU History 8.3 2024 March 29 _H_I_S_T_O_R_Y(3) +GNU History 8.3 2024 August 13 _H_I_S_T_O_R_Y(3) diff --git a/doc/history.3 b/doc/history.3 index af31f1c..481cb2e 100644 --- a/doc/history.3 +++ b/doc/history.3 @@ -6,9 +6,9 @@ .\" Case Western Reserve University .\" chet.ramey@case.edu .\" -.\" Last Change: Fri Mar 29 12:03:51 EDT 2024 +.\" Last Change: Tue Aug 13 14:29:23 EDT 2024 .\" -.TH HISTORY 3 "2024 March 29" "GNU History 8.3" +.TH HISTORY 3 "2024 August 13" "GNU History 8.3" .\" .ie \n(.g \{\ .ds ' \(aq @@ -210,6 +210,9 @@ The first word matched by the most recent .Q ?\fIstring\fP? search, if the search string begins with a character that is part of a word. +By default, searches begin at the end of each line and proceed to the +beginning, so the first word matched is the one closest to the end of +the line. .TP .I x\fB\-\fPy A range of words; diff --git a/doc/history.info b/doc/history.info index b4ffe9a..bed9680 100644 --- a/doc/history.info +++ b/doc/history.info @@ -1,7 +1,7 @@ This is history.info, produced by makeinfo version 7.1 from history.texi. -This document describes the GNU History library (version 8.3, 19 January +This document describes the GNU History library (version 8.3, 13 August 2024), a programming tool that provides a consistent user interface for recalling lines of previously typed input. @@ -196,7 +196,10 @@ spaces. ‘%’ The first word matched by the most recent ‘?STRING?’ search, if the - search string begins with a character that is part of a word. + search string begins with a character that is part of a word. By + default, searches begin at the end of each line and proceed to the + beginning, so the first word matched is the one closest to the end + of the line. ‘X-Y’ A range of words; ‘-Y’ abbreviates ‘0-Y’. @@ -1413,28 +1416,28 @@ Appendix C Function and Variable Index  Tag Table: -Node: Top847 -Node: Using History Interactively1492 -Node: History Interaction2000 -Node: Event Designators4566 -Node: Word Designators6073 -Node: Modifiers8062 -Node: Programming with GNU History9688 -Node: Introduction to History10432 -Node: History Storage12122 -Node: History Functions13261 -Node: Initializing History and State Management14250 -Node: History List Management15062 -Node: Information About the History List17372 -Node: Moving Around the History List19014 -Node: Searching the History List20115 -Node: Managing the History File22044 -Node: History Expansion23924 -Node: History Variables25883 -Node: History Programming Example29915 -Node: GNU Free Documentation License32569 -Node: Concept Index57744 -Node: Function and Variable Index58449 +Node: Top846 +Node: Using History Interactively1491 +Node: History Interaction1999 +Node: Event Designators4565 +Node: Word Designators6072 +Node: Modifiers8227 +Node: Programming with GNU History9853 +Node: Introduction to History10597 +Node: History Storage12287 +Node: History Functions13426 +Node: Initializing History and State Management14415 +Node: History List Management15227 +Node: Information About the History List17537 +Node: Moving Around the History List19179 +Node: Searching the History List20280 +Node: Managing the History File22209 +Node: History Expansion24089 +Node: History Variables26048 +Node: History Programming Example30080 +Node: GNU Free Documentation License32734 +Node: Concept Index57909 +Node: Function and Variable Index58614  End Tag Table diff --git a/doc/history.pdf b/doc/history.pdf index 79a9c2f..6028f63 100644 Binary files a/doc/history.pdf and b/doc/history.pdf differ diff --git a/doc/hsuser.texi b/doc/hsuser.texi index 4c5dc84..106c369 100644 --- a/doc/hsuser.texi +++ b/doc/hsuser.texi @@ -468,6 +468,9 @@ The last argument. @item % The first word matched by the most recent @samp{?@var{string}?} search, if the search string begins with a character that is part of a word. +By default, searches begin at the end of each line and proceed to the +beginning, so the first word matched is the one closest to the end of +the line. @item @var{x}-@var{y} A range of words; @samp{-@var{y}} abbreviates @samp{0-@var{y}}. diff --git a/doc/readline.0 b/doc/readline.0 index c638199..16edc45 100644 --- a/doc/readline.0 +++ b/doc/readline.0 @@ -571,9 +571,11 @@ EEDDIITTIINNGG CCOOMMMMAANNDDSS CCoommmmaannddss ffoorr MMoovviinngg bbeeggiinnnniinngg--ooff--lliinnee ((CC--aa)) - Move to the start of the current line. + Move to the start of the current line. This may also be bound + to the Home key on some keyboards. eenndd--ooff--lliinnee ((CC--ee)) - Move to the end of the line. + Move to the end of the line. This may also be bound to the End + key on some keyboards. ffoorrwwaarrdd--cchhaarr ((CC--ff)) Move forward a character. bbaacckkwwaarrdd--cchhaarr ((CC--bb)) @@ -653,46 +655,48 @@ EEDDIITTIINNGG CCOOMMMMAANNDDSS Search backward through the history for the string of characters between the start of the current line and the current cursor po- sition (the _p_o_i_n_t). The search string must match at the begin- - ning of a history line. This is a non-incremental search. + ning of a history line. This is a non-incremental search. This + may be bound to the Page Up key on some keyboards. hhiissttoorryy--sseeaarrcchh--ffoorrwwaarrdd Search forward through the history for the string of characters between the start of the current line and the point. The search string must match at the beginning of a history line. This is a - non-incremental search. + non-incremental search. This may be bound to the Page Down key + on some keyboards. hhiissttoorryy--ssuubbssttrriinngg--sseeaarrcchh--bbaacckkwwaarrdd Search backward through the history for the string of characters between the start of the current line and the current cursor po- - sition (the _p_o_i_n_t). The search string may match anywhere in a + sition (the _p_o_i_n_t). The search string may match anywhere in a history line. This is a non-incremental search. hhiissttoorryy--ssuubbssttrriinngg--sseeaarrcchh--ffoorrwwaarrdd - Search forward through the history for the string of characters + Search forward through the history for the string of characters between the start of the current line and the point. The search - string may match anywhere in a history line. This is a non-in- + string may match anywhere in a history line. This is a non-in- cremental search. yyaannkk--nntthh--aarrgg ((MM--CC--yy)) - Insert the first argument to the previous command (usually the + Insert the first argument to the previous command (usually the second word on the previous line) at point. With an argument _n, - insert the _nth word from the previous command (the words in the - previous command begin with word 0). A negative argument in- - serts the _nth word from the end of the previous command. Once - the argument _n is computed, the argument is extracted as if the + insert the _nth word from the previous command (the words in the + previous command begin with word 0). A negative argument in- + serts the _nth word from the end of the previous command. Once + the argument _n is computed, the argument is extracted as if the "!_n" history expansion had been specified. yyaannkk--llaasstt--aarrgg ((MM--..,, MM--__)) - Insert the last argument to the previous command (the last word + Insert the last argument to the previous command (the last word of the previous history entry). With a numeric argument, behave - exactly like yyaannkk--nntthh--aarrgg. Successive calls to yyaannkk--llaasstt--aarrgg - move back through the history list, inserting the last word (or - the word specified by the argument to the first call) of each + exactly like yyaannkk--nntthh--aarrgg. Successive calls to yyaannkk--llaasstt--aarrgg + move back through the history list, inserting the last word (or + the word specified by the argument to the first call) of each line in turn. Any numeric argument supplied to these successive - calls determines the direction to move through the history. A - negative argument switches the direction through the history + calls determines the direction to move through the history. A + negative argument switches the direction through the history (back or forward). The history expansion facilities are used to - extract the last argument, as if the "!$" history expansion had + extract the last argument, as if the "!$" history expansion had been specified. CCoommmmaannddss ffoorr CChhaannggiinngg TTeexxtt _e_n_d_-_o_f_-_f_i_l_e ((uussuuaallllyy CC--dd)) - The character indicating end-of-file as set, for example, by + The character indicating end-of-file as set, for example, by _s_t_t_y(1). If this character is read when there are no characters on the line, and point is at the beginning of the line, readline interprets it as the end of input and returns EEOOFF. @@ -701,10 +705,10 @@ EEDDIITTIINNGG CCOOMMMMAANNDDSS same character as the tty EEOOFF character, as CC--dd commonly is, see above for the effects. bbaacckkwwaarrdd--ddeelleettee--cchhaarr ((RRuubboouutt)) - Delete the character behind the cursor. When given a numeric + Delete the character behind the cursor. When given a numeric argument, save the deleted text on the kill ring. ffoorrwwaarrdd--bbaacckkwwaarrdd--ddeelleettee--cchhaarr - Delete the character under the cursor, unless the cursor is at + Delete the character under the cursor, unless the cursor is at the end of the line, in which case the character behind the cur- sor is deleted. qquuootteedd--iinnsseerrtt ((CC--qq,, CC--vv)) @@ -715,33 +719,34 @@ EEDDIITTIINNGG CCOOMMMMAANNDDSS sseellff--iinnsseerrtt ((aa,, bb,, AA,, 11,, !!,, ...)) Insert the character typed. ttrraannssppoossee--cchhaarrss ((CC--tt)) - Drag the character before point forward over the character at - point, moving point forward as well. If point is at the end of - the line, then this transposes the two characters before point. + Drag the character before point forward over the character at + point, moving point forward as well. If point is at the end of + the line, then this transposes the two characters before point. Negative arguments have no effect. ttrraannssppoossee--wwoorrddss ((MM--tt)) - Drag the word before point past the word after point, moving - point over that word as well. If point is at the end of the + Drag the word before point past the word after point, moving + point over that word as well. If point is at the end of the line, this transposes the last two words on the line. uuppccaassee--wwoorrdd ((MM--uu)) - Uppercase the current (or following) word. With a negative ar- + Uppercase the current (or following) word. With a negative ar- gument, uppercase the previous word, but do not move point. ddoowwnnccaassee--wwoorrdd ((MM--ll)) - Lowercase the current (or following) word. With a negative ar- + Lowercase the current (or following) word. With a negative ar- gument, lowercase the previous word, but do not move point. ccaappiittaalliizzee--wwoorrdd ((MM--cc)) Capitalize the current (or following) word. With a negative ar- gument, capitalize the previous word, but do not move point. oovveerrwwrriittee--mmooddee - Toggle overwrite mode. With an explicit positive numeric argu- + Toggle overwrite mode. With an explicit positive numeric argu- ment, switches to overwrite mode. With an explicit non-positive numeric argument, switches to insert mode. This command affects - only eemmaaccss mode; vvii mode does overwrite differently. Each call + only eemmaaccss mode; vvii mode does overwrite differently. Each call to _r_e_a_d_l_i_n_e_(_) starts in insert mode. In overwrite mode, charac- - ters bound to sseellff--iinnsseerrtt replace the text at point rather than - pushing the text to the right. Characters bound to bbaacckk-- - wwaarrdd--ddeelleettee--cchhaarr replace the character before point with a - space. By default, this command is unbound. + ters bound to sseellff--iinnsseerrtt replace the text at point rather than + pushing the text to the right. Characters bound to bbaacckk-- + wwaarrdd--ddeelleettee--cchhaarr replace the character before point with a + space. By default, this command is unbound, but may be bound to + the Insert key on some keyboards. KKiilllliinngg aanndd YYaannkkiinngg kkiillll--lliinnee ((CC--kk)) @@ -749,123 +754,123 @@ EEDDIITTIINNGG CCOOMMMMAANNDDSS bbaacckkwwaarrdd--kkiillll--lliinnee ((CC--xx RRuubboouutt)) Kill backward to the beginning of the line. uunniixx--lliinnee--ddiissccaarrdd ((CC--uu)) - Kill backward from point to the beginning of the line. The + Kill backward from point to the beginning of the line. The killed text is saved on the kill-ring. kkiillll--wwhhoollee--lliinnee - Kill all characters on the current line, no matter where point + Kill all characters on the current line, no matter where point is. kkiillll--wwoorrdd ((MM--dd)) - Kill from point the end of the current word, or if between - words, to the end of the next word. Word boundaries are the + Kill from point the end of the current word, or if between + words, to the end of the next word. Word boundaries are the same as those used by ffoorrwwaarrdd--wwoorrdd. bbaacckkwwaarrdd--kkiillll--wwoorrdd ((MM--RRuubboouutt)) - Kill the word behind point. Word boundaries are the same as + Kill the word behind point. Word boundaries are the same as those used by bbaacckkwwaarrdd--wwoorrdd. uunniixx--wwoorrdd--rruubboouutt ((CC--ww)) - Kill the word behind point, using white space as a word bound- + Kill the word behind point, using white space as a word bound- ary. The killed text is saved on the kill-ring. uunniixx--ffiilleennaammee--rruubboouutt - Kill the word behind point, using white space and the slash - character as the word boundaries. The killed text is saved on + Kill the word behind point, using white space and the slash + character as the word boundaries. The killed text is saved on the kill-ring. ddeelleettee--hhoorriizzoonnttaall--ssppaaccee ((MM--\\)) Delete all spaces and tabs around point. kkiillll--rreeggiioonn - Kill the text between the point and _m_a_r_k (saved cursor posi- + Kill the text between the point and _m_a_r_k (saved cursor posi- tion). This text is referred to as the _r_e_g_i_o_n. ccooppyy--rreeggiioonn--aass--kkiillll Copy the text in the region to the kill buffer. ccooppyy--bbaacckkwwaarrdd--wwoorrdd - Copy the word before point to the kill buffer. The word bound- + Copy the word before point to the kill buffer. The word bound- aries are the same as bbaacckkwwaarrdd--wwoorrdd. ccooppyy--ffoorrwwaarrdd--wwoorrdd - Copy the word following point to the kill buffer. The word + Copy the word following point to the kill buffer. The word boundaries are the same as ffoorrwwaarrdd--wwoorrdd. yyaannkk ((CC--yy)) Yank the top of the kill ring into the buffer at point. yyaannkk--ppoopp ((MM--yy)) - Rotate the kill ring, and yank the new top. Only works follow- + Rotate the kill ring, and yank the new top. Only works follow- ing yyaannkk or yyaannkk--ppoopp. NNuummeerriicc AArrgguummeennttss ddiiggiitt--aarrgguummeenntt ((MM--00,, MM--11,, ...,, MM----)) - Add this digit to the argument already accumulating, or start a + Add this digit to the argument already accumulating, or start a new argument. M-- starts a negative argument. uunniivveerrssaall--aarrgguummeenntt - This is another way to specify an argument. If this command is - followed by one or more digits, optionally with a leading minus - sign, those digits define the argument. If the command is fol- + This is another way to specify an argument. If this command is + followed by one or more digits, optionally with a leading minus + sign, those digits define the argument. If the command is fol- lowed by digits, executing uunniivveerrssaall--aarrgguummeenntt again ends the nu- meric argument, but is otherwise ignored. As a special case, if this command is immediately followed by a character that is nei- ther a digit or minus sign, the argument count for the next com- - mand is multiplied by four. The argument count is initially - one, so executing this function the first time makes the argu- + mand is multiplied by four. The argument count is initially + one, so executing this function the first time makes the argu- ment count four, a second time makes the argument count sixteen, and so on. CCoommpplleettiinngg ccoommpplleettee ((TTAABB)) Attempt to perform completion on the text before point. The ac- - tual completion performed is application-specific. BBaasshh, for - instance, attempts completion treating the text as a variable - (if the text begins with $$), username (if the text begins with - ~~), hostname (if the text begins with @@), or command (including - aliases and functions) in turn. If none of these produces a - match, filename completion is attempted. GGddbb, on the other - hand, allows completion of program functions and variables, and + tual completion performed is application-specific. BBaasshh, for + instance, attempts completion treating the text as a variable + (if the text begins with $$), username (if the text begins with + ~~), hostname (if the text begins with @@), or command (including + aliases and functions) in turn. If none of these produces a + match, filename completion is attempted. GGddbb, on the other + hand, allows completion of program functions and variables, and only attempts filename completion under certain circumstances. ppoossssiibbllee--ccoommpplleettiioonnss ((MM--??)) - List the possible completions of the text before point. When + List the possible completions of the text before point. When displaying completions, readline sets the number of columns used - for display to the value of ccoommpplleettiioonn--ddiissppllaayy--wwiiddtthh, the value - of the environment variable CCOOLLUUMMNNSS, or the screen width, in + for display to the value of ccoommpplleettiioonn--ddiissppllaayy--wwiiddtthh, the value + of the environment variable CCOOLLUUMMNNSS, or the screen width, in that order. iinnsseerrtt--ccoommpplleettiioonnss ((MM--**)) - Insert all completions of the text before point that would have + Insert all completions of the text before point that would have been generated by ppoossssiibbllee--ccoommpplleettiioonnss. mmeennuu--ccoommpplleettee - Similar to ccoommpplleettee, but replaces the word to be completed with - a single match from the list of possible completions. Repeated - execution of mmeennuu--ccoommpplleettee steps through the list of possible - completions, inserting each match in turn. At the end of the + Similar to ccoommpplleettee, but replaces the word to be completed with + a single match from the list of possible completions. Repeated + execution of mmeennuu--ccoommpplleettee steps through the list of possible + completions, inserting each match in turn. At the end of the list of completions, the bell is rung (subject to the setting of bbeellll--ssttyyllee) and the original text is restored. An argument of _n moves _n positions forward in the list of matches; a negative ar- gument may be used to move backward through the list. This com- mand is intended to be bound to TTAABB, but is unbound by default. mmeennuu--ccoommpplleettee--bbaacckkwwaarrdd - Identical to mmeennuu--ccoommpplleettee, but moves backward through the list - of possible completions, as if mmeennuu--ccoommpplleettee had been given a + Identical to mmeennuu--ccoommpplleettee, but moves backward through the list + of possible completions, as if mmeennuu--ccoommpplleettee had been given a negative argument. This command is unbound by default. ddeelleettee--cchhaarr--oorr--lliisstt - Deletes the character under the cursor if not at the beginning - or end of the line (like ddeelleettee--cchhaarr). If at the end of the + Deletes the character under the cursor if not at the beginning + or end of the line (like ddeelleettee--cchhaarr). If at the end of the line, behaves identically to ppoossssiibbllee--ccoommpplleettiioonnss. KKeeyybbooaarrdd MMaaccrrooss ssttaarrtt--kkbbdd--mmaaccrroo ((CC--xx (()) - Begin saving the characters typed into the current keyboard + Begin saving the characters typed into the current keyboard macro. eenndd--kkbbdd--mmaaccrroo ((CC--xx )))) Stop saving the characters typed into the current keyboard macro and store the definition. ccaallll--llaasstt--kkbbdd--mmaaccrroo ((CC--xx ee)) - Re-execute the last keyboard macro defined, by making the char- + Re-execute the last keyboard macro defined, by making the char- acters in the macro appear as if typed at the keyboard. pprriinntt--llaasstt--kkbbdd--mmaaccrroo (()) - Print the last keyboard macro defined in a format suitable for + Print the last keyboard macro defined in a format suitable for the _i_n_p_u_t_r_c file. MMiisscceellllaanneeoouuss rree--rreeaadd--iinniitt--ffiillee ((CC--xx CC--rr)) - Read in the contents of the _i_n_p_u_t_r_c file, and incorporate any + Read in the contents of the _i_n_p_u_t_r_c file, and incorporate any bindings or variable assignments found there. aabboorrtt ((CC--gg)) - Abort the current editing command and ring the terminal's bell + Abort the current editing command and ring the terminal's bell (subject to the setting of bbeellll--ssttyyllee). ddoo--lloowweerrccaassee--vveerrssiioonn ((MM--AA,, MM--BB,, MM--_x,, ...)) - If the metafied character _x is uppercase, run the command that + If the metafied character _x is uppercase, run the command that is bound to the corresponding metafied lowercase character. The behavior is undefined if _x is already lowercase. pprreeffiixx--mmeettaa ((EESSCC)) @@ -873,80 +878,80 @@ EEDDIITTIINNGG CCOOMMMMAANNDDSS uunnddoo ((CC--__,, CC--xx CC--uu)) Incremental undo, separately remembered for each line. rreevveerrtt--lliinnee ((MM--rr)) - Undo all changes made to this line. This is like executing the - uunnddoo command enough times to return the line to its initial + Undo all changes made to this line. This is like executing the + uunnddoo command enough times to return the line to its initial state. ttiillddee--eexxppaanndd ((MM--&&)) Perform tilde expansion on the current word. sseett--mmaarrkk ((CC--@@,, MM--<>)) - Set the mark to the point. If a numeric argument is supplied, + Set the mark to the point. If a numeric argument is supplied, the mark is set to that position. eexxcchhaannggee--ppooiinntt--aanndd--mmaarrkk ((CC--xx CC--xx)) - Swap the point with the mark. The current cursor position is - set to the saved position, and the old cursor position is saved + Swap the point with the mark. The current cursor position is + set to the saved position, and the old cursor position is saved as the mark. cchhaarraacctteerr--sseeaarrcchh ((CC--]])) A character is read and point is moved to the next occurrence of - that character. A negative argument searches for previous oc- + that character. A negative argument searches for previous oc- currences. cchhaarraacctteerr--sseeaarrcchh--bbaacckkwwaarrdd ((MM--CC--]])) - A character is read and point is moved to the previous occur- - rence of that character. A negative argument searches for sub- + A character is read and point is moved to the previous occur- + rence of that character. A negative argument searches for sub- sequent occurrences. sskkiipp--ccssii--sseeqquueennccee - Read enough characters to consume a multi-key sequence such as - those defined for keys like Home and End. Such sequences begin + Read enough characters to consume a multi-key sequence such as + those defined for keys like Home and End. Such sequences begin with a Control Sequence Indicator (CSI), usually ESC-[. If this - sequence is bound to "\[", keys producing such sequences will - have no effect unless explicitly bound to a readline command, - instead of inserting stray characters into the editing buffer. + sequence is bound to "\[", keys producing such sequences will + have no effect unless explicitly bound to a readline command, + instead of inserting stray characters into the editing buffer. This is unbound by default, but usually bound to ESC-[. iinnsseerrtt--ccoommmmeenntt ((MM--##)) - Without a numeric argument, the value of the readline ccoomm-- - mmeenntt--bbeeggiinn variable is inserted at the beginning of the current + Without a numeric argument, the value of the readline ccoomm-- + mmeenntt--bbeeggiinn variable is inserted at the beginning of the current line. If a numeric argument is supplied, this command acts as a - toggle: if the characters at the beginning of the line do not - match the value of ccoommmmeenntt--bbeeggiinn, the value is inserted, other- + toggle: if the characters at the beginning of the line do not + match the value of ccoommmmeenntt--bbeeggiinn, the value is inserted, other- wise the characters in ccoommmmeenntt--bbeeggiinn are deleted from the begin- - ning of the line. In either case, the line is accepted as if a - newline had been typed. The default value of ccoommmmeenntt--bbeeggiinn - makes the current line a shell comment. If a numeric argument + ning of the line. In either case, the line is accepted as if a + newline had been typed. The default value of ccoommmmeenntt--bbeeggiinn + makes the current line a shell comment. If a numeric argument causes the comment character to be removed, the line will be ex- ecuted by the shell. dduummpp--ffuunnccttiioonnss - Print all of the functions and their key bindings to the read- + Print all of the functions and their key bindings to the read- line output stream. If a numeric argument is supplied, the out- - put is formatted in such a way that it can be made part of an + put is formatted in such a way that it can be made part of an _i_n_p_u_t_r_c file. dduummpp--vvaarriiaabblleess - Print all of the settable variables and their values to the - readline output stream. If a numeric argument is supplied, the + Print all of the settable variables and their values to the + readline output stream. If a numeric argument is supplied, the output is formatted in such a way that it can be made part of an _i_n_p_u_t_r_c file. dduummpp--mmaaccrrooss - Print all of the readline key sequences bound to macros and the - strings they output. If a numeric argument is supplied, the + Print all of the readline key sequences bound to macros and the + strings they output. If a numeric argument is supplied, the output is formatted in such a way that it can be made part of an _i_n_p_u_t_r_c file. eemmaaccss--eeddiittiinngg--mmooddee ((CC--ee)) - When in vvii command mode, this causes a switch to eemmaaccss editing + When in vvii command mode, this causes a switch to eemmaaccss editing mode. vvii--eeddiittiinngg--mmooddee ((MM--CC--jj)) - When in eemmaaccss editing mode, this causes a switch to vvii editing + When in eemmaaccss editing mode, this causes a switch to vvii editing mode. DDEEFFAAUULLTT KKEEYY BBIINNDDIINNGGSS - The following is a list of the default emacs and vi bindings. Charac- - ters with the eighth bit set are written as M-, and are re- - ferred to as _m_e_t_a_f_i_e_d characters. The printable ASCII characters not - mentioned in the list of emacs standard bindings are bound to the - sseellff--iinnsseerrtt function, which just inserts the given character into the + The following is a list of the default emacs and vi bindings. Charac- + ters with the eighth bit set are written as M-, and are re- + ferred to as _m_e_t_a_f_i_e_d characters. The printable ASCII characters not + mentioned in the list of emacs standard bindings are bound to the + sseellff--iinnsseerrtt function, which just inserts the given character into the input line. In vi insertion mode, all characters not specifically men- tioned are bound to sseellff--iinnsseerrtt. Characters assigned to signal genera- tion by _s_t_t_y(1) or the terminal driver, such as C-Z or C-C, retain that - function. Upper and lower case metafied characters are bound to the - same function in the emacs mode meta keymap. The remaining characters - are unbound, which causes readline to ring the bell (subject to the + function. Upper and lower case metafied characters are bound to the + same function in the emacs mode meta keymap. The remaining characters + are unbound, which causes readline to ring the bell (subject to the setting of the bbeellll--ssttyyllee variable). EEmmaaccss MMooddee @@ -1162,14 +1167,14 @@ AAUUTTHHOORRSS chet.ramey@case.edu BBUUGG RREEPPOORRTTSS - If you find a bug in rreeaaddlliinnee,, you should report it. But first, you - should make sure that it really is a bug, and that it appears in the + If you find a bug in rreeaaddlliinnee,, you should report it. But first, you + should make sure that it really is a bug, and that it appears in the latest version of the rreeaaddlliinnee library that you have. - Once you have determined that a bug actually exists, mail a bug report - to _b_u_g_-_r_e_a_d_l_i_n_e@_g_n_u_._o_r_g. If you have a fix, you are welcome to mail - that as well! Suggestions and `philosophical' bug reports may be - mailed to _b_u_g_-_r_e_a_d_l_i_n_e@_g_n_u_._o_r_g or posted to the Usenet newsgroup + Once you have determined that a bug actually exists, mail a bug report + to _b_u_g_-_r_e_a_d_l_i_n_e@_g_n_u_._o_r_g. If you have a fix, you are welcome to mail + that as well! Suggestions and `philosophical' bug reports may be + mailed to _b_u_g_-_r_e_a_d_l_i_n_e@_g_n_u_._o_r_g or posted to the Usenet newsgroup ggnnuu..bbaasshh..bbuugg. Comments and bug reports concerning this manual page should be directed @@ -1178,4 +1183,4 @@ BBUUGG RREEPPOORRTTSS BBUUGGSS It's too big and too slow. -GNU Readline 8.3 2024 March 29 _R_E_A_D_L_I_N_E(3) +GNU Readline 8.3 2024 May 11 _R_E_A_D_L_I_N_E(3) diff --git a/doc/readline.3 b/doc/readline.3 index b36333d..3dbc859 100644 --- a/doc/readline.3 +++ b/doc/readline.3 @@ -6,9 +6,9 @@ .\" Case Western Reserve University .\" chet.ramey@case.edu .\" -.\" Last Change: Sat May 11 12:44:56 EDT 2024 +.\" Last Change: Fri Aug 23 09:04:51 EDT 2024 .\" -.TH READLINE 3 "2024 May 11" "GNU Readline 8.3" +.TH READLINE 3 "2024 August 23" "GNU Readline 8.3" .\" .ie \n(.g \{\ .ds ' \(aq @@ -106,17 +106,31 @@ Control keys are denoted by C\-\fIkey\fP, e.g., C\-n means Control\-N. Similarly, .I meta keys are denoted by M\-\fIkey\fP, so M\-x means Meta\-X. -(On keyboards without a -.I meta +.PP +On keyboards without a +.I Meta key, M\-\fIx\fP means ESC \fIx\fP, i.e., press the Escape key then the .I x -key. This makes ESC the \fImeta prefix\fP. +key. +This makes ESC the \fImeta prefix\fP. The combination M\-C\-\fIx\fP means ESC\-Control\-\fIx\fP, or press the Escape key then hold the Control key while pressing the .I x -key.) +key. +.PP +On some keyboards, the Meta key modifier produces meta characters with +the eighth bit (0200) set (you can use the \fBenable\-meta\-key\fP variable +to control whether or not it does this, if the keyboard allows it). +On many others, the terminal or terminal emulator converts the metafied +key to a key sequence beginning with ESC as described in the +preceding paragraph. +.PP +If the \fIMeta\fP key produces a key sequence with the ESC meta prefix, +you can make M-\fIkey\fP key bindings you specify (see +.B "Readline Key Bindings" +below) do the same thing by setting the \fBforce\-meta\-prefix\fP variable. .PP Readline commands may be given numeric .IR arguments , @@ -268,7 +282,8 @@ key sequences is control prefix .TP .B \eM\- -meta prefix +adding the meta prefix or converting the following character to a meta +character, as described below under \fBforce-meta-prefix\fP .TP .B \ee an escape character @@ -486,14 +501,17 @@ on the terminal. A negative value causes readline to never ask. .TP .B convert\-meta (On) -If set to \fBOn\fP, readline will convert characters with the -eighth bit set to an ASCII key sequence -by stripping the eighth bit and prefixing it with an -escape character (in effect, using escape as the \fImeta prefix\fP). -The default is \fIOn\fP, but readline will set it to \fIOff\fP if the -locale contains eight-bit characters. +If set to \fBOn\fP, readline will convert characters it reads +with the eighth bit set to an ASCII key sequence +by stripping the eighth bit and prefixing it with an escape character +(converting the character to have the \fImeta prefix\fP). +The default is \fIOn\fP, but readline will set it to \fIOff\fP +if the locale contains +characters whose encodings may include bytes with the eighth bit set. This variable is dependent on the \fBLC_CTYPE\fP locale category, and may change if the locale is changed. +This variable also affects key bindings; see the description of +\fBforce\-meta\-prefix\fP below. .TP .B disable\-completion (Off) If set to \fBOn\fP, readline will inhibit word completion. Completion @@ -551,13 +569,34 @@ arrow keys. .TP .B enable\-meta\-key (On) When set to \fBOn\fP, readline will try to enable any meta modifier -key the terminal claims to support when it is called. On many terminals, -the meta key is used to send eight-bit characters. +key the terminal claims to support when it is called. +On many terminals, the Meta key is used to send eight-bit characters; +this variable checks for the terminal capability that indicates the +terminal can enable and disable a mode that sets the eighth bit of a +character (0200) if the Meta key is held down when the character is +typed (a meta character). .TP .B expand\-tilde (Off) If set to \fBOn\fP, tilde expansion is performed when readline attempts word completion. .TP +.B force\-meta\-prefix (Off) +If set to \fBOn\fP, readline modifies its behavior when binding key +sequences containing \eM- or Meta- +(see \fBKey Bindings\fP above) by converting a key sequence of the form +\eM-\fIC\fP or Meta-\fIC\fP to the two-character sequence +\fBESC\fP\fIC\fP (adding the meta prefix). +If +.B force\-meta\-prefix +is set to \fBOff\fP (the default), +readline uses the value of the +.B convert\-meta +variable to determine whether to perform this conversion: +if \fBconvert\-meta\fP is \fBOn\fP, +readline performs the conversion described above; +if it is \fBOff\fP, Readline converts \fIC\fP to a meta character by +setting the eighth bit (0200). +.TP .B history\-preserve\-point (Off) If set to \fBOn\fP, the history code attempts to place point at the same location on each history line retrieved with \fBprevious-history\fP @@ -582,11 +621,13 @@ This setting is automatically enabled for terminals of height 1. .B input\-meta (Off) If set to \fBOn\fP, readline will enable eight-bit input (that is, it will not clear the eighth bit in the characters it reads), -regardless of what the terminal claims it can support. The name +regardless of what the terminal claims it can support. +The name .B meta\-flag is a synonym for this variable. -The default is \fIOff\fP, but readline will set it to \fIOn\fP if the -locale contains eight-bit characters. +The default is \fIOff\fP, but readline will set it to \fIOn\fP +if the locale contains +characters whose encodings may include bytes with the eighth bit set. This variable is dependent on the \fBLC_CTYPE\fP locale category, and may change if the locale is changed. .TP @@ -653,8 +694,9 @@ the list. If set to \fBOn\fP, readline will display characters with the eighth bit set directly rather than as a meta-prefixed escape sequence. -The default is \fIOff\fP, but readline will set it to \fIOn\fP if the -locale contains eight-bit characters. +The default is \fIOff\fP, but readline will set it to \fIOn\fP +if the locale contains +characters whose encodings may include bytes with the eighth bit set. This variable is dependent on the \fBLC_CTYPE\fP locale category, and may change if the locale is changed. .TP @@ -1275,7 +1317,7 @@ end of the line (like \fBdelete-char\fP). If at the end of the line, behaves identically to \fBpossible-completions\fP. .PD -.SS Keyboard Macros +.SS "Keyboard Macros" .PD 0 .TP .B start\-kbd\-macro (C\-x (\^) diff --git a/doc/readline.info b/doc/readline.info index 64e7d6c..9713a7e 100644 --- a/doc/readline.info +++ b/doc/readline.info @@ -1,6 +1,6 @@ This is readline.info, produced by makeinfo version 7.1 from rlman.texi. -This manual describes the GNU Readline Library (version 8.3, 19 January +This manual describes the GNU Readline Library (version 8.3, 13 August 2024), a library which aids in the consistency of user interface across discrete programs which provide a command line interface. @@ -1057,10 +1057,12 @@ File: readline.info, Node: Commands For Moving, Next: Commands For History, U ------------------------- ‘beginning-of-line (C-a)’ - Move to the start of the current line. + Move to the start of the current line. This may also be bound to + the Home key on some keyboards. ‘end-of-line (C-e)’ - Move to the end of the line. + Move to the end of the line. This may also be bound to the End key + on some keyboards. ‘forward-char (C-f)’ Move forward a character. @@ -1152,16 +1154,24 @@ File: readline.info, Node: Commands For History, Next: Commands For Text, Pre a string supplied by the user. The search string may match anywhere in a history line. +‘history-search-backward ()’ + Search backward through the history for the string of characters + between the start of the current line and the point. The search + string must match at the beginning of a history line. This is a + non-incremental search. By default, this command is unbound, but + may be bound to the Page Down key on some keyboards. + ‘history-search-forward ()’ Search forward through the history for the string of characters between the start of the current line and the point. The search string must match at the beginning of a history line. This is a - non-incremental search. By default, this command is unbound. + non-incremental search. By default, this command is unbound, but + may be bound to the Page Up key on some keyboards. -‘history-search-backward ()’ +‘history-substring-search-backward ()’ Search backward through the history for the string of characters between the start of the current line and the point. The search - string must match at the beginning of a history line. This is a + string may match anywhere in a history line. This is a non-incremental search. By default, this command is unbound. ‘history-substring-search-forward ()’ @@ -1170,12 +1180,6 @@ File: readline.info, Node: Commands For History, Next: Commands For Text, Pre string may match anywhere in a history line. This is a non-incremental search. By default, this command is unbound. -‘history-substring-search-backward ()’ - Search backward through the history for the string of characters - between the start of the current line and the point. The search - string may match anywhere in a history line. This is a - non-incremental search. By default, this command is unbound. - ‘yank-nth-arg (M-C-y)’ Insert the first argument to the previous command (usually the second word on the previous line) at point. With an argument N, @@ -1294,7 +1298,8 @@ File: readline.info, Node: Commands For Text, Next: Commands For Killing, Pre Characters bound to ‘backward-delete-char’ replace the character before point with a space. - By default, this command is unbound. + By default, this command is unbound, but may be bound to the Insert + key on some keyboards.  File: readline.info, Node: Commands For Killing, Next: Numeric Arguments, Prev: Commands For Text, Up: Bindable Readline Commands @@ -2976,16 +2981,8 @@ changed. if (rl_point >= rl_end) return (0); - if (count < 0) - { - direction = -1; - count = -count; - } - else - direction = 1; - /* Find the end of the range to modify. */ - end = start + (count * direction); + end = start + count; /* Force it to be within range. */ if (end > rl_end) @@ -2996,6 +2993,11 @@ changed. if (start == end) return (0); + /* For positive arguments, put point after the last changed character. For + negative arguments, put point before the last changed character. */ + rl_point = end; + + /* Swap start and end if we are moving backwards */ if (start > end) { int temp = start; @@ -3014,8 +3016,7 @@ changed. else if (_rl_lowercase_p (rl_line_buffer[i])) rl_line_buffer[i] = _rl_to_upper (rl_line_buffer[i]); } - /* Move point to on top of the last character changed. */ - rl_point = (direction == 1) ? end - 1 : start; + return (0); } @@ -3034,7 +3035,6 @@ understands the EOF character or "exit" to exit the program. #include #include #include - #include /* Used for select(2) */ #include @@ -3042,12 +3042,19 @@ understands the EOF character or "exit" to exit the program. #include + #include #include + #include + /* Standard readline include files. */ #include #include + #if !defined (errno) + extern int errno; + #endif + static void cb_linehandler (char *); static void sighandler (int); @@ -4795,13 +4802,13 @@ Function and Variable Index (line 48) * active-region-start-color: Readline Init File Syntax. (line 35) -* backward-char (C-b): Commands For Moving. (line 15) +* backward-char (C-b): Commands For Moving. (line 17) * backward-delete-char (Rubout): Commands For Text. (line 17) * backward-kill-line (C-x Rubout): Commands For Killing. (line 11) * backward-kill-word (M-): Commands For Killing. (line 28) -* backward-word (M-b): Commands For Moving. (line 22) +* backward-word (M-b): Commands For Moving. (line 24) * beginning-of-history (M-<): Commands For History. (line 19) * beginning-of-line (C-a): Commands For Moving. (line 6) @@ -4818,8 +4825,8 @@ Function and Variable Index (line 42) * character-search-backward (M-C-]): Miscellaneous Commands. (line 47) -* clear-display (M-C-l): Commands For Moving. (line 40) -* clear-screen (C-l): Commands For Moving. (line 45) +* clear-display (M-C-l): Commands For Moving. (line 42) +* clear-screen (C-l): Commands For Moving. (line 47) * colored-completion-prefix: Readline Init File Syntax. (line 81) * colored-stats: Readline Init File Syntax. @@ -4881,7 +4888,7 @@ Function and Variable Index * end-of-file (usually C-d): Commands For Text. (line 6) * end-of-history (M->): Commands For History. (line 22) -* end-of-line (C-e): Commands For Moving. (line 9) +* end-of-line (C-e): Commands For Moving. (line 10) * exchange-point-and-mark (C-x C-x): Miscellaneous Commands. (line 37) * execute-named-command (M-x): Miscellaneous Commands. @@ -4889,24 +4896,24 @@ Function and Variable Index * expand-tilde: Readline Init File Syntax. (line 207) * fetch-history (): Commands For History. - (line 102) + (line 104) * forward-backward-delete-char (): Commands For Text. (line 21) -* forward-char (C-f): Commands For Moving. (line 12) +* forward-char (C-f): Commands For Moving. (line 14) * forward-search-history (C-s): Commands For History. (line 32) -* forward-word (M-f): Commands For Moving. (line 18) +* forward-word (M-f): Commands For Moving. (line 20) * history-preserve-point: Readline Init File Syntax. (line 211) * history-search-backward (): Commands For History. - (line 56) -* history-search-forward (): Commands For History. (line 50) +* history-search-forward (): Commands For History. + (line 57) * history-size: Readline Init File Syntax. (line 217) * history-substring-search-backward (): Commands For History. - (line 68) + (line 64) * history-substring-search-forward (): Commands For History. - (line 62) + (line 70) * horizontal-scroll-mode: Readline Init File Syntax. (line 226) * input-meta: Readline Init File Syntax. @@ -4943,13 +4950,13 @@ Function and Variable Index (line 235) * next-history (C-n): Commands For History. (line 16) -* next-screen-line (): Commands For Moving. (line 33) +* next-screen-line (): Commands For Moving. (line 35) * non-incremental-forward-search-history (M-n): Commands For History. (line 44) * non-incremental-reverse-search-history (M-p): Commands For History. (line 38) * operate-and-get-next (C-o): Commands For History. - (line 95) + (line 97) * output-meta: Readline Init File Syntax. (line 304) * overwrite-mode (): Commands For Text. (line 73) @@ -4961,13 +4968,13 @@ Function and Variable Index (line 19) * previous-history (C-p): Commands For History. (line 12) -* previous-screen-line (): Commands For Moving. (line 26) +* previous-screen-line (): Commands For Moving. (line 28) * print-last-kbd-macro (): Keyboard Macros. (line 17) * quoted-insert (C-q or C-v): Commands For Text. (line 26) * re-read-init-file (C-x C-r): Miscellaneous Commands. (line 6) * readline: Basic Behavior. (line 12) -* redraw-current-line (): Commands For Moving. (line 49) +* redraw-current-line (): Commands For Moving. (line 51) * reverse-search-history (C-r): Commands For History. (line 26) * revert-all-at-newline: Readline Init File Syntax. @@ -5309,68 +5316,68 @@ Function and Variable Index * yank (C-y): Commands For Killing. (line 63) * yank-last-arg (M-. or M-_): Commands For History. - (line 83) + (line 85) * yank-nth-arg (M-C-y): Commands For History. - (line 74) + (line 76) * yank-pop (M-y): Commands For Killing. (line 66)  Tag Table: -Node: Top863 -Node: Command Line Editing1588 -Node: Introduction and Notation2240 -Node: Readline Interaction3888 -Node: Readline Bare Essentials5080 -Node: Readline Movement Commands6902 -Node: Readline Killing Commands7903 -Node: Readline Arguments9885 -Node: Searching10946 -Node: Readline Init File13145 -Node: Readline Init File Syntax14321 -Node: Conditional Init Constructs38971 -Node: Sample Init File43340 -Node: Bindable Readline Commands46465 -Node: Commands For Moving47536 -Node: Commands For History49339 -Node: Commands For Text54391 -Node: Commands For Killing58186 -Node: Numeric Arguments60655 -Node: Commands For Completion61811 -Node: Keyboard Macros63844 -Node: Miscellaneous Commands64549 -Node: Readline vi Mode68928 -Node: Programming with GNU Readline70797 -Node: Basic Behavior71783 -Node: Custom Functions75769 -Node: Readline Typedefs77288 -Node: Function Writing79014 -Node: Readline Variables80332 -Node: Readline Convenience Functions94832 -Node: Function Naming95908 -Node: Keymaps97178 -Node: Binding Keys100285 -Node: Associating Function Names and Bindings104889 -Node: Allowing Undoing108530 -Node: Redisplay111152 -Node: Modifying Text115307 -Node: Character Input116558 -Node: Terminal Management119707 -Node: Utility Functions121566 -Node: Miscellaneous Functions124962 -Node: Alternate Interface128686 -Node: A Readline Example131476 -Node: Alternate Interface Example133427 -Node: Readline Signal Handling136959 -Node: Custom Completers146500 -Node: How Completing Works147220 -Node: Completion Functions150595 -Node: Completion Variables154265 -Node: A Short Completion Example171897 -Node: GNU Free Documentation License184570 -Node: Concept Index209747 -Node: Function and Variable Index211268 +Node: Top862 +Node: Command Line Editing1587 +Node: Introduction and Notation2239 +Node: Readline Interaction3887 +Node: Readline Bare Essentials5079 +Node: Readline Movement Commands6901 +Node: Readline Killing Commands7902 +Node: Readline Arguments9884 +Node: Searching10945 +Node: Readline Init File13144 +Node: Readline Init File Syntax14320 +Node: Conditional Init Constructs38970 +Node: Sample Init File43339 +Node: Bindable Readline Commands46464 +Node: Commands For Moving47535 +Node: Commands For History49465 +Node: Commands For Text54639 +Node: Commands For Killing58493 +Node: Numeric Arguments60962 +Node: Commands For Completion62118 +Node: Keyboard Macros64151 +Node: Miscellaneous Commands64856 +Node: Readline vi Mode69235 +Node: Programming with GNU Readline71104 +Node: Basic Behavior72090 +Node: Custom Functions76076 +Node: Readline Typedefs77595 +Node: Function Writing79321 +Node: Readline Variables80639 +Node: Readline Convenience Functions95139 +Node: Function Naming96215 +Node: Keymaps97485 +Node: Binding Keys100592 +Node: Associating Function Names and Bindings105196 +Node: Allowing Undoing108837 +Node: Redisplay111459 +Node: Modifying Text115614 +Node: Character Input116865 +Node: Terminal Management120014 +Node: Utility Functions121873 +Node: Miscellaneous Functions125269 +Node: Alternate Interface128993 +Node: A Readline Example131783 +Node: Alternate Interface Example133710 +Node: Readline Signal Handling137329 +Node: Custom Completers146870 +Node: How Completing Works147590 +Node: Completion Functions150965 +Node: Completion Variables154635 +Node: A Short Completion Example172267 +Node: GNU Free Documentation License184940 +Node: Concept Index210117 +Node: Function and Variable Index211638  End Tag Table diff --git a/doc/rltech.texi b/doc/rltech.texi index 56519d5..0aa73ef 100644 --- a/doc/rltech.texi +++ b/doc/rltech.texi @@ -496,7 +496,7 @@ setting @var{rl_input_available_hook} as well. @end deftypevar @deftypevar {rl_voidfunc_t *} rl_redisplay_function -If non-zero, Readline will call indirectly through this pointer +Readline will call indirectly through this pointer to update the display with the current contents of the editing buffer. By default, it is set to @code{rl_redisplay}, the default Readline redisplay function (@pxref{Redisplay}). diff --git a/doc/rluser.texi b/doc/rluser.texi index bc57ccf..5bcbaa2 100644 --- a/doc/rluser.texi +++ b/doc/rluser.texi @@ -91,7 +91,7 @@ is depressed. The text @kbd{M-k} is read as `Meta-K' and describes the character produced when the Meta key (if you have one) is depressed, and the @key{k} -key is pressed. +key is pressed (a @dfn{meta character}). The Meta key is labeled @key{ALT} on many keyboards. On keyboards with two keys labeled @key{ALT} (usually to either side of the space bar), the @key{ALT} on the left side is generally set to @@ -100,13 +100,22 @@ The @key{ALT} key on the right may also be configured to work as a Meta key or may be configured as some other modifier, such as a Compose key for typing accented characters. +On some keyboards, the Meta key modifier produces meta characters with +the eighth bit (0200) set (you can use the @code{enable-meta-key} variable +to control whether or not it does this, if the keyboard allows it). +On many others, the terminal or terminal emulator converts the metafied +key to a key sequence beginning with @key{ESC} as described in the +next paragraph. + If you do not have a Meta or @key{ALT} key, or another key working as -a Meta key, the identical keystroke can be generated by typing @key{ESC} +a Meta key, you can generally achieve the latter effect by typing @key{ESC} @emph{first}, and then typing @key{k}. +The @key{ESC} character is known as the @dfn{meta prefix}). + Either process is known as @dfn{metafying} the @key{k} key. The text @kbd{M-C-k} is read as `Meta-Control-k' and describes the -character produced by @dfn{metafying} @kbd{C-k}. +character produced by metafying @kbd{C-k}. In addition, several keys have their own names. Specifically, @key{DEL}, @key{ESC}, @key{LFD}, @key{SPC}, @key{RET}, and @key{TAB} all @@ -541,15 +550,17 @@ The default limit is @code{100}. @item convert-meta @vindex convert-meta -If set to @samp{on}, Readline will convert characters with the -eighth bit set to an @sc{ascii} key sequence by stripping the eighth -bit and prefixing an @key{ESC} character, converting them to a -meta-prefixed key sequence. -The default value is @samp{on}, but -will be set to @samp{off} if the locale is one that contains -eight-bit characters. +If set to @samp{on}, Readline will convert characters it reads +with the eighth bit set to an @sc{ascii} key sequence +by stripping the eighth bit and prefixing an @key{ESC} character, +converting them to a meta-prefixed key sequence. +The default value is @samp{on}, but Readline will set it to @samp{off} +if the locale contains +characters whose encodings may include bytes with the eighth bit set. This variable is dependent on the @code{LC_CTYPE} locale category, and may change if the locale is changed. +This variable also affects key bindings; see the description of +@code{force-meta-prefix} below. @item disable-completion @vindex disable-completion @@ -615,8 +626,12 @@ arrow keys. The default is @samp{off}. @item enable-meta-key When set to @samp{on}, Readline will try to enable any meta modifier -key the terminal claims to support when it is called. On many terminals, -the meta key is used to send eight-bit characters. +key the terminal claims to support when it is called. +On many terminals, the Meta key is used to send eight-bit characters; +this variable checks for the terminal capability that indicates the +terminal can enable and disable a mode that sets the eighth bit of a +character (0200) if the Meta key is held down when the character is +typed (a meta character). The default is @samp{on}. @item expand-tilde @@ -624,6 +639,22 @@ The default is @samp{on}. If set to @samp{on}, tilde expansion is performed when Readline attempts word completion. The default is @samp{off}. +@item force-meta-prefix +@vindex force-meta-prefix +If set to @samp{on}, Readline modifies its behavior when binding key +sequences containing @kbd{\M-} or @code{Meta-} +(@pxref{Key Bindings}) by converting a key sequence of the form +@kbd{\M-}@var{C} or @code{Meta-}@var{C} to the two-character sequence +@kbd{ESC}@var{C} (adding the meta prefix). +If @code{force-meta-prefix} is set to @samp{off} (the default), +Readline uses the value of the @code{convert-meta} variable to determine +whether to perform this conversion: +if @code{convert-meta} is @samp{on}, +Readline performs the conversion described above; +if it is @samp{off}, Readline converts @var{C} to a meta character by +setting the eighth bit (0200). +The default is @samp{off}. + @item history-preserve-point @vindex history-preserve-point If set to @samp{on}, the history code attempts to place the point (the @@ -657,8 +688,9 @@ By default, this variable is set to @samp{off}. If set to @samp{on}, Readline will enable eight-bit input (it will not clear the eighth bit in the characters it reads), regardless of what the terminal claims it can support. The -default value is @samp{off}, but Readline will set it to @samp{on} if the -locale contains eight-bit characters. +default value is @samp{off}, but Readline will set it to @samp{on} +if the locale contains +characters whose encodings may include bytes with the eighth bit set. The name @code{meta-flag} is a synonym for this variable. This variable is dependent on the @code{LC_CTYPE} locale category, and may change if the locale is changed. @@ -742,8 +774,9 @@ the list. The default is @samp{off}. If set to @samp{on}, Readline will display characters with the eighth bit set directly rather than as a meta-prefixed escape sequence. -The default is @samp{off}, but Readline will set it to @samp{on} if the -locale contains eight-bit characters. +The default is @samp{off}, but Readline will set it to @samp{on} +if the locale contains +characters whose encodings may include bytes with the eighth bit set. This variable is dependent on the @code{LC_CTYPE} locale category, and may change if the locale is changed. @@ -929,7 +962,9 @@ specifying key sequences: @item @kbd{\C-} control prefix @item @kbd{\M-} -meta prefix +adding the meta prefix or converting the following character to a meta +character, as described above under @code{force-meta-prefix} +(@pxref{Variable Settings}). @item @kbd{\e} an escape character @item @kbd{\\} diff --git a/doc/rluserman.info b/doc/rluserman.info index e432a35..f09c65e 100644 --- a/doc/rluserman.info +++ b/doc/rluserman.info @@ -2,7 +2,7 @@ This is rluserman.info, produced by makeinfo version 7.1 from rluserman.texi. This manual describes the end user interface of the GNU Readline Library -(version 8.3, 19 January 2024), a library which aids in the consistency +(version 8.3, 13 August 2024), a library which aids in the consistency of user interface across discrete programs which provide a command line interface. @@ -1055,10 +1055,12 @@ File: rluserman.info, Node: Commands For Moving, Next: Commands For History, ------------------------- ‘beginning-of-line (C-a)’ - Move to the start of the current line. + Move to the start of the current line. This may also be bound to + the Home key on some keyboards. ‘end-of-line (C-e)’ - Move to the end of the line. + Move to the end of the line. This may also be bound to the End key + on some keyboards. ‘forward-char (C-f)’ Move forward a character. @@ -1150,16 +1152,24 @@ File: rluserman.info, Node: Commands For History, Next: Commands For Text, Pr a string supplied by the user. The search string may match anywhere in a history line. +‘history-search-backward ()’ + Search backward through the history for the string of characters + between the start of the current line and the point. The search + string must match at the beginning of a history line. This is a + non-incremental search. By default, this command is unbound, but + may be bound to the Page Down key on some keyboards. + ‘history-search-forward ()’ Search forward through the history for the string of characters between the start of the current line and the point. The search string must match at the beginning of a history line. This is a - non-incremental search. By default, this command is unbound. + non-incremental search. By default, this command is unbound, but + may be bound to the Page Up key on some keyboards. -‘history-search-backward ()’ +‘history-substring-search-backward ()’ Search backward through the history for the string of characters between the start of the current line and the point. The search - string must match at the beginning of a history line. This is a + string may match anywhere in a history line. This is a non-incremental search. By default, this command is unbound. ‘history-substring-search-forward ()’ @@ -1168,12 +1178,6 @@ File: rluserman.info, Node: Commands For History, Next: Commands For Text, Pr string may match anywhere in a history line. This is a non-incremental search. By default, this command is unbound. -‘history-substring-search-backward ()’ - Search backward through the history for the string of characters - between the start of the current line and the point. The search - string may match anywhere in a history line. This is a - non-incremental search. By default, this command is unbound. - ‘yank-nth-arg (M-C-y)’ Insert the first argument to the previous command (usually the second word on the previous line) at point. With an argument N, @@ -1292,7 +1296,8 @@ File: rluserman.info, Node: Commands For Text, Next: Commands For Killing, Pr Characters bound to ‘backward-delete-char’ replace the character before point with a space. - By default, this command is unbound. + By default, this command is unbound, but may be bound to the Insert + key on some keyboards.  File: rluserman.info, Node: Commands For Killing, Next: Numeric Arguments, Prev: Commands For Text, Up: Bindable Readline Commands @@ -2062,30 +2067,30 @@ their use in free software.  Tag Table: -Node: Top906 -Node: Command Line Editing1428 -Node: Introduction and Notation2082 -Node: Readline Interaction3731 -Node: Readline Bare Essentials4924 -Node: Readline Movement Commands6747 -Node: Readline Killing Commands7749 -Node: Readline Arguments9732 -Node: Searching10794 -Node: Readline Init File12994 -Node: Readline Init File Syntax14171 -Node: Conditional Init Constructs38822 -Node: Sample Init File43192 -Node: Bindable Readline Commands46318 -Node: Commands For Moving47390 -Node: Commands For History49194 -Node: Commands For Text54247 -Node: Commands For Killing58043 -Node: Numeric Arguments60513 -Node: Commands For Completion61670 -Node: Keyboard Macros63704 -Node: Miscellaneous Commands64410 -Node: Readline vi Mode68790 -Node: GNU Free Documentation License69756 +Node: Top905 +Node: Command Line Editing1427 +Node: Introduction and Notation2081 +Node: Readline Interaction3730 +Node: Readline Bare Essentials4923 +Node: Readline Movement Commands6746 +Node: Readline Killing Commands7748 +Node: Readline Arguments9731 +Node: Searching10793 +Node: Readline Init File12993 +Node: Readline Init File Syntax14170 +Node: Conditional Init Constructs38821 +Node: Sample Init File43191 +Node: Bindable Readline Commands46317 +Node: Commands For Moving47389 +Node: Commands For History49320 +Node: Commands For Text54495 +Node: Commands For Killing58350 +Node: Numeric Arguments60820 +Node: Commands For Completion61977 +Node: Keyboard Macros64011 +Node: Miscellaneous Commands64717 +Node: Readline vi Mode69097 +Node: GNU Free Documentation License70063  End Tag Table diff --git a/doc/version.texi b/doc/version.texi index 9c8540c..9093f37 100644 --- a/doc/version.texi +++ b/doc/version.texi @@ -5,7 +5,7 @@ Copyright (C) 1988-2024 Free Software Foundation, Inc. @set EDITION 8.3 @set VERSION 8.3 -@set UPDATED 11 May 2024 -@set UPDATED-MONTH May 2024 +@set UPDATED 23 August 2024 +@set UPDATED-MONTH August 2024 -@set LASTCHANGE Sat May 11 12:41:28 EDT 2024 +@set LASTCHANGE Fri Aug 23 09:46:18 EDT 2024 diff --git a/examples/._rlwrap-0.46.1.tar.gz b/examples/._rlwrap-0.46.1.tar.gz index 0547919..32794cc 100644 Binary files a/examples/._rlwrap-0.46.1.tar.gz and b/examples/._rlwrap-0.46.1.tar.gz differ diff --git a/histexpand.c b/histexpand.c index 8a28cbd..f67acd7 100644 --- a/histexpand.c +++ b/histexpand.c @@ -1,6 +1,6 @@ /* histexpand.c -- history expansion. */ -/* Copyright (C) 1989-2021,2023 Free Software Foundation, Inc. +/* Copyright (C) 1989-2021,2023-2024 Free Software Foundation, Inc. This file contains the GNU History Library (History), a set of routines for managing the text of previously typed lines. @@ -90,8 +90,7 @@ char history_subst_char = '^'; /* During tokenization, if this character is seen as the first character of a word, then it, and all subsequent characters up to a newline are - ignored. For a Bourne shell, this should be '#'. Bash special cases - the interactive comment character to not be a comment delimiter. */ + ignored. For a Bourne shell, this should be '#'. */ char history_comment_char = '\0'; /* The list of characters which inhibit the expansion of text if found @@ -142,7 +141,7 @@ get_history_event (const char *string, int *caller_index, int delimiting_quote) register char c; HIST_ENTRY *entry; int which, sign, local_index, substring_okay; - _hist_search_func_t *search_func; + int search_flags; char *temp; /* The event can be specified in a number of ways. @@ -270,10 +269,10 @@ get_history_event (const char *string, int *caller_index, int delimiting_quote) FAIL_SEARCH (); } - search_func = substring_okay ? history_search : history_search_prefix; + search_flags = substring_okay ? NON_ANCHORED_SEARCH : ANCHORED_SEARCH; while (1) { - local_index = (*search_func) (temp, -1); + local_index = _hs_history_search (temp, -1, -1, search_flags); if (local_index < 0) FAIL_SEARCH (); diff --git a/histfile.c b/histfile.c index e115922..34c999f 100644 --- a/histfile.c +++ b/histfile.c @@ -745,6 +745,9 @@ history_do_write (const char *filename, int nelements, int overwrite) history_lines_written_to_file = 0; + if (nelements < 0) + return (0); + mode = overwrite ? O_RDWR|O_CREAT|O_TRUNC|O_BINARY : O_RDWR|O_APPEND|O_BINARY; #else mode = overwrite ? O_WRONLY|O_CREAT|O_TRUNC|O_BINARY : O_WRONLY|O_APPEND|O_BINARY; diff --git a/histlib.h b/histlib.h index da8e653..d41b4ea 100644 --- a/histlib.h +++ b/histlib.h @@ -83,8 +83,8 @@ /* internal extern function declarations used by other parts of the library */ /* histsearch.c */ -extern int _hs_history_patsearch (const char *, int, int); -extern int _hs_history_search (const char *, int, int); +extern int _hs_history_patsearch (const char *, int, int, int); +extern int _hs_history_search (const char *, int, int, int); /* history.c */ extern void _hs_replace_history_data (int, histdata_t *, histdata_t *); diff --git a/histsearch.c b/histsearch.c index b43ead1..36c4699 100644 --- a/histsearch.c +++ b/histsearch.c @@ -1,6 +1,6 @@ /* histsearch.c -- searching the history list. */ -/* Copyright (C) 1989, 1992-2009,2017,2021,2023 Free Software Foundation, Inc. +/* Copyright (C) 1989, 1992-2009,2017,2021-2024 Free Software Foundation, Inc. This file contains the GNU History Library (History), a set of routines for managing the text of previously typed lines. @@ -53,23 +53,25 @@ string. */ char *history_search_delimiter_chars = (char *)NULL; -static int history_search_internal (const char *, int, int); +static int history_search_internal (const char *, int, int, int); /* Search the history for STRING, starting at history_offset. - If DIRECTION < 0, then the search is through previous entries, else - through subsequent. If ANCHORED is non-zero, the string must + If LISTDIR < 0, then the search is through previous entries, else + through subsequent. If ANCHORED is non-zero, the string must appear at the beginning of a history line, otherwise, the string - may appear anywhere in the line. If PATSEARCH is non-zero, and fnmatch(3) - is available, fnmatch is used to match the string instead of a simple - string comparison. If IGNORECASE is set, the string comparison is - performed case-insensitively. If the string is found, then + may appear anywhere in the line. If the search is not anchored, LINEDIR + determines how the line is searched: if it is < 0, the search proceeds + from the end of the line to the beginning, otherwise the substring search + starts at the beginning of each history entry. If PATSEARCH is non-zero, + and fnmatch(3) is available, fnmatch is used to match the string instead + of a simple string comparison. If IGNORECASE is set, the string comparison + is performed case-insensitively. If the string is found, then current_history () is the history entry, and the value of this - function is the offset in the line of that history entry that the - string was found in. Otherwise, nothing is changed, and a -1 is - returned. */ + function is the offset in the line of that history entry in which the + string was found. Otherwise, nothing is changed, and a -1 is returned. */ static int -history_search_internal (const char *string, int direction, int flags) +history_search_internal (const char *string, int listdir, int linedir, int flags) { int i, reverse; char *line; @@ -80,7 +82,7 @@ history_search_internal (const char *string, int direction, int flags) HIST_ENTRY **the_history; /* local */ i = history_offset; - reverse = (direction < 0); + reverse = (listdir < 0); anchored = (flags & ANCHORED_SEARCH); #if defined (HAVE_FNMATCH) patsearch = (flags & PATTERN_SEARCH); @@ -157,7 +159,7 @@ history_search_internal (const char *string, int direction, int flags) } /* Do substring search. */ - if (reverse) + if (linedir < 0) /* search backwards from end */ { size_t ll; @@ -240,7 +242,7 @@ history_search_internal (const char *string, int direction, int flags) } int -_hs_history_patsearch (const char *string, int direction, int flags) +_hs_history_patsearch (const char *string, int listdir, int linedir, int flags) { char *pat; size_t len, start; @@ -289,45 +291,48 @@ _hs_history_patsearch (const char *string, int direction, int flags) pat = string; #endif - ret = history_search_internal (pat, direction, flags|PATTERN_SEARCH); + ret = history_search_internal (pat, listdir, linedir, flags|PATTERN_SEARCH); if (pat != string) xfree (pat); return ret; } -/* Do a non-anchored search for STRING through the history in DIRECTION. */ +/* Do a non-anchored search for STRING through the history list in direction + LISTDIR. */ int -history_search (const char *string, int direction) +history_search (const char *string, int listdir) { - return (history_search_internal (string, direction, NON_ANCHORED_SEARCH)); + return (history_search_internal (string, listdir, listdir, NON_ANCHORED_SEARCH)); } -/* Do an anchored search for string through the history in DIRECTION. */ +/* Do an anchored search for string through the history list in direction + LISTDIR. */ int -history_search_prefix (const char *string, int direction) +history_search_prefix (const char *string, int listdir) { - return (history_search_internal (string, direction, ANCHORED_SEARCH)); + return (history_search_internal (string, listdir, listdir, ANCHORED_SEARCH)); } -/* At some point, make this public for users of the history library. */ +/* Perform a history search for STRING, letting the caller specify the flags. + At some point, make this public for users of the history library. */ int -_hs_history_search (const char *string, int direction, int flags) +_hs_history_search (const char *string, int listdir, int linedir, int flags) { - return (history_search_internal (string, direction, flags)); + return (history_search_internal (string, listdir, linedir, flags)); } -/* Search for STRING in the history list. DIR is < 0 for searching - backwards. POS is an absolute index into the history list at - which point to begin searching. */ +/* Search for STRING in the history list. LISTDIR is < 0 for searching + backwards through the list. POS is an absolute index into the history + list where the search should begin. */ int -history_search_pos (const char *string, int dir, int pos) +history_search_pos (const char *string, int listdir, int pos) { int ret, old; old = where_history (); history_set_pos (pos); - if (history_search (string, dir) == -1) + if (history_search (string, listdir) == -1) { history_set_pos (old); return (-1); diff --git a/mbutil.c b/mbutil.c index 8ee47f0..5243fd7 100644 --- a/mbutil.c +++ b/mbutil.c @@ -147,6 +147,61 @@ _rl_utf8_mblen (const char *s, size_t n) return -1; } +static size_t +_rl_utf8_mbstrlen (const char *s) +{ + size_t clen, nc; + int mb_cur_max; + + nc = 0; + mb_cur_max = MB_CUR_MAX; + while (*s && (clen = (size_t)_rl_utf8_mblen(s, mb_cur_max)) != 0) + { + if (MB_INVALIDCH (clen)) + clen = 1; + s += clen; + nc++; + } + return nc; +} + +static size_t +_rl_gen_mbstrlen (const char *s) +{ + size_t clen, nc; + mbstate_t mbs = { 0 }, mbsbak = { 0 }; + int f, mb_cur_max; + + nc = 0; + mb_cur_max = MB_CUR_MAX; + while (*s && (clen = (f = _rl_is_basic (*s)) ? 1 : mbrlen(s, mb_cur_max, &mbs)) != 0) + { + if (MB_INVALIDCH(clen)) + { + clen = 1; /* assume single byte */ + mbs = mbsbak; + } + + if (f == 0) + mbsbak = mbs; + + s += clen; + nc++; + } + return nc; +} + +size_t +_rl_mbstrlen (const char *s) +{ + if (MB_CUR_MAX == 1) + return (strlen (s)); + else if (_rl_utf8locale) + return (_rl_utf8_mbstrlen (s)); + else + return (_rl_gen_mbstrlen (s)); +} + static int _rl_find_next_mbchar_internal (const char *string, int seed, int count, int find_non_zero) { @@ -567,7 +622,7 @@ _rl_mb_strcaseeqn (const char *s1, size_t l1, const char *s2, size_t l2, size_t s2 += v1; n -= v1; if ((flags & 1) && (wc1 == L'-' || wc1 == L'_') && (wc2 == L'-' || wc2 == L'_')) - continue; + continue; if (wc1 != wc2) return 0; } diff --git a/readline.c b/readline.c index 9790909..c58328a 100644 --- a/readline.c +++ b/readline.c @@ -543,7 +543,11 @@ _rl_internal_char_cleanup (void) rl_vi_check (); #endif /* VI_MODE */ +#if defined (HANDLE_MULTIBYTE) + if (rl_num_chars_to_read && _rl_mbstrlen (rl_line_buffer) >= rl_num_chars_to_read) +#else if (rl_num_chars_to_read && rl_end >= rl_num_chars_to_read) +#endif { (*rl_redisplay_function) (); _rl_want_redisplay = 0; diff --git a/rlmbutil.h b/rlmbutil.h index 9aa6170..9eefa88 100644 --- a/rlmbutil.h +++ b/rlmbutil.h @@ -109,6 +109,8 @@ extern int _rl_find_next_mbchar (const char *, int, int, int); #ifdef HANDLE_MULTIBYTE +extern size_t _rl_mbstrlen (const char *); + extern int _rl_compare_chars (const char *, int, mbstate_t *, const char *, int, mbstate_t *); extern int _rl_get_char_len (const char *, mbstate_t *); extern int _rl_adjust_point (const char *, int, mbstate_t *); @@ -232,4 +234,102 @@ _rl_wcwidth (WCHAR_T wc) extern int rl_byte_oriented; +/* Snagged from gnulib */ +#ifdef HANDLE_MULTIBYTE +#ifdef __cplusplus +extern "C" { +#endif + +/* is_basic(c) tests whether the single-byte character c is + - in the ISO C "basic character set" or is one of '@', '$', and '`' + which ISO C 23 § 5.2.1.1.(1) guarantees to be single-byte and in + practice are safe to treat as basic in the execution character set, + or + - in the POSIX "portable character set", which + + equally guarantees to be single-byte. */ + +#if (' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ + && ('$' == 36) && ('%' == 37) && ('&' == 38) && ('\'' == 39) \ + && ('(' == 40) && (')' == 41) && ('*' == 42) && ('+' == 43) \ + && (',' == 44) && ('-' == 45) && ('.' == 46) && ('/' == 47) \ + && ('0' == 48) && ('1' == 49) && ('2' == 50) && ('3' == 51) \ + && ('4' == 52) && ('5' == 53) && ('6' == 54) && ('7' == 55) \ + && ('8' == 56) && ('9' == 57) && (':' == 58) && (';' == 59) \ + && ('<' == 60) && ('=' == 61) && ('>' == 62) && ('?' == 63) \ + && ('@' == 64) && ('A' == 65) && ('B' == 66) && ('C' == 67) \ + && ('D' == 68) && ('E' == 69) && ('F' == 70) && ('G' == 71) \ + && ('H' == 72) && ('I' == 73) && ('J' == 74) && ('K' == 75) \ + && ('L' == 76) && ('M' == 77) && ('N' == 78) && ('O' == 79) \ + && ('P' == 80) && ('Q' == 81) && ('R' == 82) && ('S' == 83) \ + && ('T' == 84) && ('U' == 85) && ('V' == 86) && ('W' == 87) \ + && ('X' == 88) && ('Y' == 89) && ('Z' == 90) && ('[' == 91) \ + && ('\\' == 92) && (']' == 93) && ('^' == 94) && ('_' == 95) \ + && ('`' == 96) && ('a' == 97) && ('b' == 98) && ('c' == 99) \ + && ('d' == 100) && ('e' == 101) && ('f' == 102) && ('g' == 103) \ + && ('h' == 104) && ('i' == 105) && ('j' == 106) && ('k' == 107) \ + && ('l' == 108) && ('m' == 109) && ('n' == 110) && ('o' == 111) \ + && ('p' == 112) && ('q' == 113) && ('r' == 114) && ('s' == 115) \ + && ('t' == 116) && ('u' == 117) && ('v' == 118) && ('w' == 119) \ + && ('x' == 120) && ('y' == 121) && ('z' == 122) && ('{' == 123) \ + && ('|' == 124) && ('}' == 125) && ('~' == 126) +/* The character set is ISO-646, not EBCDIC. */ +# define IS_BASIC_ASCII 1 + +/* All locale encodings (see localcharset.h) map the characters 0x00..0x7F + to U+0000..U+007F, like ASCII, except for + CP864 different mapping of '%' + SHIFT_JIS different mappings of 0x5C, 0x7E + JOHAB different mapping of 0x5C + However, these characters in the range 0x20..0x7E are in the ISO C + "basic character set" and in the POSIX "portable character set", which + ISO C and POSIX guarantee to be single-byte. Thus, locales with these + encodings are not POSIX compliant. And they are most likely not in use + any more (as of 2023). */ +# define _rl_is_basic(c) ((unsigned char) (c) < 0x80) + +#else + +static inline int +_rl_is_basic (char c) +{ + switch (c) + { + case '\0': + case '\007': case '\010': + case '\t': case '\n': case '\v': case '\f': case '\r': + case ' ': case '!': case '"': case '#': case '$': case '%': + case '&': case '\'': case '(': case ')': case '*': + case '+': case ',': case '-': case '.': case '/': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case ':': case ';': case '<': case '=': case '>': + case '?': case '@': + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': case 'G': case 'H': case 'I': case 'J': + case 'K': case 'L': case 'M': case 'N': case 'O': + case 'P': case 'Q': case 'R': case 'S': case 'T': + case 'U': case 'V': case 'W': case 'X': case 'Y': + case 'Z': + case '[': case '\\': case ']': case '^': case '_': case '`': + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': case 'g': case 'h': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'o': + case 'p': case 'q': case 'r': case 's': case 't': + case 'u': case 'v': case 'w': case 'x': case 'y': + case 'z': case '{': case '|': case '}': case '~': + return 1; + default: + return 0; + } +} + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* HANDLE_MULTIBYTE */ + #endif /* _RL_MBUTIL_H_ */ diff --git a/search.c b/search.c index 96bb83a..d7a441e 100644 --- a/search.c +++ b/search.c @@ -174,12 +174,12 @@ noninc_search_from_pos (char *string, int pos, int dir, int flags, int *ncp) } if (flags & SF_PATTERN) - ret = _hs_history_patsearch (s, dir, sflags); + ret = _hs_history_patsearch (s, dir, dir, sflags); else { if (_rl_search_case_fold) sflags |= CASEFOLD_SEARCH; - ret = _hs_history_search (s, dir, sflags); + ret = _hs_history_search (s, dir, dir, sflags); } RL_UNSETSTATE(RL_STATE_SEARCH); diff --git a/signals.c b/signals.c index 706035e..a67f621 100644 --- a/signals.c +++ b/signals.c @@ -279,7 +279,7 @@ _rl_handle_signal (int sig) #if defined (HAVE_POSIX_SIGNALS) /* Unblock any signal(s) blocked above */ if (block_sig) - sigprocmask (SIG_UNBLOCK, &oset, (sigset_t *)NULL); + sigprocmask (SIG_UNBLOCK, &set, &oset); #endif /* We don't have to bother unblocking the signal because we are not