Commit Graph

7076 Commits

Author SHA1 Message Date
Collin Funk d1e2febb6d build: update a symbol that was renamed in gnulib
As noted in a gnulib NEWS item of 2023-01-07, linking now happens
against $(CLOCK_TIME_LIB) instead of $(LIB_CLOCK_GETTIME).
2024-08-27 10:20:56 +02:00
Benno Schulenberg 3d0273de45 tweaks: improve or rewrap six comments, and add two missing ones
Also, stop initializing three variables that don't need it.
2024-08-17 10:37:41 +02:00
Benno Schulenberg b5f320a2f9 tweaks: delete three redundant checks from the undo/redo code
Since commit 50954a4b from two years ago, a replacing session will
not ever change the final empty line, and thus a fresh magic line
will never need to be undone or redone.

This complements commit c6a26641 from five months ago.
2024-08-12 08:41:58 +02:00
Benno Schulenberg b812ad2926 tweaks: unwrap three lines that don't need to be wrapped
(These lines were noticed while checking that all
calls of nrealloc() use a size bigger than zero.)
2024-08-04 16:09:42 +02:00
Benno Schulenberg fe0b928b39 tweaks: move a condition to the only place that needs it
Most calls of draw_all_subwindows() are made while in the edit window.
The only call that could occur while in the file browser is the one in
regenerate_screen().  So only this call needs to be guarded against
being made while the file list is being shown.
2024-07-31 10:04:00 +02:00
Benno Schulenberg af2f218192 bindings: at a Yes-No-All prompt, accept also ^A for "All"
This can be useful when replacing text in a Japanese locale,
avoiding the need to guide the input method to produce "A".

Inspired-by: Takeshi Hamasaki <hmatrjp@users.sourceforge.jp>
2024-07-28 13:54:41 +02:00
Benno Schulenberg 572247dbd8 tweaks: reshuffle a seldom-used function to the end of an if-else series 2024-07-22 15:43:37 +02:00
Benno Schulenberg 4b03cc60cf moving: for Alt+Home/Alt+End, refresh the screen when the mark is on
When the mark is on, moving the cursor to the top or bottom row should
highlight the relevant area -- thus requiring a call of edit_refresh()
to be scheduled.

Also, drop two calls of place_the_cursor(), as that is done anyhow in
the main loop, either directly, or indirectly through edit_refresh().

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

Bug existed since version 8.0, since Alt+Home/Alt+End were introduced.
2024-07-17 17:23:12 +02:00
Benno Schulenberg c356db9f44 macro: insert it in keystroke buffer without discarding latter's contents
Instead of simply overwriting the current contents of the keystroke
buffer with the contents of the macro buffer, insert the latter's
contents at the head of the keystroke buffer.

This allows using {runmacro} in a string bind, and allows typing ahead
over a laggy connection after invoking `runmacro` (normally with M-;).

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

Bug exists since version 2.9.4, since string binds were introduced.
2024-07-16 16:44:48 +02:00
Benno Schulenberg c53839cefa tweaks: rename a symbol, away from an obscure abbreviation
Also, reshuffle its definition, and change its value to match
other special codes.
2024-07-15 09:38:01 +02:00
Benno Schulenberg 887803cb67 bindings: let the central numpad key (with Ctrl) center the current line
When NumLock is off, let Ctrl plus the central key on the numeric keypad
center the current line.

