Commit Graph

9107 Commits (43b39ed04f113e19453de5560f8ee7f7f51188f8)

Author SHA1 Message Date
Benno Schulenberg 43b39ed04f tweaks: use knowledge of Unicode to skip the general multibyte conversion
The relevant range is so small (128 bytes) that "manual" conversion
is much faster (and a bit shorter, eliding two variables).
2020-07-20 19:31:25 +02:00
Benno Schulenberg 17a8b24fe5 tweaks: skip the conversion to multibyte for plain ASCII codes
Converting an ASCII code to "multibyte" is a no-op: it stays one byte.
2020-07-20 19:16:45 +02:00
Benno Schulenberg b9db967bc4 tweaks: reshuffle some lines, for esthetics
There is no need to reset the digit counter (because this counter
matters only when the escape counter equals two) -- resetting the
escape counter is enough.
2020-07-20 19:06:16 +02:00
Benno Schulenberg 2a5d129738 tweaks: rename a variable, and normalize the indentation 2020-07-20 18:25:19 +02:00
Benno Schulenberg 6980cfbf70 tweaks: change a 'switch' to 'if', to elide a dummy 'return' 2020-07-20 18:21:43 +02:00
Benno Schulenberg a0d2e63c8e tweaks: improve four comments 2020-07-20 17:15:06 +02:00
Benno Schulenberg 57c52de99a tweaks: rename a function, and move it to before the one that calls it 2020-07-20 17:04:48 +02:00
Benno Schulenberg 9067f7a0c7 tweaks: elide a variable, by returning the result directly 2020-07-20 16:54:22 +02:00
Benno Schulenberg e4fa0b54a2 tweaks: remove two superfluous assignments
The digit counter will be reset to zero the next time when <Esc>
is pressed, and the byte holder gets re-initialized when the next
first digit is pressed.  And the escape counter is reset to zero
after returning from a result-giving call of get_byte_kbinput().
2020-07-20 16:28:36 +02:00
Benno Schulenberg b41405233f tweaks: remove some superfluous conditions
When get_byte_kbinput() is called, it has already been determined that
the keyboard input is a digit from zero to nine (or from zero to two
for the first digit), so there is no need to check this again.
2020-07-20 12:40:26 +02:00
Benno Schulenberg 88561506c9 tweaks: improve two comments, and reshuffle some lines for conciseness 2020-07-20 11:47:10 +02:00
Benno Schulenberg a08ca026f0 input: reset the counters when a three-digit sequence is not completed
When <Esc><Esc> is followed by digit 0 or 1 or 2 but then NOT two more
digits follow, then both the escape counter and the digit counter should
start afresh when a new ESC code arrives.

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

Bug existed since before version 2.0.6.
2020-07-20 11:19:44 +02:00
Benno Schulenberg 180a53cc0c files: warn the root user when all the write bits are missing
Root has carte blanche to both read unreadable files and write
unwritable files -- the file system does not prevent this.  So,
alert root when opening a file that is intended to be read-only.

