Commit Graph

6469 Commits (b72d9af52c61e0242781aff4eea664d5c2687759)

Author SHA1 Message Date
Benno Schulenberg ac4c56f636 tweaks: fold one function into another, to elide an unneeded return value 2020-09-02 09:55:08 +02:00
Benno Schulenberg 1db7d57a24 browser: make M-W/M-Q functional right after startup, if there is history
Do the same what the normal "research" code does: if nothing was
searched for yet during this session, and there is a history of
search items, then search for the last item in that history.
2020-09-02 09:22:50 +02:00
Benno Schulenberg e32ca98ccf tweaks: condense a bit of code
Make it equal to what the normal search code does.
2020-09-02 09:15:23 +02:00
Benno Schulenberg 5a635db262 chars: reduce searching time with roughly 85 percent for plain ASCII
Make case-insensitive searching in a UTF-8 locale eight times faster
when the actual characters involved are plain ASCII.

This makes us faster than 'less', and as fast as Vim and Emacs.

The disadvantage of this change is that searching for a string that
begins with a multibyte character is nearly ten times slower than
searching for one that begins with an ASCII character.  This may be
unsettling when searching a huge file first for a simple ASCII string
and later for a UTF-8 one.  Doing this second search, the user might
get impatient: "Why is it taking so long?"

(This patch fell through the cracks four years ago, when I worked on
the searching code.  It sat in a branch on top of other changes that
I never applied because I made different improvements.  The speedup
at the time, on that machine, was only around sixty percent, though.
But measuring it now again on the same machine, it clocks in at an
82 percent reduction with -O0 and an 87 percent reduction with -O2.)
2020-09-01 19:35:34 +02:00
Hussam al-Homsi c87bc1d55f tweaks: stop casting the return of malloc() and friends
Those casts are redundant, and sometimes ugly.  And as the types of
variables are extremely unlikely to change any more at this point,
the protection they offer against miscompilations is moot.

Signed-off-by: Hussam al-Homsi <sawuare@gmail.com>
2020-08-31 12:17:27 +02:00
Benno Schulenberg 5c63975097 tweaks: rename four variables, reshuffle them, and correct one type
Also, drop three unneeded comments.
2020-08-25 12:13:55 +02:00
Benno Schulenberg fee905a34a tweaks: drop the unneeded saving and restoring of a global variable
The two functions findnextstr() and do_replace_loop() do not change
or even touch 'last_search', so there is no need to save and then
restore its value when doing corrections of misspelled words.
2020-08-25 11:58:04 +02:00
Benno Schulenberg 0f8423eb4c tweaks: elide an unneeded variable
Storing the orientation of the marked region beforehand is not needed,
as this orientation is readily available also after the justification.

(By the way, cursor and mark need to be swapped after justifying
a backward-marked region because the rule is that the cursor gets
placed *after* the justified paragraph.  Maybe that should change?)
2020-08-22 19:35:48 +02:00
Benno Schulenberg b60fec5db3 history: do not interpret a failing stat() as an error
The most likely reason for stat() returning -1 is that the file
does not exist.  And an absent positionlog file is not an error.
(In some cases it is, like immediately after writing the file,
but even then we don't want to complain, because it may have
been some other process that deleted the file straightaway.)

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

Bug existed since version 5.0, commit fcb9e58b.
2020-08-22 10:27:02 +02:00
Benno Schulenberg 7ffbf01607 tweaks: improve three comments and an indentation 2020-08-21 16:06:38 +02:00
Benno Schulenberg f6b4c243d8 tweaks: reshuffle four declarations, and rename two variables 2020-08-21 16:03:59 +02:00
Benno Schulenberg 0287be7660 tweaks: move the keyboard-checking code to the end of the search loop 2020-08-20 10:51:19 +02:00
Benno Schulenberg e6709d684b tweaks: condense two fragments of code, for compactness 2020-08-20 10:44:06 +02:00
Benno Schulenberg aa257ef58e display: restore the ability to resize the screen while searching
This ability was lost in commit 92298349 from two hours ago, which
bypasses the keystroke buffer and its integrated screen resizing.

This new implementation is better than it was before, because it
responds almost instantly to a resize instead of with a delay of
up to a second.
2020-08-20 10:31:58 +02:00
Benno Schulenberg 8daa7cbda0 tweaks: remove a variable and two functions that have become redundant 2020-08-20 09:17:48 +02:00
Benno Schulenberg 8a5449cebe input: allow also a Meta keystroke to abort a Search command
(Still, this does not allow a full escape sequence to be used as
the Cancel command, but I think that is an acceptable limitation,
because 1) nobody ought to be using --rawsequences, and 2) very
few people will bind Cancel to something like F3 or Ins.)

This improves the fix for https://savannah.gnu.org/bugs/?58825.
2020-08-20 09:17:03 +02:00
Benno Schulenberg 9229834935 search: poll the input stream directly, not nano's own keystroke buffer
When checking (during a Search command) whether the user has pressed
the Cancel keystroke, look at ncurses' input stream directly instead
of at nano's own keystroke buffer, because the latter may contain the
copied keystrokes of a macro and we don't want to discard those.

