Commit Graph

5858 Commits (0c249de9e534d3fc092171045696101f41d3bb64)

Author SHA1 Message Date
Benno Schulenberg 5c07a747bb tweaks: adjust some whitespace, reshuffle two ifs, and remove two braces 2020-02-17 11:29:13 +01:00
Benno Schulenberg a9f7277b1b tweaks: remove a now-unused helper function 2020-02-16 12:33:29 +01:00
Benno Schulenberg d13b6d6896 tweaks: elide an intermediate copy of an added character
In theory this would allow injecting more than one character at a time
into the edit buffer.  But the creation and updating of an undo item for
the addition or the deletion of a character are a bit strange.  For all
other operations and add_undo() is called before the operation, and an
update_undo() afterward.  But for an ADD, the add_undo() is called after
the operation, and for a DEL/BACK, the update_undo() is called before
the operation.  There is some logic to that, but things would be easier
to understand if all operations were handled the same: an add_undo()
beforehand (when needed), and an update_undo() afterward.
2020-02-16 12:32:10 +01:00
Benno Schulenberg 819066c5d5 tweaks: extend the undo data for deleting and backspacing more directly
To get rid of an intermediate copy of the deleted character.
2020-02-16 11:06:45 +01:00
Benno Schulenberg a65982bffb tweaks: relocate eleven functions to before they are called 2020-02-14 19:10:21 +01:00
Benno Schulenberg 6b8f446b52 tweaks: rename a constant, and rename and relocate a function 2020-02-14 19:00:16 +01:00
Benno Schulenberg 2b97d6563d tweaks: correct a typo, improve two indentations, and rewrap a line 2020-02-14 16:03:15 +01:00
Benno Schulenberg a0506a15ee undo: when undoing a paste or an insertion, remove an added magic line
When something is pasted or inserted onto the final, empty line of a
buffer, an automatic new magic line is created after it, when needed.
When this paste or insertion is undone, the added magic line should
also be removed again.

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

Bug existed since the undo capabilities were added,
since before version 2.3.0.
2020-02-14 15:27:06 +01:00
Benno Schulenberg 68ca1732b8 prompt: insert a burst of bytes in one go instead of characterwise
There is no need to count characters, so just insert the whole batch
of bytes at once.
2020-02-13 14:42:47 +01:00
Benno Schulenberg 75f4309c1f tweaks: rename four parameters, to be more distinct and telling 2020-02-13 14:22:40 +01:00
Benno Schulenberg 78767b583d tweaks: elide an intermediate copy of a character during injection, twice 2020-02-13 14:22:23 +01:00
Benno Schulenberg a0703ab62d tweaks: mesh two bits of code together 2020-02-13 13:46:31 +01:00
Benno Schulenberg 9d232cd8af input: keep a multibyte character together during verbatim entry
When the user (unexpectedly) types a multibyte character after M-V,
put its first byte back into the keyboard buffer, so that the next
call of process_a_keystroke() will retrieve the byte sequence as a
whole, and will inject them as one character into the edit buffer.

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

Bug existed since version 2.6.3, commit 08c51cfd.
2020-02-13 13:15:46 +01:00
Benno Schulenberg 03d296eb35 input: allocate sufficient bytes for entering a Unicode codepoint
This fixes https://savannah.gnu.org/bugs/?57803.

Bug existed since commit 2b27df67 from yesterday.
2020-02-13 11:57:35 +01:00
Benno Schulenberg 2b27df6733 tweaks: convert integers to bytes in one place instead of two 2020-02-12 17:16:27 +01:00
Benno Schulenberg f012d54a1d tweaks: make prompt-bar input more similar to edit-buffer input
In preparation for the next commit.
2020-02-12 16:59:48 +01:00
Benno Schulenberg 61dc2cab0b tweaks: rename two variables, and frob four comments 2020-02-12 16:20:20 +01:00
Benno Schulenberg a2313f499c tweaks: move a function to after the one that it calls 2020-02-12 16:06:57 +01:00
Benno Schulenberg cbda89766f tweaks: rename a parameter and a variable, and reword two comments
Also reshuffle a declaration.
2020-02-12 16:05:18 +01:00
Benno Schulenberg 070ccf4a5b tweaks: rename two variables, and reshuffle a few things 2020-02-12 14:28:07 +01:00
Benno Schulenberg 8e4b68917c tweaks: rename a function, and condense a few comments 2020-02-12 14:15:35 +01:00
Benno Schulenberg 0d0d011579 tweaks: combine two ifs into one 2020-02-12 12:09:12 +01:00
Benno Schulenberg 71daa1ef6b tweaks: update several comments after the previous changes 2020-02-12 12:05:52 +01:00
Benno Schulenberg 0ed62e84de tweaks: weld two fragments together, twice, by eliding an unneeded 'if'
The get_kbinput() routine will never return ERR, so there is no need
to check for that.
2020-02-12 11:46:15 +01:00
Benno Schulenberg 0a31a9aa38 tweaks: make two conditions more direct, and thus elide two functions
Using straightforward comparisons is clearer and faster and shorter.

