Commit Graph

1240 Commits (0363703073afe35579476e5dc8d3e3df5d7735de)

Author SHA1 Message Date
Benno Schulenberg 423105e371 tweaks: improve some comments and whitespace, and reshuffle a few lines
Also, silence a compiler warning.
2020-05-25 19:49:17 +02:00
Benno Schulenberg d909291b0c tweaks: rename one of the flag symbols, to be clearer
I kept understanding 'BACKUP_FILE' as a noun instead of as an imperative.
2020-05-25 18:52:09 +02:00
Benno Schulenberg b30522463a files: do not append but truncate when allowing insecure backups
When deleting an existing backup file failed, we do not want to
append to this file, but want instead to overwrite it (when the
user has put 'set allow_insecure_backup' in their nanorc file).

Also, when using O_EXCL (in the normal, secure case), O_APPEND
is pointless, because the file will be created and thus empty.

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

Bug existed since version 2.2.5, commit 461519cc.
2020-05-25 12:22:15 +02:00
Benno Schulenberg 5449d1e6a5 files: ignore errors when calling chown() on a backup file
A normal user can change the group of a file (if the user is a member
of that group), but cannot change the owner of that file.  So, when a
user edits a file that belongs to a different user, the call of fchown()
will fail.  But there is no harm in that.  Also when the user is root,
there is no harm in fchown() failing -- it will simply mean that the
backup file will remain owned by root and will not be writable by the
intended owner (when root has the normal umask of 0022).

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

Bug existed since version 2.2.5, commit 86be3af7.
2020-05-24 16:08:05 +02:00
Benno Schulenberg 53c5ace8c3 tweaks: rename a symbol, away from a double abbreviation 2020-05-22 10:04:33 +02:00
Benno Schulenberg e0d00bc750 tweaks: avoid a compiler warning 2020-05-21 10:47:04 +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 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 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 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 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 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 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 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
Benno Schulenberg b97da1dfe4 files: reinitialize the palette only when the syntax actually changed 2020-04-28 15:30:00 +02:00
Benno Schulenberg ab1a5c7abb tweaks: rename two parameters, away from abbreviations 2020-04-15 17:50:59 +02:00
Benno Schulenberg 079a679431 tweaks: rename two functions, to better indicate what they do 2020-04-15 17:20:03 +02:00
Benno Schulenberg fd4a5fc473 files: write out a marked region without partitioning the buffer
Use the same mechanism as when copying a marked region: temporarily
clipping the buffer.
2020-04-09 11:07:05 +02:00
Benno Schulenberg 23f73cb8b3 tweaks: exit from the writing loop as soon as the last line is reached
Avoid having to decrement the count in order to offset the increment
at the end of the loop.

Also, declare a variable on a separate line, and rename it.
2020-04-01 16:05:45 +02:00
Benno Schulenberg 9f6962f3f1 tweaks: condense a comment, and express a condition in a different way 2020-04-01 15:54:08 +02:00
Benno Schulenberg d1521c584d tweaks: elide a now-unused parameter -- it is always FALSE 2020-03-30 16:55:30 +02:00
Benno Schulenberg f52b6cf19f copying: change the implementation, away from cutting plus copying back
First cutting the text to be copied (before copying it back into the
buffer) had unwanted side effects: it moved the cursor, and changed
the linestructs of the current line and the line where the mark was.

[This takes thirty more lines, but the idea is to later get rid of
the partitioning routines entirely.]
2020-03-30 16:55:17 +02:00
Benno Schulenberg 59040169ed tweaks: get rid of a bunch of annoying casts, and thus condense the code 2020-03-29 20:17:32 +02:00
Benno Schulenberg 8f6559828d files: make filtering of the entire buffer into a new buffer work again
This fixes https://savannah.gnu.org/bugs/?58076.

Bug existed since version 4.9, commit 477a9b33.
2020-03-29 18:04:36 +02:00
Benno Schulenberg 0cc2104257 tweaks: elide a parameter, by calling the relevant function beforehand
This means that in most cases mark_is_before_cursor() is called twice:
once before get_region() is called, and once by get_region() itself.
This small duplication of effort is acceptable: the affected functions
are not time critical, and it makes the code shorter.
2020-03-29 13:22:17 +02:00
Benno Schulenberg ba25d0df1d tweaks: fix twenty typos, in old Changelogs and in some comments
They were found by a run of 'codespell' at https://fossies.org/.

