Commit Graph

7078 Commits

Author SHA1 Message Date
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
15c6396d42 tweaks: rename a symbol (to be clearer), and add three missing comments 2023-05-14 08:11:05 +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
Benno Schulenberg
fdcafb83e3 startup: use a format string, to deflect format-string attacks
This fixes the second part of https://savannah.gnu.org/bugs/?63964.

Reported-by: Vince Vince
2023-03-27 12:09:21 +02:00
Benno Schulenberg
b8ead3b511 linter: use a format string, to deflect format-string attacks
This fixes the first part of https://savannah.gnu.org/bugs/?63964.

Reported-by: Vince Vince
2023-03-27 12:09:21 +02:00
Benno Schulenberg
ffff664918 tweaks: shrink the set of characters recognized as line-column separator
This slightly reduces the chance that a filename is accidentally parsed
as containing both a line and a column number at its end.
2023-03-10 15:14:31 +01:00
Benno Schulenberg
f1e238a9af tweaks: condense the code that searches for a colon plus line number 2023-03-09 12:56:17 +01:00
Benjamin Valentin
5290a85afd new feature: interpret also <filename>:<linenumber> when opening a file
Various tools will output filenames with line numbers in the format
<filename>:<line>:<column>.  Support this format in addition to the
+<line>,<column> format when opening files.

Signed-off-by: Benjamin Valentin <benpicco@googlemail.com>
Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
2023-03-08 11:48:20 +01:00
Benno Schulenberg
b5157dd9cb tweaks: avoid calling isblank()/isalpha() on what could be a signed char
The isxxxxx() functions expect their parameter to be either EOF or
a value in the unsigned char range.  Passing a negative char value
could (in theory) result in unexpected behavior.
2023-02-24 17:31:58 +01:00
Benno Schulenberg
94812d17c8 tweaks: rename a struct element, to avoid a theoretical name collision
The <term.h> header file form ncurses defines the name "tab".
2023-02-23 17:08:45 +01:00
Benno Schulenberg
0662fc4d42 shutdown: ignore a modified buffer when in view mode
In view mode it should be impossible to modify any buffer, but...
when (through some bug) the user did succeed in modifying a buffer,
this should not lead to writing out this modified buffer to disk.

Had this safety stop been present earlier, it would have prevented
the second part of https://savannah.gnu.org/bugs/?63616.
2023-02-14 10:25:38 +01:00
Benno Schulenberg
7abddbd752 tweaks: slightly improve a comment, to be more accurate
A string bind can only contain bytes (chars), not keycodes (integers,
in nano upto 0x4FF).  So, apart from an error code or a placeholder
command code, get_code_from_plantation() can only return a byte.
2023-01-26 17:01:02 +01:00
Benno Schulenberg
51c9f7270c input: let the handler of string binds return a byte whenever possible
The function get_code_from_plantation() should return ERR only when
the string bind is fully exhausted.  In the normal case, where some
bytes are still available, it should return the first of these bytes,
so that the {verbatim} function will work too.

This fixes https://savannah.gnu.org/bugs/?63702.

Bug existed since version 7.0, commit 958ec294,
since command cartouches were introduced.
2023-01-26 10:01:18 +01:00
Benno Schulenberg
b896670e85 tweaks: make two strings equal to a third, to slightly ease translation 2023-01-25 16:45:50 +01:00
Benno Schulenberg
69dd0c40bb help: give the "Replace with" prompt its own help text
This addresses https://savannah.gnu.org/bugs/?63691.