Again, note that this does not filter out 0x7F (DEL).  But that is
okay, as that code will never be returned from get_kbinput().
2020-02-12 11:38:33 +01:00
Benno Schulenberg 6747142cd7 tweaks: remove some redundant filtering, and thus elide a parameter
The few calls of the injection routines that had 'filtering' set to
TRUE have already filtered out ASCII control codes earlier on.  And
in the case of injecting a completion, this completion only contains
word-forming characters -- and if the user somehow added a control
code to the word-forming characters, then nano should NOT filter it
out, so in fact that setting of 'filtering' to TRUE was mistaken.

Note that this filtering did not filter out 0x7F (DEL).  But that is
fine: it should not occur in the input stream at that point anyway,
as it gets translated to either KEY_DC or KEY_BACKSPACE earlier in
the keyboard parsing routines.
2020-02-12 11:12:34 +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 cbeea859c2 shutdown: don't refer to an open file when there aren't any
This fixes https://savannah.gnu.org/bugs/?57780.

Bug existed since commit b63c90bf from yesterday.
2020-02-10 09:28:37 +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 cc2b4f712c tweaks: unabbreviate the name of a variable 2020-02-09 12:02:37 +01:00
Benno Schulenberg 98f038ad96 rcfile: allow alternate line endings in nanorc files
When copy-pasting has resulted in a nanorc file with DOS line endings
(CR+LF), then silently ignore the carriage return, to avoid printing
an error message that partly overwrites itself.

This fulfills https://savannah.gnu.org/bugs/?57756.
Requested-by: Matthias Aßhauer <mha1993@live.de>
2020-02-09 11:55:07 +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 51371e0ca5 tweaks: exclude two unneeded fragments of code from the tiny version 2020-02-05 11:41:31 +01:00
Benno Schulenberg 3bd66b78c1 tweaks: don't bother including Haiku escape sequences in the tiny version 2020-02-05 11:31:03 +01:00
Benno Schulenberg 5ea6054a75 tweaks: use a simple subtraction instead of a function call 2020-02-05 11:29:36 +01:00
Benno Schulenberg 04738996fc tweaks: rename two parameters, to be more general and to sound shorter 2020-02-04 17:32:05 +01:00
Benno Schulenberg 07a9477213 tweaks: rename five variables, away from a single letter 2020-02-04 17:20:37 +01:00
Benno Schulenberg a5b48f9a0d build: fix compilation for --enable-{tiny,help,multibuffer} 2020-02-04 12:58:57 +01:00
Benno Schulenberg da68ee19e7 tweaks: reorder two symbols 2020-02-04 11:41:05 +01:00
Benno Schulenberg 8b2f7bd5a2 tweaks: drop a message that will never be seen
Since the previous commit, nano exits from curses mode soon after
this message is printed, so that the user does not have any time
to read it or even see it.
2020-02-03 19:59:58 +01:00
Benno Schulenberg 6119756347 speller: avoid messing up the screen when an unknown locale is used
When invoking the "internal" speller, leave curses mode while the three
programs in the pipe array are executing, to prevent 'hunspell' from
writing a long error message to the end of the status bar, making the
screen scroll, and thus messing it up.  Now the error message gets
printed to the screen that nano was started up from, and will thus be
visible when the user exits from nano.  (At least: it will be so on a
terminal emulator -- on a VT, nothing will be seen.)

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

Bug existed since version 4.6, commit 4d77e0ad.
2020-02-03 13:50:33 +01:00
Benno Schulenberg 06c80b6ccd tweaks: rearrange a few global variables, to group things better 2020-02-02 17:05:06 +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 7c57806c6f rcfile: require "bright", "start=", and "end=" to be in lowercase too 2020-01-31 16:11:38 +01:00
Benno Schulenberg a2f8703df5 tweaks: tumble three conditions, for consistency in comparisons 2020-01-31 16:05:51 +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 25b0bf0ae8 tweaks: correct a couple of comments about escape sequences 2020-01-29 18:48:03 +01:00
Benno Schulenberg f6b6bc47d6 tweaks: remove a redundant call, as there is nothing to free there
At that point, 'u->cutbuffer' will always be NULL, either from the
original creation of the INSERT undo item, or by having been freed
and set to NULL by do_redo().
2020-01-29 12:33:55 +01:00
Benno Schulenberg a692b01c04 tweaks: reshuffle two lines, to do the linking first, then the content 2020-01-29 12:33:30 +01:00
Benno Schulenberg a197ccf12d tweaks: move another function, to group the deleting ones together 2020-01-29 12:16:09 +01:00
Benno Schulenberg 67e5913edf tweaks: move another function to before the one that calls it 2020-01-29 10:54:30 +01:00
Benno Schulenberg e864107046 tweaks: move a function to right before the one that calls it 2020-01-29 10:53:05 +01:00
Benno Schulenberg 7984ea4eb6 tweaks: remove two superfluous assignments, and rename a variable
The 'prev' and 'next' links get assigned to immediately after the
call of copy_node().  And anyway, it does not make sense to link
a copied node to the predecessor and successor of its original.

