Compare commits

...

17 Commits

Author SHA1 Message Date
Benno Schulenberg
ef35ea72cf input: neutralize two spurious keycodes from VTE terminals
At least some of the VTE-based terminals claim to be compatible with
xterm-25color (and set TERM to that value).  But they really aren't:
they mishandle the focus-in and focus-out events, for example.  So,
catch and discard the corresponding keycodes that nano shouldn't be
seeing at all.

This improves the fix for https://savannah.gnu.org/bugs/?64578.
2023-10-16 08:55:06 +02:00
Benno Schulenberg
8804b6dcd4 tweaks: adjust a comment for the changed handling of gray #rgb codes 2023-10-03 15:41:00 +02:00
Andy Koppe
86b8388889 rcfile: map the gray #rgb codes (#111 to #EEE) to the xterm grayscale
When the red, green and blue components of a three-digit hex #RGB code
are equal and they aren't #000 for black or #FFF for white, map them to
xterm-256color's 24-level grayscale ranging from index 232 to 255.

This means that the 14 gray levels available in #RGB codes all map to
different tones, whereas previously they mapped to only the four gray
tones available in the 6x6x6 color cube.

Signed-off-by: Andy Koppe <andy.koppe@gmail.com>
2023-09-25 16:10:42 +02:00
Benno Schulenberg
812c48dde4 tweaks: add a comment that refers to the VTE spurious-code issue 2023-08-29 16:17:40 +02:00
Benno Schulenberg
f0f1c94afa input: intercept a spurious keycode and say what the actual problem is
Xfce Terminal sets TERM to xterm-256color even though it does not have
all the capabilities that an xterm has, leading it to misinterpret some
escape sequence and produce a spurious 0x24C key code.

Intercept this mistaken key code and tell the user what is wrong.

This mitigates https://savannah.gnu.org/bugs/?64578.
Reported-by: Lawrence R. Steeger
2023-08-27 15:01:37 +02:00
Benno Schulenberg
75b312ded1 revert the previous commit -- forget about -? as a synonym for --help
An ambiguous option like --back or --word would cause nano to spew
the entire help text.  It should do the latter only when the user
explicitly requests it.
2023-08-27 14:56:05 +02:00
Mateusz Kazimierczuk
e65b0ba654 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 <mataha+savannah@protonmail.com>
Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
2023-07-31 07:40:07 +02:00
Benno Schulenberg
d3dd403dc7 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 <jerrytstng@gmail.com>
2023-07-24 15:25:35 +02:00
Benno Schulenberg
7f4c2c6a25 docs: add a caveat in the FAQ about bracketed pastes 2023-06-04 08:07:10 +02:00
Benno Schulenberg
cb1b3a28ab tweaks: normalize the indentation after the previous changes 2023-05-21 11:29:02 +02:00
Benno Schulenberg
f7d8735b6b 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.
2023-05-21 11:27:45 +02:00
Benno Schulenberg
fc42ab9b46 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.
2023-05-21 10:51:37 +02:00
Benno Schulenberg
7f17777a4b 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.
2023-05-14 08:17:25 +02:00
Benno Schulenberg
bcdb27416c 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".
2023-05-14 08:11:44 +02:00
Benno Schulenberg
15c6396d42 tweaks: rename a symbol (to be clearer), and add three missing comments 2023-05-14 08:11:05 +02:00
Benno Schulenberg
2c19345e58 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 <esr@thyrsus.com>
2023-05-01 10:48:02 +02:00
Benno Schulenberg
69a7dd86ec 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 <alancristhian@protonmail.com>

Problem existed since version 6.0, since --zero was introduced.
2023-04-12 09:58:28 +02:00
13 changed files with 74 additions and 48 deletions

View File

@@ -222,10 +222,10 @@
<blockquote><p>Try holding down the Shift key and selecting or pasting the text as you normally would.</p></blockquote>
<h3><a name="4.6"></a>4.6. When I paste text into a document, each line gets indented further than the last. Why? And how can I stop this?</h3>
<blockquote><p>You have the <i>autoindent</i> feature turned on. Hit <b>Meta-I</b> to turn it off, paste your text, and then hit <b>Meta-I</b> again to turn it back on.</p>
<p><i>Update:</i> Since version 4.8, nano will suppress auto-indentation during a paste, so you no longer need to toggle it off and on manually.</p></blockquote>
<p><i>Update:</i> Since version 4.8, nano will suppress auto-indentation during a paste (when your terminal understands <a href="https://en.wikipedia.org/wiki/Bracketed-paste">bracketed pastes</a>), so you no longer need to toggle it off and on manually.</p></blockquote>
<h3><a name="4.7"></a>4.7. When I paste from Windows into a remote nano, nano rewraps the lines. What gives?</h3>
<blockquote><p>When pasting from Windows, in some situations linefeeds are sent instead of carriage returns (Enters). And linefeeds are <b>^J</b>s, 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: <b>unbind ^J main</b> or <b>bind ^J enter main</b>, depending on whether the paste contains CR + LF or only LF.</p>
<p><i>Update:</i> Since version 4.8, nano will ignore linefeed characters in a paste, so you no longer need the above workaround.</p></blockquote>
<p><i>Update:</i> Since version 4.8, nano will ignore linefeed characters in a paste (when your terminal understands <a href="https://en.wikipedia.org/wiki/Bracketed-paste">bracketed pastes</a>), so you no longer need the above workaround.</p></blockquote>
<h3><a name="4.8"></a>4.8. I've compiled nano with color support, but I don't see any color when I run it!</h3>
<blockquote><p>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 <b>syntax/</b> subdirectory of the nano source, which are normally installed to <b>/usr/local/share/nano/</b>. To enable all of them, uncomment the line <b># include "/usr/local/share/nano/*.nanorc"</b> in your nanorc. See also section <a href="#3.9">3.9</a>.</p></blockquote>
<h3><a name="4.9"></a>4.9. How do I make nano my default editor (in Pine, mutt, etc.)?</h3>

