Commit Graph

1240 Commits (0363703073afe35579476e5dc8d3e3df5d7735de)

Author SHA1 Message Date
Benno Schulenberg 69b12d907e tweaks: avoid unneeded calls of free() by reallocating the full name 2020-06-26 09:57:38 +02:00
Benno Schulenberg c0c4a1b2b5 tweaks: plug a leak, by always freeing the full filename [valgrind] 2020-06-26 09:47:38 +02:00
Benno Schulenberg 94f49e208f tabbing: beep at the first listing, and when there are zero possibilities
A successful single completion is silent, but when there are zero
or multiple possibilities, nano beeps.
2020-06-25 10:26:01 +02:00
Benno Schulenberg 24740815f6 files: make better use of the last row when there are many completions
Put the "(more)" not in the first column of the last row but in the
last column.
2020-06-23 08:28:47 +02:00
Benno Schulenberg c7356c2d85 files: show possible tab completions near the bottom of the edit window
Especially when it are just a handful of possible completions, it is
much nicer to have them listed close to the prompt bar where the eyes
of the user are.

This fulfills https://savannah.gnu.org/bugs/?58620.
2020-06-23 08:28:47 +02:00
Benno Schulenberg 91ba76e1e0 tweaks: normalize the indentation after the previous change
Also, improve five comments.
2020-06-23 08:28:47 +02:00
Benno Schulenberg 3dcabd6d03 tweaks: make an early return for zero matches, and rename a variable 2020-06-23 08:28:47 +02:00
Benno Schulenberg 0f843b007a tweaks: avoid an unnecessary refresh for zero or just one completion 2020-06-23 08:28:47 +02:00
Benno Schulenberg ff11ab6b66 files: list possible completions after just one <Tab> instead of two
This gives quicker feedback, and spares the user unnecessary beeps
and typing.  Also, now a beep after a <Tab> means just one thing:
there are NO completions.

This fulfills https://savannah.gnu.org/bugs/?58627.
2020-06-23 08:28:47 +02:00
Benno Schulenberg a9e171de52 tweaks: update three translator hints, add two, and frob three strings 2020-06-21 14:10:37 +02:00
Benno Schulenberg 380589d95d tweaks: reshuffle and trim a comment, and remove unneeded pair of braces 2020-06-21 09:20:44 +02:00
Benno Schulenberg bb496bf456 tweaks: rename two variables, to be shorter and without abbreviations 2020-06-21 09:12:59 +02:00
Benno Schulenberg b086d0bad0 tweaks: elide another parameter, relevant in just three menus
The parameter was referenced in just one place.  So, simply check for
the three relevant menus (and unrestricted mode) and be done with it.

This also has the pleasant effect that the menu name is now the first
parameter of do_prompt(), thus clearly indicating what prompt it is,
instead of having an opaque TRUE or FALSE value at the beginning.
2020-06-20 17:19:23 +02:00
Benno Schulenberg a13b0bc854 files: disallow tabbing when in restricted mode
Tabbing can list all files in the given directory, but restricted mode
is supposed to prevent the user from any access to the filesystem...

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

Bug existed (in this form) since version 1.3.4, commit f7b5d930.
2020-06-20 14:55:28 +02:00
Benno Schulenberg 90f6342fd1 tweaks: rename two header files, to be distinct and not an abbreviation 2020-06-20 12:09:31 +02:00
Benno Schulenberg 499b926b74 tweaks: elide a parameter that is relevant for only one menu (Goto Dir)
Instead of burdening seven other calls of do_prompt() with a useless
parameter, just check for MGOTODIR in the appropriate place.  It also
saves having to pass the parameter down through three more functions.
2020-06-19 10:55:28 +02:00
Benno Schulenberg 61dda8ff62 tweaks: rename a variable, to make more sense 2020-06-19 10:12:49 +02:00
Benno Schulenberg 6ce4e3ede8 feedback: do not list "." and ".." as possible <Tab><Tab> completions
The single dot serves no purpose, as the user is already there.  And
the double dot is reached more easily by typing a second dot first.

And anyway, . and .. are not shown when the user does not type a dot
first, so why show them when the user types a single dot followed by
<Tab><Tab>?  Most likely the user wants to see actual dot files, so
just show those.