Problem existed since the help texts were introduced,
in version 1.1.3, commit b3655b4c.
2023-01-23 16:41:25 +01:00
Benno Schulenberg
2fd7888a51 bindings: show ^- instead of ^/ for 'flipgoto' when on a Linux console
This should have been part of commit 344db835 from three days ago.
2023-01-20 14:55:11 +01:00
Benno Schulenberg
344db835e4 bindings: let ^/ toggle between the 'search' and 'gotoline' menus
This extra binding allows the user to start a forward search with ^/^/,
so that they can avoid the ^W keystroke that would close a browser tab.
2023-01-17 11:00:27 +01:00
Benno Schulenberg
c8b44816fe tweaks: separate a special thanks from the preceding ones
This separation avoids the impression that we're thanking the mentioned
people for their use of nano (something they probably don't do).

(Also, remove two other blank lines -- effectively moving these two
lines further up, keeping the total amount of whitespace the same.)
2023-01-06 12:37:08 +01:00
Benno Schulenberg
6e88389fb8 copyright: update the years for the FSF 2023-01-06 10:37:15 +01:00
Benno Schulenberg
264f305d94 input: disallow bracketed pastes when in view mode
When in view mode, nothing shouldbe allowed to be entered into
(or deleted from) the buffer.

This fixes https://savannah.gnu.org/bugs/?63616.
Reported-by: Timothy Liu <liuxf19@163.com>

Bug existed since version 4.8, commit 0e6d693d.
2023-01-04 11:10:28 +01:00
Benno Schulenberg
f8ec08a928 tweaks: avoid warnings when compiling with -Wpedantic 2023-01-02 10:48:18 +01:00
Benno Schulenberg
5771f1ea14 copyright: update the last year for significantly changed files 2022-12-11 12:28:07 +01:00
Benno Schulenberg
4b35626aec rcfile: report an error when an included file does not exist
That is: do not silently return from parse_one_include() when the
given file does not exist, *and* return the filename (or pattern)
itself when it matches nothing.

This fixes https://savannah.gnu.org/bugs/?63446.

Bug existed since version 4.0, commit d3f0d32e.
2022-12-02 11:37:05 +01:00
Benno Schulenberg
846588ee81 tweaks: avoid passing NULL to access()
This prevents an unwanted message when nano
is compiled with -fsanitize=undefined.

This fixes https://savannah.gnu.org/bugs/?63447.

Problem existed since version 4.8, commit 343f97b3,
since the --rcfile option was added.
2022-11-30 12:08:47 +01:00
Benno Schulenberg
4f92b12a6a text: upon Enter, eat only lefthand blanks, not any other characters
Make sure that there is only whitespace to the left of the cursor
before setting 'allblanks' to TRUE, because this latter value will
cause these characters to be eaten (as a special case, to avoid
creating lines that contain only blanks when both --autoindent
and --breaklonglines are on).

This fixes https://savannah.gnu.org/bugs/?63407.
Reported-by: Tasos Papastylianou <tpapastylianou@hotmail.com>

Bug existed since version 2.9.8, commit d00ab406.
2022-11-28 11:01:50 +01:00
Benno Schulenberg
4b4b20f8a9 build: fix compilation when configured with --disable-comment
This fixes https://savannah.gnu.org/bugs/?63372.
Reported-by: Hannu Nyman <hannu.nyman@iki.fi>

Problem existed since version 7.0, commit 4b928b46.
2022-11-18 16:49:23 +01:00
Benno Schulenberg
9875311bcc startup: for +/string, center the found occurrence when possible
This places the cursor in a more predictable position.

This fixes https://savannah.gnu.org/bugs/?63223.

Issue existed since version 4.4, commit a9dd73fb,
since the +/string feature was introduced.
2022-10-17 12:11:41 +02:00
Benno Schulenberg
c3a453512a startup: report an empty search string also when there is a modifier
Not just for +/ (a search command without a string) should nano report
an "Empty search string", but also for +c/ or +r/ or similar.

This fixes https://savannah.gnu.org/bugs/?63222.

Bug existed since version 4.4, commit 2326bf69.
2022-10-16 11:22:32 +02:00
Benno Schulenberg
e413ed8e1d execute: show "Cancelled" instead of "Error" when the user hits ^C
(The "Cancelled" is shown with a red background, like an error,
but that is needed so that do_undo() will be called afterward.)
2022-10-09 16:28:06 +02:00
Benno Schulenberg
858f411447 filtering: terminate also the sender process when the user hits ^C
When the user interrupts an external command that hangs or takes too
long, nano should also kill the data-sending process (when present).

This fixes https://savannah.gnu.org/bugs/?63177.

Bug existed in this form since version 4.3, commit d946f38a,
but basically existed since version 3.0, commit ec339d3b.
2022-10-09 11:24:03 +02:00
Benno Schulenberg
19c8cea8e5 files: improve the error handling when executing an external command
When something goes wrong while executing an external command or while
piping text to it, report an error on the status bar and restore the
state of the buffer to what it was before the execution.

This fixes https://savannah.gnu.org/bugs/?63114.

Bug existed since version 2.9.8, since filtering text was introduced,
but basically existed since before version 2.0.0, since executing an
external command was introduced.
2022-10-07 09:32:11 +02:00
Benno Schulenberg
1ae10b1487 tweaks: elide an unused return value
The execute_command() function — then called open_pipe() — was changed
to have a boolean return value in commit ce62e82a eighteen years ago,
but the value has never been used or checked.
2022-10-03 10:28:43 +02:00
Benno Schulenberg
35cde9f8d7 tweaks: elide an unused parameter
The parameter has been redundant since commit 9faa9545 from two years ago.
2022-10-03 10:10:10 +02:00
Benno Schulenberg
d4d2840f5d filtering: when returning to a line number, ensure it is within range
The function line_from_number() can handle only line numbers that exist,
and will crash otherwise.  (The lack of checks makes the function fast.)

This fixes https://savannah.gnu.org/bugs/?63120.

Bug existed since commit d1e28417 from five weeks ago.
2022-09-28 16:40:31 +02:00
Benno Schulenberg
119ec47072 tweaks: replace sizeof(char) with 1, as that is assumed anyway
Since commit c848ec3d from three years ago, nano has assumed that
'char' is always a single byte.  So... elide the last occurrences
of sizeof(char), as they give a false impression of generality.
2022-09-28 12:48:45 +02:00
Benno Schulenberg
ceb305a780 tweaks: avoid iterating over the same string twice in a row
The function recode_LF_to_NUL() has to iterate over the string anyway
(to replace each \n with \0), so... instead of calling strlen() right
before it, just let recode_LF_to_NUL() return the length of the string.

(This is not speed-critical code, but... it saves one iteration over
the entire buffer contents whenever writing out a file.)
2022-09-28 12:22:40 +02:00
Benno Schulenberg
1dc2a75cb6 files: before sending data to an external command, decode LF back to NUL
(There is no need to recode the NULs back to LFs because the sending of
the data happens in a separate process, which then simply disappears.)

This fixes https://savannah.gnu.org/bugs/?63106.

Bug existed since version 2.9.8, since filtering a buffer or a region
through an external command was introduced.
2022-09-27 15:48:03 +02:00
Benno Schulenberg
8d7b716ea7 startup: quit when standard input is not a TTY (after handling arguments)
Not quitting would make nano hang for several seconds (which is very
annoying) and then die and save an emergency file (which is useless).

This fixes https://savannah.gnu.org/bugs/?63109.

Bug existed chiefly since version 5.9, commit 8d1a666d,
but basically existed since before version 2.0.0.
2022-09-27 12:18:28 +02:00
Benno Schulenberg
034af70a65 tweaks: simplify a pasting routine, modelling it after the injection one 2022-09-26 16:10:15 +02:00
Benno Schulenberg
162c213e7b tweaks: improve two comments, and exclude two unneeded prototypes
And declare two more variables as 'static', like all its neighbors.
2022-09-26 15:53:22 +02:00
Benno Schulenberg
6fde7d8a51 input: allocate two small character buffers too, and never free them
Analogous to commit 3922b531: instead of allocating and later freeing
a tiny fragment of memory for every character that the user enters (in
the edit window or at a prompt), reserve a small piece in the beginning
and retain it, and increase (but never decrease) its size as needed.

This addresses the second part of https://savannah.gnu.org/bugs/?63086.
2022-09-25 16:15:31 +02:00
Benno Schulenberg
e4abef5768 input: give up when the capacity of the keystroke buffer overflows
In theory, the 'size_t' of 'capacity' could be just two bytes, which
means the keystroke buffer would overflow for pastes that are larger
than 32 kilobytes -- which are unlikely to occur, but... possible.
However, previously there was *no* overflow check when extending the
keystroke buffer (only when trying to put back a key code), so this
check is an improvement.

(On a regular machine, 'size_t' is at least four bytes, which means
the keystroke buffer would overflow at 2 gigabytes.  Such a paste
is extremely unlikely to occur, so this check is really a no-op.)
2022-09-25 10:17:32 +02:00
Benno Schulenberg
3922b531a8 input: allocate a small keystroke buffer, and never free it
Instead of allocating and freeing a tiny fragment of memory for every
keystroke, reserve a small piece in the beginning and then retain it,
because it will be needed again and again and again.  Increase the size
when needed (for a large paste, probably), but don't bother to shrink
it afterward.

This addresses the first part of https://savannah.gnu.org/bugs/?63086.
2022-09-25 09:22:29 +02:00
Benno Schulenberg
0d1438a731 tweaks: reshuffle a declaration, and correct the wording of a comment
Also, drop an unneeded condition, as memmove() allows moving zero bytes.
2022-09-23 09:34:14 +02:00
Benno Schulenberg
7eb66d3e09 tweaks: condense a comment, add two small ones, and reshuffle a line
(Apart from reducing the verbosity of the long comment, also harmonize
its format: mentioning the FreeBSD key always first.)
2022-09-22 10:50:05 +02:00
Benno Schulenberg
c7a600063d tweaks: reshuffle some lines, to be more readable instead of compact 2022-09-20 16:21:32 +02:00
Benno Schulenberg
f420f7c177 verbatim: do not overwrite the status bar when the code is invalid
Move the triggering of the line redraw out of the error path, and
into a better place: next to the normal clearing of the feedback.

This fixes https://savannah.gnu.org/bugs/?63053.

Bug existed since version 6.0, commit 6d828cf4.
2022-09-13 16:57:28 +02:00
Benno Schulenberg
50954a4b6a search: skip a match on the magic line, as it is a just convenience line
As the magic line isn't really a line (it is not counted in the number
of lines read and written), and nothing is on it (not even a newline),
it doesn't make sense to allow any regex, like ^ or $, to match it.

This fixes https://savannah.gnu.org/bugs/?63034.
Indirectly-reported-by: Mike Scalora <mike@scalora.org>

