From 69a7dd86ec3052211b33817f78321cf70e8789f4 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Tue, 11 Apr 2023 11:44:27 +0200 Subject: [PATCH 01/11] feedback: suppress filename and linecount when --zero is active This suppression prevents the filename flashing by at the bottom of the screen when switching between buffers. This addresses https://savannah.gnu.org/bugs/?64019 Reported-by: Alan Cristhian Ruiz Problem existed since version 6.0, since --zero was introduced. --- src/files.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/files.c b/src/files.c index c6eadc1c..20967446 100644 --- a/src/files.c +++ b/src/files.c @@ -535,7 +535,8 @@ void mention_name_and_linecount(void) if (ISSET(MINIBAR)) { report_size = TRUE; return; - } + } else if (ISSET(ZERO)) + return; if (openfile->fmt > NIX_FILE) /* TRANSLATORS: First %s is file name, second %s is file format. */ From 2c19345e58ddc0def4f4cb0e65ea249519cb43f2 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sun, 30 Apr 2023 17:24:23 +0200 Subject: [PATCH 02/11] docs: in a synopsis, use braces around a choice of required parts This seems to be the convention. For an example, see `man tar`. This addresses https://savannah.gnu.org/bugs/?64125. Reported-by: Eric S. Raymond --- doc/nano.1 | 2 +- doc/nano.texi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/nano.1 b/doc/nano.1 index fde6da75..af58338e 100644 --- a/doc/nano.1 +++ b/doc/nano.1 @@ -28,7 +28,7 @@ nano \- Nano's ANOther editor, inspired by Pico .B nano .RI [ options "] [" file [\fB: line [\fB: column "]]]..." .sp -.BR nano " [" \fIoptions "] [[" + [ crCR ]( / | ? ) \fIstring "] " \fIfile ]... +.BR nano " [" \fIoptions "] [[" + [ crCR ]{ / | ? } \fIstring "] " \fIfile ]... .SH DESCRIPTION \fBnano\fP is a small and friendly editor. It copies the look and feel diff --git a/doc/nano.texi b/doc/nano.texi index 6ab23579..2fc39495 100644 --- a/doc/nano.texi +++ b/doc/nano.texi @@ -163,7 +163,7 @@ A more complete command synopsis thus is: @blankline @example -@code{nano [OPTION]@dots{} [[+LINE[,COLUMN]|+[crCR](/|?)STRING] FILE]@dots{}} +@code{nano [OPTION]@dots{} [[+LINE[,COLUMN]|+[crCR]@{/|?@}STRING] FILE]@dots{}} @end example @blankline From 15c6396d42b06a85a50a78e15bb1940159647a5f Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sat, 13 May 2023 12:31:09 +0200 Subject: [PATCH 03/11] tweaks: rename a symbol (to be clearer), and add three missing comments --- src/definitions.h | 2 +- src/global.c | 5 ++++- src/winio.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/definitions.h b/src/definitions.h index d6ca001d..7f0c4918 100644 --- a/src/definitions.h +++ b/src/definitions.h @@ -219,7 +219,7 @@ * needs execution or a specified function name is invalid. */ #define MORE_PLANTS 0x4EA #define MISSING_BRACE 0x4EB -#define PLANTED_COMMAND 0x4EC +#define PLANTED_A_COMMAND 0x4EC #define NO_SUCH_FUNCTION 0x4EF /* A special keycode for when is pressed while the mark is on. */ diff --git a/src/global.c b/src/global.c index ed93fa31..5e5f80e8 100644 --- a/src/global.c +++ b/src/global.c @@ -266,9 +266,12 @@ char *startup_problem = NULL; #endif #ifdef ENABLE_NANORC char *custom_nanorc = NULL; + /* The argument of the --rcfile option, when given. */ char *commandname = NULL; + /* The name (of a function) between braces in a string bind. */ keystruct *planted_shortcut = NULL; + /* The function that the above name resolves to, if any. */ #endif bool spotlighted = FALSE; @@ -464,7 +467,7 @@ const keystruct *get_shortcut(const int keycode) return NULL; #endif #ifdef ENABLE_NANORC - if (keycode == PLANTED_COMMAND) + if (keycode == PLANTED_A_COMMAND) return planted_shortcut; #endif diff --git a/src/winio.c b/src/winio.c index fee2a84e..e73419bb 100644 --- a/src/winio.c +++ b/src/winio.c @@ -380,7 +380,7 @@ int get_code_from_plantation(void) if (*plants_pointer != '\0') put_back(MORE_PLANTS); - return PLANTED_COMMAND; + return PLANTED_A_COMMAND; } else { char *opening = strchr(plants_pointer, '{'); char firstbyte = *plants_pointer; From bcdb27416c91b01161d121a1f5c175d9bbf7c198 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sat, 13 May 2023 17:17:36 +0200 Subject: [PATCH 04/11] docs: describe nano more specifically as a text editor Especially the first sentences introducing nano should use the words "text editor" and not just "editor". --- doc/nano.1 | 4 ++-- doc/nano.texi | 2 +- doc/nanorc.5 | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/nano.1 b/doc/nano.1 index af58338e..556dedeb 100644 --- a/doc/nano.1 +++ b/doc/nano.1 @@ -19,7 +19,7 @@ .TH NANO 1 "version 7.2" "January 2023" .SH NAME -nano \- Nano's ANOther editor, inspired by Pico +nano \- Nano's ANOther text editor, inspired by Pico .SH SYNOPSIS .B nano @@ -31,7 +31,7 @@ nano \- Nano's ANOther editor, inspired by Pico .BR nano " [" \fIoptions "] [[" + [ crCR ]{ / | ? } \fIstring "] " \fIfile ]... .SH DESCRIPTION -\fBnano\fP is a small and friendly editor. It copies the look and feel +\fBnano\fP is a small and friendly text editor. It copies the look and feel of Pico, but is free software, and implements several features that Pico lacks, such as: opening multiple files, scrolling per line, undo/redo, syntax coloring, line numbering, and soft-wrapping overlong lines. diff --git a/doc/nano.texi b/doc/nano.texi index 2fc39495..df3dcbc0 100644 --- a/doc/nano.texi +++ b/doc/nano.texi @@ -35,7 +35,7 @@ The complete manual for the GNU nano text editor. @page -This manual documents the GNU @command{nano} editor. +This manual documents the GNU @command{nano} text editor. @sp 1 The contents of this manual are part of the GNU @command{nano} distribution. diff --git a/doc/nanorc.5 b/doc/nanorc.5 index 84db959d..3bd1d6e7 100644 --- a/doc/nanorc.5 +++ b/doc/nanorc.5 @@ -23,7 +23,7 @@ nanorc \- GNU nano's configuration file .SH DESCRIPTION The \fInanorc\fP files contain the default settings for \fBnano\fP, -a small and friendly editor. During startup, if \fB\-\-rcfile\fR +a small and friendly text editor. During startup, if \fB\-\-rcfile\fR is not given, \fBnano\fR will read two files: first the system-wide settings, from \fI/etc/nanorc\fP (the exact path might be different on your system), and then the user-specific settings, either From 7f17777a4ba55b5deddccd52b19edeab677611fa Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sat, 13 May 2023 17:28:48 +0200 Subject: [PATCH 05/11] docs: mention that a restricted nano does not access the history files With some imagination, the lack of access could be inferred from the other descriptions, but it's much better to be clear and explicit. Also, separate two items that are unrelated and reshuffle them into a neater order. Triggered by https://savannah.gnu.org/bugs/?64181. --- doc/rnano.1 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/doc/rnano.1 b/doc/rnano.1 index 27762bc6..5a920287 100644 --- a/doc/rnano.1 +++ b/doc/rnano.1 @@ -32,15 +32,19 @@ access to the filesystem nor to a command shell. .sp In restricted mode, \fBnano\fR will: .IP \[bu] 2 +not make backups; +.IP \[bu] not allow suspending; .IP \[bu] +not allow spell checking; +.IP \[bu] +not read nor write the history files; +.IP \[bu] not allow saving the current buffer under a different name; .IP \[bu] not allow inserting another file or opening a new buffer; .IP \[bu] -not allow appending or prepending to any file; -.IP \[bu] -not make backup files nor do spell checking. +not allow appending or prepending to any file. .SH OPTIONS .TP From fc42ab9b463acdc7cf61b6b4aeef3dce2dd569e8 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sat, 20 May 2023 17:31:05 +0200 Subject: [PATCH 06/11] bindings: allow speller and friends to be rebound also in restricted mode Speller, linter, formatter, and execute-a-command cannot be used in restricted mode, but the relevant keys should report that the function is *disabled*, not that the key is unbound. This fixes https://savannah.gnu.org/bugs/?64226. Problem existed since version 3.2, since nano reads the nanorc files also in restricted mode. --- src/global.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/global.c b/src/global.c index 5e5f80e8..430db493 100644 --- a/src/global.c +++ b/src/global.c @@ -1013,7 +1013,6 @@ void shortcut_init(void) add_to_funcs(to_next_anchor, MMAIN, N_("Down to anchor"), WHENHELP(nextanchor_gist), BLANKAFTER); - if (!ISSET(RESTRICTED)) { #ifdef ENABLE_SPELLER add_to_funcs(do_spell, MMAIN, N_("Spell Check"), WHENHELP(spell_gist), TOGETHER); @@ -1026,7 +1025,10 @@ void shortcut_init(void) add_to_funcs(do_formatter, MMAIN, N_("Formatter"), WHENHELP(formatter_gist), BLANKAFTER); #endif - } + /* Although not allowed in restricted mode, keep execution rebindable. */ + if (ISSET(RESTRICTED)) + add_to_funcs(do_execute, MMAIN, + N_("Execute"), WHENHELP(execute_gist), TOGETHER); #endif /* !NANO_TINY */ #ifdef NANO_TINY From f7d8735b6b94db445f26b62ef0f7a607f1831fd3 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sun, 21 May 2023 11:10:41 +0200 Subject: [PATCH 07/11] tweaks: reshuffle four lines, to allow folding some #ifdefs together Also remove an unneeded pair of braces, split a comment, and correct a mistaken #ifdef. --- src/global.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/global.c b/src/global.c index 430db493..d71eda75 100644 --- a/src/global.c +++ b/src/global.c @@ -981,7 +981,10 @@ void shortcut_init(void) add_to_funcs(do_verbatim_input, MMAIN, N_("Verbatim"), WHENHELP(verbatim_gist), BLANKAFTER); -#ifndef NANO_TINY +#ifdef NANO_TINY + add_to_funcs(do_search_backward, MMAIN, + N_("Where Was"), WHENHELP(wherewas_gist), BLANKAFTER); +#else add_to_funcs(do_indent, MMAIN, N_("Indent"), WHENHELP(indent_gist), TOGETHER); add_to_funcs(do_unindent, MMAIN, @@ -1029,15 +1032,11 @@ void shortcut_init(void) if (ISSET(RESTRICTED)) add_to_funcs(do_execute, MMAIN, N_("Execute"), WHENHELP(execute_gist), TOGETHER); -#endif /* !NANO_TINY */ -#ifdef NANO_TINY - add_to_funcs(do_search_backward, MMAIN, - N_("Where Was"), WHENHELP(wherewas_gist), BLANKAFTER); -#else add_to_funcs(do_suspend, MMAIN, N_("Suspend"), WHENHELP(suspend_gist), TOGETHER); -#endif +#endif /* !NANO_TINY */ + #ifdef ENABLE_HELP add_to_funcs(full_refresh, MMAIN, N_("Refresh"), WHENHELP(refresh_gist), TOGETHER); @@ -1108,7 +1107,7 @@ void shortcut_init(void) N_("No Conversion"), WHENHELP(convert_gist), BLANKAFTER); /* Command execution is only available when not in restricted mode. */ - if (!ISSET(RESTRICTED) && !ISSET(VIEW_MODE)) { + if (!ISSET(RESTRICTED) && !ISSET(VIEW_MODE)) add_to_funcs(flip_execute, MINSERTFILE, N_("Execute Command"), WHENHELP(execute_gist), BLANKAFTER); @@ -1117,7 +1116,6 @@ void shortcut_init(void) add_to_funcs(do_suspend, MEXECUTE, N_("Suspend"), WHENHELP(suspend_gist), BLANKAFTER); - } #endif /* !NANO_TINY */ #ifdef ENABLE_BROWSER @@ -1467,24 +1465,22 @@ void shortcut_init(void) #endif } #endif + add_to_sclist(MBROWSER|MHELP, "^C", 0, do_exit, 0); #ifdef ENABLE_BROWSER /* Only when not in restricted mode, allow entering the file browser. */ if (!ISSET(RESTRICTED)) add_to_sclist(MWRITEFILE|MINSERTFILE, "^T", 0, to_files, 0); -#endif - add_to_sclist(MBROWSER|MHELP, "^C", 0, do_exit, 0); - /* Allow exiting from the file browser and the help viewer with - * the same key as they were entered. */ -#ifdef ENABLE_BROWSER + /* Allow exiting the file browser with the same key as used for entry. */ add_to_sclist(MBROWSER, "^T", 0, do_exit, 0); #endif #ifdef ENABLE_HELP + /* Allow exiting the help viewer with the same keys as used for entry. */ add_to_sclist(MHELP, "^G", 0, do_exit, 0); add_to_sclist(MHELP, "F1", KEY_F(1), do_exit, 0); add_to_sclist(MHELP, "Home", KEY_HOME, to_first_line, 0); add_to_sclist(MHELP, "End", KEY_END, to_last_line, 0); #endif -#ifdef ENABLE_COLOR +#ifdef ENABLE_LINTER add_to_sclist(MLINTER, "^X", 0, do_cancel, 0); #endif add_to_sclist(MMOST & ~MFINDINHELP, "F1", KEY_F(1), do_help, 0); From cb1b3a28aba8a9cd8350c3e598838812c1c0daae Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sun, 21 May 2023 11:29:02 +0200 Subject: [PATCH 08/11] tweaks: normalize the indentation after the previous changes --- src/global.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/global.c b/src/global.c index d71eda75..a73f2ef5 100644 --- a/src/global.c +++ b/src/global.c @@ -1017,16 +1017,16 @@ void shortcut_init(void) N_("Down to anchor"), WHENHELP(nextanchor_gist), BLANKAFTER); #ifdef ENABLE_SPELLER - add_to_funcs(do_spell, MMAIN, - N_("Spell Check"), WHENHELP(spell_gist), TOGETHER); + add_to_funcs(do_spell, MMAIN, + N_("Spell Check"), WHENHELP(spell_gist), TOGETHER); #endif #ifdef ENABLE_LINTER - add_to_funcs(do_linter, MMAIN, - N_("Linter"), WHENHELP(lint_gist), TOGETHER); + add_to_funcs(do_linter, MMAIN, + N_("Linter"), WHENHELP(lint_gist), TOGETHER); #endif #ifdef ENABLE_FORMATTER - add_to_funcs(do_formatter, MMAIN, - N_("Formatter"), WHENHELP(formatter_gist), BLANKAFTER); + add_to_funcs(do_formatter, MMAIN, + N_("Formatter"), WHENHELP(formatter_gist), BLANKAFTER); #endif /* Although not allowed in restricted mode, keep execution rebindable. */ if (ISSET(RESTRICTED)) @@ -1111,11 +1111,11 @@ void shortcut_init(void) add_to_funcs(flip_execute, MINSERTFILE, N_("Execute Command"), WHENHELP(execute_gist), BLANKAFTER); - add_to_funcs(cut_till_eof, MEXECUTE, - N_("Cut Till End"), WHENHELP(cuttilleof_gist), BLANKAFTER); + add_to_funcs(cut_till_eof, MEXECUTE, + N_("Cut Till End"), WHENHELP(cuttilleof_gist), BLANKAFTER); - add_to_funcs(do_suspend, MEXECUTE, - N_("Suspend"), WHENHELP(suspend_gist), BLANKAFTER); + add_to_funcs(do_suspend, MEXECUTE, + N_("Suspend"), WHENHELP(suspend_gist), BLANKAFTER); #endif /* !NANO_TINY */ #ifdef ENABLE_BROWSER From 7f4c2c6a2556ecab6a8c2018a5f44b7fbdfc092d Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Fri, 2 Jun 2023 11:50:35 +0200 Subject: [PATCH 09/11] docs: add a caveat in the FAQ about bracketed pastes --- doc/faq.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/faq.html b/doc/faq.html index bf32fbd4..7928aa48 100644 --- a/doc/faq.html +++ b/doc/faq.html @@ -222,10 +222,10 @@