This fixes https://savannah.gnu.org/bugs/?58619.
2020-06-19 10:06:33 +02:00
Benno Schulenberg 287718cf8b tweaks: rename two parameters, to be more fitting 2020-06-18 19:12:11 +02:00
Benno Schulenberg 78f54523d9 tweaks: elide a variable and be more direct, and rename another 2020-06-18 19:02:02 +02:00
Benno Schulenberg 9faa95450b tweaks: rename two functions, and rename and reshuffle a parameter
Also, drop an unneeded nulling: the function copy_of() already
NUL-terminates the copied string.
2020-06-18 17:24:18 +02:00
Benno Schulenberg 26d7a7494e tweaks: improve several comments, and rewrap two lines 2020-06-18 17:10:05 +02:00
Benno Schulenberg 3ff524821c tweaks: move a copyright notice to a better place, and improve it
The username_tab_completion() function taken from busybox-0.46 was
just a stub, it contained basically nothing.  Chris himself wrote
the function in November 2000 (commit be77c611), and rewrote it in
January 2001 (commit 2c2c5f21).

The version of username_tab_completion() in that latter commit looks
somewhat like the version of Vladimir N. Oleynik <dzo@simtreas.ru>
(busybox commit 4e338757).  That commit comes three days after Chris'
commit, but Vladimir's original email is from a week earlier:
http://lists.busybox.net/pipermail/busybox/2001-January/035687.html.
So... it is quite possible that Rocco saw that email and suggested
to Chris to rewrite username_tab_completion() using getpwent().

Anyway, the version that was taken from busybox-0.46 was just four
lines and thus not worthy of copyright.  The two other functions
that were copied were heavily modified in 2000, so it's better to
add that year in the copyright notice.  It is fine to tweak the
notice: it just says that the original authors must be attributed,
not that the exact text must remain unchanged.
2020-06-18 12:50:24 +02:00
Benno Schulenberg 290b250141 tweaks: elide an unneeded variable, as there is nothing beyond '*place' 2020-06-18 12:12:43 +02:00
Benno Schulenberg b61d97eb9a tweaks: elide a variable, and shortcircuit a return
Instead of first trying to match things, and then discarding these
matches when the cursor is not at the end of the offered fragment
('buf'), simply don't bother to do any matching in that case.
2020-06-18 12:12:33 +02:00
Benno Schulenberg 0bced0a5e9 tweaks: condense and improve some comments 2020-06-18 11:44:25 +02:00
Benno Schulenberg 23c62c5032 tweaks: drop two unneeded assignments
The variable is set to zero at its declaration, and the second function
is called only when the first is either not called or found nothing --
thus '*num_matches' will still be zero.
2020-06-18 11:20:25 +02:00
Marco Diego Aurélio Mesquita 648eac936e files: make the M-F (New Buffer) toggle non-persistent
Having the M-F toggle non-persistent, makes the behavior of ^R
predictable.  This allows string binds that load a file to work
correctly independently of when M-F was last pressed.

The -F/--multibuffer command-line option and "set multibuffer"
in a nanorc file determine the default behavior of ^R.

Signed-off-by: Marco Diego Aurélio Mesquita <marcodiegomesquita@gmail.com>
2020-06-15 16:05:31 +02:00
Benno Schulenberg 8535b3db4c tweaks: rename a variable, to not refer to a row as a "line" 2020-06-11 16:45:47 +02:00
Benno Schulenberg 77bce9f1c4 tweaks: remove a redundant cursor movement, remove a redundant condition
Each listing of a name is preceeded by a call to wmove(), so there
is no need for an initial wmove().  And after writing "more" on the
bottom row of the edit window, the loop is terminated, so there is
no need to check that this is the first item on the bottom row.
2020-06-11 16:29:38 +02:00
Benno Schulenberg a2b85e0c12 indicator: recompute the extra rows also when justifying and resizing
And when the margin changes (when line numbers are switched on or off,
or when the buffer grows or shrinks), and when a piece of text from a
different buffer with a different margin is pasted.

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

Bug existed since commit 9a9f36fc from yesterday.
2020-06-07 12:16:15 +02:00
Benno Schulenberg 9a9f36fca7 indicator: rework how the "scrollbar" is computed when softwrapping
Instead of storing for each line the ordinal number of the first chunk
in that line, simply store the number of extra chunks in the line.

It now takes some more computation to actually draw the scrollbar, but
it saves a lot of computation when just inserting or deleting characters
(when using --softwrap and causing a change in chunk count).

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

Bug existed since commit 6bccedb3 from two days ago.
2020-06-06 19:21:23 +02:00
Benno Schulenberg d3954901a9 bindings: make ^T invoke the "Execute Command" menu, and ^T^T the Speller
Make the "Execute Command" menu accessible also with a single keystroke
(^T), not just with a double one (^R^X).  This is useful, because no one
will suspect that "Execute Command" can be found behind "Read File".