Also slightly regroup some lines.
2020-01-29 10:47:09 +01:00
Benno Schulenberg f38bd5030d tweaks: add a little change that was overlooked in the previous commit
Option --showcursor applies also to the help viewer, which means that
it can do something useful in restricted mode too.
2020-01-28 12:00:05 +01:00
Benno Schulenberg a2fea9928d build: exclude option '-g' when configured without browser and help 2020-01-28 10:33:56 +01:00
Benno Schulenberg c64f506933 tweaks: reshuffle some declarations, and expand a few variable names 2020-01-28 10:21:34 +01:00
Benno Schulenberg 445cd2a6c5 usage: improve the description of --restricted and --quickblank
Give a little more information than just a rehash of the long option.
2020-01-28 10:04:01 +01:00
Benno Schulenberg fb073ec88d display: ensure the guiding stripe can be shown when not softwrapping
This fixes https://savannah.gnu.org/bugs/?57683.

Bug existed since commit 0b54785f from yesterday.
2020-01-28 09:35:45 +01:00
Benno Schulenberg c09e96f294 suspension: put in an extra terminal-initialization call for Slang
Also, the disabling of the keyboard interrupt (SIGINT) must happen
after that initialization call, otherwise ^C will still do nothing
after returning from suspension (when nano is built against Slang).

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

Bug existed since version 2.2.0, commit daaf468c.
2020-01-27 16:46:01 +01:00
Benno Schulenberg 0b54785fe5 softwrap: suppress the guiding stripe on unaffected chunks
When the guiding stripe (when softwrapping) will be shown in
a later chunk, it shouldn't be shown in the current chunk.

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

Bug existed since --guidestripe was introduced, in version 4.0.
2020-01-27 15:46:57 +01:00
Benno Schulenberg 8835c0d486 tweaks: reduce the scope of a variable, and reshuffle a declaration 2020-01-27 13:36:28 +01:00
Benno Schulenberg 0442eef95b tweaks: elide a somewhat costly call by remembering some state
When having prepared a line for displaying on the screen, nano already
determind whether the line extends beyond the right edge or not.  There
is no need to calculate again the full width of the current line later.
Just let display_string() make a note whether the piece of text that
it converted to displayable form still has more text coming after it,
and use this note when it's time to show the ">" continuation sign.

Using a static variable is ugly, but passing it along as a parameter
would be even uglier, because for all other calls of display_string()
the parameter would be just a useless burden.
2020-01-27 13:23:56 +01:00
Benno Schulenberg 6ae11071b3 tweaks: add an error message for something that should never occur 2020-01-27 12:06:27 +01:00
Benno Schulenberg 3c177c1bb9 tweaks: elide a variable, and rename its sister 2020-01-26 19:23:37 +01:00
Benno Schulenberg e0213b1a41 tweaks: drop a pointless suffix from two function names 2020-01-26 16:36:23 +01:00
Benno Schulenberg e70ff87c86 tweaks: move another function to after the one that it calls
(The diff is stupid.  It should just remove 440 contiguous lines, and
add back 440 contiguous lines further down.  Instead it tries to find
similarities between what is moved and what remains, and makes a mess.
You have to use --patience or --minimal to get the better diff.)
2020-01-26 16:21:21 +01:00
Benno Schulenberg db10a421dc tweaks: move a function to after the one that it calls 2020-01-26 16:21:21 +01:00
Benno Schulenberg 5725336149 tweaks: slightly condense a function by conflating case 2020-01-26 16:21:21 +01:00
Benno Schulenberg b8ba27bbc0 tweaks: fuse two nearly identical functions into a single one
The plain keys that are valid in the help viewer are a perfect subset of
those that are valid in the file browser, so just use the same function
to do the interpretation for both.  It is not a problem that it returns
function pointers for some keystrokes that have no meaning in the help
viewer, because both NULL and an unhandled function pointer result in
the "Unbound key" message.
2020-01-26 16:20:37 +01:00
Benno Schulenberg e3f6638a76 prompt: for a Yes-No-All, accept the first character of an external paste
Allow the user to paste in the character for Yes, No, or All.  If the
paste contains more than one character, ignore all but the first.

