Commit Graph

8878 Commits (e0d00bc750d4f984a298175a9a8e8d3f30ae948d)

Author SHA1 Message Date
Benno Schulenberg e0d00bc750 tweaks: avoid a compiler warning 2020-05-21 10:47:04 +02:00
Benno Schulenberg b72f3b10ba prompt: at Yes-No, do not treat a screen resize as an invalid keystroke
Commit 12cf1c99 added a beep() for every invalid keystroke at the
Yes-No prompt, but overlooked that KEY_WINCH is not invalid.

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

Bug existed since version 4.8, commit 12cf1c99.
2020-05-21 09:50:13 +02:00
Benno Schulenberg c9482bcd2b display: do not try to draw content when there is no open buffer yet
Commit b63c90bf avoided creating an empty buffer before asking the
yes-no question when encountering a lock file at startup, but the
SIGWINCH code still expected to have an open buffer whose contents
to show.

This fix also has the pleasant effect that, when resizing the screen
at the lock-file yes-no prompt, the title bar doesn't suddenly appear.

This fixes https://savannah.gnu.org/bugs/?58414.
Reported-by: Liu Hao <lh_mouse@126.com>

Bug existed since version 4.9, commit b63c90bf.
2020-05-21 09:24:02 +02:00
Benno Schulenberg 747ce3b5da tweaks: don't bother statting the lock file before unlinking it
If unlinking would fail because the parent directory is unwritable,
then a check in has_valid_path() would have prevented do_lockfile()
from being called at all.
2020-05-20 16:56:32 +02:00
Benno Schulenberg 10800ee410 locking: prevent a symlink attack by not opening an existing lock file
If in between the unlink() in delete_lockfile() and the fopen() in
write_lockfile() some other process creates a symlink in the place
of the lock file, then the fopen() could unexpectedly overwite a
root-owned file (when the user is root).

This basically reverts the previous commit, b4299f4f, but makes the
code a bit conciser.
2020-05-20 16:22:15 +02:00
Benno Schulenberg b4299f4f4e tweaks: don't bother using the exclusive flag when creating a lock file
One microsecond earlier, the lock file has been deleted (if it existed),
so, if between our unlink() and our open() some other process managed to
recreate the lock file... well, we want to delete it *again*.  So, just
overwrite and truncate the lock file (if it exists).

When the lock file did NOT exist (a few microseconds earlier, when
checking in do_lockfile(), before calling write_lockfile()), then
the user expects the lock file to be written, so: just write it.

That between the check and the actual writing of the lock file there
is a small window of opportunity for other processes to write this
lock file is unfortunate, but it is not a reason to bother the user
with an error message when it happens.
2020-05-19 17:07:31 +02:00
Benno Schulenberg c45df589fa locking: ignore the insecure-backup flag when creating a lock file
One microsecond before a lock file is created an existing lock file
has been deleted, and if that deletion failed, writing the lock file
is aborted.  So why should writing the lock file not be aborted when
the lock file cannot be exclusively created one microsecond later?
This makes no sense.  So... always include the O_EXCL flag, also
when the INSECURE_BACKUP flag is set.

(And anyway: lock files are not an essential part of editing, they
are just a small service to the user, AND they have nothing to do
with backups, so a backup flag should not influence them.)
2020-05-19 14:56:37 +02:00
Benno Schulenberg 44fd299921 tweaks: add a symbol, in order to condense three function calls 2020-05-17 19:11:54 +02:00
Benno Schulenberg 40a0463250 tweaks: reshuffle an assignment, for conciseness, and rename a variable 2020-05-17 11:34:22 +02:00
Benno Schulenberg 187843d2da tweaks: exclude a bit of bracketed-paste code from the tiny version
The tiny version does not support bracketed pastes.
2020-05-14 18:47:50 +02:00
Benno Schulenberg 0f2dd8456f usage: unabbreviate option arguments where possible
And make it clearer what kind of argument is expected:
digits, characters, or a program name.
2020-05-14 17:27:15 +02:00
Benno Schulenberg 821fbf713d tweaks: reshuffle a bit of code, to elide an #ifndef 2020-05-14 11:44:21 +02:00
Benno Schulenberg ebc2364742 tweaks: move a fragment of code to the one branch that needs it
When two lines are joined, 'refresh_needed' is already set to TRUE,
so only when a midline character is deleted the check for a changed
number of chunks is needed.
2020-05-14 11:43:30 +02:00
Benno Schulenberg 15fadd700a tweaks: rename a function, to be more precise, and reshuffle it 2020-05-13 12:43:22 +02:00
Benno Schulenberg 78bfc9223a tweaks: add a condition, so that two ifs can be elided
Now all functions that are relevant only to softwrapping
get called only when softwrapping is on.