Try holding down the Shift key and selecting or pasting the text as you normally would.

4.6. When I paste text into a document, each line gets indented further than the last. Why? And how can I stop this?

You have the autoindent feature turned on. Hit Meta-I to turn it off, paste your text, and then hit Meta-I again to turn it back on.

-

Update: Since version 4.8, nano will suppress auto-indentation during a paste, so you no longer need to toggle it off and on manually.

+

Update: Since version 4.8, nano will suppress auto-indentation during a paste (when your terminal understands bracketed pastes), so you no longer need to toggle it off and on manually.

4.7. When I paste from Windows into a remote nano, nano rewraps the lines. What gives?

When pasting from Windows, in some situations linefeeds are sent instead of carriage returns (Enters). And linefeeds are ^Js, which make nano justify (rewrap) the current paragraph. To prevent these linefeeds from causing these unwanted justifications, add this line to your .nanorc on the remote Linux box: unbind ^J main or bind ^J enter main, depending on whether the paste contains CR + LF or only LF.

-

Update: Since version 4.8, nano will ignore linefeed characters in a paste, so you no longer need the above workaround.

+

Update: Since version 4.8, nano will ignore linefeed characters in a paste (when your terminal understands bracketed pastes), so you no longer need the above workaround.

4.8. I've compiled nano with color support, but I don't see any color when I run it!

