From: Chet Ramey Date: Thu, 21 Nov 2024 15:31:38 +0000 (-0500) Subject: new readline command `export-completions'; update documentation; update translations... X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=22417e78816237ae66f2da661567dfe5ed3452a1;p=thirdparty%2Fbash.git new readline command `export-completions'; update documentation; update translations with new strings; Makefile updates --- diff --git a/CHANGES b/CHANGES index dbbb40bc..4e6f2da9 100644 --- a/CHANGES +++ b/CHANGES @@ -53,7 +53,9 @@ q. Bash doesn't try to give the terminal back to the original process group r. Fix to inhibit fork optimizations in functions that set a RETURN trap. s. Fixes for parsing commands within process substitutions where they should - behave differently than command substitutions. + behave differently than command substitutions, including prohibiting the + special case for redirections that is only available for command + substitutions. t. Restrict the effect of force_fignore to the cases where FIGNORE should affect completions. diff --git a/CHANGES-5.3 b/CHANGES-5.3 index 2e15fa6b..7afd65b2 100644 --- a/CHANGES-5.3 +++ b/CHANGES-5.3 @@ -53,7 +53,9 @@ q. Bash doesn't try to give the terminal back to the original process group r. Fix to inhibit fork optimizations in functions that set a RETURN trap. s. Fixes for parsing commands within process substitutions where they should - behave differently than command substitutions. + behave differently than command substitutions, including prohibiting the + special case for redirections that is only available for command + substitutions. t. Restrict the effect of force_fignore to the cases where FIGNORE should affect completions. diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 2f4245b8..025ec9dd 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -10650,3 +10650,43 @@ Makefile.in,doc/Makefile.in ----- CHANGES,NEWS - updated for bash-5.3-beta + + 11/15 + ----- +lib/sh/snprintf.c + - wchars: fix small memory leak by freeing lbuf if wcrtomb fails + Report from SerGoGubarev + +lib/readline/complete.c + - vector_len: an inline convenience function to return the length + of an array of strings; callers are remove_duplicate_matches, + rl_old_menu_complete, rl_menu_complete + - rl_complete_internal: add `$' as a value for what_to_do that + exports a (possibly null) list of possible completions to an + application or another process by writing them, using a specific + protocol, to rl_outstream + - rl_export_completions: bindable command to perform word completion + and write the results, with other information, to rl_outstream + - _rl_export_completions: workhorse function to export the completions + Based on a patch from Matthew Tromp , + original request from Spencer Baugh back in 11/23 + +lib/readline/readline.h + - rl_export_completions: extern declaration + +lib/readline/funmap.c + - export-completions: new bindable command name + +doc/bash.1,lib/readline/doc/readline.3,lib/readline/doc/rluser.texi + - export-completions: document, including output format + + 11/19 + ----- +Makefile.in + - HYBRID_HEADERS: new variable containing header files that may appear + in the build directory or the source directory + - maybe-install-headers: rule to install header files that may appear + in the build directory or a subdirectory of it; install-headers + depends on it + - uninstall-headers: remove $(HYBRID_HEADERS); fix typo in recipe + diff --git a/Makefile.in b/Makefile.in index 174a2772..9685b852 100644 --- a/Makefile.in +++ b/Makefile.in @@ -500,7 +500,10 @@ INSTALLED_HEADERS = shell.h bashjmp.h command.h syntax.h general.h error.h \ bashtypes.h xmalloc.h config-top.h config-bot.h \ bashintl.h bashansi.h bashjmp.h alias.h hashlib.h \ conftypes.h unwind_prot.h jobs.h siglist.h \ - execute_cmd.h y.tab.h + execute_cmd.h +# these can appear in either the source directory or the build directory and +# are installed by install-headers +HYBRID_HEADERS = y.tab.h INSTALLED_BUILTINS_HEADERS = bashgetopt.h common.h getopt.h INSTALLED_INCLUDE_HEADERS = posixstat.h ansi_stdlib.h filecntl.h posixdir.h \ memalloc.h stdc.h posixjmp.h posixwait.h posixtime.h systimes.h \ @@ -929,7 +932,20 @@ install-headers-dirs: @${SHELL} $(SUPPORT_SRC)mkinstalldirs $(DESTDIR)$(headersdir)/include @${SHELL} $(SUPPORT_SRC)mkinstalldirs $(DESTDIR)$(pkgconfigdir) -install-headers: install-headers-dirs +maybe-install-headers: install-headers-dirs + @for hf in $(HYBRID_HEADERS) ; do \ + if test -f $(BUILD_DIR)/"$$hf" ; then \ + ${INSTALL_DATA} $(BUILD_DIR)/"$$hf" $(DESTDIR)$(headersdir)/$$hf || exit 1; \ + else \ + ${INSTALL_DATA} $(srcdir)/"$$hf" $(DESTDIR)$(headersdir)/$$hf || exit 1; \ + fi ; \ + done + @SDH=${CREATED_SUBDIR_HEADERS} ; \ + for hf in $${SDH} ; do \ + $(INSTALL_DATA) "$$hf" $(DESTDIR)$(headersdir)/ ; \ + done + +install-headers: maybe-install-headers @for hf in $(INSTALLED_HEADERS) ; do \ ${INSTALL_DATA} $(srcdir)/"$$hf" $(DESTDIR)$(headersdir)/$$hf || exit 1; \ done @@ -946,20 +962,16 @@ install-headers: install-headers-dirs ${INSTALL_DATA} $(srcdir)/"$$hf" $(DESTDIR)$(headersdir)/$$hf || exit 1; \ fi ; \ done - @SDH=${CREATED_SUBDIR_HEADERS} ; \ - for hf in $${SDH} ; do \ - $(INSTALL_DATA) "$$hf" $(DESTDIR)$(headersdir)/ ; \ - done -$(INSTALL_DATA) $(SUPPORT_DIR)/bash.pc $(DESTDIR)$(pkgconfigdir)/bash.pc uninstall-headers: -( cd $(DESTDIR)$(headersdir) && $(RM) $(INSTALLED_HEADERS) ) -( cd $(DESTDIR)$(headersdir)/include && $(RM) $(INSTALLED_INCLUDE_HEADERS) ) -( cd $(DESTDIR)$(headersdir)/builtins && $(RM) $(INSTALLED_BUILTINS_HEADERS) ) - -( cd $(DESTDIR)$(headersdir) && $(RM) $(CREATED_HEADERS) ) - -@SDH=${CREATED_SUBDIR_HEADERS} ; \ + -( cd $(DESTDIR)$(headersdir) && $(RM) $(CREATED_HEADERS) $(HYBRID_HEADERS) ) + -SDH=${CREATED_SUBDIR_HEADERS} ; \ for hf in $${SDH} ; do \ - ( cd $(DESTDIR)$(headersdir) && $(RM) `basename "$$hf"` ) + ( cd $(DESTDIR)$(headersdir) && $(RM) $$(basename "$$hf") ) \ done -( $(RM) $(DESTDIR)$(pkgconfigdir)/bash.pc ) diff --git a/doc/bash.0 b/doc/bash.0 index 42ad31bc..1d4f3a80 100644 --- a/doc/bash.0 +++ b/doc/bash.0 @@ -4415,6 +4415,30 @@ RREEAADDLLIINNEE 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. + eexxppoorrtt--ccoommpplleettiioonnss + Perform completion on the word before point as described above + and write the list of possible completions to rreeaaddlliinnee's output + stream using the following format, writing information on sepa- + rate lines: + + The number of matches; + The word being completed; + S:E, where S and E are the start and end offsets of the word + in the readline line buffer; then + Each match, one per line + + If there are no matches, the first line will be 0, and this com- + mand will not print any output after the S:E. If there is only + a single match, this prints a single line containing it. If + there is more than one match, this prints the common prefix of + the matches, which may be empty, on the first line after the + S:E, then the matches on subsequent lines. In this case, N will + include the first line with the common prefix. + + The user or application should be able to accommodate the possi- + bility of a blank line. The intent is that the user or applica- + tion reads N lines after the line containing S:E to obtain the + match list. 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). At the end of the line, @@ -7373,4 +7397,4 @@ BBUUGGSS Array variables may not (yet) be exported. -GNU Bash 5.3 2024 October 23 _B_A_S_H(1) +GNU Bash 5.3 2024 November 15 _B_A_S_H(1) diff --git a/doc/bash.1 b/doc/bash.1 index 58ebcb47..27ed4057 100644 --- a/doc/bash.1 +++ b/doc/bash.1 @@ -5,14 +5,14 @@ .\" Case Western Reserve University .\" chet.ramey@case.edu .\" -.\" Last Change: Wed Oct 23 11:32:05 EDT 2024 +.\" Last Change: Fri Nov 15 17:55:48 EST 2024 .\" .\" bash_builtins, strip all but Built-Ins section .\" avoid a warning about an undefined register .\" .if !rzY .nr zY 0 .if \n(zZ=1 .ig zZ .if \n(zY=1 .ig zY -.TH BASH 1 "2024 October 23" "GNU Bash 5.3" +.TH BASH 1 "2024 November 15" "GNU Bash 5.3" .\" .ie \n(.g \{\ .ds ' \(aq @@ -7703,6 +7703,39 @@ of possible completions, as if \fBmenu\-complete\fP had been given a negative argument. This command is unbound by default. .TP +.B export\-completions +Perform completion on the word before point as described above +and write the list of possible completions to \fBreadline\fP's output +stream using the following format, writing information on separate lines: +.sp +.IP +.RS +.nf +The number of matches; +The word being completed; +S:E, where S and E are the start and end offsets of the word +in the readline line buffer; then +Each match, one per line +.fi +.RE +.sp +.IP +If there are no matches, the first line will be 0, and this command will +not print any output after the S:E. +If there is only a single match, this prints a single line containing it. +If there is more than one match, this prints the common prefix of the +matches, which may be empty, on the first line after the S:E, +then the matches on subsequent lines. +In this case, N will include the first line with the common prefix. +.PD +.IP +.PD 0 +The user or application +should be able to accommodate the possibility of a blank line. +The intent is that the user or application reads N lines after the line +containing S:E to obtain the match list. +This command is unbound by default. +.TP .B delete\-char\-or\-list Deletes the character under the cursor if not at the beginning or end of the line (like \fBdelete\-char\fP). diff --git a/doc/bash.info b/doc/bash.info index 8c46c206..75456b8c 100644 --- a/doc/bash.info +++ b/doc/bash.info @@ -9866,6 +9866,30 @@ File: bash.info, Node: Commands For Completion, Next: Keyboard Macros, Prev: of possible completions, as if ‘menu-complete’ had been given a negative argument. This command is unbound by default. +‘export-completions ()’ + Perform completion on the word before point as described above and + write the list of possible completions to Readline's output stream + using the following format, writing information on separate lines: + + The number of matches; + The word being completed; + S:E, where S and E are the start and end offsets of the word + in the readline line buffer; then + Each match, one per line + + If there are no matches, the first line will be 0, and this command + will not print any output after the S:E. If there is only a single + match, this prints a single line containing it. If there is more + than one match, this prints the common prefix of the matches, which + may be empty, on the first line after the S:E, then the matches on + subsequent lines. In this case, N will include the first line with + the common prefix. + + The user or application should be able to accommodate the + possibility of a blank line. The intent is that the user or + application reads N lines after the line containing S:E to obtain + the match list. This command is unbound by default. + ‘delete-char-or-list ()’ Deletes the character under the cursor if not at the beginning or end of the line (like ‘delete-char’). At the end of the line, it @@ -13104,17 +13128,17 @@ D.4 Function Index * complete (): Commands For Completion. (line 6) * complete-command (M-!): Commands For Completion. - (line 81) + (line 105) * complete-filename (M-/): Commands For Completion. - (line 50) + (line 74) * complete-hostname (M-@): Commands For Completion. - (line 73) + (line 97) * complete-into-braces (M-{): Commands For Completion. - (line 100) + (line 124) * complete-username (M-~): Commands For Completion. - (line 57) + (line 81) * complete-variable (M-$): Commands For Completion. - (line 65) + (line 89) * copy-backward-word (): Commands For Killing. (line 62) * copy-forward-word (): Commands For Killing. @@ -13122,10 +13146,10 @@ D.4 Function Index * copy-region-as-kill (): Commands For Killing. (line 58) * dabbrev-expand (): Commands For Completion. - (line 95) + (line 119) * delete-char (C-d): Commands For Text. (line 12) * delete-char-or-list (): Commands For Completion. - (line 44) + (line 68) * delete-horizontal-space (): Commands For Killing. (line 50) * digit-argument (M-0, M-1, ... M--): Numeric Arguments. (line 6) @@ -13141,7 +13165,7 @@ D.4 Function Index * dump-variables (): Miscellaneous Commands. (line 77) * dynamic-complete-history (M-): Commands For Completion. - (line 91) + (line 115) * edit-and-execute-command (C-x C-e): Miscellaneous Commands. (line 142) * end-kbd-macro (C-x )): Keyboard Macros. (line 9) @@ -13153,6 +13177,8 @@ D.4 Function Index (line 37) * execute-named-command (M-x): Miscellaneous Commands. (line 90) +* export-completions (): Commands For Completion. + (line 44) * fetch-history (): Commands For History. (line 106) * forward-backward-delete-char (): Commands For Text. (line 23) @@ -13209,17 +13235,17 @@ D.4 Function Index (line 99) * overwrite-mode (): Commands For Text. (line 77) * possible-command-completions (C-x !): Commands For Completion. - (line 87) + (line 111) * possible-completions (M-?): Commands For Completion. (line 17) * possible-filename-completions (C-x /): Commands For Completion. - (line 53) -* possible-hostname-completions (C-x @): Commands For Completion. (line 77) +* possible-hostname-completions (C-x @): Commands For Completion. + (line 101) * possible-username-completions (C-x ~): Commands For Completion. - (line 61) + (line 85) * possible-variable-completions (C-x $): Commands For Completion. - (line 69) + (line 93) * prefix-meta (): Miscellaneous Commands. (line 19) * previous-history (C-p): Commands For History. @@ -13553,37 +13579,37 @@ Node: Commands For Text434183 Node: Commands For Killing438308 Node: Numeric Arguments441096 Node: Commands For Completion442248 -Node: Keyboard Macros446748 -Node: Miscellaneous Commands447449 -Node: Readline vi Mode454002 -Node: Programmable Completion454979 -Node: Programmable Completion Builtins463025 -Node: A Programmable Completion Example474690 -Node: Using History Interactively480035 -Node: Bash History Facilities480716 -Node: Bash History Builtins484451 -Node: History Interaction490922 -Node: Event Designators495876 -Node: Word Designators497454 -Node: Modifiers499762 -Node: Installing Bash501703 -Node: Basic Installation502819 -Node: Compilers and Options506695 -Node: Compiling For Multiple Architectures507445 -Node: Installation Names509198 -Node: Specifying the System Type511432 -Node: Sharing Defaults512178 -Node: Operation Controls512892 -Node: Optional Features513911 -Node: Reporting Bugs526291 -Node: Major Differences From The Bourne Shell527649 -Node: GNU Free Documentation License549069 -Node: Indexes574246 -Node: Builtin Index574697 -Node: Reserved Word Index581795 -Node: Variable Index584240 -Node: Function Index601653 -Node: Concept Index615509 +Node: Keyboard Macros447931 +Node: Miscellaneous Commands448632 +Node: Readline vi Mode455185 +Node: Programmable Completion456162 +Node: Programmable Completion Builtins464208 +Node: A Programmable Completion Example475873 +Node: Using History Interactively481218 +Node: Bash History Facilities481899 +Node: Bash History Builtins485634 +Node: History Interaction492105 +Node: Event Designators497059 +Node: Word Designators498637 +Node: Modifiers500945 +Node: Installing Bash502886 +Node: Basic Installation504002 +Node: Compilers and Options507878 +Node: Compiling For Multiple Architectures508628 +Node: Installation Names510381 +Node: Specifying the System Type512615 +Node: Sharing Defaults513361 +Node: Operation Controls514075 +Node: Optional Features515094 +Node: Reporting Bugs527474 +Node: Major Differences From The Bourne Shell528832 +Node: GNU Free Documentation License550252 +Node: Indexes575429 +Node: Builtin Index575880 +Node: Reserved Word Index582978 +Node: Variable Index585423 +Node: Function Index602836 +Node: Concept Index616831  End Tag Table diff --git a/doc/bashref.info b/doc/bashref.info index 1e0a8f1b..bae71d85 100644 --- a/doc/bashref.info +++ b/doc/bashref.info @@ -9867,6 +9867,30 @@ File: bashref.info, Node: Commands For Completion, Next: Keyboard Macros, Pre of possible completions, as if ‘menu-complete’ had been given a negative argument. This command is unbound by default. +‘export-completions ()’ + Perform completion on the word before point as described above and + write the list of possible completions to Readline's output stream + using the following format, writing information on separate lines: + + The number of matches; + The word being completed; + S:E, where S and E are the start and end offsets of the word + in the readline line buffer; then + Each match, one per line + + If there are no matches, the first line will be 0, and this command + will not print any output after the S:E. If there is only a single + match, this prints a single line containing it. If there is more + than one match, this prints the common prefix of the matches, which + may be empty, on the first line after the S:E, then the matches on + subsequent lines. In this case, N will include the first line with + the common prefix. + + The user or application should be able to accommodate the + possibility of a blank line. The intent is that the user or + application reads N lines after the line containing S:E to obtain + the match list. This command is unbound by default. + ‘delete-char-or-list ()’ Deletes the character under the cursor if not at the beginning or end of the line (like ‘delete-char’). At the end of the line, it @@ -13105,17 +13129,17 @@ D.4 Function Index * complete (): Commands For Completion. (line 6) * complete-command (M-!): Commands For Completion. - (line 81) + (line 105) * complete-filename (M-/): Commands For Completion. - (line 50) + (line 74) * complete-hostname (M-@): Commands For Completion. - (line 73) + (line 97) * complete-into-braces (M-{): Commands For Completion. - (line 100) + (line 124) * complete-username (M-~): Commands For Completion. - (line 57) + (line 81) * complete-variable (M-$): Commands For Completion. - (line 65) + (line 89) * copy-backward-word (): Commands For Killing. (line 62) * copy-forward-word (): Commands For Killing. @@ -13123,10 +13147,10 @@ D.4 Function Index * copy-region-as-kill (): Commands For Killing. (line 58) * dabbrev-expand (): Commands For Completion. - (line 95) + (line 119) * delete-char (C-d): Commands For Text. (line 12) * delete-char-or-list (): Commands For Completion. - (line 44) + (line 68) * delete-horizontal-space (): Commands For Killing. (line 50) * digit-argument (M-0, M-1, ... M--): Numeric Arguments. (line 6) @@ -13142,7 +13166,7 @@ D.4 Function Index * dump-variables (): Miscellaneous Commands. (line 77) * dynamic-complete-history (M-): Commands For Completion. - (line 91) + (line 115) * edit-and-execute-command (C-x C-e): Miscellaneous Commands. (line 142) * end-kbd-macro (C-x )): Keyboard Macros. (line 9) @@ -13154,6 +13178,8 @@ D.4 Function Index (line 37) * execute-named-command (M-x): Miscellaneous Commands. (line 90) +* export-completions (): Commands For Completion. + (line 44) * fetch-history (): Commands For History. (line 106) * forward-backward-delete-char (): Commands For Text. (line 23) @@ -13210,17 +13236,17 @@ D.4 Function Index (line 99) * overwrite-mode (): Commands For Text. (line 77) * possible-command-completions (C-x !): Commands For Completion. - (line 87) + (line 111) * possible-completions (M-?): Commands For Completion. (line 17) * possible-filename-completions (C-x /): Commands For Completion. - (line 53) -* possible-hostname-completions (C-x @): Commands For Completion. (line 77) +* possible-hostname-completions (C-x @): Commands For Completion. + (line 101) * possible-username-completions (C-x ~): Commands For Completion. - (line 61) + (line 85) * possible-variable-completions (C-x $): Commands For Completion. - (line 69) + (line 93) * prefix-meta (): Miscellaneous Commands. (line 19) * previous-history (C-p): Commands For History. @@ -13554,37 +13580,37 @@ Node: Commands For Text434477 Node: Commands For Killing438605 Node: Numeric Arguments441396 Node: Commands For Completion442551 -Node: Keyboard Macros447054 -Node: Miscellaneous Commands447758 -Node: Readline vi Mode454314 -Node: Programmable Completion455294 -Node: Programmable Completion Builtins463343 -Node: A Programmable Completion Example475011 -Node: Using History Interactively480359 -Node: Bash History Facilities481043 -Node: Bash History Builtins484781 -Node: History Interaction491255 -Node: Event Designators496212 -Node: Word Designators497793 -Node: Modifiers500104 -Node: Installing Bash502048 -Node: Basic Installation503167 -Node: Compilers and Options507046 -Node: Compiling For Multiple Architectures507799 -Node: Installation Names509555 -Node: Specifying the System Type511792 -Node: Sharing Defaults512541 -Node: Operation Controls513258 -Node: Optional Features514280 -Node: Reporting Bugs526663 -Node: Major Differences From The Bourne Shell528024 -Node: GNU Free Documentation License549447 -Node: Indexes574627 -Node: Builtin Index575081 -Node: Reserved Word Index582182 -Node: Variable Index584630 -Node: Function Index602046 -Node: Concept Index615905 +Node: Keyboard Macros448237 +Node: Miscellaneous Commands448941 +Node: Readline vi Mode455497 +Node: Programmable Completion456477 +Node: Programmable Completion Builtins464526 +Node: A Programmable Completion Example476194 +Node: Using History Interactively481542 +Node: Bash History Facilities482226 +Node: Bash History Builtins485964 +Node: History Interaction492438 +Node: Event Designators497395 +Node: Word Designators498976 +Node: Modifiers501287 +Node: Installing Bash503231 +Node: Basic Installation504350 +Node: Compilers and Options508229 +Node: Compiling For Multiple Architectures508982 +Node: Installation Names510738 +Node: Specifying the System Type512975 +Node: Sharing Defaults513724 +Node: Operation Controls514441 +Node: Optional Features515463 +Node: Reporting Bugs527846 +Node: Major Differences From The Bourne Shell529207 +Node: GNU Free Documentation License550630 +Node: Indexes575810 +Node: Builtin Index576264 +Node: Reserved Word Index583365 +Node: Variable Index585813 +Node: Function Index603229 +Node: Concept Index617227  End Tag Table diff --git a/execute_cmd.c b/execute_cmd.c index 4dea87eb..d4d0febd 100644 --- a/execute_cmd.c +++ b/execute_cmd.c @@ -4277,13 +4277,13 @@ fix_assignment_words (WORD_LIST *words) { WORD_LIST *w, *wcmd; struct builtin *b; - int assoc, global, array, integer; + int assoc, global, array; if (words == 0) return; b = 0; - assoc = global = array = integer = 0; + assoc = global = array = 0; /* Skip over assignment statements preceding a command name */ wcmd = words; diff --git a/lib/readline/complete.c b/lib/readline/complete.c index 76bc252c..1cee86e5 100644 --- a/lib/readline/complete.c +++ b/lib/readline/complete.c @@ -153,6 +153,8 @@ static int complete_get_screenwidth (void); static char *make_quoted_replacement (char *, int, char *); +static void _rl_export_completions (char **, char *, int, int); + /* **************************************************************** */ /* */ /* Completion matching, from readline's point of view. */ @@ -539,6 +541,18 @@ _rl_complete_sigcleanup (int sig, void *ptr) /* */ /************************************/ +static inline size_t +vector_len (char **vector) +{ + size_t ret; + + if (vector == 0 || vector[0] == 0) + return (size_t)0; + for (ret = 0; vector[ret]; ret++) + ; + return ret; +} + /* Reset public readline state on a signal or other event. */ void _rl_reset_completion_state (void) @@ -1301,8 +1315,7 @@ remove_duplicate_matches (char **matches) char **temp_array; /* Sort the items. */ - for (i = 0; matches[i]; i++) - ; + i = vector_len (matches); /* Sort the array without matches[0], since we need it to stay in place no matter what. */ @@ -2046,7 +2059,9 @@ compare_match (char *text, const char *match) `!' means to do standard completion, and list all possible completions if there is more than one. `@' means to do standard completion, and list all possible completions if - there is more than one and partial completion is not possible. */ + there is more than one and partial completion is not possible. + `$' implements a protocol for exporting completions and information about + what is being completed to another process via rl_outstream. */ int rl_complete_internal (int what_to_do) { @@ -2103,9 +2118,11 @@ rl_complete_internal (int what_to_do) nontrivial_lcd = matches && strcmp (text, matches[0]) != 0; if (what_to_do == '!' || what_to_do == '@') tlen = strlen (text); - xfree (text); - if (matches == 0) + if (what_to_do != '$') + xfree (text); + + if (matches == 0 && what_to_do != '$') /* we can export no completions */ { rl_ding (); FREE (saved_line_buffer); @@ -2121,7 +2138,7 @@ rl_complete_internal (int what_to_do) rl_filename_completion_function does this. */ i = rl_filename_completion_desired; - if (postprocess_matches (&matches, i) == 0) + if (postprocess_matches (&matches, i) == 0 && what_to_do != '$') /* we can export no completions */ { rl_ding (); FREE (saved_line_buffer); @@ -2207,6 +2224,11 @@ rl_complete_internal (int what_to_do) do_display = 1; break; + case '$': + _rl_export_completions (matches, text, start, end); + xfree (text); + break; + default: _rl_ttymsg ("bad value %d for what_to_do in rl_complete", what_to_do); rl_ding (); @@ -2772,8 +2794,8 @@ rl_old_menu_complete (int count, int invoking_key) RL_UNSETSTATE(RL_STATE_COMPLETING); - for (match_list_size = 0; matches[match_list_size]; match_list_size++) - ; + match_list_size = vector_len (matches); + /* matches[0] is lcd if match_list_size > 1, but the circular buffer code below should take care of it. */ @@ -2907,8 +2929,7 @@ rl_menu_complete (int count, int ignore) RL_UNSETSTATE(RL_STATE_COMPLETING); - for (match_list_size = 0; matches[match_list_size]; match_list_size++) - ; + match_list_size = vector_len (matches); if (match_list_size == 0) { @@ -3007,3 +3028,55 @@ rl_backward_menu_complete (int count, int key) arguments for menu-complete, and vice versa. */ return (rl_menu_complete (-count, key)); } + +/* This implements a protocol to export completions to another process or + calling application via rl_outstream. + + MATCHES are the possible completions for TEXT, which is the text between + START and END in rl_line_buffer. + + We print: + N - the number of matches + T - the word being completed + S:E - the start and end offsets of T in rl_line_buffer + then each match, one per line + + If there are no matches, MATCHES is NULL, N will be 0, and there will be + no output after S:E. + + Since MATCHES[0] can be empty if there is no common prefix of the elements + of MATCHES, applications should be prepared to deal with an empty line + preceding the matches. +*/ + +static void +_rl_export_completions (char **matches, char *text, int start, int end) +{ + size_t len, i; + + len = vector_len (matches); + + if (RL_ISSTATE (RL_STATE_TERMPREPPED)) + fprintf (rl_outstream, "\r\n"); + fprintf (rl_outstream, "%zd\n", len); + fprintf (rl_outstream, "%s\n", text); + fprintf (rl_outstream, "%d:%d\n", start, end); /* : because it's not a radix character */ + for (i = 0; i < len; i++) + fprintf (rl_outstream, "%s\n", matches[i]); + fflush (rl_outstream); +} + +int +rl_export_completions (int count, int key) +{ + rl_complete_internal ('$'); + + /* Clear the line buffer, currently requires a count argument. */ + if (count > 1) + { + rl_delete_text (0, rl_end); /* undoable */ + rl_point = rl_mark = 0; + } + + return 0; +} diff --git a/lib/readline/doc/history.info b/lib/readline/doc/history.info index f87c0ee2..d5f7fe2d 100644 --- a/lib/readline/doc/history.info +++ b/lib/readline/doc/history.info @@ -1,9 +1,9 @@ This is history.info, produced by makeinfo version 7.1 from history.texi. -This document describes the GNU History library (version 8.3, 15 October -2024), a programming tool that provides a consistent user interface for -recalling lines of previously typed input. +This document describes the GNU History library (version 8.3, 15 +November 2024), a programming tool that provides a consistent user +interface for recalling lines of previously typed input. Copyright © 1988-2024 Free Software Foundation, Inc. @@ -1430,28 +1430,28 @@ Appendix C Function and Variable Index  Tag Table: -Node: Top847 -Node: Using History Interactively1492 -Node: History Interaction2000 -Node: Event Designators4714 -Node: Word Designators6216 -Node: Modifiers8527 -Node: Programming with GNU History10178 -Node: Introduction to History10922 -Node: History Storage12654 -Node: History Functions13834 -Node: Initializing History and State Management14823 -Node: History List Management15626 -Node: Information About the History List18057 -Node: Moving Around the History List19670 -Node: Searching the History List20750 -Node: Managing the History File22696 -Node: History Expansion25166 -Node: History Variables27139 -Node: History Programming Example31281 -Node: GNU Free Documentation License33935 -Node: Concept Index59110 -Node: Function and Variable Index59815 +Node: Top848 +Node: Using History Interactively1493 +Node: History Interaction2001 +Node: Event Designators4715 +Node: Word Designators6217 +Node: Modifiers8528 +Node: Programming with GNU History10179 +Node: Introduction to History10923 +Node: History Storage12655 +Node: History Functions13835 +Node: Initializing History and State Management14824 +Node: History List Management15627 +Node: Information About the History List18058 +Node: Moving Around the History List19671 +Node: Searching the History List20751 +Node: Managing the History File22697 +Node: History Expansion25167 +Node: History Variables27140 +Node: History Programming Example31282 +Node: GNU Free Documentation License33936 +Node: Concept Index59111 +Node: Function and Variable Index59816  End Tag Table diff --git a/lib/readline/doc/readline.0 b/lib/readline/doc/readline.0 index df4c16d7..11b65a5e 100644 --- a/lib/readline/doc/readline.0 +++ b/lib/readline/doc/readline.0 @@ -918,6 +918,30 @@ EEDDIITTIINNGG CCOOMMMMAANNDDSS 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. + eexxppoorrtt--ccoommpplleettiioonnss + Perform completion on the word before point as described above + and write the list of possible completions to rreeaaddlliinnee's output + stream using the following format, writing information on sepa- + rate lines: + + The number of matches; + The word being completed; + S:E, where S and E are the start and end offsets of the word + in the readline line buffer; then + Each match, one per line + + If there are no matches, the first line will be 0, and this com- + mand will not print any output after the S:E. If there is only + a single match, this prints a single line containing it. If + there is more than one match, this prints the common prefix of + the matches, which may be empty, on the first line after the + S:E, then the matches on subsequent lines. In this case, N will + include the first line with the common prefix. + + The user or application should be able to accommodate the possi- + bility of a blank line. The intent is that the user or applica- + tion reads N lines after the line containing S:E. 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). At the end of the line, diff --git a/lib/readline/doc/readline.3 b/lib/readline/doc/readline.3 index d0708e33..7915bcce 100644 --- a/lib/readline/doc/readline.3 +++ b/lib/readline/doc/readline.3 @@ -6,9 +6,9 @@ .\" Case Western Reserve University .\" chet.ramey@case.edu .\" -.\" Last Change: Thu Oct 10 16:33:40 EDT 2024 +.\" Last Change: Fri Nov 15 17:57:09 EST 2024 .\" -.TH READLINE 3 "2024 October 10" "GNU Readline 8.3" +.TH READLINE 3 "2024 November 15" "GNU Readline 8.3" .\" .ie \n(.g \{\ .ds ' \(aq @@ -1410,6 +1410,39 @@ of possible completions, as if \fBmenu\-complete\fP had been given a negative argument. This command is unbound by default. .TP +.B export\-completions +Perform completion on the word before point as described above +and write the list of possible completions to \fBreadline\fP's output +stream using the following format, writing information on separate lines: +.sp +.IP +.RS +.nf +The number of matches; +The word being completed; +S:E, where S and E are the start and end offsets of the word +in the readline line buffer; then +Each match, one per line +.fi +.RE +.sp +.IP +If there are no matches, the first line will be 0, and this command will +not print any output after the S:E. +If there is only a single match, this prints a single line containing it. +If there is more than one match, this prints the common prefix of the +matches, which may be empty, on the first line after the S:E, +then the matches on subsequent lines. +In this case, N will include the first line with the common prefix. +.PD +.IP +.PD 0 +The user or application +should be able to accommodate the possibility of a blank line. +The intent is that the user or application reads N lines after the line +containing S:E to obtain the match list. +This command is unbound by default. +.TP .B delete\-char\-or\-list Deletes the character under the cursor if not at the beginning or end of the line (like \fBdelete\-char\fP). diff --git a/lib/readline/doc/readline.info b/lib/readline/doc/readline.info index a1be7fea..336211db 100644 --- a/lib/readline/doc/readline.info +++ b/lib/readline/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, 15 October +This manual describes the GNU Readline Library (version 8.3, 15 November 2024), a library which aids in the consistency of user interface across discrete programs which provide a command line interface. @@ -1477,6 +1477,30 @@ File: readline.info, Node: Commands For Completion, Next: Keyboard Macros, Pr of possible completions, as if ‘menu-complete’ had been given a negative argument. This command is unbound by default. +‘export-completions ()’ + Perform completion on the word before point as described above and + write the list of possible completions to Readline's output stream + using the following format, writing information on separate lines: + + The number of matches; + The word being completed; + S:E, where S and E are the start and end offsets of the word + in the readline line buffer; then + Each match, one per line + + If there are no matches, the first line will be 0, and this command + will not print any output after the S:E. If there is only a single + match, this prints a single line containing it. If there is more + than one match, this prints the common prefix of the matches, which + may be empty, on the first line after the S:E, then the matches on + subsequent lines. In this case, N will include the first line with + the common prefix. + + The user or application should be able to accommodate the + possibility of a blank line. The intent is that the user or + application reads N lines after the line containing S:E to obtain + the match list. This command is unbound by default. + ‘delete-char-or-list ()’ Deletes the character under the cursor if not at the beginning or end of the line (like ‘delete-char’). At the end of the line, it @@ -4937,7 +4961,7 @@ Function and Variable Index (line 49) * delete-char (C-d): Commands For Text. (line 12) * delete-char-or-list (): Commands For Completion. - (line 38) + (line 62) * delete-horizontal-space (): Commands For Killing. (line 41) * digit-argument (M-0, M-1, ... M--): Numeric Arguments. (line 6) @@ -4979,6 +5003,8 @@ Function and Variable Index (line 87) * expand-tilde: Readline Init File Syntax. (line 212) +* export-completions (): Commands For Completion. + (line 38) * fetch-history (): Commands For History. (line 105) * force-meta-prefix: Readline Init File Syntax. @@ -5411,59 +5437,59 @@ Function and Variable Index  Tag Table: -Node: Top863 -Node: Command Line Editing1588 -Node: Introduction and Notation2240 -Node: Readline Interaction4596 -Node: Readline Bare Essentials5788 -Node: Readline Movement Commands7600 -Node: Readline Killing Commands8600 -Node: Readline Arguments10627 -Node: Searching11688 -Node: Readline Init File13919 -Node: Readline Init File Syntax15117 -Node: Conditional Init Constructs41509 -Node: Sample Init File45898 -Node: Bindable Readline Commands49023 -Node: Commands For Moving50407 -Node: Commands For History52337 -Node: Commands For Text57542 -Node: Commands For Killing61387 -Node: Numeric Arguments63843 -Node: Commands For Completion64999 -Node: Keyboard Macros67086 -Node: Miscellaneous Commands67791 -Node: Readline vi Mode72115 -Node: Programming with GNU Readline74012 -Node: Basic Behavior74998 -Node: Custom Functions79061 -Node: Readline Typedefs80583 -Node: Function Writing82469 -Node: Readline Variables83775 -Node: Readline Convenience Functions98729 -Node: Function Naming99805 -Node: Keymaps101136 -Node: Binding Keys104298 -Node: Associating Function Names and Bindings109123 -Node: Allowing Undoing112953 -Node: Redisplay115703 -Node: Modifying Text120005 -Node: Character Input121544 -Node: Terminal Management124701 -Node: Utility Functions126588 -Node: Miscellaneous Functions129698 -Node: Alternate Interface133588 -Node: A Readline Example136483 -Node: Alternate Interface Example138401 -Node: Readline Signal Handling142020 -Node: Custom Completers151570 -Node: How Completing Works152290 -Node: Completion Functions155666 -Node: Completion Variables159333 -Node: A Short Completion Example177651 -Node: GNU Free Documentation License190320 -Node: Concept Index215497 -Node: Function and Variable Index217018 +Node: Top864 +Node: Command Line Editing1589 +Node: Introduction and Notation2241 +Node: Readline Interaction4597 +Node: Readline Bare Essentials5789 +Node: Readline Movement Commands7601 +Node: Readline Killing Commands8601 +Node: Readline Arguments10628 +Node: Searching11689 +Node: Readline Init File13920 +Node: Readline Init File Syntax15118 +Node: Conditional Init Constructs41510 +Node: Sample Init File45899 +Node: Bindable Readline Commands49024 +Node: Commands For Moving50408 +Node: Commands For History52338 +Node: Commands For Text57543 +Node: Commands For Killing61388 +Node: Numeric Arguments63844 +Node: Commands For Completion65000 +Node: Keyboard Macros68270 +Node: Miscellaneous Commands68975 +Node: Readline vi Mode73299 +Node: Programming with GNU Readline75196 +Node: Basic Behavior76182 +Node: Custom Functions80245 +Node: Readline Typedefs81767 +Node: Function Writing83653 +Node: Readline Variables84959 +Node: Readline Convenience Functions99913 +Node: Function Naming100989 +Node: Keymaps102320 +Node: Binding Keys105482 +Node: Associating Function Names and Bindings110307 +Node: Allowing Undoing114137 +Node: Redisplay116887 +Node: Modifying Text121189 +Node: Character Input122728 +Node: Terminal Management125885 +Node: Utility Functions127772 +Node: Miscellaneous Functions130882 +Node: Alternate Interface134772 +Node: A Readline Example137667 +Node: Alternate Interface Example139585 +Node: Readline Signal Handling143204 +Node: Custom Completers152754 +Node: How Completing Works153474 +Node: Completion Functions156850 +Node: Completion Variables160517 +Node: A Short Completion Example178835 +Node: GNU Free Documentation License191504 +Node: Concept Index216681 +Node: Function and Variable Index218202  End Tag Table diff --git a/lib/readline/doc/rluser.info b/lib/readline/doc/rluser.info new file mode 100644 index 00000000..ea820964 --- /dev/null +++ b/lib/readline/doc/rluser.info @@ -0,0 +1,1648 @@ +This is rluser.info, produced by makeinfo version 7.1 from rluser.texi. + + +File: rluser.info, Node: Command Line Editing + +1 Command Line Editing +********************** + +This chapter describes the basic features of the GNU command line +editing interface. + +* Menu: + +* Introduction and Notation:: Notation used in this text. +* Readline Interaction:: The minimum set of commands for editing a line. +* Readline Init File:: Customizing Readline from a user's view. +* Bindable Readline Commands:: A description of most of the Readline commands + available for binding +* Readline vi Mode:: A short description of how to make Readline + behave like the vi editor. + + +File: rluser.info, Node: Introduction and Notation, Next: Readline Interaction, Up: Command Line Editing + +1.1 Introduction to Line Editing +================================ + +The following paragraphs use Emacs style to describe the notation used +to represent keystrokes. + + The text ‘C-k’ is read as 'Control-K' and describes the character +produced when the key is pressed while the Control key is depressed. + + The text ‘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 is pressed (a “meta character”), then both are released. The Meta +key is labeled or