This fully fixes https://savannah.gnu.org/bugs/?57623.
Reported-by: Brand Huntsman <alpha@qzx.com>
2020-01-26 12:22:49 +01:00
Benno Schulenberg f8553f6d3a feedback: restore a message that can occur in help viewer or file browser
It was mistakenly removed in commit ea874112, two days ago.
2020-01-24 19:45:07 +01:00
Benno Schulenberg a78da18aa4 input: ignore bracketed pastes in help viewer and file browser
This partially fixes https://savannah.gnu.org/bugs/?57623.
Reported-by: Brand Huntsman <alpha@qzx.com>
2020-01-24 19:20:21 +01:00
Benno Schulenberg d764d7094f tweaks: don't enable bracketed pasting when not handling such pastes
The tiny version is oblivious of bracketed pastes, as it serves no
purpose: in the tiny version there is no auto-indent nor undo nor
tabs-to-spaces conversion.
2020-01-24 17:21:47 +01:00
Benno Schulenberg fa686457c2 input: ignore modifiers on a VT while executing a macro or a string bind
Any modifier keys that are needed to start the execution of a macro
(or of a string bind) should not affect the interpretation of the
keystrokes that are contained within the macro or the string.

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

Bug existed since macros were introduced, in version 2.9.0.
2020-01-23 12:39:23 +01:00
Benno Schulenberg a65f0ec80c tweaks: elide a function that has become too small for its two calls 2020-01-23 12:06:32 +01:00
Benno Schulenberg e01e1d8ab5 tweaks: remove the now-unused meta flag from 'keystruct' 2020-01-23 12:06:32 +01:00
Benno Schulenberg 58597b6d9b tweaks: judge from the key code itself whether it is a Meta keystroke 2020-01-23 12:06:32 +01:00
Benno Schulenberg 196e913681 tweaks: elide three checks of a shortcut's meta flag
A control code cannot be a Meta keystroke, and a plain printable
character as key code necessarily means it is a Meta keystroke.
So, comparing just the key code is enough.
2020-01-23 12:06:32 +01:00
Benno Schulenberg 620553b795 input: filter out Ctrl+Meta keystrokes, as they can never be shortcuts
Note that DEL_CODE (0x7F) will never occur as input key code, because
it gets translated to KEY_DC in the input routine (or to KEY_BACKSPACE
when --rebinddelete is in effect).
2020-01-23 12:06:32 +01:00
Benno Schulenberg 6df50790cd input: prevent unintentional marking of text for shifted Meta keystrokes
The Shift detection on a Linux console was meant to affect only the
dedicated cursor-movement keys, not <Shift+Meta+character>.

This fixes https://savannah.gnu.org/bugs/?57598.
Indirectly-reported-by: Brand Huntsman <alpha@qzx.com>
2020-01-23 11:22:23 +01:00
Benno Schulenberg 1cd5005d06 bindings: allow to bind shifted Meta+letter combinations with Sh-M-X
As long as the user does not define any Sh-M-X bindings in their nanorc,
<Shift> and <CapsLock> will not have any effect on <Alt+letter> combos.
But as soon as any Sh-M-X combination is bound, <Shift+Alt+letter> will
be seen as different from the unshifted keystroke.

This kind of fulfills https://savannah.gnu.org/bugs/?54659.
Requested-by: Peter Passchier <peter@passchier.net>
2020-01-23 11:11:34 +01:00
Benno Schulenberg f7a3b996fa bindings: force the first letter in a key name to uppercase
So that converting it to a key code remains easy.

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

Bug existed since commit 077d307b from yesterday.
2020-01-22 19:05:23 +01:00
Benno Schulenberg ea874112d8 tweaks: remove a feedback message that is never shown
A plain printable ASCII character (from 0x20 to 0x7E) can never be
a shortcut, so it also can never get reported as being unbound.
2020-01-22 15:41:04 +01:00
Benno Schulenberg 25d397e7b3 feedback: report Ctrl+Alt keystrokes as unbindable
When reporting them as simply unbound, the user might think that M-^X
keystrokes might somehow become bound.
2020-01-22 15:10:41 +01:00
Benno Schulenberg 5111b20bf5 build: exclude bracketed pasting from the tiny version 2020-01-22 12:58:48 +01:00
Benno Schulenberg f571d6ba36 tweaks: gather four calls that are always done together into a function 2020-01-22 12:49:00 +01:00
Benno Schulenberg 0e21baf611 tweaks: reshuffle three lines, to make the grouping tighther 2020-01-21 15:47:03 +01:00
Benno Schulenberg 1e78881a70 tweaks: avoid analyzing the key string when the target key code is known
For the special keys, pass the key code directly, so that later on
keycode_from_string() does not need to be called.
2020-01-21 15:40:28 +01:00
Benno Schulenberg 077d307b30 tweaks: trim some excessive error checking and key-name frobbing
Also, it is clearer to say that "key name %s is invalid" than it is
to say that some unspecified key name is too short.
2020-01-21 12:14:07 +01:00
Benno Schulenberg 998992ddcb tweaks: condense three comments to one, and do the masking more directly 2020-01-20 19:00:44 +01:00
Benno Schulenberg 0ff9499583 tweaks: reshuffle some lines, to avoid tallying the menus when not needed 2020-01-20 17:44:41 +01:00
Benno Schulenberg eb1668ce81 tweaks: reshuffle some declarations 2020-01-20 17:44:01 +01:00
Benno Schulenberg 54b97a6f03 bindings: allow to rebind also ^`, although it is synonymous with ^Space
Since ^@ is rebindable too and also a synonym of ^Space, it makes
more sense to allow the user to specify ^` instead, as it is an
unshifted keystroke on US keyboards.

