Commit Graph

9128 Commits (7157f5a3ce7a89a020b67e079ef4941a1980a795)

Author SHA1 Message Date
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
Benno Schulenberg 1542cbf942 bindings: add mistakenly removed M-J (Full Justify) back to the main menu
This fixes https://savannah.gnu.org/bugs/?58729.

Bug existed since commit ee03c4b8 from six weeks ago.
2020-07-08 15:46:50 +02:00
Benno Schulenberg 727abceb0f tweaks: adjust comments and indentation after the previous change 2020-07-06 16:59:35 +02:00
Benno Schulenberg 5899181a31 verbatim: show an error message when an invalid Unicode code is entered
The codes from (for example) U+D800 to U+DFFF are invalid.  If any
such invalid code is entered at the Unicode Input prompt, nano should
not act as if the code was accepted and inserted into the buffer, and
should certainly not mark the buffer as Modified.

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

Bug existed since version 4.9, commit b3faf353.
2020-07-06 16:47:23 +02:00
Benno Schulenberg a2fdf6c486 tweaks: remove an unneeded cursor movement, and rename a variable
There is no need to place the cursor up front, as the drawing of
each name includes the coordinates where the name must be drawn.

Also, trim two comments and reshuffle a free().
2020-07-05 19:29:05 +02:00
Benno Schulenberg 29d493a986 tweaks: move an initialization function to before the one that calls it
Also, frob two comments in that function,
and delete three unneeded blank lines.
2020-07-05 19:01:31 +02:00
Benno Schulenberg 940a17268b speller: take into account that statting a file can fail [coverity] 2020-07-05 17:21:56 +02:00
Benno Schulenberg ee78f2348b rcfile: rename bindable function 'curpos' to 'location'
It is better that the bindable function is named the same as the
tag in the help lines, and that it is not an ugly abbreviation.
2020-07-05 11:05:45 +02:00
Benno Schulenberg 2261377309 docs: complete the renaming of 'tempfile' to 'saveonexit'
This should have been part of commit d4ee6a2b from two months ago.
2020-07-05 10:53:57 +02:00
Benno Schulenberg cb1675dac7 tweaks: rename two functions and a variable, and improve two comments 2020-07-04 17:43:16 +02:00
Benno Schulenberg 808d0894f1 tweaks: condense a comment, and reshuffle a few lines 2020-07-04 17:25:32 +02:00
Benno Schulenberg 07c1ac9035 tweaks: delete two functions that are never executed
Those two operations are performed directly in do_browser().
2020-07-04 17:14:52 +02:00
Benno Schulenberg 2b9c0c5724 tweaks: rename a variable, and reduce the scope of two others 2020-07-04 15:12:04 +02:00
Benno Schulenberg abfde53945 tweaks: drop an unneeded assignment, and reshuffle a few lines
And reset the 'lastmessage' variable to a more fitting value.
2020-07-04 09:36:17 +02:00
Benno Schulenberg f21508f071 tweaks: improve some comments, and reshuffle an assignment 2020-07-03 19:10:48 +02:00
Benno Schulenberg 2c228796a8 docs: improve some descriptions concerning the file browser 2020-07-03 18:45:09 +02:00
Benno Schulenberg a84653dc19 feedback: show the cursor position also at startup in an empty buffer
When using --constantshow and --nohelp and opening a new buffer,
the cursor location should be shown on the status bar right away.

Bug existed since commit 2e688640 from a few hours ago.
2020-07-03 13:03:44 +02:00
Benno Schulenberg 1388af2bdc tweaks: elide a wrapper function, by checking a precondition earlier 2020-07-03 12:41:40 +02:00
Benno Schulenberg 2e6886406c tweaks: elide an unneeded global variable
The constant cursor display must be suppressed whenever a message
was printed to the status bar.  That is: whenever 'lastmessage' is
something other than 'VACUUM'.
2020-07-03 12:41:40 +02:00
Benno Schulenberg 80ff5e76d6 help: pair the items in the two bottom lines better in the tiny version
This fixes https://savannah.gnu.org/bugs/?58693.

Bug existed since commit 9b8930cc from ten days ago.
2020-07-03 11:28:41 +02:00
Benno Schulenberg 1a2d0c1770 scrolling: add a function and a key binding to center the cursor line
By default, this function is bound to ^L, to make that keystroke do
something actually useful.  To not lose the Refresh function that this
keystroke had, the centering function additionally does a full redraw
and refresh of the screen.
2020-07-02 11:11:44 +02:00
Benno Schulenberg eb413a99f2 tweaks: do not use the string "stat()" in any of the comments 2020-06-30 10:56:37 +02:00
Benno Schulenberg fcb9e58b2d history: take into account that statting a file can fail too 2020-06-30 10:53:28 +02:00
Benno Schulenberg 675a8e4899 history: take into account that closing a file can fail 2020-06-29 13:47:20 +02:00
Benno Schulenberg 3344571227 tweaks: reshuffle some conditions, to straighten the logic 2020-06-29 12:39:46 +02:00
Benno Schulenberg f9b1306adf tweaks: normalize the indentation after the previous change 2020-06-29 12:35:17 +02:00
Benno Schulenberg 722467cb6b tweaks: add four early returns for read/write errors of history files
Also rewrap a comment and rename a variable.
2020-06-29 12:23:59 +02:00
Benno Schulenberg b3b3d04552 tweaks: rename a variable, to better fit related ones
Since commit c16e79b6 from nearly three years ago, the string "histfile"
does not occur in other variables any more, so it is fine to use it.
2020-06-29 12:04:15 +02:00
Benno Schulenberg b9e3e4edb8 history: don't send error messages to the screen; store them in the queue 2020-06-29 11:56:36 +02:00
Benno Schulenberg 2d204bcbfd rcfile: restore terminal settings when exiting upon excessive unbindings
This fixes https://savannah.gnu.org/bugs/?58671.

Bug existed since commit 24cdf78a from two weeks ago.
2020-06-29 11:25:57 +02:00