Bug existed since before version 2.0.0.
2022-09-12 08:47:51 +02:00
Benno Schulenberg
567310e698 tweaks: reduce four variations of a message to a single common form
(This could have been done a long time ago, but it simply didn't occur
to me.)
2022-09-12 08:45:37 +02:00
Benno Schulenberg
f90b710c9b tweaks: group the special keycodes for implanted strings together
This shows better that they are related.
2022-09-11 17:49:44 +02:00
Benno Schulenberg
8198fd9c58 tweaks: reword and/or condense four comments 2022-09-11 16:29:02 +02:00
Benno Schulenberg
358a10e3cc tweaks: elide an assignment by iterating with the target variable 2022-09-11 12:03:06 +02:00
Benno Schulenberg
7b935e0d40 tweaks: elide an intermediary variable that is no longer needed 2022-09-11 11:57:11 +02:00
Benno Schulenberg
7034c3cc47 tweaks: drop shunting of flags by calling the needed function directly
Calling strstrwrapper() with the Backwards, Casesens, and Regex flags
unset is equivalent to calling mbstrcasestr().  So... do that instead
and quit saving and restoring the flags for each call of findfile().

This saving-and-restoring has been redundant since commit b0957254
from eight years ago.
2022-09-11 11:51:34 +02:00
Benno Schulenberg
e30eadb4de verbatim: don't show dots during Unicode input, as they give wrong idea
The dots gave the impression that the next keystroke (hex digit) would
land somewhere on the dots.  But this is not so -- the current digits
are instead shifted to the left and the new digit is added at the end.

Also adjust and improve several comments.
2022-09-11 09:23:44 +02:00
Benno Schulenberg
3e3f4a167a tweaks: elide a function that does not need to be a separate function
Also elide three calls of tolower(), using ORing with 0x20 instead,
as we're dealing with plain ASCII here.

Rename a variable too, away from a double abbreviation.
2022-09-11 09:01:06 +02:00
Benno Schulenberg
c98528f8d3 tweaks: simplify a function now that a Unicode code can be typed quicker 2022-09-11 09:01:06 +02:00
Benno Schulenberg
75e5f885e5 verbatim: allow the user to finish Unicode input with <Enter> or <Space>
Instead of requiring always six digits, allow the user to indicate
with <Enter> or <Space> that the digits typed so far are the complete
Unicode code point (when prefixed with the missing number of zeroes).

This fulfills https://savannah.gnu.org/bugs/?63021.

Inspired-by: the <Ctrl+Shift+U> shortcut that some desktops have
2022-09-11 09:01:06 +02:00
Benno Schulenberg
40b9e68e02 goto: don't center the current line when the user specified a column only
This does not quite do what I would have liked (scroll only when needed)
when on a softwrapped line and jumping to a different chunk, but... it's
still better than needlessly centering the line.

(The user can still center the line, if that is what they want, by using
a period or a slash instead of a comma.)

This addresses https://savannah.gnu.org/bugs/?63008.
2022-09-04 10:49:52 +02:00
Benno Schulenberg
9904aa5538 tweaks: make the crawl use the whole screen also in the tiny version
Nobody will configure nano with --enable-tiny --enable-extra, but *if*
someone does, the title bar should be absent during the crawl.

Also, swap two messages, so that their order in the POT file will be
more sensible -- a closing brace comes after the function name.
2022-09-01 08:38:18 +02:00
Benno Schulenberg
41b89aef8c tweaks: move the arrays of menu names and symbols to where they are used
Also, use a better return value for the "unrecognized name" case,
so that it cannot possibly be confused with the "all menus" case.
2022-08-31 17:28:09 +02:00
Benno Schulenberg
3925c137a4 tweaks: make two error messages more succinct and easier to translate
"Cannot map name %s to <thing>..." was unnecessarily verbose and vague.
I have kept these strings unchanged all these years because I didn't
want to invalidate the existing translations.  But now it's time to
harmonize things and simply say "Unknown <thing>: %s" for an invalid
function name, menu name, option name, and syntax name.

("No such <thing>: %s" is nice and snappy, but its translations often
are clumsy and longer and unclear.)
2022-08-31 16:57:58 +02:00
Benno Schulenberg
97fa42c82b memory: avoid a leak when a string bind specifies an unknown menu
(It is a harmless leak, but LeakSanitizer is loud when it complains.)

After having determined that there is a menu name, first check that
it is valid, before processing the string or the function name.

This fixes https://savannah.gnu.org/bugs/?62991.

Problem existed since version 2.9.4, since string binds were introduced.
2022-08-31 16:32:40 +02:00
Benno Schulenberg
ccabaac5a0 build: exclude two unneeded functions correctly from the tiny version
This also amends commit 4f9abb52 from yesterday -- I don't know how I
managed to overlook the warning.  :/
2022-08-29 12:31:39 +02:00
Benno Schulenberg
6243831dfb build: add options --disable-formatter and --disable-linter to configure
This makes more sense than letting the formatter and the linter depend
on ENABLE_COLOR (which maybe should have been named ENABLE_SYNTAX).

This fulfills https://savannah.gnu.org/bugs/?50080.
2022-08-29 08:28:28 +02:00
Benno Schulenberg
4f9abb52a4 build: fix compilation when configured with --enable-tiny
Problem existed since commit d1e28417 from four days ago.
2022-08-28 14:56:44 +02:00
Benno Schulenberg
7bab8780ad tweaks: rewrap some lines, drop a redundant call, and reshuffle a line
Six years ago, commit a878f5f1 introduced a call of regenerate_screen()
directly in the input routine, which made the call of refresh_func() in
the prompt routine redundant -- except when in the file browser.
2022-08-28 09:03:09 +02:00
Benno Schulenberg
d0dc270eec tweaks: rename two record elements and three parameters, for clarity 2022-08-28 08:58:36 +02:00
Benno Schulenberg
cd9402075a tweaks: elide a variable, rename another, and reshuffle an assignment 2022-08-26 09:29:44 +02:00
Benno Schulenberg
b1f3bdfcbd extra: use the whole terminal for the crawl, and quicken it a bit
Since version 6.0, with option --zero, the edit window can cover
the whole terminal.  Make use of this also for the credits crawl.

Also, shorten and quicken the crawl a bit, and make it start always
on the bottom row, instead of (for mysterious reasons) one row higher
when the terminal has an odd number of rows.

Furthermore, don't put back the key the user typed to stop the crawl.
2022-08-26 09:17:17 +02:00
Benno Schulenberg
541a2dbc88 feedback: suppress undo/redo messages when option --zero is in effect
This fixes https://savannah.gnu.org/bugs/?62956.

Problem existed since version 6.0, since --zero was introduced.
2022-08-25 08:48:07 +02:00
Benno Schulenberg
d1e28417d5 tweaks: move to a given line number more efficiently
Instead of starting always from the top of the buffer, start at the
current line, as it is quite likely to be near the target line.

(Since the previous commit we're assuming that openfile->current is
always valid, so we might as well make use of this assumption.)

Also, rename a parameter to make its meaning more explicit.
2022-08-24 16:29:29 +02:00
Benno Schulenberg
9410a55679 undo: make sure the current line is defined before it is referenced
After undoing an <Enter> or redoing a line join, it is likely that the
"eaten" and freed line was the current line.  In fact, goto_line_posx()
should not refer to it any more, but... accommodate for this and just
set openfile->current to a valid value before calling goto_line_posx().

This fixes https://savannah.gnu.org/bugs/?62952.