(This does not yet allow a Meta keystroke to be used for Cancel, but
the next commit will fix that.)

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

Bug existed since version 2.9.0, since the macro was introduced.
2020-08-20 08:25:26 +02:00
Benno Schulenberg 6469e9668b tweaks: condense two declarations 2020-08-19 16:52:28 +02:00
Benno Schulenberg 68d71f649e rcfile: make sure that "bright"/"light" are prefixes, not separate words
This fixes https://savannah.gnu.org/bugs/?58984.

The bug was old -- it existed since at least version 2.0.6.
2020-08-19 16:18:29 +02:00
Benno Schulenberg 51f27d3f0c input: hold on to a shift-selected region when an unbound key is struck
There is no reason to deselect the region, as nothing has changed.

(This also retains the shift-selected region when a non-shortcut key is
typed in view mode, which makes sense, as again nothing was changed.)

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

Bug existed since version 4.9, commit 0ed62e84.
2020-08-19 08:36:00 +02:00
Benno Schulenberg b38265cfb8 search: retain the current answer when something is toggled
This fixes https://savannah.gnu.org/bugs/?58972.

Bug existed since version 5.0, commit bccb0ea0.
2020-08-18 09:17:39 +02:00
Benno Schulenberg bc6b9bf955 tweaks: rename a variable, to not seem to refer to the scrollbar 2020-08-17 13:36:03 +02:00
Benno Schulenberg 4b6090ded3 replacing: do not try to wipe nonexistent multidata, to avoid crashing
This fixes https://savannah.gnu.org/bugs/?58970.
Reported-by: Matteo Raso <mraso@uoguelph.ca>

Bug existed since version 5.0, commit 569d0056.
2020-08-17 10:05:25 +02:00
Benno Schulenberg fb98f0ced7 tweaks: adjust a comment, and reshuffle the setting of a boolean 2020-08-15 16:07:30 +02:00
Benno Schulenberg d09055db43 input: dawdle after an ESC also when --rawsequences is used
When keypad() is set to FALSE, like for verbatim input, ncurses is
not waiting its fifty milliseconds after an ESC to see if another
code will follow it, so nano itself will have to pause a little.

Otherwise 'solitary' could get set to TRUE when in fact the ESC
is followed very closely by another code.

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

Bug existed since version 2.6.2, commit f2150d3f.
2020-08-15 14:45:02 +02:00
Benno Schulenberg 50b61bef6f input: discard any multibyte character when <Alt> is being held
Otherwise the <Alt> key would simply be ignored.  It's better to reject
the combination, to compel the user to be precise in what they type.
2020-08-15 14:00:53 +02:00
Benno Schulenberg 3d0bfb0a00 input: do not enter invalid bytes when holding down both Alt keys
This fixes https://savannah.gnu.org/bugs/?58954.

Bug existed since version 5.1, commit 49231191.
2020-08-15 13:18:48 +02:00
Benno Schulenberg 3cb55c8b27 verbatim: reserve enough space for the result also in non-UTF-8 locales
Also when each character is just one byte, parse_verbatim_kbinput()
can produce two bytes; plus the terminating NUL that is three bytes.

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

Bug existed since version 4.9, commit 03d296eb.
2020-08-15 11:55:48 +02:00
Benno Schulenberg b2ea7d29d0 build: fix compilation for --enable-tiny --enable-nanorc --enable-color 2020-08-11 20:10:40 +02:00
Benno Schulenberg e597ad4908 build: fix compilation when configured with --enable-tiny 2020-08-11 19:59:24 +02:00
Benno Schulenberg 100747f56b verbatim: discard entire keystroke when it's not valid for Unicode Input
This will not work for the deviant escape sequences for F1 to F5
on the Linux console nor for Alt+arrow on urxvt and such, but...
I can't be bothered to handle those too.

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

Bug existed since commit be203832 from earlier today.
2020-08-10 16:18:03 +02:00
Benno Schulenberg d7b2b55bf5 display: show the cursor position also right after the screen is resized
Bug existed since commit 8e226a9f from half an hour ago.
2020-08-10 12:16:18 +02:00
Benno Schulenberg 9875252fd7 tweaks: remove an unneeded beep, and reshuffle the lines for compactness
The beep is produced later, after get_verbatim_kbinput() returns.
2020-08-10 12:07:16 +02:00
Benno Schulenberg 1551c1c771 verbatim: do not report "Invalid code" when a Unicode character is typed
This fixes https://savannah.gnu.org/bugs/?58928.

Bug existed since version 5.0, commit 5899181a.
2020-08-10 11:48:31 +02:00
Benno Schulenberg 8e226a9f28 verbatim: do not report "Invalid code" when the terminal is resized
During verbatim input at most four integers are produced (the longest
possible unicode sequence), so use the value 999 to indicate a special
condition (a screen resize) that should not enter anything into the
buffer AND should not produce any error message or beep.

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