Also, color ^` as valid in a nanorc file, and color ^` and ^@ in
the help viewer.
2020-01-20 17:19:23 +01:00
Benno Schulenberg 5e48c36877 rcfile: do set the meta flag for plain <Meta+ASCII> combinations
The meta flag needs to be suppressed only for the self-defined
<Meta+arrow> key codes.

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

Bug existed since commit 5130c35b from a few hours ago.
2020-01-20 16:37:15 +01:00
Benno Schulenberg 9e3fca4021 rcfile: unbind keys by their key code instead of by their key string
Some key strings map to the same key code, so to unbind also a string's
synonyms, go through the list comparing against the key code.  It has
the additional advantage that it is faster: a plain value comparison
instead of a string comparison.

There is no need to compare also the meta flag, because plain printable
ASCII characters (from 0x20 to 0x7E) cannot be shortcuts, so when such
a character matches, it necessarily means it is a meta keystroke.

This fixes https://savannah.gnu.org/bugs/?57397.
2020-01-20 15:44:17 +01:00
Benno Schulenberg 5130c35b85 tweaks: avoid determining the key code from the key string twice
When assign_keyinfo() gets passed zero as key code, it will call
keycode_from_string() to determine the key code from the string.
So, remember the key code when keycode_from_string() gets called
the first time to avoid the second call.
2020-01-20 15:41:34 +01:00
Benno Schulenberg e01651cde1 pasting: retain the mark's position when it was set at the cursor
When the mark is set at the current cursor position, and then something
is pasted (either with ^U or from outside of nano), then this entire
pasted text should be marked -- just like when it had been typed.  So,
the mark's position should not be adjusted not only when it is located
before the cursor but also when it is at the same place as the cursor.

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

Bug existed since version 2.0.7.
2020-01-20 10:34:27 +01:00
Brand Huntsman 12cf1c9980 input: beep when invalid key is pressed at yesno prompt or in linter menu
Just like nano beeps when an unbound key is pressed at other prompts,
or in the help viewer, or in the file browser.

Signed-off-by: Brand Huntsman <alpha@qzx.com>
2020-01-19 16:37:14 +01:00
Benno Schulenberg 092711e412 tweaks: remove the now-unneeded code related to bracketed pasting
The suppression of auto-indentation, automatic hard-wrapping, and
tab-to-spaces conversion is now inherent in the way the reading-in
of a bracketed paste is handled by the previous commit: as a single
block of text.
2020-01-19 14:44:28 +01:00
Benno Schulenberg 0e6d693dc8 input: read in an external paste in one go, to allow undoing with one M-U
This makes an external paste (with mouse or <Shift+Insert>) behave
the same as an internal paste (^U), and also inherently suppresses
auto-indentation, automatic hard-wrapping, and tab conversion.

This fulfills https://savannah.gnu.org/bugs/?54950.
2020-01-19 14:44:28 +01:00
Benno Schulenberg 486d4956ff tweaks: elide an 'if', by moving the relevant code to a better place 2020-01-17 19:19:22 +01:00
Benno Schulenberg 7567a67cdd tweaks: elide a small function, as it's in fact needed just once 2020-01-17 19:19:04 +01:00
Benno Schulenberg c4939c76a5 tweaks: rename a function, to make it not contain the name of another
Also, improve the names of its two parameters,
and make the tiny version a wee bit smaller.
2020-01-17 17:28:48 +01:00
Benno Schulenberg 04e557fdaf tweaks: avoid fiddling with the keybuffer when it's not needed
Just change KEY_MOUSE directly into KEY_ENTER for a double click.
2020-01-17 17:06:17 +01:00
Benno Schulenberg 7dcc8f1d7a tweaks: adjust the indentation after the previous change
Also reshuffle some lines, and adjust the comments.
2020-01-17 16:51:21 +01:00
Benno Schulenberg 343f97b3ac new feature: allow specifying a custom nanorc file on the command line
This fulfills https://savannah.gnu.org/bugs/?57547.
Requested-by: Saagar Jha <saagar@saagarjha.com>
2020-01-17 16:51:21 +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 f47ef539db display: skip zero-width characters on a Linux console, to avoid a mess
This is a workaround for the VT not being able to handle zero-width
characters properly, displaying them mistakenly as visible characters.