If you want nano to actually use color, you have to specify the color configurations you want it to use in your .nanorc. Several example configurations are in the syntax/ subdirectory of the nano source, which are normally installed to /usr/local/share/nano/. To enable all of them, uncomment the line # include "/usr/local/share/nano/*.nanorc" in your nanorc. See also section 3.9.

4.9. How do I make nano my default editor (in Pine, mutt, etc.)?

From d3dd403dc7565c3bd362996b3b602714a1e9e76b Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Mon, 24 Jul 2023 15:12:48 +0200 Subject: [PATCH 10/11] browser: report an error instead of crashing when the folder disappears When the directory that the user is browsing in is deleted by another process at the moment that nano is building the list of file names, this can result in an empty list, which some items in the main loop in browse() cannot handle. Prevent this mishandling by not entering the loop when the list is empty. This fixes https://savannah.gnu.org/bugs/?64465. Reported-by: Jerry Meng --- src/browser.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/browser.c b/src/browser.c index d569bb43..e5a4047c 100644 --- a/src/browser.c +++ b/src/browser.c @@ -436,7 +436,10 @@ char *browse(char *path) titlebar(path); - while (TRUE) { + if (list_length == 0) { + statusline(ALERT, _("No entries")); + napms(1200); + } else while (TRUE) { functionptrtype function; int kbinput; From e65b0ba6542b03a76fa6fecabdea56c04c2792b5 Mon Sep 17 00:00:00 2001 From: Mateusz Kazimierczuk Date: Thu, 27 Jul 2023 02:01:14 +0200 Subject: [PATCH 11/11] options: add -? as a synonym of -h (--help) The short option '-?' was removed nine years ago in commit 43019189, then restored six years later in 5bd92d4c, and then removed again two months later in 743100fe due to getopt() returning '?' for options that aren't recognized, preventing the use of '-?' as a valid option. However, getopt() provides a way to check for unrecognized options via the 'optopt' variable, which gets set only for invalid options. Signed-off-by: Mateusz Kazimierczuk Signed-off-by: Benno Schulenberg --- doc/nano.1 | 2 +- doc/nano.texi | 1 + doc/rnano.1 | 2 +- src/nano.c | 15 +++++++++------ 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/doc/nano.1 b/doc/nano.1 index 556dedeb..73219b38 100644 --- a/doc/nano.1 +++ b/doc/nano.1 @@ -250,7 +250,7 @@ Make the cursor visible in the file browser (putting it on the highlighted item) and in the help viewer. Useful for braille users and people with poor vision. .TP -.BR \-h ", " \-\-help +.BR \-h ", " \-? ", " \-\-help Show a summary of the available command-line options and exit. .TP .BR \-i ", " \-\-autoindent diff --git a/doc/nano.texi b/doc/nano.texi index df3dcbc0..0fe14e23 100644 --- a/doc/nano.texi +++ b/doc/nano.texi @@ -574,6 +574,7 @@ highlighted item) and in the help viewer. Useful for braille users and people with poor vision. @item -h +@itemx -? @itemx --help Show a summary of command-line options and exit. diff --git a/doc/rnano.1 b/doc/rnano.1 index 5a920287..1892d3e9 100644 --- a/doc/rnano.1 +++ b/doc/rnano.1 @@ -48,7 +48,7 @@ not allow appending or prepending to any file. .SH OPTIONS .TP -.BR \-h ", " \-\-help +.BR \-h ", " \-? ", " \-\-help Show the available command-line options and exit. .P For all existing options, see the \fBnano\fR(1) man page. diff --git a/src/nano.c b/src/nano.c index 8578ee7d..591545ff 100644 --- a/src/nano.c +++ b/src/nano.c @@ -607,7 +607,7 @@ void usage(void) #if defined(ENABLE_BROWSER) || defined(ENABLE_HELP) print_opt("-g", "--showcursor", N_("Show cursor in file browser & help text")); #endif - print_opt("-h", "--help", N_("Show this help text and exit")); + print_opt("-h, -?", "--help", N_("Show this help text and exit")); #ifndef NANO_TINY print_opt("-i", "--autoindent", N_("Automatically indent new lines")); print_opt("-j", "--jumpyscrolling", N_("Scroll per half-screen, not per line")); @@ -1849,7 +1849,7 @@ int main(int argc, char **argv) SET(RESTRICTED); while ((optchr = getopt_long(argc, argv, "ABC:DEFGHIJ:KLMNOPQ:RS$T:UVWX:Y:Z" - "abcdef:ghijklmno:pqr:s:tuvwxy!%_0", long_options, NULL)) != -1) { + "abcdef:gh?ijklmno:pqr:s:tuvwxy!%_0", long_options, NULL)) != -1) { switch (optchr) { #ifndef NANO_TINY case 'A': @@ -1999,9 +1999,6 @@ int main(int argc, char **argv) SET(SHOW_CURSOR); break; #endif - case 'h': - usage(); - exit(0); #ifndef NANO_TINY case 'i': SET(AUTOINDENT); @@ -2098,7 +2095,13 @@ int main(int argc, char **argv) SET(ZERO); break; #endif - default: + case 'h': + case '?': + /* If the option is valid, print the help text and exit. */ + if (!optopt) { + usage(); + exit(0); + } printf(_("Type '%s -h' for a list of available options.\n"), argv[0]); exit(1); }