Bug existed since version 5.0, commit 5899181a.
2020-08-10 11:42:09 +02:00
Benno Schulenberg be20383240 verbatim: report and ignore an invalid keystroke for Unicode input
When Unicode Input has started (by typing 0 or 1 at the Verbatim Input
"prompt"), and something is typed that is not a hexadecimal digit, then
don't try to enter this character into the buffer but simply report it
as invalid and ignore it.  Because most likely the user mistyped and
actually meant to enter a valid hex digit.

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

The bug was old -- it existed since at least version 2.0.6.
2020-08-10 09:31:24 +02:00
Benno Schulenberg cf769bbd2f tweaks: adjust the indentation after the previous change 2020-08-10 07:55:00 +02:00
Benno Schulenberg 4ec96f9f2e tweaks: reshuffle a few lines, to condense the code, and improve comment 2020-08-10 07:53:41 +02:00
Benno Schulenberg bdc856812f tweaks: read keycodes from the keystroke buffer without copying them
Allocating and freeing memory for reading every single keycode
is a waste of time and effort.

This addresses https://savannah.gnu.org/bugs/?58806.
2020-08-10 07:39:29 +02:00
Benno Schulenberg 96bb8149e9 moving: make <Ctrl+Up> go to the top when above the cursor all is blank
Just like <Ctrl+Down> goes to the end of the buffer when after the
cursor there are only blank lines.

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

Bug existed since version 2.6.2, since <Ctrl+Up/Down> were introduced.
2020-08-09 16:57:25 +02:00
Benno Schulenberg 07e69d54b2 tweaks: elide two variables that are no longer needed, and update comment 2020-08-09 15:40:53 +02:00
Benno Schulenberg aeb15e9549 tweaks: parse the escape-sequence bytes without copying them first 2020-08-09 15:25:22 +02:00
Benno Schulenberg 435d9acb5c tweaks: exclude old and mistaken "Esc O" sequences from the tiny version
The correct sequences begin with "Esc [" instead.  I cannot find in the
histories of VTE and Gnome Terminal when these sequences were corrected.

Also exclude a bug check from the tiny version.
2020-08-09 10:48:03 +02:00
Benno Schulenberg 12fe0a3b29 tweaks: normalize the indentation after the previous change
This finally gets rid of the piece of specially reduced indentation
(<-<- ... ->->) that made it hard to see the structure of the code.
2020-08-09 10:48:03 +02:00
Benno Schulenberg c14e77ce9e tweaks: split a function into two, one for "Esc O" and one for "Esc [" 2020-08-09 10:48:03 +02:00
Benno Schulenberg 2c8c061e67 tweaks: pass first byte of sequence directly to the decoding function
Don't bother stuffing it back into the keyboard buffer when it will be
taken out again straight afterward.
2020-08-09 10:48:03 +02:00
Benno Schulenberg 5fab1e6754 verbatim: pause a little after an ESC, to not miss a succeeding code
When we get an ESC from the keyboard, it might be the start of an
escape sequence, but the keyboard routines will need a little time
(tens of microseconds, probably) to get these codes to ncurses.
So, when doing verbatim input, pause a moment after an ESC.

This completes the fix for https://savannah.gnu.org/bugs/?58909.
2020-08-08 07:51:47 +02:00
Benno Schulenberg b0e3767af5 input: understand M-Bsp also when terminfo does not match the terminal
Always interpret ESC followed by BS or DEL as <Alt+Backspace>.

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

Bug existed since commit 40b03162 from one week ago,
since M-Bsp was hard-bound to deleting a word backwards.
2020-08-07 19:17:36 +02:00
Benno Schulenberg 4923119174 tweaks: reshuffle some fragments, to make the next change easier 2020-08-07 18:46:55 +02:00
Benno Schulenberg cdd6882541 verbatim: insert the full code sequence when <Alt+Backspace> is pressed
(This could lead to unwanted behavior when the user wants to enter
a literal escape character (0x1B) while the input is somehow getting
stalled, because then a command keystroke after the M-V <Esc> would
get inserted verbatim too, instead of getting acted upon.  But that
is a small price to pay for getting the correct behavior for both
M-V M-Bsp and M-V M-Enter.)

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