This fulfills https://savannah.gnu.org/bugs/?58685.
Requested-by: Marius Bakke <mbakke@fastmail.com>
2020-07-20 10:26:45 +02:00
Benno Schulenberg d18cfb26cd tweaks: adjust the indentation after the previous change 2020-07-19 11:52:57 +02:00
Benno Schulenberg eb70578c5e tweaks: do not use 'switch' when there are just two possibilities
Also, remove an unneeded 'if', as parse_escape_sequence() is only
ever called when there are at least two bytes after the Esc code.
(If there were not, the 'for' loop after calling convert_sequence()
would use an uninitialized 'consumed' value.)
2020-07-19 11:52:47 +02:00
Benno Schulenberg 63efc59758 tweaks: don't check for escape sequences that start with a lowercase "o"
Such escape sequences don't exist -- those mistaken sequences were
removed in commit 4991b3bb from half a year ago.
2020-07-19 11:50:30 +02:00
Benno Schulenberg dcd34b246a tweaks: move a function to the file where it is used the most
Also, fully exclude the function from the tiny version.
2020-07-19 10:43:26 +02:00
Benno Schulenberg b0dcb15f94 tweaks: elide a function that is too sparse
The two calls of the function can be replaced with two lines each.
2020-07-17 18:40:34 +02:00
Benno Schulenberg 7dbfbbb8d6 tweaks: reshuffle a few lines, for conciseness 2020-07-17 17:13:43 +02:00
Benno Schulenberg 4cefd699ca tweaks: shorten an error message, to be appropriate in all situations
Saying "Cannot write backup %s" is misleading when it is the original
file that cannot be reread.
2020-07-17 17:10:46 +02:00
Benno Schulenberg 8eddf7bc26 tweaks: reshuffle a condition, to avoid a repetition of code 2020-07-17 16:53:48 +02:00
Benno Schulenberg 2623f39c7b backup: when rereading the original file fails, ask the user what to do
Rereading is unlikely to fail, but *if* it fails, maybe there is a
serious problem and the user wants to try and fix it before saving
the buffer and thus overwriting the original file.
2020-07-17 16:50:25 +02:00
Benno Schulenberg da71322000 tweaks: rename two labels, for brevity 2020-07-17 16:24:53 +02:00
Benno Schulenberg 292e505e01 tweaks: rename two variables, to avoid a repetitive prefix
Also, fold a condition into an assignment, for conciseness.
2020-07-17 16:23:22 +02:00
Benno Schulenberg a322dab482 tweaks: elide a function that is called just once
It also nicely groups the backup stuff together in a single function.
2020-07-16 15:03:06 +02:00
Benno Schulenberg 0ed1695fd4 build: fix miscompilation for --enable-{tiny,color,nanorc}
This should have been part of commit 096e3627 from a month ago.
2020-07-16 12:47:43 +02:00
Benno Schulenberg 60d31d2ea6 tweaks: avoid a warning about an unused variable in the tiny version 2020-07-16 12:41:01 +02:00
Benno Schulenberg b744eec1a9 tweaks: remove an incorrect mention of umask() from a comment
Since commit f8366cd5, umask() is no longer used.
2020-07-15 10:52:49 +02:00
Benno Schulenberg a6f64212ae tweaks: rename a function, to not shadow a variable, and elide parameter 2020-07-15 10:52:49 +02:00
Benno Schulenberg a6cee410ef tweaks: normalize the indentation after the previous change 2020-07-15 10:52:49 +02:00
Benno Schulenberg f7682730bd files: make a backup only when requested, not an unrequested failsafe one
After thinking about it, I don't like it that nano makes an unrequested
failsafe backup: in the vast, vast majority of cases it is a waste both
of time and of disk wear.  If the user is worried about data loss, they
can use --backup.  The fsync() after writing out the buffer (added in
commit a84cdaaa) already reduces the chances on data loss somewhat.
2020-07-15 10:50:36 +02:00
Benno Schulenberg 5f90e067f1 tweaks: rename a parameter and a variable, to be more meaningful 2020-07-14 17:31:47 +02:00
Benno Schulenberg b0f563980d tweaks: elide an unneeded call of strlen(), and copy NUL byte with string 2020-07-14 17:22:08 +02:00
Benno Schulenberg 258e7c6e65 oops -- restore an accidentally changed file 2020-07-14 15:22:22 +02:00
Benno Schulenberg 65321f9234 files: do not make a failsafe backup when in restricted mode
When in restricted mode, nano should not write to any other file
than to the ones mentioned on the command line.
2020-07-14 15:19:50 +02:00
Benno Schulenberg bde8858a3a tweaks: rename a variable, to avoid overrepetition of 'backup'
Also, reshuffle three calls of fclose().
2020-07-14 13:52:34 +02:00
Benno Schulenberg a2b7fc1c81 tweaks: slightly improve a comment and the ordering of some lines 2020-07-14 13:00:34 +02:00
Benno Schulenberg 69e6ccf641 tweaks: reshuffle a fragment of code, to elide a 'goto' 2020-07-14 13:00:34 +02:00
Michalis Kokologiannakis 14717d7449 tweaks: adjust some indentation after the previous change
Signed-off-by: Michalis Kokologiannakis <michalis@mpi-sws.org>
2020-07-14 12:59:30 +02:00
Michalis Kokologiannakis ed76a045ae tweaks: move the backup code to a separate function
This change moves the code responsible for backup creation to a new,
separate function, backup_file().  This function returns a boolean
indicating whether saving the buffer should proceed or not.