This avoids https://savannah.gnu.org/bugs/?52954.

The problem has existed since forever, but has become noticeable
since the capability for line numbers was added in version 2.7.1.
2020-01-15 18:50:44 +01:00
Benno Schulenberg 2148e857e5 copyright: update the years for significantly changed files 2020-01-15 12:11:56 +01:00
Benno Schulenberg afa4c6b9fc copyright: update the years for the FSF 2020-01-15 11:42:38 +01:00
Benno Schulenberg 27127853db tweaks: exclude an unneeded fragment of code from the tiny version 2020-01-14 16:28:28 +01:00
Benno Schulenberg a81ba0215a display: exclude a bit of feedback from the tiny version 2020-01-14 11:22:28 +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 e8d20a8e4b display: clear the help lines before a briefly shown warning
This makes the message stand out more.

Also slightly shorten the duration of the pause.
2020-01-14 10:49:12 +01:00
Benno Schulenberg 6896d8df47 tweaks: reduce the scope of two constants and of four variables 2020-01-14 10:35:54 +01:00
Benno Schulenberg 8455251c35 files: revert the previous commit, as the extra warning is annoying
It also erroneously left the succeeding prompt on the screen.

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

This fixes https://savannah.gnu.org/bugs/?47975,
and fixes https://savannah.gnu.org/bugs/?53883.
2020-01-13 20:00:07 +01:00
Benno Schulenberg 4687322398 tweaks: rewrap two lines, for consistency with similar lines 2020-01-13 20:00:07 +01:00
Benno Schulenberg 99f0265d34 tweaks: condense a fragment of code 2020-01-12 12:32:20 +01:00
Benno Schulenberg 7d483987ce input: do not auto-indent when something is pasted into nano from outside
Also, do not break overlong lines and do not convert tabs to spaces,
nor interpret a <Tab> as an indent command (when the mark is on).
In other words: accept an outside paste as literally as possible.

This fulfills https://savannah.gnu.org/bugs/?40060.
Requested-by: Egmont Koblinger <egmont@gmail.com>

And fulfills https://savannah.gnu.org/bugs/?57527.
Requested-by: Sébastien Desreux <seb@h-k.fr>
Requested-by: Hans Ecke <hecke@gxt.com>

Original-idea-by: Brand Huntsman <alpha@qzx.com>
2020-01-12 11:18:51 +01:00
Brand Huntsman f705a9674b input: recognize the start and stop sequences of a bracketed paste
Also, tell the terminal to switch on bracketed-paste mode, and toggle
a boolean when the start and stop sequences of such a paste are seen.
This boolean can later be used to suppress auto-indent and such.

Signed-off-by: Brand Huntsman <alpha@qzx.com>
2020-01-12 11:18:51 +01:00
Benno Schulenberg 3233e9cfe0 tweaks: correct a comment
The maximum length was increased two weeks ago, in commit 4dcbd40c.
2020-01-12 11:18:29 +01:00
Benno Schulenberg 5a98a51173 bindings: do not show the Full-Justify keystroke when in View mode
The file may not be modified when in View mode, so it makes no sense
to prominently show the M-J keystroke in the Search menu when in that
mode, especially since the keystroke does not really belong there.

This addresses https://savannah.gnu.org/bugs/?57574.
2020-01-10 17:24:29 +01:00
Benno Schulenberg 2eaba21a4c help: increase the minimum help-text width from 24 to 32 columns
Even at 32 columns, the key descriptions are already hopelessly
fragmented.  Any width smaller than that is useless.
2020-01-09 15:10:52 +01:00
Benno Schulenberg 9a227de3e7 tweaks: recompute the wrapping point just once
Instead of for every row after the intro.
2020-01-09 14:47:48 +01:00
Benno Schulenberg 3f57200e10 help: prevent double spaces from protruding across the right edge
This fixes https://savannah.gnu.org/bugs/?57563.
2020-01-09 12:02:49 +01:00
Benno Schulenberg 1486f32d42 help: when a key description wraps, indent its wrapped part
This prevents the wrapped text from cluttering up the two key columns.