Reported-by: Jens Schleusener <Jens.Schleusener@fossies.org>
2020-03-25 16:57:43 +01:00
Benno Schulenberg 8dc83951ee tweaks: normalize a translator hint, update one, and add another 2020-03-11 14:21:08 +01:00
Benno Schulenberg 750b51c343 copyright: update to the current year for significantly changed files 2020-03-11 11:52:15 +01:00
Benno Schulenberg 2428c5cbe6 tweaks: strip a parameter that is equivalent to 'openfile' for both calls 2020-03-08 12:54:47 +01:00
Benno Schulenberg 01bc0148c0 tweaks: strip a parameter that is TRUE for both calls
The parameter has been redundant since version 4.0, commit d54840c1,
when the last call with FALSE was removed.
2020-03-08 12:48:41 +01:00
Benno Schulenberg a92511ceaf tweaks: move another function to where it is used 2020-03-06 18:52:42 +01:00
Benno Schulenberg 71c35d3ca2 tweaks: move a function to where it is used 2020-03-06 17:00:31 +01:00
Benno Schulenberg 38af812a82 tweaks: reshuffle the setting of the starting point of a cut 2020-03-06 16:57:22 +01:00
Benno Schulenberg 5c6fe50487 tweaks: rename a variable, to be a bit clearer 2020-03-01 19:45:02 +01:00
Benno Schulenberg 6c34ae5804 files: don't check uninitialized memory when writing new file [valgrind]
This fixes https://savannah.gnu.org/bugs/?57934.

Bug existed since version 4.3, commit e8e30e51.
2020-03-01 19:22:35 +01:00
Benno Schulenberg 1907174c5f tweaks: drop a check for something that will not occur
The check has been there for a few months, and will be there for
five more years in the next Ubuntu LTS.
2020-02-26 14:01:25 +01:00
Benno Schulenberg be7e000389 tweaks: pull the NUL-terminating of a string into a function
Also, avoid copying one byte too many that afterward gets
overwritten with '\0'.
2020-02-20 17:08:32 +01:00
Benno Schulenberg 8d7f8cda8c tweaks: improve two comments 2020-02-10 17:13:12 +01:00
Benno Schulenberg 75a70d98d5 tweaks: reshuffle two declarations plus a fragment of code
Also, don't bother statting the path that the user provided,
as that case will happen right away in the next 'if'.
2020-02-10 17:12:53 +01:00
Benno Schulenberg b3374ea1fb tweaks: rename two parameters, to not overlap with other names 2020-02-10 16:11:07 +01:00
Benno Schulenberg 0905c6ae7e files: be consistent in which code means "New File"
This fixes https://savannah.gnu.org/bugs/?57782.

Bug existed since commit dd429d9c from yesterday.
2020-02-10 15:57:40 +01:00
Benno Schulenberg 3eeedd7caf tweaks: move a function to before the one that calls it 2020-02-10 09:55:21 +01:00
Benno Schulenberg 410dcee0a1 tweaks: move some definitions closer to where they are used
Also slightly improve a few comments.
2020-02-10 09:53:10 +01:00
Benno Schulenberg 5b4d2350e6 tweaks: condense two fragments of code 2020-02-10 09:40:12 +01:00
Benno Schulenberg 422cd726fa tweaks: normalize the indentation after the previous change 2020-02-09 20:17:05 +01:00
Benno Schulenberg 9f43b4c758 tweaks: update some comments after the previous changes 2020-02-09 20:10:28 +01:00
Benno Schulenberg dd429d9c00 tweaks: rename a variable, reshuffle an assignment, and change a code 2020-02-09 19:50:33 +01:00
Benno Schulenberg b63c90bf6b locking: do not open an empty buffer when respecting the first lock file
When opening multiple files, and the first of them has a lock file,
and the user chooses to not open the corresponding file, then nano
should NOT create an empty buffer in its stead.

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

Bug existed since lock files were introduced, in version 2.4.0,
specifically since commit 6948d2e7.
2020-02-09 17:35:00 +01:00
Benno Schulenberg fa26889d03 tweaks: change a function to return the name of the lock file on success
This makes it possible to fix a small bug in the next commit.
2020-02-09 17:01:38 +01:00
Benno Schulenberg 30011b8525 tweaks: elide one variable and three gotos
Returning the relevant value directly is clearer.
2020-02-09 16:35:18 +01:00
Benno Schulenberg 3ac5432e29 tweaks: reshuffle a few declarations and assignments
Also reshuffle two fragments of code.
2020-02-09 14:54:15 +01:00
Benno Schulenberg 1d52548575 tweaks: change another function with two possible results to boolean 2020-02-09 14:30:57 +01:00
Benno Schulenberg d5ce44820a tweaks: change a function with two possible results to boolean 2020-02-09 14:24:26 +01:00
Benno Schulenberg 325d774393 locking: accept a minimal amount of data, enough for PID plus username
Maybe reading from a remote filesystem happens in small chunks;
don't call foul when the first chunk contains all we need.
2020-02-06 16:13:22 +01:00
Benno Schulenberg 7ce1f6d86d locking: when finding a lock file at startup, quit when user cancels
When at startup the user presses Cancel at the "open anyway?" prompt,
cancel the whole startup: quit.  But when the user answers No, just
skip the file and continue starting up.
2020-02-02 13:00:37 +01:00
Benno Schulenberg 88087f2b2f tweaks: move a function to related ones, and after one that it calls 2020-02-02 12:26:33 +01:00
Benno Schulenberg 16c4f5bbd0 tweaks: move a function to be before the ones that call it 2020-02-02 12:21:28 +01:00
Benno Schulenberg e877c2406e tweaks: allocate the lock data only when ready to write them 2020-02-02 12:05:45 +01:00
Benno Schulenberg b6a1583e8e tweaks: take just one shot at reading the lock file, and correct a type
Don't bother looping until the 1024 bytes are read.  Writing the lock
file takes just one shot too, and that is more important to get right.