Bug existed since version 6.3, commit eea3e1f0.
2022-08-24 15:45:24 +02:00
Benno Schulenberg
25ceefbd89 prompt: ingest queued characters before handling any subsequent function
This fixes https://savannah.gnu.org/bugs/?62946.

Bug existed since commit 40a4225e from five days ago.
2022-08-24 09:28:14 +02:00
Benno Schulenberg
a37c4bb59e tweaks: reshuffle a line, to group things better 2022-08-23 15:40:27 +02:00
Benno Schulenberg
ee1f8a0494 prompt: return FALSE for non-editing functions also in the tiny version
This fixes https://savannah.gnu.org/bugs/?62942.

Bug existed since commit 2f25b6a6 from four days ago.
2022-08-23 15:32:30 +02:00
Benno Schulenberg
2c5459a1b7 tweaks: fold two cases together, because they basically do the same 2022-08-21 16:57:03 +02:00
Benno Schulenberg
b561c386c3 tweaks: discard a bracketed paste in the browser more efficiently 2022-08-21 10:45:49 +02:00
Benno Schulenberg
a374dd0359 prompt: toggle the help lines only for the 'nohelp' toggle
This fixes https://savannah.gnu.org/bugs/?62914.

Problem existed since commit 958ec294 from three days ago.
2022-08-21 10:22:38 +02:00
Benno Schulenberg
aba4f4e0e2 tweaks: avoid sometimes calling a function three times in a row 2022-08-21 09:59:55 +02:00
Benno Schulenberg
210c94d82f prompt: allow rebinding also ^N, ^Q, and ^Y at the yes-no prompt
Checking for the literal ^N, ^Q, and ^Y before checking for do_toggle
and full_refresh made it impossible to rebind any of those keystrokes
to these two functions.  (Not that anyone would want this, but...)

Problem existed since version 4.3, commits 341601e1 and 82aea04c.
2022-08-21 09:42:21 +02:00
Benno Schulenberg
c410ba4d42 tweaks: reshuffle two lines, for conciseness and in preparation 2022-08-21 09:28:07 +02:00
Benno Schulenberg
f3738fe164 tweaks: don't use a pointer when the value itself is all that is needed 2022-08-21 09:12:35 +02:00
Benno Schulenberg
04a08fe6a5 tweaks: rename a variable, away from an abbreviation 2022-08-21 09:02:32 +02:00
Benno Schulenberg
40a4225ed8 tweaks: reshuffle some code, to not determine a shortcut twice
This addresses https://savannah.gnu.org/bugs/?62913.

Problem has existed since version 2.1.0, commit eb64314f.
2022-08-19 16:38:55 +02:00
Benno Schulenberg
801622ce19 tweaks: normalize the indentation after the previous change 2022-08-19 12:48:15 +02:00
Benno Schulenberg
67750a30ba tweaks: reshuffle some code and drop some comments, for conciseness 2022-08-19 12:47:49 +02:00
Benno Schulenberg
2f25b6a650 tweaks: elide a parameter by moving the general case one level up 2022-08-19 11:56:01 +02:00
Benno Schulenberg
5a3bd329d6 prompt: prevent execution of inadmissible functions in view mode
This fixes https://savannah.gnu.org/bugs/?62912.

Bug existed since commit 958ec294 from earlier today,
but was enabled by commit 433dd921 from three days ago.
2022-08-18 16:01:31 +02:00
Benno Schulenberg
5cee9f183b build: exclude some pieces that are not needed with --disable-nanorc 2022-08-18 09:11:49 +02:00
Benno Schulenberg
958ec294b2 input: interpret commands of the form {functionname} inside string binds
This allows specifying bindable functions in a string bind by name
instead of by the literal control code or escape sequence to which
they are bound, which makes for a much more readable string bind,
and also allows specifying functions that are not bound to any key.