This also allows to elide an intermediate function call.
2020-05-13 12:32:57 +02:00
Benno Schulenberg e8e9b8ad82 tweaks: move an 'if', to not call leftedge_for() when not softwrapping 2020-05-13 12:01:55 +02:00
Benno Schulenberg 964771afc3 tweaks: reshuffle a condition, for symmetry 2020-05-13 11:11:24 +02:00
Benno Schulenberg fe94999c1c tweaks: don't bother overwriting a CR -- decreasing the length is enough
The string of bytes get properly terminated by encode_data(); there is
no need to do that earlier.
2020-05-13 10:31:39 +02:00
Benno Schulenberg 56bf29409b tweaks: correct a comment, and avoid third repetition of some conditions 2020-05-12 20:53:08 +02:00
Benno Schulenberg fcbf85887b files: never report a file as being of mixed format
A file is always in either Unix or DOS or Mac format, and should
by default be saved again in that same format.

Any lone CRs or LFs after the first line should not change the
format that was deduced from that very first line.
2020-05-12 18:55:31 +02:00
Benno Schulenberg ac0f2c9485 files: do not let a stray CR in a DOS file trigger Mac format
Only when a CR is seen before any LF, and the CR is not followed
by a LF, should this CR be interpreted as a line separator.  And
only then the file should be reported as being in Mac format --
as long as --noconvert is not used.

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

Bug existed since at least version 2.0.6.
2020-05-12 17:25:04 +02:00
Benno Schulenberg 0a1817e893 tweaks: exclude an unneeded fragment of code from the tiny version 2020-05-12 11:09:23 +02:00
Benno Schulenberg b18f1265ff tweaks: reshuffle a condition, to make a little more sense 2020-05-11 19:40:17 +02:00
Benno Schulenberg 2dd97a0352 tweaks: rename two variables, and reduce the scope of a third 2020-05-11 16:59:39 +02:00
Benno Schulenberg ef4b0edd4e tweaks: rename a symbol, to better suit its purpose, and reduce its scope 2020-05-11 16:44:16 +02:00
Benno Schulenberg b47d111a3d tweaks: don't use a symbol for other purposes 2020-05-11 16:18:03 +02:00
Benno Schulenberg d80ecf0209 tweaks: trim some oververbose comments -- they overshadow the code
The text was harder to understand than the code itself.
2020-05-11 15:58:08 +02:00
Benno Schulenberg ff4973458c tweaks: adjust the file format indicator in a quicker way 2020-05-11 15:32:41 +02:00
Benno Schulenberg f9ff902bbc tweaks: drop two redundant conditions, and improve three comments 2020-05-08 11:06:43 +02:00
Benno Schulenberg 95c966c3fc tweaks: do the saving of histories in a single place
Also, when finish() is called when the user presses Cancel upon
encountering a lock file, there is no need to save any history
files because nothing has changed.
2020-05-08 11:01:37 +02:00
Benno Schulenberg 982e226c3f tweaks: elide three parameters, as they are the same for both calls 2020-05-08 10:40:03 +02:00
Benno Schulenberg 42ca89039a tweaks: improve three comments, drop one, and unwrap a line 2020-05-08 10:21:02 +02:00
Benno Schulenberg 07b48024d1 tweaks: condense a comment, and reshuffle some conditions 2020-05-07 13:34:07 +02:00
Benno Schulenberg 1c4dd79b9b files: trigger the Easter egg only when "zzy" is typed at the prompt
When the user mentions the file "zzy" on the command line,
the magic spell "Xyzzy" does not actually get typed, so the
Easter egg should then not be triggered.
2020-05-07 13:28:41 +02:00
Benno Schulenberg 56fc8f6d30 tweaks: improve a comment, reshuffle a scroll command, elide a variable
Also, drop an unneeded keyboard check: the next check is just a few
microseconds away.
2020-05-06 17:29:20 +02:00
Benno Schulenberg ad1331527e color: when syntax coloring is toggled back on, calculate multiline data
This will not catch all cases, but at least it will precalculate the
data when syntax coloring was toggled off (M-Y) while in one buffer
and then toggled back on after having switched to a new buffer.
2020-05-01 14:08:55 +02:00
Benno Schulenberg 1bbf07b27e color: avoid allocating emptiness when there are no multiline regexes
When a file is saved under a different name, and as a result the
applicable syntax changes, and the old syntax had multiline regexes
and the new syntax doesn't, then the call of precalc_multicolorinfo()
in write_file() should not result in nano setting up a multicache of
zero bytes for each line in the buffer.