This addresses https://savannah.gnu.org/bugs/?57451.
2020-01-09 11:37:49 +01:00
Benno Schulenberg e3edce4e7b tweaks: elide a helper function, in preparation for an improvement 2020-01-09 11:02:36 +01:00
Benno Schulenberg 0e559c5bbc tweaks: initialize three more booleans straightaway, at declaration
Also improve three comments.
2020-01-09 10:37:56 +01:00
Benno Schulenberg edfbfbfd0a tweaks: initialize three booleans straightaway, when they are declared
Also improve three comments.
2020-01-08 16:55:45 +01:00
Benno Schulenberg a4eae770ce tweaks: rename a function, to be a bit more expressive 2020-01-08 16:13:04 +01:00
Benno Schulenberg 72e5c15110 tweaks: move three functions to the file where they are mainly used
The extract() and copy_from_buffer() functions are mainly used for
cutting a line or a region, so move them to src/cut.c.  Also move
the function for which copy_from_buffer() is a wrapper.
2020-01-08 16:04:49 +01:00
Benno Schulenberg 97c8140cea tweaks: rename two functions, to make more sense 2020-01-08 11:09:57 +01:00
Benno Schulenberg c5b03ca4ae tweaks: rename two variables, to make more sense 2020-01-08 11:00:51 +01:00
Benno Schulenberg c2f2c659d9 tweaks: rename a parameter and invert its logic, and correct a comment
This changes the main injection routine in the same way that the prompt
injection routine was changed four years ago in commit e540053e.
2020-01-08 10:49:19 +01:00
Benno Schulenberg 9364bd6c81 tweaks: reword two comments, and rewrap another 2020-01-08 10:27:30 +01:00
Benno Schulenberg baa2be3217 tweaks: improve a comment by indirectly referring to the ncurses docs
See https://invisible-island.net/ncurses/ncurses-intro.html#xterm.
2020-01-07 20:25:31 +01:00
Benno Schulenberg 3f0d2fd5ca display: don't let a message write over the second help line
When suspending nano on a Linux console (or FreeBSD console), the
helpful message about using the 'fg' command overwrote the start
of the second help line, kind of hiding the message.  So, output
a double newline before the message to make it stand out.

Also, drop a pointless cursor movement, as endwin() determines
the placement of the cursor all by itself.
2020-01-07 13:38:52 +01:00
Benno Schulenberg 5b07e5fd1f input: discard partial sequences that Slang produces for F17 to F24
This fixes https://savannah.gnu.org/bugs/?57503.
2020-01-03 12:34:15 +01:00
Benno Schulenberg 3cae32390d display: show the cursor during suspension also when built with Slang
This fixes https://savannah.gnu.org/bugs/?57517.

Bug existed since version 2.9.0.
2020-01-03 12:08:27 +01:00
Benno Schulenberg 1be0285832 tweaks: delete some fragments of code that have become irrelevant
Since the previous commit, USE_SLANG can only be defined when NANO_TINY
is also defined.  This means that code that is present only in non-tiny
versions does not need to cater for Slang.
2020-01-03 12:00:06 +01:00
Benno Schulenberg c4d2bf59fb display: adjust line and column count upon a resize also when using Slang
This partially fixes https://savannah.gnu.org/bugs/?57513.
2020-01-01 14:17:03 +01:00
Benno Schulenberg 5527883c43 input: don't discard the first keystroke after a resize when using Slang
With ncurses, a window resize will cause getch() to return immediately
with some dummy value, which nano can discard.  But with Slang, getch()
will return only when the next keystroke is typed, so the received code
should then not be discarded.

This fixes https://savannah.gnu.org/bugs/?57507.
2020-01-01 13:54:07 +01:00
Benno Schulenberg 84b305f3f0 build: exclude the escape sequences for F13...F16 from the tiny version
The F13 to F16 function keys are no longer bound by default, and when
there is no nanorc file, there is no way to bind them, so there is no
point in recognizing their escape sequences.
2019-12-30 11:55:41 +01:00
Benno Schulenberg 67b89459d5 tweaks: drop an unneeded call of keypad() -- we never read from topwin
The title bar is used only for showing things, never for typing anything
into.  That is: we never call wgetch() with 'topwin' as an argument.
2019-12-29 14:14:08 +01:00
Benno Schulenberg 6d916c6c4a tweaks: rewrap a comment and a line, and reshuffle a fragment of code 2019-12-29 14:13:27 +01:00
Benno Schulenberg 87542eeaf1 tweaks: move a function to before the one that calls it
And condense its logic.  And improve its comment.
2019-12-27 17:01:15 +01:00
Benno Schulenberg 29f2e3181a tweaks: rename a function and its parameter, to be more fitting
Also, avoid calling a case-changing function when it's not needed.
And elide a default case that can never occur (because the function
always gets called with one of the four letters).
2019-12-27 16:48:07 +01:00
Benno Schulenberg 8255696b45 tweaks: condense five more fragments of repetitious code 2019-12-27 13:49:03 +01:00
Benno Schulenberg fc00e89499 tweaks: comment fully, so that all handled escape sequences are findable
Also correct a few other comments.
2019-12-27 13:48:36 +01:00
Benno Schulenberg 55946c15e7 tweaks: reshuffle some lines, to group all ignored keystrokes together 2019-12-27 12:16:50 +01:00
Benno Schulenberg 2e539e2c97 tweaks: stop recognizing escape sequences for a key without meaning
Nano does not do anything for the keystroke anyway (KEY_B2, the center
key on the numeric keypad, gets translated to ERR later on), so there
is no point in recognizing some of its escape sequences -- let those
sequences result in "Unknown sequence" instead.
2019-12-27 12:13:40 +01:00
Benno Schulenberg 38c286c019 input: recognize the raw escape sequences for F13 to F16 on xterm too
For symmetry with Gnome Terminal, Konsole, and the Linux console.