Also, correct the type for the result of read(), so that -1 doesn't
get turned into a positive number, which would mean that any error
would get ignored.
2020-02-02 11:41:20 +01:00
Benno Schulenberg 48df800db3 tweaks: rewrite the same file name into the lock file as the first time
It would be better if nano wrote the full filename into the lock file,
because that would be clearer when Vim displays its warning, but...
this is faster and will do for now.

(Nano should simply also store the full filename in the openfile struct,
so that get_full_path() needs to be called just once for each file.)

This addresses https://savannah.gnu.org/bugs/?57713.
2020-02-02 11:22:22 +01:00
Benno Schulenberg ee05daab92 tweaks: do not leak a file descriptor when fdopen() fails 2020-02-02 11:08:59 +01:00
Benno Schulenberg 74f4c37d5f locking: avoid crashing when there is a problem writing the lock file
The call of ferror() as parameter of a %s specifier was a mistake --
it returns a number, not a string.  Avoid the problem by combining
two error checks.

The man page of fwrite() does not say anything about errno, but I guess
that the function calls write() and that the possible error numbers of
that function apply.

In theory it is now possible that fclose() fails and returns an error
that then masks an earlier error of fwrite().  But I can't be bothered:
lock files are not essential, and any errors that might occur are most
likely overlooked anyway because they are not displayed in red.

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

Bug existed since lock files were introduced, in version 2.3.2,
commit bf88d27a.
2020-02-02 10:55:19 +01:00
Benno Schulenberg 073251fdb1 tweaks: condense two comments, and reshuffle an #endif
There is no need to fake success when the whole writing of the lock file
is skipped, because also a zero return value means "continue anyway".
2020-01-31 11:39:11 +01:00
Benno Schulenberg 5a0ee3c2f9 tweaks: harmonize the amount of lock data that we read and write
All the things that we need are located within the first 68 bytes of
the .swp file.  We do write byte 1007 when the file is modified, but
we never reference it.  We always wrote just 1024 bytes to the .swp
file, so it makes no sense to read in any more than that.

(Vim writes 4096 bytes to a .swp at first, before adding undo stuff
four seconds later.  But the 1024 bytes appear to be enough for Vim
to recognize it as a lock file.)
2020-01-31 11:06:11 +01:00
Benno Schulenberg 6bd5dce954 tweaks: ensure that editor name and user name are NUL terminated
When copying those pieces from a lock file, it is not certain that
they end with a NUL character.
2020-01-30 20:00:17 +01:00
Benno Schulenberg f25059c244 tweaks: frob a couple of indentations and white lines 2020-01-30 19:55:26 +01:00
Benno Schulenberg 856f2c433e feedback: ask a clearer question when a valid lock file is encountered
When asking "continue?", I always thought that answering No would mean
that nano would not continue, that it would stop, that it would abort.
But No only means that it will not open the relevant file but continues
anyway to start up.  Asking "open anyway?" is more easily understood in
that way.
2020-01-30 19:44:25 +01:00
Benno Schulenberg 38c5a4465b tweaks: reshuffle some assignments for a return value 2020-01-30 19:43:19 +01:00
Benno Schulenberg f494bfcbb9 locking: when a lock file is unreadable, open the file itself anyway
Unreadable or corrupt lock files are not a user error nor user intent,
so they should not keep the user from editing the corresponding file.

Also, combine some error conditions to compact the code.

This addresses https://savannah.gnu.org/bugs/?57700.
2020-01-30 19:10:34 +01:00
Benno Schulenberg b856fc4664 locking: check two magic bytes, to verify that it is a lock file
Also, when the check fails, then nano should continue and simply
open the file, just like Vim.