(This binding is not advertised anywhere
-- it's left as a little Easter egg.)
2024-07-15 09:37:48 +02:00
Benno Schulenberg ade975891b tweaks: add a space after a '+', for consistent formatting 2024-07-07 17:11:30 +02:00
Benno Schulenberg e5d36de24c tweaks: discard a bracketed paste in the help viewer with fewer beeps
The same change was made for the file browser two years ago,
in commit b561c386.
2024-07-07 14:25:04 +02:00
Benno Schulenberg ef1c9b9f2b tweaks: implement do_center() with a single call instead of three
This works because the main loop sets 'cycling_aim' to zero
whenever the current keystroke is not bound to `cycle`.
2024-06-15 09:57:06 +02:00
Benno Schulenberg 90e62db26e help: regroup the `center` item, placing it with the new `cycle` 2024-06-15 09:57:06 +02:00
Benno Schulenberg 498154804c bindings: let ^L put the cursor line at center, then top, then bottom
Something similar can be achieved with:

  bind ^T "{center}{bottomrow}{center}{toprow}" main
  bind ^B "{center}{toprow}{center}{bottomrow}" main

But that requires allocating two extra shortcuts, and it works right only
when the edit window has an odd number of rows, not with an even number.
Also, this new ^L behavior is available by default, out-of-the-box.
2024-06-15 09:57:06 +02:00
Benno Schulenberg d1c723bc14 new feature: add bindable function `cycle` that pushes cursor line around
On the first call, `cycle` centers the line with the cursor, on the
second consecutive call it pushes that line to the top of the viewport,
and on the third consecutive call to the bottom of the viewport.
2024-06-15 09:57:06 +02:00
Benno Schulenberg d477bfd4ee tweaks: drop two redundant conditions
The function do_tab() is only ever called when in the main edit window,
and never called while a bracketed paste is in progress.

(The two conditions were thoughtlessly copied when this fragment of code
was moved here three commits ago.)
2024-06-10 14:07:30 +02:00
Benno Schulenberg 6c81f60914 moving: use edit_scroll() only when scrolling one row is enough
When softwrapping with a tabsize larger than the width of the viewport,
scrolling one row when the cursor goes offscreen might not be enough,
so in that case use edit_redraw() instead.

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

Bug existed since version 2.9.6, commit 0d9080a2.
2024-06-10 08:15:28 +02:00
Benno Schulenberg aa844ada4e tweaks: remove the now unneeded special keycode INDENT_KEY 2024-06-09 16:48:06 +02:00
Benno Schulenberg 9b7a813069 text: do not check for <Tab> + mark while getting input but in do_tab()
This allows a {tab} in a string bind to indent a marked region.

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

Problem existed since version 7.0, since braced function names
were introduced.
2024-06-09 16:42:14 +02:00
Benno Schulenberg bc09f0992e tweaks: reshuffle some lines, to put vaguely related things together
And to slightly reduce the number of #ifdefs.
2024-06-08 17:08:17 +02:00
Benno Schulenberg 00e2309987 tweaks: make the inclusion condition for do_center() more strict
There is no reason why --enable-help should cause the centering function
to be included in a tiny version.
2024-06-08 16:56:52 +02:00
Benno Schulenberg a98f82e27b startup: no not activate --modernbindings when name starts with "e"
Activating --modernbindings when the binary's name starts with "e"
interferes with Debian's alternatives system that symlinks `editor`
to `nano` in a default install.

(Also: why "e"?  It would have made more sense to check for "m",
similar to the checking for "r" for a restricted nano.)

This reverts commit 580eaf29 from fifteen months ago.

This addresses https://savannah.gnu.org/bugs/?65810.
Reported-by: Colin Snover <nano@zetafleet.com>
2024-06-08 12:14:08 +02:00
Benno Schulenberg dcbbbf8134 input: make sure that a string-bind return value is non-negative
A negative value would lead to misinterpretation by parse_kbinput().

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

Bug existed since version 8.0, commit 51c9f727.
2024-06-03 15:40:03 +02:00
Benno Schulenberg 689748843c files: with --rectrict, prevent invoking the browser and toggling backups
Prevent also the toggling of Append and Prepend.  All four functions
should not be available in restricted mode, and are absent from the
WriteOut menu in that mode, but using {browser}, {backup}, {append}
or {prepend} in a string bind allowed to bypass the menu checks.

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

Problem existed since version 7.0, since braced function names
were introduced.
2024-06-01 11:31:09 +02:00
Benno Schulenberg ea07eb6aa3 help: show option -Y/--syntax in --help output also in restricted mode
Since version 3.2, commit 5ca444e5, nano reads the nanorc files also
in restricted mode (when not also --ignorercfiles is given), meaning
that syntaxes are available and that a specific syntax can be selected
on the command line.  So, the --help output in restricted mode should
list the relevant option: -Y<name> / --syntax=<name>.

(This should have been part of commit b81995af from six years ago.)
2024-06-01 11:00:49 +02:00
Benno Schulenberg 5251ce1b20 tweaks: simplify a condition, to match the same condition five lines back 2024-06-01 09:30:44 +02:00
Benno Schulenberg 5bc6d0ef2e tweaks: extend the deprecation period of 'set nowrap' and prefix 'bright' 2024-05-31 16:41:46 +02:00
Benno Schulenberg b92cbf5f09 rcfile: remove old bindable function 'nowrap', alias of 'breaklonglines'
The bindable function 'nowrap' has been deprecated for three years,
since version 5.5, commit e14127b8.

(The obsolete options --nowrap and 'set nowrap' continue to exist.)
2024-05-31 15:57:01 +02:00
Benno Schulenberg c26f901ba9 options: remove the deprecated synonym -$ of -S/--softwrap
The old short option -$ has been deprecated for four years,
since version 5.0, commit 7d3aad40.
2024-05-31 12:45:18 +02:00
Benno Schulenberg 49c2f5dea9 new feature: option -z lists the names of available syntaxes
When one has installed additional syntaxes, one tends to forget
what exactly is there.  So it's nice to be able to list them.

The syntaxes are listed in the reverse order in which they were
read: the most recent first.

The long form of the option is, of course, --listsyntaxes,
which can be abbreviated to --list.

This fulfills https://savannah.gnu.org/bugs/?65779.
The feature was suggested by `davidhcefx`.
2024-05-31 11:14:24 +02:00
Benno Schulenberg b408147f48 tweaks: exclude the colon-parsing code from the tiny version
The option --colonparsing is not available in the tiny version,
so there is no need for the code either.
2024-05-28 17:12:30 +02:00
Benno Schulenberg 02dd0b4ed5 options: require --colonparsing/-@ to parse colon+number after a filename
Stop doing colon parsing by default, to avoid surprises and frustration
for users that have filenames that end in a colon plus digits.

The equivalent rcfile option is, of course, 'set colonparsing'.

Using +1, or similar, before the filename disables any colon parsing
and the filename is taken as is.
2024-05-25 16:48:35 +02:00
Benno Schulenberg add945e717 files: look for digits and colons starting from the end of the filename
Starting from the end of the provided filename avoids needlessly looking
at colons that are somewhere in the middle of the path or the filename.

It also avoids inconsistenly interpreting a specified line number as a
column number when the filename itself ends with a colon plus digits
and the filename without the colon plus digits exists too.

This also removes the eliding of a backslash before a colon, which
would mangle the filename if the name actually contained a backslash
followed by a colon.

Negative line and column numbers are no longer allowed when using the
colon notation.

This fixes https://savannah.gnu.org/bugs/?65781,
and fixes https://savannah.gnu.org/bugs/?65782.

Problems existed since version 8.0, since colon parsing was introduced.
2024-05-25 16:48:24 +02:00
Benno Schulenberg 259a3c70e3 general: disable the type-ahead checking that ncurses normally does
While updating the screen, ncurses by default polls the input source
now and then to see if there is new input, and if so, stops updating
the screen and waits for the next call of doupdate() or refresh().

  https://lists.gnu.org/archive/html/bug-ncurses/2024-05/msg00077.html

Disable this polling, as it is just a waste of time, and there *might*
be situations where the intruding keystroke does not actually trigger
a new update, which could result in a half-updated screen.
2024-05-20 17:14:09 +02:00
Benno Schulenberg 2445e77535 files: avoid mistakenly setting the column number to a given line number
When the file 'foo:24' exists (but not 'foo') and the user wants to
use the colon notation to place the cursor on a certain line, then
nano would first interpret the given line number as a column number,
before noticing that 'foo' does not exist and then skipping the first
colon.  So, when such a misinterpretation occurs, the column number
needs to be reset to zero.
2024-05-18 16:02:09 +02:00
Benno Schulenberg d64235eb6e tweaks: reshuffle a declaration, adjust a comment, normalize indentation 2024-05-18 16:02:09 +02:00
Benno Schulenberg 54c8cb8c81 files: when a filename with a colon and digits exists, open that file
When the user specifies, on the command line, a filename that ends with
a colon plus digits, and that filename exists in the file system, then
open that file, instead of interpreting the digits as a line number.

Also, if the filename stripped of the colon plus digits does not exist,
then do not interpret the digits as a line number either but treat them
as part of the file name.

Before this change, the user would have to escape the colon whenever
they wanted to open a file whose name ended with a colon plus digits.
Now the user needs to escape the colon only when 'foo' exists and they
want to create, say, 'foo:24'.

Problem-was-reported-by: Ralph Corderoy <ralph@inputplus.co.uk>
  https://lists.gnu.org/archive/html/nano-devel/2024-05/msg00001.html
Mitigation-was-suggested-by: Mike Scalora <mike@scalora.org>
  https://lists.gnu.org/archive/html/nano-devel/2024-05/msg00008.html
2024-05-18 16:02:09 +02:00
Benno Schulenberg 803a16cbcd input: drop recognition of the urxvt escape sequences for M-Home/M-End
Nano does not recognize the urxvt escape sequences for other
<Alt+cursorkey> combinations either.  And with the previous
two commits, the urxvt user can now "help themselves".

This reverts commit 363a4378 from three days ago.
2024-05-14 16:39:34 +02:00
Benno Schulenberg c446904c19 input: recognize the raw Xterm escape sequences for Alt+Home and Alt+End
This makes those keystrokes work too when --raw is used.

But more importantly: these raw sequences can be used in an
~/.Xresources file to override the odd behavior of urxvt for
those keystrokes, making the previous commit redundant.
2024-05-12 10:27:35 +02:00
Benno Schulenberg 363a4378b7 input: provide for urxvt setting a high bit or sending an extra escape
When pressing Alt+Home/Alt+End on urxvt, urxvt either sets the high bit
of the last byte in the sequence for Home/End (when Meta8 is True), or
sends an extra escape before that same sequence (when Meta8 is False).
Accommodate for this bug by recognizing the produced code sequences.

Indirectly-reported-by: Sébastien Desreux <seb@h-k.fr>
  https://lists.gnu.org/archive/html/nano-devel/2024-05/msg00007.html
2024-05-11 16:28:04 +02:00
Benno Schulenberg f70f528730 build: check for the correct function in an #ifdef
Problem existed since version 7.0, commit 19c8cea8,
that replaced calls of wait() with calls of waitpid().
2024-05-05 10:43:23 +02:00
Benno Schulenberg 2334dedba6 tweaks: make a comment more accurate, and unabbreviate a variable name 2024-05-05 10:27:21 +02:00
Benno Schulenberg e9c7dfa992 minibar: do not falsely report that a new, empty file is in Mac format
The 'openfile->fmt' element gets initialized to 'UNSPECIFIED',
so the code has to take that possibility into account.

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

Bug existed since version 8.0, commit fe4f74f6.
2024-05-03 12:12:09 +02:00
Benno Schulenberg e4c3ffcd38 tweaks: rename a variable, away from an abbreviation 2024-04-28 13:45:08 +02:00
Benno Schulenberg 5e7a3c2e7e files: run `chmod` and `chown` on the descriptor, not on the filename
This closes a window of opportunity where the emergency file could be
replaced by a malicious symlink.

The issue was reported by `MartinJM` and `InvisibleMeerkat`.

Problem existed since version 2.2.0, commit 123110c5, when chmodding
and chowning of the emergency .save file was added.
2024-04-28 10:56:21 +02:00
Benno Schulenberg c020d53e23 input: snip the `recordmacro` and `runmacro` keystrokes in a better way
When recording a macro over a laggy connection or on a slow, overloaded
computer, several keystrokes could be recorded in one burst, and if any
but the last of those keystrokes was the shortcut for `runmacro`, then
running the macro would lead to an infinite loop and nano would hang.

This new implementation of snipping the "last keystroke" will, however,
snip *too many* keystrokes when several of them were recorded at once
and `runmacro` or `recordmacro` was among them, resulting in a cropped
and thus misrecorded macro.  But... that's better than hanging.

In general, though, the user should be slow and deliberate when
recording a macro: waiting for nano to have processed the last
keystroke before typing the next.

This fixes https://savannah.gnu.org/bugs/?65649.
The issue was reported by `correctmost`.

Problem existed since version 2.9.0, since macros were introduced.
2024-04-27 17:17:03 +02:00
Benno Schulenberg cb02937714 wrapping: delete only single characters, not a possibly marked region
These calls of do_delete() were meant to delete just one character,
but over time do_delete() morphed into doing also other things...
Change the calls to invoke the correct function instead.

(This also avoids snipping any zero-width characters that come after
a snipped space, as that is probably not what the user wants.)

This fixes https://savannah.gnu.org/bugs/?65636.
The issue was reported by `correctmost`.

Bug existed since version 3.2, commit ae3ec178,
when --zap was introduced.
2024-04-25 11:01:42 +02:00
Benno Schulenberg 1327e296c2 tweaks: rename a function, for contrast, and update antiquated comments 2024-04-25 10:34:03 +02:00