Signed-off-by: Michalis Kokologiannakis <michalis@mpi-sws.org>
2020-07-14 12:12:26 +02:00
Benno Schulenberg 62ffc221aa tweaks: rename a function, and move it to before the one that calls it 2020-07-11 19:43:37 +02:00
Benno Schulenberg ec8fd9f365 tweaks: reshuffle some code, to avoid needlessly calling a function 2020-07-11 19:11:00 +02:00
Benno Schulenberg d3a8488b0e tweaks: use a better symbol than 'ERR' to signify a valid hex digit 2020-07-11 18:58:12 +02:00
Benno Schulenberg b3d6c27502 tweaks: improve a comment, rename a function, and elide a parameter
Checking the current menu instead of the current subwindow works fine.
2020-07-11 18:36:52 +02:00
Benno Schulenberg 2e4d78a714 tweaks: fold translation of all modified keypad keystrokes together
The escape-sequence codes for the different keypad keys are simply
the relevant ASCII code plus 0x40, so they are easy to translate.

Also, do not accept keypad keys with multiple modifiers (Shift+Alt,
Shift+Ctrl, Alt+Ctrl, Shift+Alt+Ctrl) -- report "Unknown sequence"
for those.
2020-07-11 12:16:18 +02:00
Benno Schulenberg 476c838753 bindings: allow typing digits on the numeric keypad by holding Shift
Until now, on an xterm, Shift plus any keypad key would say
"Unknown sequence", which is not useful.  On other terminal
emulators (urxvt, Pantheon, LXTerminal), Shift plus a keypad
key already produces the relevant digit or symbol, so this
change harmonizes the behavior of the different emulators.

However, on a Linux console, Shift plus a keypad key moves
the cursor and selects the text that is passed over.  And
holding Alt while pressing a keypad key does nothing at all.
2020-07-11 11:49:41 +02:00
Benno Schulenberg ecb4dac494 bindings: stop <Alt+operator> on the keypad from entering spurious letter
For the operator keys on the numeric keypad (/, *, -, and +),
make both the Alt and the Ctrl modifier a no-op.

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

Bug existed since version 2.9.3, commit e734488c.
2020-07-11 11:46:43 +02:00
Benno Schulenberg 95df7dbc8e tweaks: correct some comments, as VT100 and such have smaller keypads
The DEC VTnnn terminals only have period, comma, and minus on the
numeric keypad, not slash nor star nor plus nor Insert nor Delete.
2020-07-11 11:44:23 +02:00
Michalis Kokologiannakis a84cdaaa50 files: improve the backup procedure to ensure no data is lost
The file-saving procedure that nano followed was not crash-safe
under ext4 (and perhaps other filesystems) when editing existing
files.  Specifically, modifying an existing file could lead to data
loss, since a modified file is not replaced atomically on disk.
Using "-B" did not ensure crash-safety either since the backup might
not have persisted on disk when the writeout of the file started.

In addition, if I/O pressure filled up the remaining disk space
after an existing file is truncated during save, nano would not
be able to finish saving the file, which would remain truncated.

This change addresses these issues by making nano do the following:

1) Make a temporary backup of the file being written so that there
is no time window such that (a) an existing file is truncated, and
(b) the buffer corresponding to said file has not been flushed to
disk.  Such time windows are dangerous because, under certain
circumstances, they can lead to data loss on some filesystems.

The backup is made by copying the original file, and a second
attempt to HOME is made in case that first copy fails.

2) Use fsync() so that, when the save finishes, it is certain
that the file has been successfully written to disk.

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

Signed-off-by: Michalis Kokologiannakis <michalis@mpi-sws.org>
2020-07-09 16:28:21 +02:00
Benno Schulenberg 97a993d401 verbatim: turn bracketed-paste mode off while waiting for input
This allows pasting six hexadecimal digits after typing M-V
in order to enter a specific Unicode character.

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

Bug existed since version 4.8, since bracketed pastes
were introduced in commit f705a967.
2020-07-08 16:24:53 +02:00