This fixes https://savannah.gnu.org/bugs/?57698.
2020-01-30 18:48:35 +01:00
Benno Schulenberg faa96ead44 tweaks: correct the description of what nano writes into the lock file
Also, limit the stored program's name to ten bytes.  Vim uses four for
its name plus a space, and a maximum of six for its version number.
2020-01-30 17:44:04 +01:00
Benno Schulenberg 26444bf8df tweaks: reformat a comment, and resuffle a line to match byte order 2020-01-30 15:55:42 +01:00
Benno Schulenberg 662e8b2d20 tweaks: remove some superfluous conditions for rewriting a lock file
A lock file needs to be rewritten (with the modified flag) only when the
relevant lock file already exists.  All other conditions are redundant.
2020-01-29 19:38:07 +01:00
Benno Schulenberg 4502295a34 locking: do not write a lock file when in view mode
When in view mode, the file cannot be edited, so there is no need to
warn anyone (through a lock file) that the file might soon change.

This fixes https://savannah.gnu.org/bugs/?57694.
2020-01-29 19:14:41 +01:00
Benno Schulenberg e0213b1a41 tweaks: drop a pointless suffix from two function names 2020-01-26 16:36:23 +01:00
Benno Schulenberg 706f3e93f4 tweaks: in comments, reword "titlebar" and "statusbar" to two words each
To differentiate them from the function names.
2020-01-16 19:37:28 +01:00
Benno Schulenberg afa4c6b9fc copyright: update the years for the FSF 2020-01-15 11:42:38 +01:00
Benno Schulenberg 3e0bd533db tweaks: free two strings as soon as they are no longer needed 2020-01-14 11:01:32 +01:00
Benno Schulenberg 6896d8df47 tweaks: reduce the scope of two constants and of four variables 2020-01-14 10:35:54 +01:00
Benno Schulenberg 8455251c35 files: revert the previous commit, as the extra warning is annoying
It also erroneously left the succeeding prompt on the screen.