Bug existed since version 2.6.3, commit 08c51cfd,
but also occurred erratically beforehand.
2020-08-07 16:21:21 +02:00
Benno Schulenberg d7c2b98ead feedback: when creating a pipe fails, report also the reason
After commit 59bbc0b8 from five days ago (that made a divergent pipe
failure to be treated in the same way as the other two), this became
possible without having two different pipe-failure messages.
2020-08-06 08:47:52 +02:00
Benno Schulenberg 4c63ef204d tweaks: make a few more direct returns, and reshuffle another bit of code 2020-08-05 11:03:35 +02:00
Benno Schulenberg 4c6b6cad99 tweaks: elide an unneeded variable, by transforming the key code directly 2020-08-05 10:51:02 +02:00
Benno Schulenberg cc6d1d59a6 tweaks: optimize for byte-range characters, and shorten some comments 2020-08-05 10:12:03 +02:00
Benno Schulenberg f80ce71d13 tweaks: adjust the indentation after the previous change 2020-08-05 10:09:49 +02:00
Benno Schulenberg 2bbbd85852 tweaks: stop using a 'switch' when there are just three possibilities 2020-08-05 10:08:51 +02:00
Benno Schulenberg 54238a5c46 tweaks: reshuffle the zeroing of a counter, to allow some direct returns 2020-08-05 10:06:43 +02:00
Benno Schulenberg 8b2114a25f rcfile: allow to bind M-[ (even though it is an escape-sequence starter)
The user had better avoid using the keystroke in a macro, but
when typing directly at a responsive machine there is no problem,
M-[ is a perfectly valid and recognizable keystroke.

This fulfills https://savannah.gnu.org/bugs/?58820.
2020-08-04 17:28:16 +02:00
Benno Schulenberg 65da6341ba tweaks: avoid a maybe-uninitialized-variable warning from gcc 2020-08-04 17:08:02 +02:00
Benno Schulenberg c8a87b4d2a softwrap: initialize the 'extrarows' value for the magic line correctly
The make_new_node() function initializes 'extrarows' to a bad value
on purpose, to catch cases like this one where it doesn't get updated
properly.

This fixes https://savannah.gnu.org/bugs/?58890.
Reported-by: Jerry Kindall <kindall@gmail.com>

Bug existed since version 5.0, since the indicator was introduced.
2020-08-04 09:40:25 +02:00
Benno Schulenberg 551a971e16 tweaks: reshuffle four lines, for esthetics 2020-08-03 11:36:35 +02:00
Benno Schulenberg c2b6eb01cd feedback: use three dots to indicate processing, like everywhere else
For all occurrences, run:  grep '\.\.\."))' src/*.c
2020-08-03 11:33:28 +02:00
Benno Schulenberg e9e26934ea speller: give startup feedback (relevant when running on a Linux console)
This fixes https://savannah.gnu.org/bugs/?58856.

Bug existed since version 4.8, commit 8b2f7bd5.
2020-08-03 11:21:19 +02:00
Benno Schulenberg 71c0cde5ce anchor: show an anchor also when the line is horizontally scrolled
This fixes https://savannah.gnu.org/bugs/?58884.

Bug existed since version 5.0, since anchors were introduced.
2020-08-03 10:02:09 +02:00
Benno Schulenberg 18a4658d4f anchor: in a UTF-8 locale, show an anchor as a diamond, for visibility 2020-08-03 09:43:55 +02:00
Benno Schulenberg 6fa81ca5b8 formatter: force the mark off, to not crash by accessing empty cutbuffer
More generally, after invoking the formatter, the entire buffer should
be cut (to be replaced with the reformatted text) and not just the part
before the mark, because then everything after it would be duplicated.

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

Bug existed since version 4.9, commit 19517fc5.
2020-08-02 19:29:31 +02:00
Michalis Kokologiannakis 4940b02ae0 build: avoid compilation warnings by using memcpy() instead of strncpy()
When compiling with GCC 10.1.0 and -O2 -Wall, the strncpy() call
in measured_copy() produced two stringop-truncation warnings.

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

Signed-off-by: Michalis Kokologiannakis <michalis@mpi-sws.org>
2020-08-02 16:47:05 +02:00
Benno Schulenberg 7942dab014 tweaks: make a misplaced call of statusline() more obvious by crashing
Also, reshuffle the lines, to take advantage of an other #ifndef.
2020-08-02 14:50:50 +02:00
Benno Schulenberg 312bcebf44 files: do not try writing to the status bar while not in curses mode
Between an endwin() and a doupdate() there should be no calls of
statusline() or statusbar() -- these two functions may be called
only when in curses mode.

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

Bug existed since version 4.3, commit 57390cff.
2020-08-02 10:29:29 +02:00
Benno Schulenberg 844f95e6df speller: give proper feedback when the user tries to check emptiness
(The wording is general, because it should cover also the formatter.)

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

Bug existed since version 4.6, commit d2fb371f.
2020-08-01 20:57:23 +02:00
Benno Schulenberg 67d22f4cce tweaks: simplify two functions, as they now return always NULL 2020-08-01 19:00:07 +02:00
Benno Schulenberg 59bbc0b858 tweaks: print error message directly instead of passing it to the caller
This will allow a simplification in the next commit.
2020-08-01 11:50:55 +02:00
Benno Schulenberg 731fd935ff feedback: add the reason to the error message when forking fails
This makes all the "Could not fork" messages the same again
after the change in commit 3eff34b0 from yesterday.
2020-08-01 11:34:23 +02:00
Benno Schulenberg 0e1f7fe2ef tweaks: normalize the indentation, and regroup two lines 2020-07-31 20:39:28 +02:00
Benno Schulenberg 3eff34b075 speller: re-enter curses mode before trying to report an error
If forking fails, we must first return to curses mode before we can show
an error message on the status bar.  (This additionally requires storing
the error number, because doupdate() apparently sets it to zero.)

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

Bug existed since version 4.8, commit 61197563.
2020-07-31 20:28:10 +02:00
Benno Schulenberg 40b03162c3 bindings: make <Alt+Backspace> delete a word backwards, like in Bash
It jars a bit that it is <Ctrl+Delete> that deletes a word rightward
and <Alt+Backspace> that deletes a word leftward.  But it's good to
also have a two-key keystroke bound by default to 'chopwordleft',
and not just the three-key <Ctrl+Shift+Delete>.

This fulfills https://savannah.gnu.org/bugs/?58709.
Requested-by: Axel Scheepers <axel.scheepers76+gnu@gmail.com>
2020-07-31 18:52:51 +02:00
Benno Schulenberg 34f4ceb77e help: list again the keystroke for toggling the help lines (M-X)
This fixes https://savannah.gnu.org/bugs/?58855.

Bug existed since version 5.0, commit d8249917.
2020-07-30 10:23:35 +02:00
Michalis Kokologiannakis d0ad1e42d9 files: ignore only EPERM when fchmod() or fchown() fails
While ignoring permission errors from fchmod() and fchown() is okay
(since normal users are not always privileged to make such changes),
ignoring also more serious errors (like EIO) is not ideal.

Signed-off-by: Michalis Kokologiannakis <michalis@mpi-sws.org>
2020-07-30 09:48:12 +02:00
Benno Schulenberg 7475b4d3bf tweaks: reshuffle a few lines, and remove a few unneeded comments 2020-07-28 19:12:02 +02:00
Benno Schulenberg fd667b5191 tweaks: add four more translator hints 2020-07-27 10:33:42 +02:00
Benno Schulenberg bccb0ea0bb tweaks: handle two similar things in the same way 2020-07-26 11:51:34 +02:00
Benno Schulenberg 6ca22b80ef tweaks: elide a redundant intermediate function
It hasn't been used elsewhere since commit 7f203100 from two years ago.
2020-07-25 15:08:32 +02:00
Benno Schulenberg cf52f2ed62 tweaks: rename a variable, and condense a comment 2020-07-25 13:51:34 +02:00
Benno Schulenberg 294051769c tweaks: remove a superfluous check on the length of the key buffer
None of the calls of get_input() ask for more codes than those which
already were or will now have become available in the key buffer.
2020-07-25 13:42:06 +02:00
Benno Schulenberg 7157f5a3ce tabbing: properly terminate the answer when the sole match is a folder
When there is just one match when <Tab> is pressed, and this match
is a directory, then a slash is added to 'shared', overwriting the
terminating NUL character.  So, strcpy() cannot be used for copying
this 'shared' string, but strncpy() is needed, and the result needs
to be NUL terminated afterward.

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

Bug existed since commit b0f56398 from eleven days ago.
2020-07-25 13:25:48 +02:00
Benno Schulenberg 5ca4e9f5b3 tweaks: remove three unneeded while loops from two input routines
The whiles are unneeded because the result of get_input() can
never be NULL when in waiting mode -- and only when searching
for something are we NOT in waiting mode.
2020-07-25 12:11:48 +02:00
Benno Schulenberg 3e899b15c2 tweaks: reduce the indentation after the previous change 2020-07-24 17:12:31 +02:00
Benno Schulenberg a33b04ce90 tweaks: cascade the ifs properly: without increasing the indentation 2020-07-24 17:08:53 +02:00
Benno Schulenberg 36ab5d91de input: interpret an escape sequence only when it starts with "[" or "O"
This fixes https://savannah.gnu.org/bugs/?58818.

Bug existed since version 2.9.0, since macros were introduced.
2020-07-24 16:49:39 +02:00
Benno Schulenberg 8dc1b97465 tweaks: three escapes is the same as either zero escapes or one escape 2020-07-24 13:38:44 +02:00
Benno Schulenberg 350115242d bindings: stop supporting <Esc> <Esc> <numeric slash> without NumLock
<Ctrl+numeric slash> does not invoke Go To Line, so it is fitting
that <Esc> <Esc> <numeric slash> does neither.  If some user does
want the double escape plus slash to work, they can use --raw.

(Also, if someone really uses <Esc> <Esc> <numeric slash>, they
probably also type the desired line number on the numeric keypad,
and for that to work they needed to have NumLock engaged, and in
that case the double escape plus slash will work fine.)

(Getting rid of this numeric-slash support makes the three-escapes
case very similar to the one-escape case, allowing the first to be
folded into the latter in the next commit.)
2020-07-24 13:16:41 +02:00
Benno Schulenberg 7bf413db76 tweaks: rename two parameters, away from an abbreviation 2020-07-23 09:56:38 +02:00
Benno Schulenberg aafda2358f tweaks: rename two variables, away from abbreviations 2020-07-23 09:44:14 +02:00
Benno Schulenberg 6b9084ad09 tweaks: reshuffle a few lines, to elide an 'if' from the most common path
And for compactness.
2020-07-22 20:32:38 +02:00
Benno Schulenberg d0501d0ebd tweaks: update a translator hint, and add another 2020-07-22 11:38:29 +02:00
Benno Schulenberg 364a1518de tweaks: reshuffle some lines, to better separate the three cases 2020-07-22 11:07:20 +02:00
Benno Schulenberg 93b2877758 tweaks: use three switches instead of cascading ifs, for brevity 2020-07-22 10:56:41 +02:00
Benno Schulenberg 832037e2ec tweaks: condense some cases to a single line, for more clarity
And return directly for codes that will not be changed any more.
2020-07-22 10:43:24 +02:00
Benno Schulenberg ad2920acd0 tweaks: handle the double escapes directly, instead of going round again
Immediately pull the available extra character from the keyboard buffer,
instead of cycling through the whole circus again.
2020-07-22 10:17:48 +02:00
Benno Schulenberg e59a0f5e77 build: replace the non-standard backslash escape "\e" with "\x1B"
Older compilers do not understand "\e".  Also, it's not in the standard
(see http://open-std.org/JTC1/SC22/WG14/www/docs/n1570.pdf, §6.4.4.4).

This addresses https://savannah.gnu.org/bugs/?58799.
Reported-by: Henry Bent <henry.r.bent@gmail.com>
2020-07-22 09:17:57 +02:00
Benno Schulenberg fd10c0eadd tweaks: rake a common statement to the end of the case
With the two situations that need to preserve the escape counter
now returning directly, the resetting of this counter can happen
at the end of each case block.
2020-07-21 14:03:18 +02:00
Benno Schulenberg 7e53fcb581 tweaks: remove two redundant conditions, and make a more direct return
The escape-parsing routine nowadays returns FOREIGN_SEQUENCE instead
of ERR when encountering an unknown sequence.  So, with the two cases
that demand ERR now handled directly, there is no need to check for
ERR any more.
2020-07-21 14:02:55 +02:00
Benno Schulenberg 8249f3560f tweaks: normalize the indentation after the previous change 2020-07-20 19:46:27 +02:00
Benno Schulenberg dd1b16cd54 tweaks: trim an ASCII case, as the function is called only for UTF-8 2020-07-20 19:37:40 +02:00
Benno Schulenberg 43b39ed04f tweaks: use knowledge of Unicode to skip the general multibyte conversion
The relevant range is so small (128 bytes) that "manual" conversion
is much faster (and a bit shorter, eliding two variables).
2020-07-20 19:31:25 +02:00
Benno Schulenberg 17a8b24fe5 tweaks: skip the conversion to multibyte for plain ASCII codes
Converting an ASCII code to "multibyte" is a no-op: it stays one byte.
2020-07-20 19:16:45 +02:00
Benno Schulenberg b9db967bc4 tweaks: reshuffle some lines, for esthetics
There is no need to reset the digit counter (because this counter
matters only when the escape counter equals two) -- resetting the
escape counter is enough.
2020-07-20 19:06:16 +02:00
Benno Schulenberg 2a5d129738 tweaks: rename a variable, and normalize the indentation 2020-07-20 18:25:19 +02:00
Benno Schulenberg 6980cfbf70 tweaks: change a 'switch' to 'if', to elide a dummy 'return' 2020-07-20 18:21:43 +02:00
Benno Schulenberg a0d2e63c8e tweaks: improve four comments 2020-07-20 17:15:06 +02:00
Benno Schulenberg 57c52de99a tweaks: rename a function, and move it to before the one that calls it 2020-07-20 17:04:48 +02:00
Benno Schulenberg 9067f7a0c7 tweaks: elide a variable, by returning the result directly 2020-07-20 16:54:22 +02:00
Benno Schulenberg e4fa0b54a2 tweaks: remove two superfluous assignments
The digit counter will be reset to zero the next time when <Esc>
is pressed, and the byte holder gets re-initialized when the next
first digit is pressed.  And the escape counter is reset to zero
after returning from a result-giving call of get_byte_kbinput().
2020-07-20 16:28:36 +02:00
Benno Schulenberg b41405233f tweaks: remove some superfluous conditions
When get_byte_kbinput() is called, it has already been determined that
the keyboard input is a digit from zero to nine (or from zero to two
for the first digit), so there is no need to check this again.
2020-07-20 12:40:26 +02:00
Benno Schulenberg 88561506c9 tweaks: improve two comments, and reshuffle some lines for conciseness 2020-07-20 11:47:10 +02:00
Benno Schulenberg a08ca026f0 input: reset the counters when a three-digit sequence is not completed
When <Esc><Esc> is followed by digit 0 or 1 or 2 but then NOT two more
digits follow, then both the escape counter and the digit counter should
start afresh when a new ESC code arrives.

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

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

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

Bug existed since commit 009fb2fa from two days ago.
2020-06-29 11:09:12 +02:00
Benno Schulenberg 712f68c697 options: add -O/--bookstyle to make leading whitespace mean new paragraph
Before version 2.9.8, nano would consider any line that started with
leading whitespace as the beginning of a new paragraph, and would thus
be unable to justify an indented piece of text (unless autoindent was
switched on).  I thought that this was too limiting and changed the
way nano detects and parses paragraphs.  It works fine in texts where
paragraphs occupy multiple lines, but breaks down for paragraphs of
a single line: nano merges those with adjoining lines.

Now, when -O or --bookstyle or 'set bookstyle' is used, nano will again
consider a line that begins with whitespace as the start of a paragraph
-- when 'autoindent' is OFF.

This addresses https://savannah.gnu.org/bugs/?57402.
Indirectly-reported-by: Sébastien Desreux <seb@h-k.fr>
Also-reported-by: Bill Kendrick <nbs@sonic.net>
2020-06-27 11:12:21 +02:00
Benno Schulenberg 331bd7662e tweaks: delete a now-unused function 2020-06-27 10:23:03 +02:00
Benno Schulenberg 009fb2fae6 tweaks: make three hard-bindings of special keys more efficiently
Instead of calling a function that tries to find the relevant operation,
just add three hidden hard-bindings at the end of the shortcuts list.

They are hidden because we don't want them to show up in the help text,
because we don't know what to call them (as a Cancel and Suspend key
don't exist on normal keyboards) or naming the key would be confusing
(Sh-Ins is grabbed by the desktop manager and doesn't reach nano).
2020-06-27 10:20:45 +02:00
Benno Schulenberg 7fa6e95ce1 tweaks: avoid a function call when a simple boolean will do 2020-06-26 19:44:19 +02:00
Benno Schulenberg 8bce70e038 tweaks: rename a variable, to better describe what it holds 2020-06-26 19:27:28 +02:00
Benno Schulenberg b55153524a tweask: adjust the indentation after the previous change
Also improve a comment.
2020-06-26 19:18:05 +02:00
Benno Schulenberg a9ce488cc5 tweaks: drop a superfluous check for a non-zero length
The get_history_completion() function is called in just one place,
and gets called only when the length parameter is larger than zero.

Also, improve a few comments.
2020-06-26 19:07:47 +02:00
Benno Schulenberg 8061a981b1 tweaks: correct two spelling mistakes [codespell] 2020-06-26 11:27:07 +02:00
Benno Schulenberg e64c950896 tweaks: close opened files when something goes wrong [coverity] 2020-06-26 10:24:52 +02:00
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 18659f3485 build: fix the Makefile after two header files were renamed
Reported-by: Kamil Dudka <kdudka@redhat.com>
2020-06-25 21:11:26 +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 7f77cad1b4 tweaks: condense the code a little further, by grouping things better 2020-06-25 10:03:56 +02:00
Benno Schulenberg e7511abd86 tweaks: avoid checking a variable three times for each pass in the loop 2020-06-25 09:57:41 +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 096e36279f build: fix compilation for --enable-tiny --enable-color --enable-nanorc 2020-06-22 14:03:48 +02:00
Benno Schulenberg f601eeda57 build: fix compilation when configured with --disable-color 2020-06-22 12:49:04 +02:00
Benno Schulenberg 2430c5b230 build: allow compilation to succeed on curses without italic support
The OpenBSD system that I have access to still uses ncurses-5.7,
and support for A_ITALIC appeared in version 6.0.
2020-06-22 11:19:05 +02:00
Benno Schulenberg 9b8930cc13 tweaks: adjust the conditional help-item pairing for absence of speller
The Spell Checker is no longer among the first twelve items of the
main menu, so the conditional placing of the Go To Line item should
no longer depend on it.
2020-06-22 09:09:05 +02:00
Benno Schulenberg 0f0b620c65 build: fix compilation when configured with --disable-speller
Move two functions that are used by the formatter too
to between the proper #ifdef.

Problem existed since commit 8089f5ad from a month ago.
2020-06-22 08:42:49 +02:00
Benno Schulenberg a7aab18dfe colors: move purple one step away from magenta, and use a darker mauve 2020-06-21 19:21:07 +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
Pedro Victor de Brito Cordeiro 84b187f627 tweaks: make parameter names in prototypes match those in the definitions
Also, remove three prototypes of functions that no longer exist.

Signed-off-by: Pedro Victor de Brito Cordeiro <pedrocga1.opensource@gmail.com>
2020-06-20 11:25:09 +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 d8249917c3 bindings: allow toggling the help lines at several prompts and in browser
Now the help lines can be toggled not only while editing, but also at
the Read (^R), Write (^O), Execute (^T), Search (^W), Replace (M-R),
Goto (^/), and Yesno prompts, and also in the file browser and when
searching for a file name.  The help lines cannot be toggled in the
help viewer, nor when searching in a help text, nor in the linter,
as these three things force the help lines to be on.

Furthermore, the 'nohelp' function can be rebound in all relevant
menus (default binding: M-X).

This fulfills https://savannah.gnu.org/bugs/?58471.
2020-06-18 15:36:10 +02:00
Benno Schulenberg bafcc19b7a tweaks: rename a symbol, from a phrase to a noun 2020-06-18 15:31:06 +02:00
Benno Schulenberg 61c94c2f81 rcfile: report the first bad color element, not a later one that is okay
This fixes https://savannah.gnu.org/bugs/?58605.

Bug existed since commit c275c515 from several days ago.
2020-06-18 15:31:06 +02:00
Benno Schulenberg 69a90dd7af tweaks: elide two redundant calls of strchr() 2020-06-18 15:31:06 +02:00
Benno Schulenberg fae2eeadce rcfile: introduce the modifier 'italic', for slanted text
The modifier has to come before the foreground color name, separated
by a comma, and after 'bold,' (when present).  This has no effect on
terminals that are incapable of cursive text, like the Linux console.

This fulfills https://savannah.gnu.org/bugs/?56525.
2020-06-18 15:31:06 +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
Benno Schulenberg f6e7b7fbc5 rcfile: introduce nine new named colors, from "pink" to "latte"
Names give a rough idea of what the color will look like, whereas
numerical indexes would not do this at all.

Nine extra colors seems enough.  If there were more, no one would be
able to say for sure which is which when two similar colors are used
several rows apart.

This partially fulfills https://savannah.gnu.org/bugs/?56445.
2020-06-17 11:18:22 +02:00
Benno Schulenberg 96a5aa9e90 syntax: nanorc: colorize 'bright' anyway, so existing syntaxes look okay
After a year or so, when people have had time to convert their syntaxes
to use 'bold' and/or 'light' instead of 'bright', we can drop this
colorizing, and still later stop recognizing 'bright' altogether.
2020-06-16 17:33:49 +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 7ff82aa5e2 rcfile: add bindable function 'execute', for access to "Execute Command"
(This should have been added three weeks ago when ^T was rebound.)
2020-06-15 14:27:49 +02:00
Benno Schulenberg fd28e5f36c build: fix compilation when configured with --enable-tiny 2020-06-15 12:38:16 +02:00
Benno Schulenberg 7f40eeab0a tweaks: call the spotlighting routines only for the relevant line
Otherwise the affected piece of text gets drawn and spotlighted as
many times as there are rows in the edit window.
2020-06-15 09:45:01 +02:00
Benno Schulenberg d67faa2bb5 tweaks: remove a superfluous global variable
There were no calls of statusbar() or statusline() before curses mode
was entered.  But since the previous commit curses mode is entered
even earlier, so...
2020-06-14 13:09:23 +02:00
Benno Schulenberg 24cdf78a93 startup: enter curses mode before reading the nanorc files
This way the COLORS variable will be set when the nanorc files specify
interface colors, so that "light" will work for them.
2020-06-14 12:57:46 +02:00
Benno Schulenberg d01dbbb284 rcfile: do not complain when "bright" is used with a background color
A background color *can* be bright (in the sense of lighter, shinier).
It's just that the background cannot be bold.  Only the typeface used
on the foreground can be bold (if the terminal supports it).  So, let
"bright", when used with a background color, simply mean "light".
2020-06-14 12:05:18 +02:00
Benno Schulenberg c275c5158e rcfile: introduce the modifier "bold", for specifying bolding separately
This makes it possible to avoid the misnamed prefix "bright".  It is
misnamed because (on current terminal emulators, when the brightening
of bold is switched off) it just makes the typeface bold, not the color
brighter.  The prefix "light" will now only make the color brigther,
and the modifier "bold" will just make the typeface bold (on terminal
emulators, when the brightening of bold is switched off).

On a Linux console, which is not capable of bolding the typeface,
"bold" will brighten the color.

This fully fulfills https://savannah.gnu.org/bugs/?58503.
2020-06-14 11:54:18 +02:00
Benno Schulenberg adf7f33ea8 rcfile: allow specifying a bright background color (with prefix "light")
If the terminal is capable of more than eight colors, specifying
indexes 8 to 15 works fine for getting a light background color.
2020-06-14 11:51:00 +02:00
Benno Schulenberg 4d10f583e4 rcfile: accept prefix "light" to make a color brighter without bolding it
The prefix "bright" will continue to make the color brighter AND/OR
make the typeface bold (depending on how the terminal is configured
and on its capabilities), but the prefix "light" will just make the
color brighter (if the terminal can do that).

The prefix "bright" continues to do the same as what it did before,
to not change the appearance of user-defined syntaxes.  And having
an option to change the meaning of "bright"... would be confusing.

This partially fulfills https://savannah.gnu.org/bugs/?58503.
2020-06-14 11:45:45 +02:00
Benno Schulenberg 926bc6751e startup: check stdout instead of stdin when probing for a Linux console
This way we don't have to probe twice, and the result is accurate also
when nano is reading data from standard input.  Standard output should
always be connected to a terminal, as nano is not meant to operate
without a screen.
2020-06-14 10:52:42 +02:00
Benno Schulenberg 1c8c02f63b tweaks: move a function, to be in the order in which they are called
In addition, rename two variables and adjust the type of one of them.
2020-06-13 17:16:33 +02:00
Benno Schulenberg 43a1756783 tweaks: call init_pair() just once for each pair number 2020-06-13 14:17:45 +02:00
Benno Schulenberg 34528db096 tweaks: remove unneeded variables after the previous change 2020-06-13 14:17:45 +02:00
Benno Schulenberg c79b52da1d tweaks: do the conversion of -1 to a specific color just once
Do the conversion (when needed) when the syntax is loaded,
not for each buffer switch.
2020-06-13 14:17:45 +02:00
Benno Schulenberg 454dc6e1ec tweaks: elide two ifs for the most likely case, when defaults are allowed 2020-06-13 14:17:45 +02:00