View File

@@ -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
@@ -28,10 +28,10 @@ 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
\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.

View File

@@ -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.
@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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;

View File

@@ -214,12 +214,15 @@
#define SHIFT_DELETE 0x45D
#define SHIFT_TAB 0x45F
#define FOCUS_IN 0x491
#define FOCUS_OUT 0x499
/* Special keycodes for when a string bind has been partially implanted
* or has an unpaired opening brace, or when a function in a string bind
* 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 <Tab> is pressed while the mark is on. */

View File

@@ -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. */

View File

@@ -107,6 +107,7 @@ int altpageup, altpagedown;
int altinsert, altdelete;
int shiftaltleft, shiftaltright, shiftaltup, shiftaltdown;
#endif
int mousefocusin, mousefocusout;
#ifdef ENABLED_WRAPORJUSTIFY
ssize_t fill = -COLUMNS_FROM_EOL;
@@ -266,9 +267,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 +468,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
@@ -978,7 +982,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,
@@ -1010,29 +1017,27 @@ 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);
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
}
#endif /* !NANO_TINY */
/* Although not allowed in restricted mode, keep execution rebindable. */
if (ISSET(RESTRICTED))
add_to_funcs(do_execute, MMAIN,
N_("Execute"), WHENHELP(execute_gist), TOGETHER);
#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);
@@ -1103,16 +1108,15 @@ 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);
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
@@ -1462,24 +1466,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);

View File

@@ -2426,6 +2426,8 @@ int main(int argc, char **argv)
shiftaltup = get_keycode("kUP4", SHIFT_ALT_UP);
shiftaltdown = get_keycode("kDN4", SHIFT_ALT_DOWN);
#endif
mousefocusin = get_keycode("kxIN", FOCUS_IN);
mousefocusout = get_keycode("kxOUT", FOCUS_OUT);
#ifdef HAVE_SET_ESCDELAY
/* Tell ncurses to pass the Esc key quickly. */

View File

@@ -80,6 +80,7 @@ extern int altinsert, altdelete;
extern int shiftaltleft, shiftaltright;
extern int shiftaltup, shiftaltdown;
#endif
extern int mousefocusin, mousefocusout;
#ifdef ENABLED_WRAPORJUSTIFY
extern ssize_t fill;

View File

@@ -991,16 +991,22 @@ void parse_includes(char *ptr)
}
/* Return the index of the color that is closest to the given RGB levels,
* assuming that the terminal uses the 6x6x6 color cube of xterm-256color. */
* assuming that the terminal uses the 6x6x6 color cube of xterm-256color.
* When red == green == blue, return an index in the xterm gray scale. */
short closest_index_color(short red, short green, short blue)
{
/* Translation table, from 16 intended levels to 6 available levels. */
/* Translation table, from 16 intended color levels to 6 available levels. */
static const short level[] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
if (COLORS == 256)
return (36 * level[red] + 6 * level[green] + level[blue] + 16);
else
/* Translation table, from 14 intended gray levels to 24 available levels. */
static const short gray[] = { 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 15, 18, 21, 23 };
if (COLORS != 256)
return THE_DEFAULT;
else if (red == green && green == blue && 0 < red && red < 0xF)
return 232 + gray[red - 1];
else
return (36 * level[red] + 6 * level[green] + level[blue] + 16);
}
#define COLORCOUNT 34

View File

@@ -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;
@@ -1245,6 +1245,10 @@ int parse_kbinput(WINDOW *frame)
return INDENT_KEY;
#endif
/* Spurious codes from VTE -- see https://sv.gnu.org/bugs/?64578. */
if (keycode == mousefocusin || keycode == mousefocusout)
return ERR;
switch (keycode) {
case KEY_SLEFT:
shift_held = TRUE;