This fixes https://savannah.gnu.org/bugs/?57593.
2020-01-13 21:42:44 +01:00
Benno Schulenberg 5cf351913e files: warn doubly when the user is about to overwrite an existing file 2020-01-13 20:05:56 +01:00
Benno Schulenberg 416386edcd files: alert the user afterward when an overwritten file is being edited
(The ideal behavior would be that nano would warn the user beforehand,
before the file that is being edited by someone else gets overwritten,
but that would require many more changes.  So... just give a helpful
warning -- that's already better than it was.)
2020-01-13 20:00:07 +01:00
Benno Schulenberg 497f126bb2 files: write a lock file also for a new file and when the name changed
(When the new or changed name is that of an existing file AND this
file is being edited by some other editor (or nano itself), then the
behavior is rather strange: nano asks whether to continue, but the
file has already been overwritten and there is nothing the user can
do to cancel or revert things.  A later commit should improve this.)

This fixes https://savannah.gnu.org/bugs/?47975,
and fixes https://savannah.gnu.org/bugs/?53883.
2020-01-13 20:00:07 +01:00
Benno Schulenberg 4687322398 tweaks: rewrap two lines, for consistency with similar lines 2020-01-13 20:00:07 +01:00
Benno Schulenberg 413b9cb774 tweaks: rename a function, to get rid of a useless suffix 2019-12-15 19:47:05 +01:00
Benno Schulenberg 76d90617cc build: avoid three compiler warnings when using gcc-9.2 or newer
This addresses https://savannah.gnu.org/bugs/?57360.
Reported-by: Brand Huntsman <alpha@qzx.com>
2019-12-08 11:27:06 +01:00
Benno Schulenberg 38743b0016 tweaks: reshuffle an 'if' to avoid a negation, and improve a comment 2019-11-27 11:56:35 +01:00
Benno Schulenberg 68c3aaf2df softwrap: when switching to another buffer, re-align the starting column
When we switch to another buffer, the window may have been resized
since we were last in this buffer, so make sure that 'firstcolumn'
gets a fitting value.

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

Bug existed since version 2.8.0, since the softwrap overhaul.
2019-11-27 11:49:09 +01:00
Benno Schulenberg af8ffa8c94 tweaks: silence a warning when configured with --enable-tiny 2019-11-25 19:21:03 +01:00
Benno Schulenberg fa88fcc8f2 tweaks: rename a function, and elide a parameter that is always NULL
After the previous change, all remaining calls of parse_mbchar() have
NULL as their third parameter.  So, drop that parameter and remove the
chunk of code that handles it.  Also rename the function, as there are
already too many functions that start with "parse".
2019-10-21 12:35:14 +02:00
Benno Schulenberg 17c16a4bf5 tweaks: rename a function and elide its first parameter 2019-10-20 09:45:58 +02:00
Benno Schulenberg f816da413a tweaks: elide a variable that is the same as another 2019-10-18 17:12:51 +02:00
Benno Schulenberg 3a0ac428ba tweaks: remove a redundant check for an existing emergency file
This case is caught (by O_EXCL) later on, at the appropriate moment:
when the file is created.

Also, this removes a superfluous lstat() for each temporary file.
2019-10-18 17:04:55 +02:00
Benno Schulenberg 97ab28a164 tweaks: exclude two fragments of code from the tiny version
Also improve a comment, and recorrect an indentation.
2019-10-18 14:25:55 +02:00
Benno Schulenberg ccb739dd7d tweaks: don't wrap calls of statusline() that slightly overshoot 80 cols 2019-10-18 14:04:15 +02:00
Benno Schulenberg 1082f2adec files: don't mention the name of the temp file when reading goes wrong
When writing a temp file goes wrong, its name is not mentioned either.
2019-10-18 13:38:20 +02:00
Benno Schulenberg 042b8394a0 tweaks: use a simpler positive/negative check for after copy_file() 2019-10-18 13:25:38 +02:00
Benno Schulenberg f2d6e6fa5e tweaks: check the return value of copy_file() also after its other uses 2019-10-18 12:37:39 +02:00
Benno Schulenberg 5390f96900 files: distinguish between read error and write error when prepending
This fixes https://savannah.gnu.org/bugs/?57066.

Bug existed in this form since version 2.4.3 -- in older versions
it segfaulted.
2019-10-18 12:15:14 +02:00
Benno Schulenberg 50ed18be17 tweaks: move a call of umask() closer to where it is relevant 2019-10-17 17:29:11 +02:00
Benno Schulenberg a6365707c0 tweaks: remove the superfluous closing of a file descriptor
The file itself is closed three lines earlier; this also closes the
corresponding descriptor.
2019-10-17 16:43:07 +02:00
Benno Schulenberg 6fad6a17da tweaks: rename a variable, to be distinct and visible 2019-10-17 12:17:09 +02:00
Benno Schulenberg eb757e7c5b tweaks: simplify the opening of files when prepending
There is no need for a file descriptor: all reading and writing
is done on streams.
2019-10-17 12:12:07 +02:00
Benno Schulenberg b554606047 tweaks: add a local variable, for clarity, to not preuse another one 2019-10-17 11:49:21 +02:00
Benno Schulenberg e915fb1650 tweaks: adjust the indentation after the previous change, and another 2019-10-17 11:45:03 +02:00
Benno Schulenberg 4e40ec057e tweaks: elide an unneeded check when making a backup
When making a backup, we can be certain that the relevant file
is not a temporary file, so 'stream' will necessarily be NULL.
2019-10-17 11:45:03 +02:00
Benno Schulenberg bd0026be86 tweaks: elide another two calls of umask(), and rename two variables 2019-10-17 11:43:42 +02:00
Benno Schulenberg a1bef0e953 tweaks: avoid three unneeded calls of umask() in the normal case 2019-10-16 19:17:42 +02:00
Benno Schulenberg f5693d4151 tweaks: elide a duplicate opening of the existing file when prepending 2019-10-16 17:40:52 +02:00
Benno Schulenberg e3807f00a2 tweaks: rename two variables, and add a third, for more contrast 2019-10-16 17:16:48 +02:00
Benno Schulenberg 022cc084a7 files: when opening a file for copying, it should NOT be created
Weird bug.  The first occurrence is probably never hit because the
existing file has been tentatively opened fourteen lines earlier,
but that looks superfluous: double work.  And the second occurrence
will not be hit because the temp file is unlikely to have disappeared.
2019-10-16 16:27:23 +02:00
Benno Schulenberg 0f98466e2f tweaks: adjust the indentation after the previous change
Also, don't bother assigning the stream pointer of the existing file
to variable 'f', as it gets overwritten right away by the pointer of
the temp file.
2019-10-16 16:05:40 +02:00
Benno Schulenberg 40c067133a tweaks: remove two superfluous conditions when prepending
When prepending, we cannot be writing to a temp file,
so 'stream' (and thus 'f') will necessarily be NULL.
2019-10-16 15:47:35 +02:00
Benno Schulenberg 36270748dc tweaks: condense or improve some comments 2019-10-16 13:47:30 +02:00
Benno Schulenberg 1894c81412 tweaks: rename two parameters, for contrast and to match others 2019-10-16 13:07:41 +02:00
Benno Schulenberg e917ef0105 tweaks: die on an impossible condition -- to be removed later 2019-10-16 12:27:27 +02:00
Benno Schulenberg 3347682fd0 tweaks: remove a pointless updating of the title bar
A possible change in filename won't be pushed to the screen until a
doupdate() is done, and that won't happen until nano is waiting for
a keystroke again.  So... just let it be.
2019-10-16 12:22:39 +02:00
Benno Schulenberg 3b9a24a7ca tweaks: rename a local variable, to not shadow another 2019-10-16 11:11:19 +02:00
Benno Schulenberg 7d3290fb91 tweaks: rename three variables, to be consistent with other linestructs 2019-10-16 11:04:26 +02:00
Benno Schulenberg df0ae2ace5 tweaks: reshuffle a few declarations, and reduce the scope of one 2019-10-16 10:48:14 +02:00
Benno Schulenberg 34170611d3 restored feature: a per-syntax 'fixer' command that processes the buffer
The command can be used to run some kind of formatter or corrector or
arranging tool on the buffer.  By default the command is bound to M-F.
The formatter/corrector/arranging program must be non-interactive.

This addresses https://savannah.gnu.org/bugs/?55365,
and addresses https://savannah.gnu.org/bugs/?54651.
2019-10-14 10:28:45 +02:00
Benno Schulenberg 094758be15 tweaks: reshuffle a fragment of code into two alternatives 2019-10-13 16:11:15 +02:00
Benno Schulenberg 06bbc70d4a tweaks: use a string-copy function that checks for out-of-memory 2019-10-13 12:38:46 +02:00
Benno Schulenberg d256d0cbc0 tweaks: add a helper function without the ubiquitous NULL argument
For conciseness and clarity.
2019-10-13 12:24:27 +02:00
Benno Schulenberg d12191db5a tweaks: pass any special undo/redo messages to the add_undo() function
For the three operations (justification, spell checking, and filtering)
that need to undo or redo two suboperations (cutting and then pasting)
in one go, pass the message that describes the operation to add_undo(),
so that the undo item does not need to be modified after the call.

This looks better, but does add some twenty NULL parameters elsewhere.
2019-10-09 19:21:27 +02:00
Benno Schulenberg 785efc2087 tweaks: make a function do a check so its calls don't need to 2019-10-09 18:58:30 +02:00
Benno Schulenberg 557ad827f9 tweaks: condense two comments, and rewrap a line 2019-10-09 14:49:42 +02:00
Benno Schulenberg 600f81cf98 tweaks: rename three variables, and reshuffle some lines 2019-10-09 14:20:29 +02:00
Benno Schulenberg cc4ce8d83b tweaks: rename a type, to better fit the general pattern 2019-10-02 17:09:22 +02:00
Benno Schulenberg 2a4d338d97 tweaks: reshuffle a fragment, to group some toggles together 2019-10-02 15:07:04 +02:00
Benno Schulenberg ab6390cad0 tweaks: remove two superfluous macros, as sizeof(char) is always 1 2019-09-18 15:20:08 +02:00
Benno Schulenberg ebd9eb346d tweaks: improve a bunch of comments, and reshuffle some declarations 2019-09-17 17:38:42 +02:00
Benno Schulenberg 413116e1b5 tweaks: rename another variable, for a better fit 2019-09-17 16:46:11 +02:00
Benno Schulenberg 69a3d39bc4 tweaks: rename three variables, for more contrast 2019-09-17 16:42:53 +02:00
Benno Schulenberg f081fa3047 tweaks: rename two variables, to better describe what they contain
The 'tilded' variable is used for two purposes: a user's home directory,
and an intermediate user name.
2019-09-17 14:26:09 +02:00
Benno Schulenberg 4383b01b9b tweaks: adjust indentation after previous change, reshuffle declarations 2019-09-17 14:11:45 +02:00
Benno Schulenberg b901a20a06 tweaks: use an early return when there is no tilde
Also improve a comment, and use a 'while' instead of a 'for'.
2019-09-17 14:09:40 +02:00
Benno Schulenberg 63e04ac31e tweaks: make a function name unique, to not overlap with others 2019-08-09 19:34:03 +02:00
Benno Schulenberg bbab9e2e62 tweaks: shorten two messages that translators tend to make too long 2019-06-19 19:34:19 +02:00
Benno Schulenberg 345cf5accc files: don't close a newly-created buffer when it is the only one
This fixes https://savannah.gnu.org/bugs/?56504.
Reported-by: Liu Hao <lh_mouse@126.com>

Bug existed since commit 7e422402 from two weeks ago.
2019-06-16 19:12:52 +02:00
Benno Schulenberg ce69d5be88 tweaks: condense two comments, and normalize the whitespace of a label 2019-06-12 11:10:27 +02:00
Benno Schulenberg 3da4240229 tweaks: rename a variable, to fit a little better 2019-06-12 11:03:03 +02:00
Benno Schulenberg 43caf7bb7b tweaks: avoid an unneeded, extra stat() for temporary files 2019-06-12 10:48:03 +02:00
Benno Schulenberg e8e30e5197 tweaks: elide an unneeded, duplicate stat() for the FIFO check 2019-06-12 10:34:53 +02:00
Benno Schulenberg 189de5ee78 files: suppress feedback when writing an emergency or temporary file
This fixes https://savannah.gnu.org/bugs/?56474.

Bug existed since commit 47770bd3 from two weeks ago.
2019-06-12 09:51:14 +02:00
Benno Schulenberg 967f581860 tweaks: adjust some whitespace and rewrap a few lines
And remove two unneeded casts.
2019-06-09 20:03:44 +02:00
Benno Schulenberg f63fee79e3 tweaks: merge two functions, as the first is called just once 2019-06-01 11:14:21 +02:00
Benno Schulenberg 2003413989 tweaks: move a function to the file where it is used 2019-06-01 10:52:38 +02:00
Benno Schulenberg 7e9dd385f5 tweaks: elide a parameter and a return value
As 'filepart' is a global variable, there is no need to pass it around.
Just use it directly.
2019-05-31 19:00:20 +02:00
Benno Schulenberg 122cabd3ba tweaks: elide another parameter, and rename the function to match 2019-05-31 09:33:28 +02:00
Benno Schulenberg c5d157dd9d tweaks: close a buffer differently and elide a parameter 2019-05-31 09:15:12 +02:00
Benno Schulenberg 484523b3bb tweaks: drop two checks that were made redundant by the previous commit 2019-05-30 17:18:30 +02:00
Benno Schulenberg 5a48edc9ae tweaks: reshuffle some code to the one place that needs it
The extra things that close_buffer() did are only needed and useful
when manually closing a buffer, so move them there.  The other three
calls of close_buffer() only need to get rid of the current buffer
(making the preceding buffer the new current one) and nothing else.
2019-05-30 17:09:49 +02:00
Benno Schulenberg 7e422402d5 tweaks: change a function to void, to make things more direct 2019-05-29 20:02:50 +02:00
Benno Schulenberg 821445d284 tweaks: drop some checks that were made redundant by the previous commit
And move one to a better place.
2019-05-29 19:48:42 +02:00
Benno Schulenberg d656b0d3b9 feedback: show an appropriate message when reading a file was cut short 2019-05-28 17:06:07 +02:00
Benno Schulenberg b75563b88e tweaks: use a symbol instead of zero to refer to standard input 2019-05-28 12:31:16 +02:00
Benno Schulenberg d946f38a2b files: when needed, reconnect the keyboard and reenter curses mode
When after reading a file we are not in curses mode, it means we have
read data from standard input, either from the keyboard or from a pipe.
In the latter case, we first need to reconnect standard input to the tty.
And in both cases, we then need to reenter curses mode before being able
to display the number of lines that were read (or an error message).

So, move the reconnecting code from scoop_stdin() to its own function,
and call this function from read_file() when needed.

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

Bug existed since version 2.1.8 when reading from stdin was introduced.
2019-05-28 11:28:23 +02:00
Benno Schulenberg d972c17050 build: exclude the ability to open a FIFO from the tiny version 2019-05-27 09:55:24 +02:00
Benno Schulenberg f6e182ca72 tweaks: check in a single place for files that should not be opened 2019-05-27 09:42:41 +02:00
Benno Schulenberg 6a83bb7508 tweaks: delete a leftover 2019-05-27 09:33:36 +02:00
Benno Schulenberg 728498fde5 files: don't say "Error...: Success" when aborting after resizing
For some reason 'errno' is not EINTR but zero when a SIGINT is
produced after a SIGWINCH.
2019-05-26 19:49:23 +02:00
Brand Huntsman 05f34bbfaf files: block SIGWINCH while opening a FIFO for reading or writing
This fixes https://savannah.gnu.org/bugs/?56354.
Reported-by: Brand Huntsman <alpha@qzx.com>

Signed-off-by: Brand Huntsman <alpha@qzx.com>
2019-05-26 19:40:33 +02:00
Benno Schulenberg 308a094d8d feedback: show a more fitting message when opening a FIFO is interrupted 2019-05-26 14:17:35 +02:00
Benno Schulenberg 5757aa8a0c tweaks: reuse the install and restore functions for a signal handler 2019-05-26 13:57:29 +02:00
Benno Schulenberg 8c5b67379f tweaks: factor out the installing and restoring of the ^C signal handler
So that these two functions can be used elsewhere too.
2019-05-26 13:55:59 +02:00
Benno Schulenberg ea11709564 files: allow to abort the reading of slow files with Ctrl+C
This addresses https://savannah.gnu.org/bugs/?44907.

Original-patch-by: Martin van Zijl <martin.vanzijl@gmail.com>
2019-05-26 13:34:38 +02:00
Benno Schulenberg 8550c6bd93 files: allow to interrupt the opening of a FIFO for writing with Ctrl+C 2019-05-26 11:45:51 +02:00
Benno Schulenberg 9a475bf2d3 speller: don't crash when the spell-checked tempfile cannot be opened
This addresses https://savannah.gnu.org/bugs/?56361.
2019-05-24 17:31:35 +02:00
Benno Schulenberg b512e253b6 tweaks: drop an unneeded parameter from open_file()
The 'quiet' parameter is only used when opening a help-text tempfile
or a spell-checked tempfile, and these files necessarily exist, so
'quiet' will never be checked for them.  But in the weird case that
the help-text tempfile could not be opened, it is not a problem that
"New File" gets printed to the status bar because nano will crash
shortly afterwards.  And when the spell-checked tempfile could not
be opened, a "Not Found" message is appropriate, but nano will crash
in this case too.
2019-05-24 13:00:00 +02:00
Benno Schulenberg 4cacb626a0 files: allow to interrupt the opening of a FIFO with Ctrl+C
With-help-from: Brand Huntsman <alpha@qzx.com>
2019-05-24 10:51:56 +02:00
Benno Schulenberg acd23551c3 help: don't check for confinement when opening a temporary help-text file
This fixes https://savannah.gnu.org/bugs/?56369.
2019-05-23 12:43:31 +02:00
Benno Schulenberg d7555d071f tweaks: adjust a comment and drop two others, and reshuffle two lines 2019-05-21 19:42:08 +02:00
Benno Schulenberg 9596f7de9d tweaks: delete a now-unused function 2019-05-21 18:56:35 +02:00
Benno Schulenberg 20635b40f4 tweaks: merge two very similar functions into a single one 2019-05-21 18:56:13 +02:00
Benno Schulenberg 1128a40d42 tweaks: remove an unneeded setting and unsetting of a flag
This twiddling was made superfluous by commit faa0eb99 from a year ago.
2019-05-21 18:55:34 +02:00
Benno Schulenberg 4f1eb5fdd4 tweaks: remove the two remaining handfuls of asserts
They are just clutter -- no one runs a debug build for any length
of time.
2019-05-19 18:58:02 +02:00
Benno Schulenberg 1d3a4df3b3 browser: don't show a mistaken message when exiting from help viewer
This fixes https://savannah.gnu.org/bugs/?56346.

Bug existed since version 3.0, commit 8d6b205e.
2019-05-18 19:59:54 +02:00
Benno Schulenberg afbaf8ae2d files: give feedback while waiting for a FIFO to open up 2019-05-18 19:14:32 +02:00
Benno Schulenberg 1b2018e921 files: check for writability by the access bits, not by trying to append
Trying to append does not work on a fifo, and we'd like to be able to
open a fifo again.  Also, the append test causes a close event for the
given file at the moment of opening it, which makes using 'inotify' for
waiting for this file to be closed useless.

Commit f8f90272 added the append test, but the original request
(https://lists.gnu.org/archive/html/info-nano/2009-05/msg00000.html
by Damien Joldersma) asked only for a warning when the user did not
have enough privileges to write to the file.

So, drop the append test and just check the access bits.

This fixes https://bugs.debian.org/583196
and fixes https://savannah.gnu.org/bugs/?29312.
2019-05-18 19:13:42 +02:00
Benno Schulenberg 26642a39c3 files: allow a given file to be a special file but not a directory
The original requests (https://bugs.debian.org/551717 by Paul Wise,
and https://savannah.gnu.org/bugs/?45383 by Mike Frysinger) asked
only that specifying a directory instead of a file name should not
open a new buffer.  But commit 98ffb642 excluded everything that was
not a normal file.  This avoids a hang when the user accidentally
tries to open a pipe or a socket, but also prevents any user from
doing so on purpose.  And opening a fifo can be useful when wanting
to handle sensitive data that shouldn't be stored on disk.

This prepares the fix for https://bugs.debian.org/583196.
2019-05-18 17:24:13 +02:00
Benno Schulenberg 368f1a1c9d tweaks: elide a function that is called in just one place
Since commit b5f15cb5 from a year ago, there remains just one call
of initialize_buffer_text().
2019-05-16 16:16:52 +02:00
Benno Schulenberg 4fb9f298c9 tweaks: adjust some indentation after the previous change
Also reshuffle some arguments.
2019-05-08 19:35:42 +02:00