This fixes https://savannah.gnu.org/bugs/?57482.
2019-12-26 17:07:51 +01:00
Benno Schulenberg 56d842258c tweaks: condense three fragments of repetitious code 2019-12-26 16:50:19 +01:00
Benno Schulenberg 8ed8ab69d5 tweaks: make a couple of comments more precise 2019-12-26 14:32:44 +01:00
Benno Schulenberg 4dcbd40c49 input: consume and ignore the raw escape sequences for F17 to F24
When --rawsequences is used, consume the full escape sequences for
the F17 to F24 function keys (on xterm-compatible terminals and on
the Linux console), to prevent them entering junk into the buffer.

This fixes https://savannah.gnu.org/bugs/?57483.
2019-12-26 14:02:17 +01:00
Benno Schulenberg 72645b160d input: correct the escape sequence for PageUp/PageDown on Eterm/Urxvt
There is not a single terminal in the terminfo database that has an
"Esc [ n ^" sequence for any keystroke (where n is a digit).
2019-12-26 12:23:08 +01:00
Benno Schulenberg dda1b167c9 help: don't waste the last column in the help viewer on narrow terminals
When a line in a help text is wider than the terminal, then do not break
that line at COLS - 1, but simply at COLS.  In olden times it made some
sense to have an empty column on the right of the introductory text, to
mirror the one on the left.  But since the width of the introductions
got limited to 74 columns (four years ago, in commit a9aa0ef9), those
texts have (on a default 80-column terminal) at least six empty columns
on their righthand side.  And on narrower terminals, we really don't
want to waste anything and should use all available space.

Also, this whole mechanism of making an exception for end-of-string or
end-of-paragraph and letting only those make use of the final column,
it was a waste of time: it kind-of did the whole break_line() process
again, but then for the entire string (which can be some five hundred
characters long in the introductory texts).  So... get rid of it, make
it simple.  On an 80-column terminal it doesn't make any difference.
2019-12-25 14:39:17 +01:00
Benno Schulenberg 074cf40409 tweaks: remove a superfluous check
When break_line() is called with its last parameter set to TRUE
(meaning that it will break also at a newline) it will return a
value that is bigger than 1.  So it is pointless to ensure that
it is at least 1.
2019-12-25 14:32:04 +01:00
Benno Schulenberg 4991b3bb1a input: Ctrl+arrow is "Esc O x" on Eterm, as on rxvt -- not "Esc o x"
(Checked on Eterm-0.9.6 running on Xubuntu 18.04.)
2019-12-24 20:01:48 +01:00
Benno Schulenberg 4314feae11 build: fix compilation for --enable-tiny --enable-wrapping 2019-12-22 12:56:18 +01:00
Benno Schulenberg 410280b089 build: fix compilation when configured with --disable-justify 2019-12-22 11:32:49 +01:00
Benno Schulenberg 178dd9181f tweaks: slightly streamline the search for a possible wrapping point
That is, elide an 'if' for the it-is-a-blank case.
2019-12-19 19:22:02 +01:00
Benno Schulenberg d30ca576b7 tweaks: optimize the trimming of trailing whitespace
When justifying a paragraph, always first squeeze() is called on
the text (which at that moment consists of a single long line),
which means that (in its wrappable part) this line contains only
single spaces as word separators (and maybe a double space after
a period).  So there is no need to call the general is_blank()
function -- checking for a space is enough.
2019-12-19 12:16:15 +01:00
Benno Schulenberg ed520c89bc tweaks: improve two comments and the ordering of some operands 2019-12-19 12:15:47 +01:00
Benno Schulenberg cb44a2bd2c tweaks: reshuffle and rename a few things, to elide duplication 2019-12-19 10:52:06 +01:00