(Problem was found by locally letting nano crash when zero bytes are
allocated, and then happening to rename a file.py to a file.sh.)
2020-05-01 13:59:56 +02:00
Benno Schulenberg b9deb883fa tweaks: shorten the name of a symbol, to match its bindable function 2020-05-01 13:25:15 +02:00
Benno Schulenberg 9c4ebed3ff tweaks: remove an unneeded element from the openfilestruct 2020-05-01 12:38:02 +02:00
Benno Schulenberg e64e54d57f tweaks: condense a bit of code, by reusing an existing variable 2020-05-01 12:37:50 +02:00
Benno Schulenberg d4ee6a2b53 options: rename --tempfile to --saveonexit, to be far clearer
A long option should describe what it does, not vaguely hint at it.

Also, in several places of nano's code we deal with actual temp files,
and then having a flag called TEMP_FILE that doesn't have anything to
do with temp files is somewhat confusing.
2020-04-30 19:12:54 +02:00
Benno Schulenberg af062af490 docs: mention that doing a full-buffer operation wipes away all anchors 2020-04-30 18:58:17 +02:00
Benno Schulenberg 4bdd6013b0 anchor: do not let piping and spelling transfer an anchor to the top
Just let all anchors disappear when doing an external spell check or
formatting or piping the buffer through an external command, because
leaving just a single anchor on the top line is useless.

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

Bug existed since commit 732cf887 from one month ago.  That code
causes an anchor to persist at the point where lines are removed.
2020-04-30 16:51:22 +02:00
Benno Schulenberg 11f099e1da anchor: during full justification preserve anchors as during single ones
When a single paragraph is justified, any anchor on any of its lines
gets moved to its first line.  Let a full justification do the same
for each of the paragraphs.

This fixes https://savannah.gnu.org/bugs/?58272 in a better way.
2020-04-30 16:07:31 +02:00
Benno Schulenberg 703cebaaac anchor: do not let a full justification transfer an anchor to the top
This fixes https://savannah.gnu.org/bugs/?58272.

Bug existed since commit 732cf887 from one month ago.  That code
causes an anchor to persist at the point where lines are removed.
2020-04-29 19:34:48 +02:00
Benno Schulenberg 4710b94cfb tweaks: move a function to before the one that calls it 2020-04-29 12:22:02 +02:00
Benno Schulenberg 5ca2fd887a startup: initialize colors only when the terminal is capable of colors
This avoids trying to show colors on a vt100, for example.
2020-04-29 12:07:31 +02:00
Benno Schulenberg d1e1438ca0 tweaks: delete some unneeded code, and rename the function accordingly
When set_colorpairs() is called, no files have been loaded yet, so
no syntaxes will have been loaded yet either.  Thus it is pointless
to run through the list of available syntaxes.
2020-04-28 16:49:45 +02:00
Benno Schulenberg 382ec84248 tweaks: rename a function, to match with the boolean that guards it 2020-04-28 16:38:27 +02:00
Benno Schulenberg bc4240dda5 tweaks: rename a function, to better describe what it does
Its major function is to find an applicable syntax, if there is any.
And if the syntax hasn't been used before, to prime its color pairs.

Also, reshuffle a line to be able to elide an #ifdef.
2020-04-28 16:34:45 +02:00