To not disturb muscle memory too much for people who are used to ^T
invoking the Spell Checker, a second ^T will invoke it.
2020-05-30 18:56:55 +02:00
Benno Schulenberg cd594b85f4 general: make five tools accessible through the "Execute Command" menu
Instead of creating a special Tools menu, add the five functions that
affect the whole buffer to the "Execute Command" menu.  There is room
for these five functions there, and they kind of fit in because three
of them (Speller, Linter, and Formatter) actually invoke an external
command, and Full Justify could have been implemented externally, and
the destructive Cut Till End ought to have required a double keystroke
since the beginning.
2020-05-30 18:56:51 +02:00
Benno Schulenberg e1f80b9707 tweaks: move a function to a more logical place
Initialization should come first.
2020-05-29 17:12:45 +02:00
Benno Schulenberg 6b4e7d0f78 tweaks: reshuffle a declaration and six calls of free(), to avoid a leak
If the user chose to skip making a backup,
'backupname' would not be freed.
2020-05-29 13:57:38 +02:00
Benno Schulenberg 4b4a8be58b files: before prompting, show also the reason why the backup failed
Also, do not prompt when there is no space left on the device,
because then trying to save the actual file would likely lead
to truncating it, resulting in an empty file.
2020-05-29 11:57:33 +02:00
Benno Schulenberg 512b0fd32d files: take into account that also closing a backup file can fail
Only when fclose() is called, does the data get flushed out to disk,
and maybe only then the system realizes that there is no space left on
the device, as Chris noted in: https://savannah.gnu.org/bugs/?24000.
2020-05-29 11:40:27 +02:00
Benno Schulenberg 586d22109b files: show a warning when writing a backup fails, before prompting
Make the behavior similar to that of the other failure cases.

Also, plug a tiny memory leak.
2020-05-29 11:22:57 +02:00
Benno Schulenberg 47953bd6ac files: also when creating a backup fails, ask the user whether to proceed
When asking this question when deleting fails or writing fails,
it should be asked too when creating fails.  Otherwise the user
is blocked from saving the file -- until she realizes that maybe
toggling off backups would help.
2020-05-29 10:58:11 +02:00
Benno Schulenberg 11d3b01050 files: give a more precise warning when deleting an existing backup fails
This addresses https://savannah.gnu.org/bugs/?58410.
2020-05-29 10:48:01 +02:00
Benno Schulenberg eddd8963e7 files: ask the user whether to proceed every time a backup fails
If the user answered "No" or "Cancel" the first time, they should
be allowed to answer "Yes" the next time -- possibly after fixing
the necessary permissions in another terminal.

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

Bug existed since version 2.3.0, commit 3d411188.
2020-05-29 10:23:54 +02:00
Benno Schulenberg 160f07baba tweaks: simplify an error message, by mentioning just the main point
Also, correct a comment.
2020-05-28 19:30:09 +02:00
Benno Schulenberg 822d764d27 files: ignore errors when calling futimens() on a backup file
Access control lists can permit read and write access to a file
but not permit to manipulate any attributes of the file.  So it
is quite possible for futimens() to fail, just like chown() and
chmod() can fail, but this should be no cause for alarm: as long
as writing the backup file worked, then writing the file itself
will probably work too.
2020-05-28 17:19:45 +02:00
Benno Schulenberg 6d00e75dc2 tweaks: rename a function, to be more correct 2020-05-28 16:59:50 +02:00
Benno Schulenberg 90772ad05b backup: do not understand ^C as "Yes" when asking whether to continue
This fixes https://savannah.gnu.org/bugs/?58443.

Bug existed since version 2.3.0, commit 3d411188.
2020-05-28 14:58:05 +02:00
Benno Schulenberg 756b95748b tweaks: rename a struct element, to be shorter and preciser
And anyway, there are too many occurrences of 'current'.
2020-05-28 14:38:48 +02:00
Benno Schulenberg 8d31ad8a70 files: ignore errors when calling chmod() on a backup file
First, it is very unlikely that chmod() would fail as the user just
created the file herself.  Second, even if chmod() would fail, this
is not a problem, because we have created the file with read+write
permissions for the owner only, so the file cannot accidentally be
left accessible to unintended others.

But most of all, such a failure should not stop nano from trying to
write the backup file.  Only when the actual *writing* fails, should
we bother the user with a prompt.
2020-05-28 14:35:42 +02:00
Benno Schulenberg b48dfde3b2 files: remove two superfluous calls for shielding temp files from others
If there are still systems where mkstemp() creates world-readable
temporary files, then please holler.  On current BSDs and on GNU,
I've verified that mkstemp() creates files with 0600 permissions.
2020-05-26 13:40:11 +02:00
Benno Schulenberg f8366cd5c9 tweaks: remove two calls of umask() by specifying permissions directly 2020-05-26 12:36:18 +02:00
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