The opening brace, {, is made into a special symbol inside a string
bind, and each literal occurrence there needs to be escaped as {{}.

This fulfills https://savannah.gnu.org/bugs/?61692.
Requested-by: Tasos Papastylianou <tpapastylianou@hotmail.com>

Original-idea-by: Brand Huntsman <alpha@qzx.com>
  https://lists.gnu.org/archive/html/nano-devel/2018-02/msg00006.html
2022-08-18 09:07:05 +02:00
Benno Schulenberg
3a781fd719 help: move the M-Del item up, so that M-PgUp and M-PgDn are paired
(It needs a huge terminal and a tiny font for these to come into view,
but... it's possible.)
2022-08-17 15:11:03 +02:00
Benno Schulenberg
f4a2e7efe2 tweaks: move the --magic option up, so that --zero comes last
This makes that the three options that change the default layout
of the interface (--stateflags, --minibar, --zero) come last.

Also, sort the option letters into a consistent order in the code.
2022-08-17 14:31:44 +02:00
Benno Schulenberg
027365503f tweaks: add parentheses for consistency, and reshuffle for conciseness
(That 'also_the_last' now gets reset to FALSE whenever the cursor moves
to a different line is fine -- it is redundant when the mark is off, but
it does no harm.)
2022-08-17 09:34:08 +02:00
Benno Schulenberg
e31d59ebc8 tweaks: move two checks plus corresponding calls to a better place
It was silly to check again specifically for <Del> and <Bsp> after
any possible keystroke had been handled.  It was an anomaly.

This makes the tail of do_deletion() similar to the tail of inject().

(That sometimes the current line is redrawn twice is acceptable -- how
often does one type <Backspace> while having Shift-selected something?
Normally one wouldn't, because it would cancel the selection, so it's
fine to accept some inefficiency for this case.)
2022-08-17 09:01:55 +02:00
Benno Schulenberg
11178e14ab tweaks: rename a macro for clarity, and normalize some indentation
(Continuation lines should be indented by at least two extra tabs.)
2022-08-17 08:41:14 +02:00
Benno Schulenberg
0bcbd0015f tweaks: check the multiline regexes only for Delete and Backspace
The checking for all functions that are marked as not-okay-for-view-mode
was excessive and unneeded.  It had been inherited from commit d47d8cd4
from thirteen years ago, and was never verified for correctness.

This addresses the main part of https://savannah.gnu.org/bugs/?62903.
2022-08-16 16:23:44 +02:00
Benno Schulenberg
271bd5d3ba tweaks: allow the linter to be used in view mode, as it makes no changes
The linter has been marked as NOVIEW since it was introduced in 2.3.3.
But that was a mistake, as the tool does not change the buffer contents.

This addresses a minor part of https://savannah.gnu.org/bugs/?62903.
2022-08-16 16:06:18 +02:00
Benno Schulenberg
74d252a68f tweaks: drop a parameter that is no longer used
The previous commit made the 'viewok' parameter redundant.
2022-08-16 15:12:52 +02:00
Benno Schulenberg
4b928b466a tweaks: determine in another way whether a shortcut is okay in view mode
This addresses the other part of https://savannah.gnu.org/bugs/?62899.
2022-08-16 15:03:02 +02:00
Benno Schulenberg
10b4d0c8ad tweaks: use an auxiliary variable to avoid dereferences of 'shortcut'
This is especially meant to avoid dereferences of 'shortcut' after its
linked function has been executed, because in an upcoming commit this
execution may have freed the shortcut's structure.

(For symmetry, make the same change also in do_statusbar_input(), even
though it is not needed there.)

This addresses one part of https://savannah.gnu.org/bugs/?62899.
2022-08-16 15:03:02 +02:00
Benno Schulenberg
433dd92196 tweaks: drop an unneeded check for permissibility of prompt shortcuts
The only menus that are accessible in view mode are WhereIs, Insert,
WhereIsFile, GoToDirectory, and Help.  In the WhereIs menu, the only
keystroke that is not allowed in view mode (^R) is caught explicitly.
In the other four menus, all available shortcuts are permissible in
view mode, so... there is no need to check them at execution time.

(The ^R keystroke in the WhereIs menu is still shown in view mode
so as not to upset the pairing of the subsequent shortcuts.)
2022-08-15 14:49:03 +02:00
Benno Schulenberg
78d284881c help: don't show the New-Buffer toggle when in view mode
Since commit 63f2be7a from four years ago, view mode always sets
multibuffer mode, allowing ^R (Insert) to be invoked.  But the
user is then not allowed to switch multibuffer mode off, so...
don't show the toggle.
2022-08-15 11:53:54 +02:00
Benno Schulenberg
a36b726bde completion: search through all open buffers for possible completions
This allows one to complete also words that are present in other files
(when these are open in other buffers).

This fulfills https://savannah.gnu.org/bugs/?61691.
Requested-by: Tasos Papastylianou <tpapastylianou@hotmail.com>

Original-patch-by: Marco Diego Aurélio Mesquita <marcodiegomesquita@gmail.com>
2022-08-12 10:20:27 +02:00
Benno Schulenberg
83629b9991 startup: ensure that +/string centers the match also with --linenumbers
When confirm_margin() first sets the margin needed for the requested
line numbers, also then it needs to keep 'focusing' TRUE.  Only when
actually toggling --linenumbers ON (from a zero margin to something)
should focusing be suppressed, in order to obtain smooth scrolling
when the cursor is pushed off-screen.

This fixes https://savannah.gnu.org/bugs/?62885.

Bug existed since version 4.4, since the search-at-startup feature
was introduced.
2022-08-11 09:32:01 +02:00
Benno Schulenberg
405c66e864 tweaks: delete a flag that is no longer used
Suspension is always enabled since version 6.0.

(Also, swap two conditions, to match identical pairs elsewhere.)
2022-08-09 12:01:09 +02:00
Benno Schulenberg
e5df84a9ed help: prioritize the unshifted Meta keystrokes for buffer switching
In many keyboard layouts M-< and M-> are awkward to type (in a Spanish
layout, for example: Alt+Shift+AltGr+Z and Alt+Shift+AltGr+X when there
is no LSGT key), whereas M-, and M-. are simple two-key keystrokes in
most Latin-script layouts.  So, show M-,/M-. before showing M-</M->.

Also, make a condition more precise, to not show M-Left and M-Right in
the tiny version, when those shortcuts are not understood.
2022-08-05 16:29:21 +02:00
Benno Schulenberg
c599bc9bff tweaks: rename a variable, to not be the same as a function name 2022-08-01 09:17:35 +02:00
Benno Schulenberg
54ded4527a options: stop accepting -z, as --suspendable has been dropped too
This should have been part of commit 98f9518b from seven weeks ago.
2022-07-31 19:47:11 +02:00
Benno Schulenberg
4f433cd601 tweaks: add a translator hint 2022-07-27 11:24:08 +02:00
Benno Schulenberg
accecb9863 tweaks: reshuffle a few lines, to group things better 2022-07-26 12:28:49 +02:00
Benno Schulenberg
b760388bbf help: reshuffle two shortcuts so that more help-line items are paired
Since version 6.0, Suspend is no longer bound by default, which meant
that it dropped out of the help lines, leaving the items after it in an
unpaired arrangement.  Move the Suspend item and its intended partner
to near the end of the list, to reestablish pairing for several items.
2022-07-25 09:08:02 +02:00
Benno Schulenberg
bb18524cce formatter: instead of leaving curses, use full_refresh() to wipe messages
This makes invoking the formatter cleaner, by giving feedback and *not*
leaving curses mode.  Leaving curses mode had the small advantage that
any messages from the formatter would be on the terminal after closing
nano.  But it had the disadvantage that invoking the formatter flashed
the screen.

This basically reverts commit 2b9f0619 from three years ago and then
solves the issue of intruding formatter messages in a different way.

This fulfills https://savannah.gnu.org/bugs/?62789.
Requested-by: Gert Cuykens <gert.cuykens@gmail.com>
2022-07-25 08:25:15 +02:00
Benno Schulenberg
05eaa0f0d7 tweaks: improve a comment, and reshuffle two functions plus some lines 2022-07-24 16:51:39 +02:00
Benno Schulenberg
d4a1dbd4a9 tweaks: rename two variables, to not contain the name of another
Also, elide an unneeded condition: when not softwrapping, left_x will
be zero, which is always smaller than or equal to the indentation.

Furthermore, reshuffle a few lines, improve three comments, and adjust
one to mention the parameter that was added in the previous commit.
2022-07-22 15:27:41 +02:00
Benno Schulenberg
0e9bef3429 display: remember text and column positions when softwrapping a line
This adjusts the main softwrapping routine so that it remembers the
reached point in a line's text and the corresponding column.  This
avoids having to scan the line from the beginning for each iterative
call, and thus saves a substantial amount of time when softwrapping
very long lines.

This mitigates https://savannah.gnu.org/bugs/?62442.
Reported-by: Devin Hussey <husseydevin@gmail.com>

Original-patch-by: Devin Hussey <husseydevin@gmail.com>
2022-07-20 14:06:24 +02:00
Benno Schulenberg
34238dc119 files: designate the root directory with a simple "/", not with "//"
The double slash would derail the file browser, causing a crash.

This fixes https://savannah.gnu.org/bugs/?62760.
Reported-by: Frank Wolff

Bug existed since version 6.3, commit fdd946c0.
2022-07-13 19:28:53 +02:00
LIU Hao
ec0c13afda build: ignore errors from git describe
Due to CVE-2022-24765, Git refuses to operate on local repositories if
it runs as a different user from its owner.  Since version 2.35.2:

  $ sudo git describe --tags
  fatal: unsafe repository ('/home/lh_mouse/GitHub/nano-win' is owned by someone else)
  To add an exception for this directory, call:

    git config --global --add safe.directory /home/lh_mouse/GitHub/nano-win

Conventionally, a user, who wishes to build and install nano from Git,
does this:

  $ ./configure
  $ make
  $ sudo make install

The first `make` command builds the program as the current user.
The `make install` then installs the built files.

However, we have a recipe for 'revision.h' that is always executed,
even in the case of `make install`.  As here it is run as root, Git
actually fails and produces an empty string.  This causes `make install`
to rebuild nano.o and winio.o and results in an empty version string in
the upper left corner.

The solution is simple: First we attempt a dryrun of `git describe`.
If it fails, 'revision.h', which should have been updated by the first
`make` command, will be left intact.

Reference: https://nvd.nist.gov/vuln/detail/CVE-2022-24765

Signed-off-by: LIU Hao <lh_mouse@126.com>
2022-06-14 11:54:47 +02:00
Benno Schulenberg
ed41b3cefa version: condense the copyright message, to not dominate the output
It is enough to mention the year of the current release in the copyright
statement -- no need to specify the historical range of years.
2022-06-12 17:31:08 +02:00
Benno Schulenberg
98f9518bf2 rcfile: remove five obsolete or deprecated keywords 2022-06-12 17:03:15 +02:00
Benno Schulenberg
450bfa7a75 build: fix compilation for --enable-{tiny,nanorc,color} 2022-04-22 11:47:21 +02:00
Benno Schulenberg
a52ac1375a formatting: change cursor position only after saving it in the undo item
When one wants an Undo to restore the cursor to where it was before an
operation, one shouldn't fiddle with the position before it is stored
in the relevant undo item.

This fixes https://savannah.gnu.org/bugs/?62341.

Bug existed since version 4.9, commit 38af812a.

(This effectively reverts commit 38af812a from two years ago.)
2022-04-21 12:31:19 +02:00
Benno Schulenberg
6257dec0a7 filtering: close all output descriptors, so that 'xsel' will terminate
For some reason, when copying something to the system clipboard
with 'xsel', it wants to see all output descriptors closed before
it will exit without requiring ^C.

This fixes https://savannah.gnu.org/bugs/?62276.
Reported-by: Shi Yanling <sylphenix@126.com>

Bug existed since version 2.9.8, since piping text through an
external command was introduced.
2022-04-12 11:09:09 +02:00
Benno Schulenberg
ea9d49b9d8 tweaks: remove some stray spaces before a comma 2022-04-11 10:31:39 +02:00
Benno Schulenberg
42c7bfcf8a verbatim: with --zero, keep cursor in viewport when it was on bottom row
This fixes https://savannah.gnu.org/bugs/?62285.

Bug existed since version 6.0, since --zero was introduced.
2022-04-11 10:28:09 +02:00
Benno Schulenberg
e67d1bfeb8 build: fix compilation when configured with --disable-color 2022-04-08 11:35:44 +02:00
Benno Schulenberg
03b85df4eb tweaks: remove redundant braces, and add two translator hints 2022-04-08 09:38:42 +02:00
Benno Schulenberg
7db5c2f225 files: when the working directory exists, still check its accessibility
This fixes https://savannah.gnu.org/bugs/?62258.

Bug existed since commit 940b5eaa from yesterday.
2022-04-06 16:41:45 +02:00
Benno Schulenberg
603ce231d0 tweaks: simplify a fragment of code, and fold two lines together 2022-04-05 12:40:45 +02:00
Benno Schulenberg
940b5eaad1 files: show a warning when the working directory is gone (when used)
Instead of silently opening an empty buffer when the user tries to
open a file in the current but disappeared directory, give a clear
warning about the absence of this directory.

This improves the fix for https://savannah.gnu.org/bugs/?62244.
2022-04-05 12:34:04 +02:00
Benno Schulenberg
fdd946c02c files: do not change to a higher directory when the working one is gone
When the working directory has been deleted from under nano's feet,
get_full_path() would move up in the directory tree until getcwd()
would succeed.  This meant that a filename that was specified on the
command line without any path (or with a relative path) would refer
to a different file than what the user intended.  Not good.

So, stop changing directories in get_full_path().  Use the realpath()
function with NULL as second parameter instead -- it has been part of
the POSIX standard since 2008, time enough for operating systems to
have caught up.

In the bargain, this saves seventy lines of complicated logic.

This fixes https://savannah.gnu.org/bugs/?62244.

Bug existed since version 2.0.0, commit 85e35e67.
2022-04-04 12:52:35 +02:00
Benno Schulenberg
fe42eb7a1a painting: stop coloring an extremely long line after 2000 bytes
Especially when softwrapping and when multiline regexes are involved,
colorizing takes roughly exponential time relative to the line length.
To avoid bogging down, stop colorizing a line beyond a certain point.

This mitigates https://savannah.gnu.org/bugs/?61799.
Reported-by: Devin Hussey <husseydevin@gmail.com>
2022-04-03 12:28:22 +02:00
Benno Schulenberg
df7b0a6d97 execute: clear an anchor only when the whole buffer gets filtered
Although an anchor at the top line is rather pointless, it shouldn't
get cleared when the user pipes just a part of the buffer through an
external command.
2022-03-28 11:38:22 +02:00
Benno Schulenberg
fcf598e797 execute: stay on the same line number when filtering the whole buffer
When the filter command makes just small, per-line changes, keeping the
cursor at the same line number allows the user to observe the effect of
the changes -- which is not possible when the cursor gets moved to the
end of the buffer.

This partially fulfills https://savannah.gnu.org/bugs/?57248.
2022-03-28 11:15:04 +02:00
Benno Schulenberg
d9cb12f6e3 tweaks: move the saving and restoring of flags to where it is needed 2022-03-27 18:44:48 +02:00
Benno Schulenberg
0f23729253 tweaks: prevent the adding of an unwanted newline in a different way
The prevention is needed only for temporary files, not for normal files.
2022-03-27 18:20:17 +02:00
Benno Schulenberg
3def429290 tweaks: don't leave an orphaned temporary file behind when writing fails 2022-03-27 12:37:01 +02:00
Benno Schulenberg
803ea0d7a0 justify: stay at the same line number when doing a full justification
The same line number may not be the same position in the text, but
it will be approximately -- and it is certainly better than leaving
the cursor at the end of the buffer.

This fulfills https://savannah.gnu.org/bugs/?61175.
2022-03-24 17:05:55 +01:00
Benno Schulenberg
9b014876cd tweaks: trim a few comments, rename a function, and reshuffle some code 2022-03-20 13:20:31 +01:00
Benno Schulenberg
9ccf85eaa8 tweaks: avoid a function call when two plain assignments will do 2022-03-18 11:40:03 +01:00
Benno Schulenberg
93fa53c3e8 tweaks: elide an unneeded call of strlen() 2022-03-18 11:36:10 +01:00
Benno Schulenberg
eea3e1f0b2 tweaks: make the triggering of the recalculation of multidata less eager
Also, trigger recalculation when an undo or redo causes a large enough
forward jump.
2022-03-18 11:29:18 +01:00
Benno Schulenberg
e6e22ea976 tweaks: normalize the indentation after the previous change 2022-03-17 14:09:09 +01:00
Benno Schulenberg
80c2000f87 tweaks: simplify a bit of code, eliding two labels and three gotos 2022-03-17 14:09:09 +01:00
Benno Schulenberg
15a0a129c8 painting: recalculate the multidata when making large strides or changes
When making a forward movement larger than a screenful, we cannot rely
on the multidata of the line before the new screen start to have been
set correctly by a previous screen drawing, so we need to recompute all
of the multidata, for the whole buffer, so that afterward we can freely
move around and draw the screen without having to do any backtracking.

Also when a piece of text larger than a screenful is pasted or inserted,
all the multidata needs to be recomputed.

This fixes https://savannah.gnu.org/bugs/?60041,
and fixes https://savannah.gnu.org/bugs/?62056.

First bug existed in this form since version 2.4.2, commit d49c267f
(but editing Python was incomparably slower in those days).

Second bug existed since version 5.6, commit 43d94692.
2022-03-17 14:07:42 +01:00
Benno Schulenberg
51bd04b541 painting: colorize text also after an unterminated start match
This does not waste time looking for an end match, which is especially
wasteful when there is none.  Also, it makes the coloring behavior more
consistent: any start match will cause coloring of the subsequent text,
no matter whether the user is in the middle of the file or near the end.
2022-03-14 09:12:55 +01:00
Benno Schulenberg
18ba7f60c1 painting: tighten the check for a lacking end match on a colored line
As it's possible for the start regex to match what is actually the end
match of a multiline thing (see the Python triple quotes, for example),
make sure that such a detected start match is *not* an end match, just
to avoid a needless full-screen refresh.
2022-03-08 09:47:36 +01:00
Benno Schulenberg
67adef8f6c display: suppress spotlight yellow and error red when NO_COLOR is set
This makes nano conform to the https://no-color.org/ idea: suppressing
any color in the output (in the default setup) when NO_COLOR is set in
the environment.

Specifying a color for any interface element will, however, re-enable
also yellow for the spotlight and red for error messages.
2022-03-06 17:03:42 +01:00
Benno Schulenberg
ed60e16974 tweaks: exclude the extra truncation warning from the tiny version 2022-03-04 12:12:48 +01:00
Benno Schulenberg
47c11ae83d feedback: show extra warning when writing failed due to "No space left"
This mitigates https://savannah.gnu.org/bugs/?36864.
Reported-by: Clarence Risher <sparr0@gmail.com>

Problem has existed since the beginning, as nano empties the existing
file before writing the current buffer contents into it.
2022-03-03 11:12:41 +01:00
Mike Frysinger
8173b1bfbe general: fix building for Windows
Fix building with x86_64-w64-mingw32 to cross-compile native Windows
programs.  Need to:

  * add checks for missing functions
  * don't use signals that are unavailable on the platform
  * avoid useless non-Linux sys/ioctl.h include
  * use putenv instead of setenv as the latter is unavailable
2022-03-01 11:05:07 +01:00
Benno Schulenberg
93400ec8a1 execute: don't crash when an empty buffer is piped through a command
That is, take into account that the cutbuffer could be NULL
(when updating the undo item).

This fixes https://savannah.gnu.org/bugs/?62107.

Bug existed since version 4.9, commit b15c5a7e.
2022-02-24 16:50:18 +01:00
Benno Schulenberg
0d85a798e5 painting: look for another start match only after the actual end match
The 'endmatch.rm_eo' value is relative to the end of the start match,
so to find the end of the end match, one has to add 'startmatch.rm_eo'
plus 'endmatch.rm_eo' to the starting point of the line.

This addresses https://savannah.gnu.org/bugs/?62091.

Problem existed since version 5.6, commit 0596b875.
2022-02-21 10:46:28 +01:00
Benno Schulenberg
756cd4a4b8 tweaks: store a result, to avoid calling a function twice 2022-02-18 10:27:47 +01:00
Benno Schulenberg
1b186fcff3 tweaks: rename two more variables, and drop unneeded initializations
Also, make sure that there is a space in the complaint so that the
later strstr() call cannot fail.  And reshuffle a line.
2022-02-17 14:20:45 +01:00
Benno Schulenberg
165da9b447 tweaks: rename a variable, reshuffle five lines, and snip two comments 2022-02-17 14:00:55 +01:00
Benno Schulenberg
aea10ed383 tweaks: rename two variables (to get rid of a prefix), and elide a third 2022-02-17 13:57:22 +01:00
Benno Schulenberg
8fccb31436 linter: adjust the parsing to accommodate for a modern 'pyflakes'
In version 2.2.0, pyflakes changed its output format,
from 'filename:line: text' to 'filename:line:column text'.

This fixes https://savannah.gnu.org/bugs/?62057.

Problem existed since version 2.9.0, commit 5dcf375f.

(That commit tried to compensate for an introductory message from gcc
that no longer seems to exist.)
2022-02-16 15:39:01 +01:00
Benno Schulenberg
fe1fecc5da tweaks: rename a variable, to be more correct, and adjust two comments
The new name 'gauge' more clearly indicates that it is a distance
between two "columns", two "pillars", two "piles".  Using 'longest'
was poor, because in fact it was set to 'widest + 10'.

(Also, change the type of 'piles' to an integer -- it will always
be smaller than COLS, and COLS is an integer.)
2022-02-13 13:07:52 +01:00
Benno Schulenberg
87612582ff tweaks: use an intermediate variable, to avoid using one for two purposes 2022-02-13 12:43:55 +01:00
Benno Schulenberg
c3a53cffbc tweaks: rename a variable, to be more fitting
It is about width (cells/columns), not about length (bytes).
2022-02-13 12:19:16 +01:00
Benno Schulenberg
aeea83703b tweaks: rename a misnamed variable 2022-02-13 12:04:57 +01:00
Benno Schulenberg
27c8f13fc9 tweaks: change the type of a variable, to avoid a compiler warning
A newer compiler (gcc-10.3) said: browser.c:174:34: warning:
  field width specifier '*' expects argument of type 'int'

It's fine for 'longest' to be an integer, as a filename in Unix is
at most 255 bytes long, which can occupy at most 510 columns (when
the name consists entirely of control codes), and that fits easily
within an 'int', which has at least fifteen bits, unsigned.

Well... in theory 'tabsize' could be set to an insanely high number,
and if a filename contains several tabs, this could cause 'longest'
to overflow.  (Why doesn't the compiler warn about that?)  If that
were to occur, and the filename with the tabs were the last in the
list, then 'longest' would get set to the minimum width: 15.  That
would not be correct, but... nothing bad would happen.

This addresses https://savannah.gnu.org/bugs/?62014.
Reported-by: Mike Frysinger <vapier@gentoo.org>
2022-02-13 11:54:14 +01:00
Benno Schulenberg
c6ddae70f7 display: suppress the bottom-bar wiping only when the user is editing
This wipe suppression is meant to prevent the last row of the edit window
getting cleared when edit window and bottom window overlap, and this is
relevant only when the user is actually editing -- the file browser and
help viewer take care not to use this bottom row for content.

This fixes https://savannah.gnu.org/bugs/?62031.

Bug existed since version 6.0, commit be61aad9.
2022-02-11 16:46:05 +01:00
Benno Schulenberg
989e6a9a7e tweaks: rename two variables, and elide a near-enough duplicate
(The 'in_edit' variable was a duplicate because also when the pointer is
on the line numbers, we want to scroll when the mouse wheel is rolled.)
2022-02-04 15:51:40 +01:00
Benno Schulenberg
c28048d20f tweaks: rename another variable, to better fit in with its sisters 2022-02-04 12:17:37 +01:00
Benno Schulenberg
a24e72f972 tweaks: rename a variable, to make it clearer it refers to a window 2022-02-04 12:11:05 +01:00
Benno Schulenberg
a29aa31e93 tweaks: when discarding keycodes, don't bother parsing them 2022-02-04 11:18:52 +01:00
Benno Schulenberg
8546139997 build: fix compilation when configured with --enable-tiny
Problem existed since commit 3b657a26 from five days ago.

In addition, exclude pasting-at-the-prompt from the tiny version, as
it's hardly useful when one cannot copy a selected piece of text.
2022-02-03 13:06:21 +01:00
Benno Schulenberg
5e4645b082 copyright: update the last year for significantly changed files 2022-02-02 17:40:25 +01:00
Benno Schulenberg
f9f0a8fd67 copyright: update the years for the FSF 2022-02-02 17:10:09 +01:00
Benno Schulenberg
637a2eeb66 tweaks: rename a variable and a parameter, to be more descriptive
Also, improve two comments, to describe what the functions actually do.
2022-02-01 12:22:29 +01:00
Benno Schulenberg
13caef2de0 tweaks: remove two redundant checks
The checks have been there for fifteen months, and no one ever reported
seeing those messages.
2022-02-01 12:21:31 +01:00
Benno Schulenberg
61c6d43231 tweaks: adjust a translator hint, to fit the order in the POT file
Also, reword another hint.
2022-02-01 11:38:55 +01:00
Benno Schulenberg
a04f6e0165 help: update the description of M-D, to match the actual order of counts 2022-02-01 11:16:07 +01:00
Benno Schulenberg
3f494e359d tweaks: stop asking the terminal for its new size -- let ncurses do it
When re-entering curses mode, ncurses will pick up the new size of
the terminal and set the LINES and COLS variables appropriately.

(We don't ask the terminal for its size when nano starts up, so why
would we need to do it when the terminal is resized?)
2022-01-31 16:53:35 +01:00
Benno Schulenberg
8a06f70379 tweaks: rename a function and reshuffle its call 2022-01-31 12:31:03 +01:00
Benno Schulenberg
2290152743 menus: don't show M-6 in the help lines of any prompt
None of the editing keystrokes are shown in the menus -- they are
all "blind" keys.  This corrects a mistake in the previous commit.
2022-01-31 10:48:14 +01:00
Benno Schulenberg
3b657a26a6 prompt: allow the user to copy the answer to the cutbuffer (with M-6)
Since version 2.8.7 the user can paste text at the prompt (with ^U),
but the ability to copy what is present at the prompt was overlooked.

For feedback, the cursor is moved to the start of the answer -- like
it moves to the start of the next line when in the edit buffer.

This addresses https://savannah.gnu.org/bugs/?61702.
Reported-by: Tasos Papastylianou <tpapastylianou@hotmail.com>
2022-01-30 17:39:55 +01:00
Benno Schulenberg
ff5084479b prompt: let ^K erase text after cursor (if any), otherwise whole answer
In most cases, the cursor will be at the end of what the user typed
at the prompt (or retrieved from history), and ^K will work as it
always did, erasing the whole answer.  But if the user has moved the
cursor to somewhere in the middle of the answer, a ^K will now erase
just the part after the cursor.  A second ^K will erase the rest.

Inspired-by: Tasos Papastylianou <tpapastylianou@hotmail.com>
2022-01-29 17:23:42 +01:00
Benno Schulenberg
97f4a3f4eb tweaks: rename a variable, away from an abbreviation 2022-01-29 17:14:22 +01:00
Benno Schulenberg
1ca1732d32 tweaks: remove a redundant check -- add a different one for symmetry
Function get_input() with a non-null parameter will never return ERR.
2022-01-29 16:32:04 +01:00
Benno Schulenberg
accd2308f1 tweaks: reword two comments, and rename a variable (away from an abbrev) 2022-01-29 16:01:35 +01:00
Benno Schulenberg
10eec2fe17 input: suppress any spotlighting when there are more keycodes waiting
Because doing the spotlighting after those extra keycodes have been
handled will most likely spotlight the wrong piece of text.  Also,
if those keycodes hadn't arrived early, the first of them would have
cancelled the spotlighting.

This fixes https://savannah.gnu.org/bugs/?61962.

Bug existed since version 5.8, commit 3f340836.
2022-01-29 11:16:41 +01:00
Benno Schulenberg
d69cd759cb input: instead of moving waiting keycodes, just increment a pointer
When a large piece of text was pasted into nano, then the old way of
repeatedly moving the buffered text one more position toward the head
of the keystroke buffer would waste a lot of time.  With this change,
pasting the current NEWS file into a buffer goes down (on my machine)
from around 30 seconds to just 2.

This addresses https://savannah.gnu.org/bugs/?61822.
Reported-by: Radu Caragea <rcaragea@protonmail.com>

Problem existed in this form since version 1.3.6, commit 7483571f.
2022-01-27 10:41:24 +01:00
Benno Schulenberg
f261a8aca5 tweaks: rename a function, to not contain the name of a variable 2022-01-27 09:21:21 +01:00
Benno Schulenberg
bdf64d660b tweaks: rename a variable, for clarity and contrast 2022-01-27 09:21:21 +01:00
Benno Schulenberg
2fd30ee095 tweaks: rename a function and its two parameters, for clarity 2022-01-25 12:23:14 +01:00
Benno Schulenberg
9bc6f1797e tweaks: use some symbolic names instead of unclear numeric values 2022-01-25 11:57:34 +01:00
Benno Schulenberg
32e63fe1b8 tweaks: add some small, clarifying comments
Suggested-by: Tasos Papastylianou <tpapastylianou@hotmail.com>
2022-01-22 13:12:55 +01:00
Benno Schulenberg
1c074cc8cc files: let ^C cancel the exiting when the file on disk was changed
When the user exits with ^X and gets warned that the file on disk
has changed, then typing ^C at the question whether to continue
saving should not discard the buffer and exit, but should return
the user to the filename prompt.

This fixes https://savannah.gnu.org/bugs/?61883.
Reported-by: Tasos Papastylianou <tpapastylianou@hotmail.com>

Bug existed since version 2.9.0, commit 217cfbf3.
2022-01-22 12:30:15 +01:00
Benno Schulenberg
4d16f26ba4 help: make the description of <Tab> more accurate
And don't mention <Tab> for the 'indent' function, as the keystroke
is equivalent to M-} only when lines are marked.

Reported-by: Tasos Papastylianou <tpapastylianou@hotmail.com>
2021-12-26 11:57:57 +01:00
Benno Schulenberg
fae5f823e1 input: ensure that no more bytes are consumed than are available
The value of 'consumed' may not exceed the given 'length'.

Bug existed since version 2.9.3, commit e739448c.

(Bug was found by studying Fedora crash reports.  Thank you, Fedora!)
2021-12-12 16:45:09 +01:00
Benno Schulenberg
02d77ad5ad rcfile: recognize fourteen new color names, mostly for subdued shades
This is for people for whom the #rgb color codes are too cryptic.
2021-12-12 12:01:45 +01:00
Benno Schulenberg
abafc2ba14 tweaks: reduce redundancy (--enable-color implies --enable-nanorc)
(To make use of color, syntaxes are needed,
and syntaxes require a nanorc for their definition.)
2021-12-08 12:11:10 +01:00
Benno Schulenberg
1f0eb8d915 build: fix compilation with --enable-tiny --enable-nanorc 2021-12-08 12:06:33 +01:00
Benno Schulenberg
48a19178b8 build: fix compilation when configured with --disable-color 2021-12-08 10:00:13 +01:00
Benno Schulenberg
e542e5943e build: fix compilation when configured with --disable-nanorc 2021-12-08 09:46:02 +01:00
Benno Schulenberg
1c6f6ba212 tweaks: rename three parameters, away from single letters
Also, reshuffle two lines, to have the code after the declaration.
2021-12-03 12:19:58 +01:00