Commit Graph

1006 Commits (1961c052c85394d1dfb5d2d98d31f154757c8d08)

Author SHA1 Message Date
David Lawrence Ramsey 4c0572a799 text: make justify_paragraph() work on any buffer
Remove the handling of 'edittop', 'totsize', and the mark, to make the
function more general, which is needed to make it undoable eventually.

This breaks the function somewhat.  Fixes for this are forthcoming.
2018-11-20 19:21:35 +01:00
David Lawrence Ramsey 9aa382e69e text: make justify_format() work on any buffer
The function assumes that it works on the current buffer by handling
'totsize' and the mark.  Remove this handling to make the function
more general, which is needed to make it undoable eventually.

This breaks the function somewhat.  Fixes for this are forthcoming.
2018-11-20 19:21:35 +01:00
Brand Huntsman ae3ec1784d options: add --zap, that makes <Bsp> and <Del> erase a marked region
Using --zap or -Z on the command line, or 'set zap' in a nanorc file,
makes the <Bsp> and <Del> keys erase selected text (a marked region)
as they do in some other editors, and without affecting the cutbuffer.

This fulfills https://savannah.gnu.org/bugs/?54837.
Requested-by: Liu Hao <lh_mouse@126.com>

Signed-off-by: Brand Huntsman <alpha@qzx.com>
2018-11-04 11:46:57 +01:00
Brand Huntsman 5662a38802 new feature: a bindable 'zap', to erase text without changing cutbuffer
This function allows the user to "make space": annihilating lines or
regions while keeping intact for pasting the stuff in the cutbuffer
that was cut or copied earlier.

Signed-off-by: Brand Huntsman <alpha@qzx.com>
2018-11-04 11:46:19 +01:00
Benno Schulenberg 477f63d8b5 linter: do not pause when there are no messages for unopened files
Return immediately to editing mode when there are no messages for
the original file and the user does not wish to open any of the
included files that do have messages.

Also, reword the message that the linter gives then, and leave it
on the status bar (just like when Cancel is pressed).
2018-10-24 17:14:02 +02:00
Benno Schulenberg 280ac81b31 display: ensure that the help lines are shown when in linting mode
The help lines will help differentiate this mode from normal editing
mode, and will tell the user how to jump to other messages.

This is a third step to address https://savannah.gnu.org/bugs/?54714.
2018-10-23 19:35:21 +02:00
Benno Schulenberg b7f53096fb display: use a different color when showing a linting message
This is a second step to address https://savannah.gnu.org/bugs/?54714.
2018-10-23 19:31:40 +02:00
Benno Schulenberg f7f7767e7d display: let the title bar show when nano is in linting mode
This is a first step to address https://savannah.gnu.org/bugs/?54714.
2018-10-23 19:30:22 +02:00
Brand Huntsman 71de0b9e2f linter: throttle "first"/"last" message on repeated key presses
To avoid stacking up pauses, which would make nano unresponsive
for too long.

Signed-off-by: Brand Huntsman <alpha@qzx.com>
2018-10-22 20:36:00 +02:00
Benno Schulenberg b8c51329f6 linter: for "first"/"last", reshow actual message after a short pause
This fixes https://savannah.gnu.org/bugs/?54754.
2018-10-21 17:57:28 +02:00
Benno Schulenberg bab5eeb808 bindings: allow using <Enter> to exit from the linter
Understand the key as: "Enter into editing mode on the current line".
2018-10-21 17:55:17 +02:00
David Lawrence Ramsey c2e4f77594 display: do spotlighting as part of drawing the screen
When something is spotlighted, it should survive a refresh of
the screen and an excursion to a help text, so the spotlight
should get painted whenever the edit window is drawn.

This fully fixes https://savannah.gnu.org/bugs/?54721.
2018-10-09 20:03:47 +02:00
Benno Schulenberg d245b07c25 tweaks: remove a now-unused parameter from four functions 2018-10-01 19:56:32 +02:00
David Lawrence Ramsey 13a4f3130d tweaks: normalize the indentation of the shuffled code
And remove some superfluous braces.
2018-09-30 20:47:08 +02:00
David Lawrence Ramsey b32deee382 tweaks: move the justifying of a single paragraph into its own function
The new function, justify_paragraph(), takes a quote length and a
paragraph length (which it should get from find_paragraph()), and
runs the paragraph at (current, current_x) through justify_format().
2018-09-30 20:47:08 +02:00
David Lawrence Ramsey 076bc31ce5 tweaks: simplify by using a 'do/while' loop instead of 'while (TRUE)'
The do/while loop will run once when doing a justify, and enough times
for the entire file when doing a full-justify.
2018-09-30 20:47:08 +02:00
David Lawrence Ramsey 22c8ef6c39 tweaks: reshuffle some code to avoid several checks for having justified
Move some fragments out of the justifying loop, and adjust/clarify comments
to account for the changes.  This will allow some of the code to be cleaned
up and simplified in the next commits.
2018-09-30 20:47:08 +02:00
Benno Schulenberg 4b32c62674 tweaks: reshuffle some lines to get standard order (first up, then down) 2018-09-29 09:46:05 +02:00
Benno Schulenberg b4b9e9b012 linter: allow using <Ctrl+Up> and <Ctrl+Down> to jump to other message
These are more "natural" keystrokes for jumping than <PgUp> and <PgDn>.
2018-09-29 09:42:25 +02:00
Benno Schulenberg 0b63de335e tweaks: elide a wrapper function that is no longer useful 2018-09-28 20:09:12 +02:00
David Lawrence Ramsey bed997171c speller: restore the mark coordinates slightly later
To avoid a confusing mishighlighting of just part of a marked region.

This partially addresses https://savannah.gnu.org/bugs/?54721.
2018-09-26 19:45:38 +02:00
Benno Schulenberg 8d0b7a490d undo: move another piece of checking to the two places that need it
And in the bargain get rid of a function that is used just once.
2018-09-26 19:25:21 +02:00
Benno Schulenberg efa323ec88 tweaks: improve two comments, and reshuffle a line for consistency
(Line number first, x position second.)
2018-09-25 20:26:26 +02:00
Benno Schulenberg 4c6ec6377f undo: move some special checking code to the one place that needs it
Only for BACK and DEL was the first call to update_undo() -- all other
types of action would call add_undo() first, so for them the action in
update_undo() would never be different, but the line number might have
changed (like for ENTER and INSERT), so for them exceptions needed to
be made, which was wasteful.

This addresses https://savannah.gnu.org/bugs/?54728.
2018-09-25 18:09:28 +02:00
Benno Schulenberg be69a7c299 tweaks: rename a variable, to be a bit more fitting 2018-09-23 14:51:40 +02:00
Benno Schulenberg 33b576c289 speller: remove a pointless message -- it is never seen
When using the internal spell checker, the message gets overwritten
immediately by "Creating misspelled word list...", and when using
the external spell checker, nano immediately exits from curses mode
and thus the message disappears (when in a terminal emulator) or it
soon gets wiped by the spell checker (when on a Linux console), thus
creating a little flash on the bottom row, which we can do without.
2018-09-23 14:41:25 +02:00
Benno Schulenberg 1f39f60b2f tweaks: there is no reason to block SIGWINCHes while waiting for speller
In the past, SIGWINCHes were responded to immediately (which was madness),
but since commit 75d64e67 all a SIGWINCH does is set a flag so that, when
the time comes to update the screen, nano knows the dimensions may have
changed.  The mentioned commit removed most blockings and unblockings of
SIGWINCH, but not this one.
2018-09-23 14:07:36 +02:00
Benno Schulenberg e21ce0db1f cutting: when deleting whole words, don't join lines unexpectedly
That is, wait with deleting words until they start under cursor,
so the user can see which word is goin to be eaten, and join lines
only when the cursor already sits at the edge of a line.
2018-09-07 19:35:01 +02:00
David Lawrence Ramsey 93c8e316a8 justify: verify being in a paragraph before trying to find its beginning
If find_paragraph() detects that we're not in a paragraph, it moves
forward a paragraph and then backward to that paragraph's beginning.
Make it check whether we're in a paragraph before moving backward
(since there might not *be* any more paragraphs), to prevent going
forth-and-back and never reaching the end of the buffer.

This fixes https://savannah.gnu.org/bugs/?54573.
2018-08-27 20:27:02 +02:00
David Lawrence Ramsey 03f9761c35 undo: store the correct cursor position after a paired cut+insert
And restore the cursor to this position when redoing the cut+insert.

Also remove two unneeded conditions.

This fully fixes https://savannah.gnu.org/bugs/?54466.
2018-08-21 19:21:14 +02:00
Benno Schulenberg ec339d3b08 filtering: wait for the data-sending process to terminate too
When piping the buffer (or the marked region) to an external command,
we should wait not only for the external command to terminate but also
for the data-sending process, so that it will release its resources.

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

With-help-from: Marco Diego Aurélio Mesquita <marcodiegomesquita@gmail.com>
2018-08-20 19:46:38 +02:00
Benno Schulenberg 3218d8358a tweaks: remove a redundant "struct" word, and replace it in comments 2018-08-20 19:33:31 +02:00
David Lawrence Ramsey 07447f3278 undo: restore the cursor position when a cut and paste are paired
When undoing/redoing an alternate spell check (of the entire file
or of a backwards marked region), put the cursor back where it was
when the spell check was invoked/finished.

This fixes https://savannah.gnu.org/bugs/?54466.
2018-08-15 19:58:46 +02:00
David Lawrence Ramsey fd65f74428 undo: always initialize the 'newsize' element in the undo struct
So that do_redo() cannot set the file size to a "random" value.

This fixes https://savannah.gnu.org/bugs/?54478.
2018-08-11 10:07:20 +02:00
Benno Schulenberg 975b491235 dropping a feature: remove the ability to use the 'formatter' command
Since the last version, the user can filter an entire buffer through
an external command.  This external command can also be a formatting
program, so there is no longer any need for this specific and special
formatter command.
2018-08-09 20:29:30 +02:00
Benno Schulenberg 94b4f07281 tweaks: adjust indentation after the previous change
Also improve a couple of comments.
2018-08-08 19:53:05 +02:00
Benno Schulenberg 61b4eeda66 speller: do not replace the text when the temporary file did not change 2018-08-08 19:44:40 +02:00
Benno Schulenberg 667fcea65e undo: differentiate between general filtering and spell checking
With-help-from: David Lawrence Ramsey <pooka109@gmail.com>
2018-08-07 20:42:39 +02:00
David Lawrence Ramsey c39c9c241b undo: actually enable undoing/redoing an alternative spellcheck
Make sure the inserts of the spell-checked text are undoable, and no
longer discard the undo stack after running the alternate spell checker.
2018-08-07 20:41:05 +02:00
David Lawrence Ramsey bc6787826a speller: make replace_marked_buffer() use the cutting functions directly 2018-08-07 20:38:50 +02:00
Benno Schulenberg 60ee4408be signals: don't call a print routine in a signal handler
Print routines are not asynchronous-safe.

But... the only reason the call of kill() could return an error code
is when the relevant process has already terminated -- which is not
a problem, because that was the goal of calling kill().

This fixes https://savannah.gnu.org/bugs/?54409.
Reported-by: Daniel Kozovsky <dkozovsk@redhat.com>
2018-07-30 20:22:24 +02:00
Benno Schulenberg 72a590d60a tweaks: rename a variable and a function, for more clarity 2018-07-30 20:07:25 +02:00
Benno Schulenberg c4d09cc24b text: add auto-whitespace to the file size after creating the undo item
The undo item for ENTER should record the file size *before* the amount
of auto-indentation whitespace is added to it.

This fixes https://savannah.gnu.org/bugs/?54344.
Reported-by: Liu Hao <lh_mouse@126.com>
2018-07-23 17:57:47 +02:00
Benno Schulenberg 05592a84ec completion: when the cursor is not after a word fragment, say so
Instead of being entirely silent when ^] is hit after whitespace
or punctuation, report what is lacking -- similar to M-] saying
"Not a bracket" when the cursor is not sitting on a bracket.
This makes the ^] keystroke more discoverable.
2018-07-19 19:29:24 +02:00
Benno Schulenberg 6d3b16b761 tweaks: close a temp file only when descriptor is valid [coverity scan] 2018-07-14 21:33:46 +02:00
Benno Schulenberg 14b9a42f5b tweaks: move a call to where it will be executed [coverity scan] 2018-07-14 21:02:32 +02:00
Benno Schulenberg d994af0334 tweaks: avoid dereferencing a pointer when it is NULL [coverity scan] 2018-07-14 20:02:03 +02:00
Benno Schulenberg 3ac821ee0c build: fix compilation when configured with --enable-tiny 2018-07-10 15:31:04 +02:00
Benno Schulenberg f456794045 tweaks: adjust two comments, to be more accurate and general 2018-07-08 17:40:19 +02:00
David Lawrence Ramsey 20971e8392 undo: position the cursor properly when undoing/redoing magicline cuts
Take our cue from undoing/redoing line joins: when they take place on
the magicline without --nonewlines, they produce undo/redo items that
don't do anything to the text, but still position the cursor properly.
Reshuffle a bit of code so that we can do the same for magicline cuts.

This fixes https://savannah.gnu.org/bugs/?54032.
2018-07-08 17:29:28 +02:00
Benno Schulenberg fb372ed0a8 tweaks: remove two superfluous assignments
The variable 'last_action' is set at the end of these functions,
serving to prevent a fresh action from being merged with an older
action further down on the stack.  Setting 'last_action' before
exiting from undo()/redo() makes no sense.

Also adjust a sideways related old Changelog item.
2018-06-02 19:32:54 +02:00
Benno Schulenberg ed433f6af0 tweaks: drop a condition that has been made redundant two commits ago 2018-06-02 18:17:31 +02:00
Benno Schulenberg 44814055b5 tweaks: correct a comment, rewrap a line, and drop some debugging stuff
An add can be contiguous even when the cursor has moved around in the
meantime but has returned to the same spot before more characters are
typed.
2018-06-02 18:04:36 +02:00
Benno Schulenberg 71f859377d cut: concentrate the logic for clearing the cutbuffer mostly in one place
It should not be the task of the undo code to take care that the
cutbuffer will be cleared at the right moments.
2018-06-02 17:57:19 +02:00
Benno Schulenberg 5550d15418 tweaks: improve a couple of comments, and reshuffle a group of lines 2018-06-01 16:56:56 +02:00
Benno Schulenberg 6df30a634e docs: register Marco as the author of the filtering feature
The macro stuff, however, is basically my code: I told him exactly
how to do it, and I changed most of the patch before applying it.

Also, put myself in second place, as I've just about overtaken David
in the duration of maintainership.
2018-06-01 10:00:08 +02:00
Benno Schulenberg ad5d0f7530 wrapping: use "smart" autoindenting only when hard-wrapping is enabled
The paragraph-aware indenting is needed only when automatic long-line
wrapping is on (that is, when not using 'nowrap': when writing prose).
When writing code, the user most likely uses --nowrap, which will make
nano indent a new line always to the same amount as the preceding line
-- when --autoindent is in effect, of course.
2018-06-01 08:45:25 +02:00
David Lawrence Ramsey dc4146f077 tweaks: avoid an unused variable warning with --enable-tiny
This fixes https://savannah.gnu.org/bugs/?53998.
2018-05-29 09:00:08 +02:00
Benno Schulenberg 738487f13d tweaks: make better use of an existing variable 2018-05-28 10:39:47 +02:00
Benno Schulenberg c8a9a96578 build: fix compilation when configured with --disable-justify 2018-05-28 09:57:24 +02:00
David Lawrence Ramsey fce54a724d tweaks: fix some grammar plus a typo in the comments 2018-05-27 20:19:46 +02:00
Benno Schulenberg ebdb647450 tweaks: adjust a translator hint 2018-05-27 17:53:36 +02:00
Benno Schulenberg 0c2aac5ff8 tweaks: reshuffle a couple of assignments 2018-05-27 17:45:51 +02:00
Benno Schulenberg 7952d68830 tweaks: frob a couple of comments 2018-05-27 17:27:07 +02:00
Benno Schulenberg 5cb4485fa5 tweaks: remove a superfluous assignment -- the lead length never changes 2018-05-27 17:16:04 +02:00
Benno Schulenberg d7c1ab8e80 tweaks: rename two variables, to better fit their tasks 2018-05-27 17:11:18 +02:00
Benno Schulenberg 1881db099d tweaks: make better use of an intermediate variable 2018-05-27 16:41:55 +02:00
Benno Schulenberg 36c83d92dd tweaks: stop decreasing both the iterator and the limit of a loop 2018-05-27 16:34:20 +02:00
Benno Schulenberg 9021725d53 justification: limit the amount of recursion to prevent a stack overflow 2018-05-27 16:09:53 +02:00
Benno Schulenberg d00ab406bc wrapping: when autoindenting, use indentation of next line as example
When doing autoindentation, and the next line is not the start of
a new paragraph, then use the indentation of that line for the new
line, as it is more likely to have the desired indentation -- the
current line might be the start of the paragraph and thus could
have a deviant indentation.
2018-05-27 16:09:53 +02:00
Benno Schulenberg d63d79b067 tweaks: elide another function that is called just once 2018-05-27 16:09:53 +02:00
Benno Schulenberg 446c7d5fff tweaks: elide a function that is called just once 2018-05-27 16:09:53 +02:00
Benno Schulenberg 52efac535b tweaks: rename a variable, to give it some meaning 2018-05-27 16:09:53 +02:00
Benno Schulenberg 45c36f93e5 tweaks: simplify the determining of the prefix for justified lines 2018-05-27 16:09:53 +02:00
Benno Schulenberg 432a7d7729 justification: find the beginning of a paragraph in a better way
Any line whose indentation differs from that of a pair of adjacent lines
is the beginning of a paragraph, also when its indentation is smaller.

This fulfills https://savannah.gnu.org/bugs/?53932,
and fixes point 2) of https://savannah.gnu.org/bugs/?53933.
2018-05-27 16:09:53 +02:00
Benno Schulenberg d7fe5a7db3 justification: recognize indented paragraphs also without --autoindent
Pico does not require any option to do this, so nano should neither.

This fixes point 1) of https://savannah.gnu.org/bugs/?53933.
2018-05-27 16:09:53 +02:00
Benno Schulenberg a832f33291 justification: when leading whitespace exceeds fill width, wrap anyway
Pico wraps at the last blank character before or on the target column;
if there is no such blank, then it will wrap at the first blank *after*
the target column -- when it can wrap, it will wrap.  Nano should do
the same (and judging from the comments, it intended to do the same),
instead of turning the paragraph into a single unwrapped line.

This fixes https://savannah.gnu.org/bugs/?53986.
2018-05-27 10:24:02 +02:00
Benno Schulenberg b9f533a69e tweaks: rename a function, for more aptness and extra contrast 2018-05-25 20:09:24 +02:00
Benno Schulenberg ac31669ec3 linter: don't try to access absent stat info, as that gives a crash
This fixes https://savannah.gnu.org/bugs/?53981.
2018-05-25 19:25:11 +02:00
Benno Schulenberg 86c08560ad linter: make sure that the margin is updated before displaying a buffer
This fixes https://savannah.gnu.org/bugs/?53977.
Reported-by: Marco Diego Aurélio Mesquita <marcodiegomesquita@gmail.com>
2018-05-25 17:58:25 +02:00
Benno Schulenberg 3757683e3f build: fix compilation when configured with --disable-multibuffer 2018-05-24 21:09:14 +02:00
Benno Schulenberg 3e9ef3032f tweaks: use a more meaningful variable name, and avoid a distant 'else'
Also, indent a continuation line better.
2018-05-24 19:40:52 +02:00
Benno Schulenberg 6fb1509817 tweaks: condense two statements into one, and elide a 'break' 2018-05-24 18:17:58 +02:00
Benno Schulenberg 07ddf25cc0 tweaks: exclude an unneeded 'if' from the single-buffer version 2018-05-24 18:14:35 +02:00
Marco Diego Aurélio Mesquita 73d397c64b linter: check all open buffers, instead of just the next one
First step to the next buffer, and then iterate until we either
find a match or are back at the buffer where we started.

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

Signed-off-by: Marco Diego Aurélio Mesquita <address@hidden>
2018-05-24 18:10:52 +02:00
Benno Schulenberg e0c7ff2a7e linter: make sure the shortcuts bar will redrawn when exiting early
The two help lines will be redrawn in main() only when the current
menu is not MMAIN.  So, set it to MLINTER as soon as the help lines
are cleared, just before preparing to invoke the linter.

This fixes https://savannah.gnu.org/bugs/?53967.
Reported-by: Marco Diego Aurélio Mesquita <marcodiegomesquita@gmail.com>
2018-05-24 11:37:14 +02:00
Benno Schulenberg 5d02ee64b6 filtering: pair the cut and the insert, so they can be undone together
When executing a command in the current buffer and piping this buffer
(or marked region) to that command, then the cutting of the existing
text and the insertion of the new text should be undone and redone
together, as to the user they appear as a single operation.

With-help-from: Marco Diego Aurélio Mesquita <marcodiegomesquita@gmail.com>
2018-05-22 19:36:21 +02:00
Benno Schulenberg 5ffd8d96ae tweaks: rename a variable, for contrast, and improve two comments 2018-05-22 19:36:21 +02:00
Marco Diego Aurélio Mesquita f304b9aee1 new feature: allow piping (selected) text to an external command
When executing a command, it is now possible to pipe the entire buffer
(or the marked region, if anything is marked) to the external command.
The output from the command replaces the buffer (or the marked region),
or goes to a new buffer.

This fulfills https://savannah.gnu.org/bugs/?28993,
and fulfills https://savannah.gnu.org/bugs/?53041.

Signed-off-by: Marco Diego Aurélio Mesquita <marcodiegomesquita@gmail.com>
Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
2018-05-22 19:36:21 +02:00
Benno Schulenberg 9d6621afd0 tweaks: remove two superfluous checks, after making one of them so 2018-05-21 09:44:06 +02:00
Benno Schulenberg 4d232a4aef tweaks: frob some comments, and rename two parameters to make sense 2018-05-18 13:24:07 +02:00
Mark-Weston 858663444e new feature: an option to make the 'nextword' function stop at word ends
When 'afterends' is set and Ctrl+Right or Shift+Ctrl+Right is pressed,
nano will stop at the ends of words instead of their beginnings.

Signed-off-by: Mark-Weston <markweston@cock.li>
Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
2018-05-10 11:32:01 +02:00
Benno Schulenberg 553940760e tweaks: set the correct flags just once for each spell-fixing session 2018-04-25 17:27:15 +02:00
Benno Schulenberg faa0eb991e speller: don't add an extra newline when saving the text to a tempfile
Set the NO_NEWLINES flag to achieve this.  And move the saving and
restoring of the global flags to the main speller routine, so the
flags aren't saved and restored for each internal spell fix.

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

Acked-by: David Lawrence Ramsey <pooka109@gmail.com>
2018-04-25 17:26:14 +02:00
Benno Schulenberg 4872f42cd2 tweaks: rename a function, to be more distinct from its caller 2018-04-25 12:21:40 +02:00
Benno Schulenberg 1ae90e205a command-execution: do not crash when opening the pipe would fail
This fixes https://savannah.gnu.org/bugs/?53723.
2018-04-23 18:04:25 +02:00
Benno Schulenberg d53086d38d completion: correctly do a signed comparison, to avoid a segfault
Bug existed since commit 30fc197b (a month ago) which changed the
type of 'i' from int to size_t, causing the comparison to do the
wrong thing when 'threshold' is negative.

This fixes https://savannah.gnu.org/bugs/?53722.
Reported-by: Devin Hussey <husseydevin@gmail.com>
2018-04-23 17:09:54 +02:00
Benno Schulenberg 0b6bb37c56 tweaks: improve some comments, and exit with nonzero status upon error 2018-04-23 14:04:08 +02:00
Benno Schulenberg c43a6fdcc1 tweaks: rename a variable, to match another and to be more visible 2018-04-23 13:04:31 +02:00
Benno Schulenberg 0c613cb1ac tweaks: rename a variable, to be more clear and to match another 2018-04-23 12:57:58 +02:00
Benno Schulenberg 1e5064ef84 tweaks: fix a typo, remove a blank line, and improve some comments 2018-04-23 12:19:25 +02:00
Benno Schulenberg 45f8fc77e0 tweaks: rename a variable, to be a bit more fitting 2018-04-22 12:05:19 +02:00
Benno Schulenberg 94347f0811 memory: use a reallocation to reduce the amount of leakage 2018-04-22 12:00:26 +02:00
Benno Schulenberg 1a4a3de68b formatting, linting: redetermine the argument list for every run
The formatter or linter might have changed in the meantime -- when
the filename was changed to have a different extension, for example.

This fixes https://savannah.gnu.org/bugs/?53716.
2018-04-22 11:44:07 +02:00
Benno Schulenberg 02d8da3bdd tweaks: rename a function, to be more fitting and descriptive
It is not an abort but simply a bit of cleaning up.
2018-04-13 10:32:29 +02:00
Benno Schulenberg 8965103a4d tweaks: remove the group handling for undoing/redoing (un)indents
Indenting/unindenting always happens in a single contiguous block.
Lines that cannot or should not be indented or unindented do not
need to remembered separately as it follows from their content.
2018-04-01 11:41:26 +02:00
Benno Schulenberg d0d293b8af tweaks: correct or improve a couple of comments 2018-04-01 11:24:44 +02:00
Benno Schulenberg 839743fd24 tweaks: move a function to its proper location 2018-04-01 10:54:14 +02:00
Benno Schulenberg 5726514869 linting: drop messages for other files when configured for one buffer
This fixes https://savannah.gnu.org/bugs/?53445.
2018-03-26 08:56:03 +02:00
Benno Schulenberg 88234c90bc tweaks: adjust the indentation after the previous changes 2018-03-26 08:53:06 +02:00
Benno Schulenberg 02719ec4bf tweaks: fuse two ifs into one 2018-03-26 08:52:51 +02:00
Benno Schulenberg 415bf82690 tweaks: move an 'if' and then remove an unneeded label 2018-03-26 08:52:04 +02:00
Benno Schulenberg bf1a080923 build: exclude more things when configured with --disable-multibuffer
This will make the tiny version slightly smaller.
2018-03-23 11:09:37 +01:00
Benno Schulenberg 30fc197b66 tweaks: adjust a couple of types, to reduce the number of warnings
This avoids eleven warnings of the kind "comparison between signed
and unsigned integer expressions [-Wsign-compare]".
2018-03-22 19:33:22 +01:00
Benno Schulenberg b9de5525c4 tweaks: elide a parameter, as it's always the inverse of another 2018-03-22 12:52:28 +01:00
Benno Schulenberg f4d1ef1c4e tweaks: remove unneeded settings and unsettings of MULTIBUFFER
In the preceding commit, open_buffer() was changed so that it gets
told whether to load into a new buffer or not, so it is no longer
needed to convey this information through a flag.
2018-03-22 12:50:48 +01:00
Benno Schulenberg dd157f1494 tweaks: change a parameter of open_buffer() and invert its logic 2018-03-22 12:35:50 +01:00
Benno Schulenberg dcda98fb73 tweaks: remove an inconsistent space from two pointer declarations
Reported-by: Brand Huntsman <alpha@qzx.com>
2018-03-17 15:53:22 +01:00
Benno Schulenberg e8505b2d3e memory: plug a leak, by actually freeing a discarded undo struct
This fixes https://savannah.gnu.org/bugs/?53269.
Reported-by: Ashish Kunwar <dorkerdevil280@gmail.com>

The leak was mistakenly introduced by commit dc3618a1
-- probably as a leftover of testing things.
2018-03-11 20:16:09 +01:00
Benno Schulenberg 95fffa99aa tweaks: adjust two comments, move two declarations, rewrap three lines 2018-03-05 10:43:05 +01:00
Benno Schulenberg 22f7861694 tweaks: reshuffle the undo types into mostly the same order everywhere
First the two that add something (ADD, ENTER), then the three that
delete something (BACK, DEL, JOIN), and then the one that changes
something (REPLACE).  Then the SPLITs, CUT, PASTE, and INSERT, and
then the INDENTs and COMMENTs, when they exist.
2018-03-05 10:05:07 +01:00
Benno Schulenberg ba96d507dd tweaks: drop some debugging stuff, and adjust what remains of it 2018-03-05 09:42:57 +01:00
Benno Schulenberg 9bf57e5ca0 tweaks: do not needlessly renumber the lines in the buffer
For cuts, pastes, and inserts, the lines have already been renumbered;
for indents, comments, and replacements, the line numbers cannot have
changed.  (And anyway, variable 'f' is not set for those cases.)

Only when lines get split (ENTER) or fused together (JOIN) do the later
lines need to be renumbered.  This mirrors what is done for do_redo().
2018-03-04 10:27:07 +01:00
Benno Schulenberg f9103a5cb5 tweaks: make the fsfromline() call only for the undo types that need it
The 'f' variable is used only in the ADD, BACK, DEL, ENTER, JOIN, and
REPLACE undo/redo cases.  So, avoid making a somewhat costly call when
it is entirely superfluous.  Rearrange the undo types to make checking
for the above six types easier.
2018-03-03 17:12:25 +01:00
Benno Schulenberg e9eabdcdcb undo: when redoing, don't try to find a line number that might not exist
This fixes https://savannah.gnu.org/bugs/?53272.
2018-03-03 16:41:33 +01:00
Benno Schulenberg dd9766c2e0 editing: when --smooth is used, make <Enter>-at-bottom scroll one row
When using --smooth or 'set smooth', the screen should scroll the
minimum amount needed to get the cursor back into view.  (The only
exceptions are search, undo, and redo -- when there the cursor goes
offscreen, the cursor line is centered.)

This change brings the behavior of pressing <Enter> on the bottom
row into line with, for example, pasting a single line.  See also
http://lists.gnu.org/archive/html/nano-devel/2018-02/msg00027.html.
2018-02-16 11:48:24 +01:00
Benno Schulenberg 4295baa5fe tweaks: transform a 'do' to a 'while', and reshuffle a comment 2018-02-04 18:14:28 +01:00
Benno Schulenberg f72fecee9b copyright: update the years for the FSF
And one for me, for the much changed keyboard stuff.
2018-01-24 10:14:43 +01:00
Benno Schulenberg a429dc4a76 tweaks: rename a variable, to better fit its usage 2018-01-23 13:09:12 +01:00
Benno Schulenberg 91073be49c wrapping: don't trim a blank character that the user just typed
Trimming trailing spaces is good, but we should not trim the space
(or tab or other blank) that the user just typed and that caused the
hard-wrapping to occur.

This fixes https://savannah.gnu.org/bugs/?52948.
Reported-by: Andreas Schamanek <schamane@fam.tuwien.ac.at>
2018-01-23 13:06:05 +01:00
Benno Schulenberg 7947d9d2a5 build: fix compilation when configured with --enable(tiny,color,nanorc}
This fixes https://savannah.gnu.org/bugs/?52834.
Reported-by: <akiko@mailbox.org>
2018-01-09 13:30:25 +01:00
Benno Schulenberg ada78dc89d build: fix compilation with --enable-tiny --enable-justify 2018-01-08 19:12:41 +01:00
Benno Schulenberg 17429d7f38 tweaks: fix some whitespace errors, and convert alignment tabs to spaces 2017-12-29 21:35:14 +01:00
Benno Schulenberg 87206c0607 tweaks: convert the indentation to use only tabs
Each leading tab is converted to two tabs, and any leading four spaces
is converted to one tab.  The intended tab size (for keeping most lines
within 80 columns) is now four.
2017-12-29 20:06:50 +01:00
Benno Schulenberg b574f73e60 tweaks: add a separate function that actually wipes the status bar 2017-12-29 17:40:41 +01:00
David Lawrence Ramsey 62ebd93579 tweaks: use printf's z modifier for (s)size_t, instead of casting 2017-12-26 14:11:18 +01:00
Benno Schulenberg 184bb11fd9 tweaks: factor out a piece of common code 2017-12-24 11:25:10 +01:00
Benno Schulenberg a70db34fc9 tweaks: remove two irrelevant conditions
They were mistakenly added by changeset fb85c055, four commits ago.
2017-12-24 11:10:41 +01:00
Benno Schulenberg fbde1b2d71 tweaks: reshuffle another bit of code, for conciseness 2017-12-24 10:56:16 +01:00
Benno Schulenberg c22fef18e4 tweaks: reshuffle a bit of common code, moving it to an existing function 2017-12-23 21:50:18 +01:00
Benno Schulenberg fb85c05594 text: keep cursor at left edge when it IS there when indenting/commenting
Suggested-by: Brand Huntsman <alpha@qzx.com>
2017-12-21 19:47:22 +01:00
Benno Schulenberg 25b1114e03 tweaks: elide two parameters from the get_region() function 2017-12-21 19:47:22 +01:00
Benno Schulenberg 4b8a387529 text: let indenting/commenting skip the last line if its x is zero
If the marked region ends at the start of a line, do not include that
line in the indenting/undenting or commenting/uncommenting.  This is
closer to what the eye would expect.
2017-12-21 19:47:22 +01:00
Benno Schulenberg dc3618a127 text: set and reset the Modified state correctly when undoing/redoing
Unset the "Modified" marker only at the point where the file was last
saved -- if there is such a point, because it can be missing when the
undo stack was discarded.

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

Original-idea-by: Brand Huntsman <alpha@qzx.com>
2017-12-19 19:22:52 +01:00
Benno Schulenberg e2843ede7e text: let a Shift-selection persist when indenting and commenting
To achieve that, fake the Shift key being held when indenting/
unindenting/commenting/uncommenting.

Reported-by: Brand Huntsman <alpha@qzx.com>
2017-12-12 21:09:28 +01:00
Benno Schulenberg bcd187d7d6 tweaks: rewrap some lines and some comments, and trim two others 2017-12-10 20:03:51 +01:00
Benno Schulenberg 03783a7d1b tweaks: trim another placing of a terminating nul byte
Make both preceding character moves include the terminating byte.
2017-12-10 19:56:36 +01:00
Benno Schulenberg f2fb8c01f4 tweaks: remove a superfluous placing of a terminating nul byte
The character move has already copied the terminating byte.
And a reallocation to save just one character of memory is
a waste of time.
2017-12-10 19:49:57 +01:00
Benno Schulenberg eb937f81fa text: allow unindenting when not all lines are indented
And also allow it when lines are only partially indented.

This makes it possible to equalize the indentations of (accidentally)
unevenly indented lines: by first fully unindenting a group of lines,
and then reindenting them to the desired amount.

Suggested-by: Liu Hao <lh_mouse@126.com>
2017-12-09 17:44:12 +01:00
Benno Schulenberg 66fd6a5ab1 options: rename 'justifytrim' to 'trimblanks', because it has morphed
The option now causes nano to trim trailing whitespace also when
hardwrapping occurs while the user is typing.
2017-12-06 20:38:13 +01:00
Benno Schulenberg c30d3d8010 wrapping: delete trailing blanks upon hardwrapping, when requested
This fulfills https://savannah.gnu.org/bugs/?52198.
2017-12-06 20:32:08 +01:00
Benno Schulenberg 0c40f87b55 tweaks: invert the logic of a variable, and rename it
To get rid of two double negatives.
2017-12-03 20:49:01 +01:00
Benno Schulenberg 0133d5cba8 tweaks: elide two variables that are used just once 2017-12-02 18:07:50 +01:00
Benno Schulenberg 9066a96dde tweaks: rename three variables, for more contrast and variety 2017-12-02 18:07:22 +01:00
Benno Schulenberg 6abb551fdd tweaks: avoid incrementing a variable that won't be used again later 2017-12-02 17:55:27 +01:00
Benno Schulenberg 97bdf13b59 tweaks: remove a redundant call of renumber()
The call of do_delete() four lines earlier already does a renumber.
2017-12-02 17:47:01 +01:00
Benno Schulenberg dae88f8dc7 tweaks: remove a superfluous condition
When the WAS_FINAL_LINE flag is relevant (when NO_NEWLINES isn't set),
the only way for 'current' to be equal to 'filebot' is when 'current_x'
is zero.
2017-12-02 17:40:16 +01:00
David Lawrence Ramsey b9638cb7cc undo: when adding text adds a magicline, an undo should remove both
This fixes http://savannah.gnu.org/bugs/?52523.
2017-11-30 21:20:38 +01:00
Benno Schulenberg c17a8a9836 undo: discarding the stack does not always lose information
When some or all edits have been undone, and the user starts to make
new edits, the old part of the undo stack is discarded, but this does
not mean that the undo stack doesn't go back to the very beginning.

This really fixes https://savannah.gnu.org/bugs/?52504.
2017-11-27 16:19:28 +01:00
Benno Schulenberg 0c9905dbd0 undo: clear the Modified state when the very first edit is undone
This also means that no question needs to be asked when exiting.

This fixes https://savannah.gnu.org/bugs/?52504.
Reported-by: Peter Passchier <peter@passchier.net>
2017-11-26 19:55:44 +01:00
Benno Schulenberg 2b314ed18f selecting: let a justification cancel a softmark
Otherwise a second justification will cancel it, which is weird.
2017-11-26 19:54:29 +01:00
Benno Schulenberg 77d24300f3 tweaks: reshuffle a couple of lines, and frob a comment or two 2017-11-22 19:36:33 +01:00
Benno Schulenberg d33b5f3dab tweaks: rename, rewrap, and reshuffle some stuff, and frob some comments 2017-11-21 21:17:08 +01:00
Benno Schulenberg c24e95e3d6 tweaks: elide the 'mark_set' boolean -- the 'mark' pointer is enough
The pointer not being NULL is enough indication that the mark is set.

Also, rename the pointer from 'mark_begin' to simply 'mark', since
the former is kind of pleonastic.
2017-11-21 21:14:33 +01:00
Benno Schulenberg c42489d946 linting: switch the mark off when the linter starts
Because the highlighting hinders the display of affected lines,
and, more importantly, only the highlighted part would be written
if the file was modified and the user answers yes to the "Save?"
prompt.

This fixes https://savannah.gnu.org/bugs/?52474.
2017-11-21 21:12:16 +01:00
Benno Schulenberg 5239e7c52b copyright: update some years, and standardize on the dashed format 2017-11-12 10:46:20 +01:00
Benno Schulenberg 2122a1a2b5 tweaks: constify the result strings of getenv(), as a reminder
Also, remove an unneeded pair of braces.
2017-11-10 20:03:07 +01:00
Benno Schulenberg 7e6bb91593 tweaks: add a translator hint, and adjust two others 2017-11-07 19:39:00 +01:00
Benno Schulenberg 7b133aa6f9 tweaks: change some mayday messages, to urge the user to report a bug
Also, diversify them, and no longer mark them for translation.
2017-11-07 19:14:33 +01:00
Benno Schulenberg d5ac1ed395 tweaks: transform the token DISABLE_COLOR to ENABLE_COLOR 2017-11-01 19:45:50 +01:00
Benno Schulenberg 2a4fc9591f tweaks: transform the token DISABLE_SPELLER to ENABLE_SPELLER 2017-10-31 19:32:42 +01:00
Benno Schulenberg f034992ed6 tweaks: transform the token DISABLE_WRAPJUSTIFY to ENABLED_WRAPORJUSTIFY 2017-10-31 17:40:54 +01:00
Benno Schulenberg db0b849f9b tweaks: transform the token DISABLE_JUSTIFY to ENABLE_JUSTIFY 2017-10-31 17:40:44 +01:00
Benno Schulenberg a5974bd1ec tweaks: transform the token DISABLE_WRAPPING to ENABLE_WRAPPING 2017-10-29 21:00:09 +01:00
Benno Schulenberg 3f27c312c4 tweaks: get rid of some cluttering conditional compilation
In the tiny version, do_prompt() will now have an extra NULL
parameter, which will cost maybe twenty extra bytes of code.
That is acceptable when it saves thirty lines in the source.
2017-10-29 11:39:27 +01:00
Benno Schulenberg ded02d858f search: suppress the "Search Wrapped" message when doing replacements
This completes the fix for https://savannah.gnu.org/bugs/?52282.
Reported-by: Chime Hart <chime@hubert-humphrey.com>
2017-10-26 21:07:06 +02:00
Viorel Bota 217cfbf362 files: check for a changed disk file also for 'savefile' and --tempfile
Before writing a file out, nano should check that the file on disk
hasn't been modified since it was read -- not only for the normal
"Write Out" action (^O), but also for "Save File" (future ^S) and
for "Save and Exit" (^X when --tempfile is used).

When writing fails and --tempfile is in effect, don't go on to prompt
for a file name; instead let the user decide what she wants to do.

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

Signed-off-by: Viorel Bota <botaviorel@gmail.com>
Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
2017-10-13 20:24:10 +02:00
Benno Schulenberg 7c3c3cbb3b tweaks: discard some obsolete debugging stuff 2017-09-22 21:59:51 +02:00
Benno Schulenberg c74d2632bb tweaks: make the switching on and off of the cursor a bit more compact 2017-09-22 21:31:01 +02:00
Benno Schulenberg ae34825f58 display: rework the switching on and off of the cursor
The basic idea is that the cursor is always off, except when it needs
to be on: when waiting for text input, and in a few other cases: when
something was searched and found in the help viewer, and in the file
browser when option -g is in effect.

This fixes https://savannah.gnu.org/bugs/?51923.
Reported-by: Mike Frysinger <vapier@gentoo.org>
2017-09-20 21:35:25 +02:00
Benno Schulenberg ac8eb42a4f tweaks: elide a superfluous allocation 2017-09-12 20:46:14 +02:00
David Lawrence Ramsey 19a1129698 text: hook up indenting and unindenting to the undo/redo code
This is modeled after the comment/uncomment code.  Each line's
individual indent is saved in the string array of the undo
group structure.

This fixes http://savannah.gnu.org/bugs/?46860.
2017-09-12 20:08:30 +02:00
David Lawrence Ramsey f722c53223 undo: generalize update_comment_undo() into update_multiline_undo()
The function does not contain any comment-specific code, so it can
be used to handle any kind of multiline undo item.

Also, extend the undo group structure to contain an array of strings,
one for each line in the group.  When indent/unindent is hooked up to
the undo/redo code, this will allow the latter to restore the exact
original indents.
2017-09-12 19:49:44 +02:00
Benno Schulenberg ffc550521c tweaks: chuck a bunch of asserts -- they have lost their usefulness 2017-09-10 14:08:24 +02:00
Benno Schulenberg 8d229cb712 tweaks: rename a variable, to make more sense
Also, remove an unneeded null_at() -- the null byte has been copied,
and reallocating the string would recover very little memory.

Also, call charmove() without using the & operator.
2017-09-10 13:28:13 +02:00
Benno Schulenberg abf7ac48a1 tweaks: rename three variables, for more contrast 2017-09-10 13:04:03 +02:00
David Lawrence Ramsey fc0e16f6bc text: move the unindenting of a single line into its own function 2017-09-10 12:59:04 +02:00
David Lawrence Ramsey 57d7f8852d text: move the indenting of a single line into its own function
This is modeled after the undo/redo code for commenting.  do_indent() now
calls indent_a_line() on each line it covers.  The latter function will
eventually be used by the undo/redo code.
2017-09-10 12:43:10 +02:00
Benno Schulenberg 807f5c2e69 tweaks: do not leak the indentation when all lines are empty 2017-08-16 17:16:18 +02:00
Benno Schulenberg 1b2a091de9 tweaks: condense or improve some comments
Also reshuffle an initialization and drop two useless asserts.
2017-08-16 17:10:40 +02:00
Benno Schulenberg bd770ea2e7 text: properly unindent lines that consist of only whitespace
The preceding 'for' loop has already established that all the lines are
either unindentable or composed of only blanks.  So if now a line cannot
be unindented, it means it is fully blank, so it can be simply skipped.

This fixes https://savannah.gnu.org/bugs/?51760.
Reported-by: David Lawrence Ramsey <pooka109@gmail.com>
2017-08-16 16:42:44 +02:00
Benno Schulenberg d8e5799e84 tweaks: adjust the indentation after the previous change
Also, trim or improve some comments.
2017-08-15 10:38:58 +02:00
David Lawrence Ramsey 0f4716e168 text: make unindenting remove from the beginning of the line
Also, only unindent when all selected lines can be unindented,
which means that the relative indentation will be preserved.
For this purpose, it ignores empty lines and lines consisting
of only whitespace.

When unindenting is not possible, a message is shown.

This fixes https://savannah.gnu.org/bugs/?47684.
2017-08-15 10:38:58 +02:00
David Lawrence Ramsey 749b1b3d79 text: make indenting add to the beginning of the line
Instead of inserting the extra whitespace after the current indentation
of a line, add it to the start of the line.  This causes a fixed amount
of visual whitespace to be added regardless of whether --tabstospaces
is used or not.

This fixes http://savannah.gnu.org/bugs/?51438,
and its ancestor https://savannah.gnu.org/bugs/?51408.
2017-08-15 10:38:58 +02:00
Benno Schulenberg 11072ed587 tweaks: sort the includes, so it's a little easier to see what is there 2017-08-06 19:40:30 +02:00
Benno Schulenberg 80686bb525 tweaks: remove includes that appear to be superfluous
Without them, nano still compiles for me, with everything enabled,
even when using --enable-debug, --enable-utf8, and --with-slang.
2017-08-06 09:08:30 +02:00
David Lawrence Ramsey ac2c81fad1 tweaks: correct a comment typo and an indentation error 2017-07-31 21:42:39 +02:00
Benno Schulenberg 5dcf375f33 linting: skip the introductory message produced by 'gcc -fshow-column'
Assume that a linter line that contains an actual error message or
warning includes a colon followed by a space -- something that that
opening message from a modern gcc lacks.
2017-07-29 13:15:22 +02:00
Benno Schulenberg 50379cc4ff tweaks: elide an unneeded pointer 2017-07-27 22:05:19 +02:00
David Lawrence Ramsey e2d3ee2364 tweaks: replace a misplaced tab with a space 2017-07-27 21:58:00 +02:00
Benno Schulenberg 79c836b11b tweaks: drop some debugging stuff, and frob two comments 2017-07-27 21:45:53 +02:00
Benno Schulenberg c24432edc4 linting: don't try to put the cursor at a negative x position
Human column numbers are one-based, whereas x positions are zero-based.
Converting from the one to the other involves subtracting one.  But when
the linter message does not provide a column number, the latter defaults
to zero.  Catch that case and change the number to one.

This fixes https://savannah.gnu.org/bugs/?51550.
2017-07-26 21:31:41 +02:00
David Lawrence Ramsey 85bffcfeb9 tweaks: use charalloc() instead of (char *)nmalloc() * sizeof(char)
The charalloc() macro does exactly this.
2017-07-25 21:50:13 +02:00
David Lawrence Ramsey 381a386b01 weeding: drop the forreal parameter from place_the_cursor()
Commit 28beb3f added the 'forreal' parameter to prevent spotlight() from
placing the cursor wrongly due to an invalid placewewant.  However, since
the variable-width softwrap overhaul (specifically, since commit 8490f4a),
place_the_cursor() no longer checks placewewant, so the parameter is no
longer needed.

Furthermore, dropping 'forreal' and thus always setting current_y won't
affect the operation of spotlight(), since the only functions that use
spotlight() (do_replace_loop() and do_int_spell_fix()) both call
edit_refresh() beforehand, which means that current_y will already
have been set to the value it will be set to again.
2017-07-24 21:07:42 +02:00
Benno Schulenberg 14c5f03e38 tweaks: rename another constant, to be more precise 2017-07-14 16:18:41 +02:00
Benno Schulenberg 1e2d9a697a tweaks: rename a constant, to match the corresponding option 2017-07-14 16:14:02 +02:00
Benno Schulenberg 5df47bfef6 display: avoid a jumpy cursor by redrawing bottom bars only when needed
The help lines need to be redrawn one step after a justification
(whether it has been undone or not, to replace "Unjustify" with
"Uncut" again for ^U), and after switching buffers (to update a
possibly changed tag for ^T).

This fixes https://savannah.gnu.org/bugs/?51455.
2017-07-13 11:10:51 +02:00
David Lawrence Ramsey fb51d617fd text: adjust the comments in do_indent() and do_unindent()
Make them reflect the split into two functions, the direct use of
tabsize, and the difference in behavior between indent and unindent.
2017-07-12 17:24:46 +02:00
David Lawrence Ramsey 7e9799d42b text: remove the last usage of cols in do_indent() and do_unindent()
Since all indentation and unindentation is by a tab, or by a tab's
worth of spaces, use tabsize directly.
2017-07-12 17:23:46 +02:00
David Lawrence Ramsey d02c1993d8 text: normalize the indentation in do_indent() and do_unindent()
Also remove one unneeded blank line.
2017-07-12 16:58:23 +02:00
David Lawrence Ramsey 42f5a84c6f text: remove indent-related code from do_unindent() 2017-07-12 16:57:20 +02:00
David Lawrence Ramsey 109ad0915d text: remove unindent-related code from do_indent() 2017-07-12 16:56:36 +02:00
David Lawrence Ramsey ee52f45b01 text: remove unneeded references to cols from the indentation routines
The parameter 'cols', that indicates how many columns to indent or
unindent, is changed to be always positive, so the check for being
negative can go.  And it could never be zero anyway.
2017-07-12 16:51:21 +02:00
David Lawrence Ramsey 2367f3d8e6 text: make do_unindent() an exact copy of do_indent()
This is the first step toward splitting them into two dedicated
functions, instead of letting do_indent() handle both cases.
2017-07-12 16:45:41 +02:00
Benno Schulenberg ecc7c26641 tweaks: rename a variable, to have more contrast 2017-07-09 21:11:01 +02:00
Benno Schulenberg fbbf501f8f tweaks: rename four functions, to be more distinct 2017-07-09 21:07:38 +02:00
David Lawrence Ramsey aa04ad4f83 replacing: make spotlight() account for varying chunk width
spotlight() now displays softwrapped lines chunk by chunk instead of all
at once.  Since softwrapped lines are no longer of constant width, the
latter approach would fail if softwrapping breaks the spotlighted text.

Instead of taking a string, spotlight() now takes the starting and ending
columns of that string.  Also, its handling of softwrapped lines is now
split off into a separate function, spotlight_softwrapped().
2017-07-07 13:07:10 +02:00
David Lawrence Ramsey e375995d98 softwrap: add new functions for chunks of varying width
get_chunk_row() replaces the formula "column / editwincols".

get_chunk_leftedge() replaces "(column / editwincols) * editwincols".

get_last_chunk_row() replaces "strlenpt() / editwincols".

get_last_chunk_leftedge() replaces "(strlenpt() / editwincols) * editwincols".

This prepares us for any changes in those formulas, and for more such
functions later.
2017-07-07 13:07:10 +02:00
David Lawrence Ramsey 5bc4abeefe text: update placewewant properly when indenting/unindenting
If the position of the cursor changes horizontally,
placewewant should change with it.

This fixes https://savannah.gnu.org/bugs/?51407.
Reported-by: David Lawrence Ramsey <pooka109@gmail.com>
2017-07-07 12:09:14 +02:00
Benno Schulenberg 1439016c20 tweaks: recognize the empty string as comment inhibitor, instead of NULL 2017-07-07 10:15:17 +02:00
David Lawrence Ramsey 7c41c8641f tweaks: remove unneeded braces, and mark empty parameter list as void
This matches the style in the rest of the code.
2017-07-03 09:52:13 +02:00
Benno Schulenberg 14bd52ced8 display: wipe stale messages from the status bar straightaway
When blank_statusbar() has been called, make sure it is effective.

This fixes https://savannah.gnu.org/bugs/?51358.
2017-07-02 19:57:11 +02:00
Benno Schulenberg 7d46eff738 display: when back in the main loop, always redraw the help lines
(Well, redraw them when they're switched on, of course.)  Redraw
them so that they are shown correctly if their content changed.

This fixes https://savannah.gnu.org/bugs/?51356.
and fixes https://savannah.gnu.org/bugs/?51357.
2017-07-02 19:57:11 +02:00
David Lawrence Ramsey 2abe7c03fe text: make sure commenting is disabled when comment "" was specified
When the active syntax contains a comment command that specifies the
empty string, this should override the default comment of "#" and
should disable the Meta-3 keystroke.

To achieve this, the comment string is now set by default to "#" for
all syntaxes, so that it will be set when no comment command is given
(including for the "none" syntax), and is unset only by explicitly
specifying «comment ""» in a syntax file.

This fixes https://savannah.gnu.org/bugs/?51355.
Reported-by: David Lawrence Ramsey <pooka109@gmail.com>
2017-07-02 19:44:56 +02:00
Benno Schulenberg bf72cdd814 tweaks: rename two variables, to make a little sense
And rename a third variable, to match another in its style.
2017-07-02 12:05:12 +02:00
Benno Schulenberg 4239e5fe1a tweaks: put declarations always first, so it will compile on Haiku 2017-07-02 11:53:59 +02:00
Benno Schulenberg 6ad3d3d6c0 display: show the cursor position also when searching took a while
Achieve this by making the suppression flag global, so that we can
just reset it instead of making an improper call of do_cursorpos().

This fixes the secondary part of https://savannah.gnu.org/bugs/?51134.
2017-05-29 22:15:38 +02:00
Benno Schulenberg 5cdadc3eb1 tweaks: avoid an unused-variable warning when using --disable-comment 2017-05-19 11:55:37 +02:00
Benno Schulenberg 28beb3f9c5 replacing: don't let placewewant influence the placement of the cursor
When spotlighting the string to be replaced, placewewant isn't valid,
so tell place_the_cursor() to ignore its value to avoid the cursor
getting mistakenly placed at the beginning of the next row.

This fixes https://savannah.gnu.org/bugs/?50997.
Reported-by: David Lawrence Ramsey <pooka109@gmail.com>
2017-05-11 22:28:34 +02:00
Benno Schulenberg 46430999d5 build: make --enable-help properly depend on --enable-multibuffer
And in the process transform the token DISABLE_HELP to ENABLE_HELP.
2017-04-25 18:27:55 +02:00
Benno Schulenberg 040bd93cc4 tweaks: distinguish (in the comments) between buffers and linestructs
Call something a buffer when it refers to a linked list of linestructs,
and call something a linestruct when it is a struct that describes a
single line.
2017-04-19 17:48:52 +02:00
Benno Schulenberg a43eee6aec tweaks: fix compilation with --enable-tiny --enable-color --enable-speller
Also avoid an unused-variable warning, and trim a useless assert.
2017-04-19 14:30:36 +02:00
Benno Schulenberg 74f128859b tweaks: rename a constant, to match the corresponding option 2017-04-17 11:51:48 +02:00
Benno Schulenberg 3dc6ccbe86 tweaks: rename a function, to be more accurate
Because nothing gets reset to zero or to some initial value.
2017-04-17 11:29:29 +02:00
Benno Schulenberg 2439e1e451 linting: treat a tab as one "column", not eight
This fixes https://savannah.gnu.org/bugs/?47131.
2017-04-10 20:32:36 +02:00
Benno Schulenberg dab70d06ed linting: when no is said to a file, remove all corresponding entries
When the user chooses not to open a file that some message refers to,
remove all messages for that file from the linting results, so the user
does not get asked about that same file again.

This fixes https://savannah.gnu.org/bugs/?47130.
2017-04-10 19:55:46 +02:00
Benno Schulenberg 754c62c5cc copyright: update the years, use ranges, and explain this usage
The interval 2013-2017 for the Free Software Foundation is valid
because in those years there were releases with changes by either
Chris or David, and the GNU maintainers guide advises to mention
a new year in all files of a package, not just in the ones that
actually changed, and be done with it for the rest of the year.
2017-04-09 12:09:23 +02:00
Benno Schulenberg 005ee8eda6 editing: avoid creating blank lines when using autoindent
When Enter is pressed while the cursor is exactly on the current
indent width, remove the blank characters on that line to avoid
creating a line that consists only of trailing whitespace.

(When Enter is pressed somewhere in the middle of the blanks,
however, the whitespace is preserved.)

Suggested-by: Florian Zeitz <florob@babelmonkeys.de>
2017-04-06 20:34:04 +02:00
Benno Schulenberg aedc3ddd49 tweaks: replace a function call or a macro with a hard number
Verify at startup that the number is not too small.
2017-04-04 19:17:02 +02:00
Benno Schulenberg 53cea142e0 tweaks: use memory on the stack instead of calling malloc() and free()
Rename some variables in the process, and remove two cluttering asserts.
2017-04-04 19:14:14 +02:00
Benno Schulenberg 582a624998 tweaks: frob some parentheses and other things, to be more consistent 2017-03-29 19:30:37 +02:00
David Lawrence Ramsey c888edf409 softwrap: save and restore firstcolumn when internally spell-fixing text
In do_int_spell_fix(), spell-checking text may change firstcolumn if
the next match is offscreen, and spell-checking text after that will
not change it back.  In order to keep the viewport unchanged, we have
to save and restore not just edittop, but firstcolumn as well.
2017-03-22 10:44:06 +01:00
David Lawrence Ramsey 7cd50b8c02 softwrap: save firstcolumn when justifying, restore it when unjustifying
In do_justify(), justifying text may change firstcolumn if the paragraph
ends offscreen, and unjustifying the text again will not change it back.
In order to keep the viewport unchanged, we have to save and restore not
just edittop, but firstcolumn as well.
2017-03-22 10:44:06 +01:00
David Lawrence Ramsey 80b3a3011b weeding: remove ensure_line_is_visible()
Since all lines can be partially scrolled off the screen now
(except for the top line of the edit window, which is forthcoming),
ensure_line_is_visible() is no longer needed.
2017-03-22 10:44:05 +01:00
Benno Schulenberg d42f71a2ef tweaks: avoid a few needless reallocations
Most of these variables are freed moments later -- reallocating
them is thus a waste of time.
2017-03-20 13:07:57 +01:00
Mike Frysinger 3deec4352b assume regex.h support is always available
Now that we pull in the gnulib regex module, we can assume it exists.
2017-03-06 12:01:08 +01:00
Benno Schulenberg 0af5788a94 tweaks: reduce the scope of five variables, and frob some comments 2017-03-01 09:56:38 +01:00
Benno Schulenberg d5b950cc29 tweaks: don't turn the mark off before it's needed
The mark only needs to be off when calling replace_marked_buffer(),
because this indirectly calls ingraft_buffer(), which fiddles with
the end points if the mark is on.
2017-03-01 09:35:45 +01:00
Benno Schulenberg adf69a05f1 spelling: keep the cursor at end-of-line if it was there
This fixes https://savannah.gnu.org/bugs/?50415.
2017-02-28 20:45:49 +01:00
David Lawrence Ramsey 29681e0e9f weeding: remove partitioning and related stuff from do_justify()
Replace partitioning with calls to extract_buffer() and ingraft_buffer().

In addition to pasting the unjustified text back into the buffer at
current[current_x], ingraft_buffer() also deals with renumbering and
updating totsize, so do_justify() doesn't need to do those anymore
when unjustifying.
2017-02-28 14:35:44 +01:00
David Lawrence Ramsey 234bd9c9be speller: fix replacing marked text in the alternate spell checker
With read_file() revamped, it now uses partition_filestruct() indirectly
via ingraft_buffer(), so we can't use partition_filestruct() to replace
marked text in the alternate spell checker anymore without segfaulting.

Add the new function replace_marked_buffer() to accomplish this instead.
Based on replace_buffer(), it uses extract_buffer() to throw away the
marked un-spell-checked text, and then uses read_file() to insert the
spell-checked text at the position where the mark was.

Accordingly, remove unneeded partitioning and related stuff from
do_alt_speller().  Besides pasting the file into the buffer at
current[current_x], ingraft_buffer() also deals with renumbering,
updating totsize, and handling a magicline, so do_alt_speller()
doesn't need to do those anymore.
2017-02-28 14:35:44 +01:00
David Lawrence Ramsey 0d9313763d undo: fix undoing/redoing insertions, since they no longer do partitioning 2017-02-28 14:35:44 +01:00
Benno Schulenberg e5731fe198 tweaks: reshuffle three statements, and shorten a comment 2017-02-25 12:33:01 +01:00
Benno Schulenberg 2bbb6cfeb5 wrapping: add the correct char length when skipping consecutive blanks
In this last loop of break_line(), the pointer 'line' is one step ahead
of the index 'lastblank'.  So the loop should first add the length of
the preceding character to 'lastblank' before determining the length
of the current character (and using this to advance 'line').
2017-02-25 11:18:24 +01:00
Benno Schulenberg 1623bc7779 tweaks: rename three variables, to better distinguish bytes from columns
(There is something wrong in the last loop: line is one character ahead
of lastblank, but the current character length is added to both of them.
It thus assumes that all blank characters are the same number of bytes.
For spaces and tabs this works fine.  But for more exotic blanks...)
2017-02-24 22:08:55 +01:00
Benno Schulenberg 99ecd33c18 tweaks: elide two variables, and condense some statements
Also, remove an assert and adjust some comments.
2017-02-24 21:11:37 +01:00
David Lawrence Ramsey 6500f769aa tweaks: move comments outside of if blocks in break_line() 2017-02-24 21:04:31 +01:00
David Lawrence Ramsey f95836a951 tweaks: remove cluttering #ifdefs from break_line()
Also, rename a parameter to be less cryptic, and remove an entire
condition because the relevant block will never be reached when
getting called from the help routines: if blank_loc is negative,
the function will have bailed out in the preceding if.
2017-02-24 17:33:39 +01:00
Benno Schulenberg 07ebba5e99 tweaks: rename a variable and invert its logic 2017-02-24 12:21:59 +01:00
Benno Schulenberg de3260cdb1 justify: reduce the character count when trimming trailing spaces
This fixes https://savannah.gnu.org/bugs/?50379.
2017-02-22 17:29:39 +01:00
David Lawrence Ramsey 1cb945fe8e tweaks: rename the functions for moving to and copying from a buffer
The name "filestruct" was a mistake.  What was meant was:
buffer -- a linked list of structs that each describe a line.
2017-02-17 20:06:32 +01:00
Benno Schulenberg d60e7d374c spelling: correctly adjust the length of a single-line region
When the marked region covers only a single line (or a part of it),
its new endpoint is not simply the length of the last line of the
spell-checked text, but instead the old endpoint plus the /change/
in length.

This fixes https://savannah.gnu.org/bugs/?50316.
Reported-by: David Lawrence Ramsey <pooka109@gmail.com>
2017-02-16 11:52:24 +01:00
Benno Schulenberg 914af36546 spelling: don't unnecessarily fiddle with the viewport
If we're somewhere deep into the file and do a spell check, and the
first misspelled word happens to be right there, onscreen already,
then this word does not need to be centered -- it /should/ not be
centered.  We should scroll only when necessary.
2017-02-10 22:09:03 +01:00
Benno Schulenberg 8f10e364bb replacing: stop searching in a region when edge of buffer is reached
Just like when spell-checking, there is no need to wrap around when
doing replacements in a region, because a region cannot straddle the
buffer's edges.

This is the proper fix for https://savannah.gnu.org/bugs/?50158,
and fixes https://savannah.gnu.org/bugs/?50273.
2017-02-10 13:51:51 +01:00
David Lawrence Ramsey 83ff644b6a tweaks: do a comparison a bit differently in do_output() and do_deletion()
Make it clearer we're comparing the number of rows, not string lengths.
2017-02-05 12:30:09 +01:00
Benno Schulenberg 94e563232e general: stop the spell checker from crashing after the changes in search
The spell fixer does not provide a beginning line, so the search routine
should then not try to refer to any data of this line.  Also, since the
changes to the search routine there is no need any more to retreat one
step before starting to search for a misspelled word.

This fixes https://savannah.gnu.org/bugs/?50159.
2017-01-26 20:21:41 +01:00
Benno Schulenberg ef7a7c5360 replacing: ignore the first match when the user said no
When the user answered No to a replacement prompt, skip the match
at the current position, so we don't stay stuck there.

Also, when replacing in the backward direction, or the match is
of length zero, skip the match at the current position, to not
get stuck.

This fixes https://savannah.gnu.org/bugs/?50126.
Reported-by: David Lawrence Ramsey <pooka109@gmail.com>

This also fixes https://savannah.gnu.org/bugs/?50137,
and refixes https://savannah.gnu.org/bugs/?48635,
and fixes https://savannah.gnu.org/bugs/?50144.
2017-01-26 17:41:49 +01:00
Benno Schulenberg c0aa5ad258 tweaks: miscellaneous frobbings 2017-01-09 18:25:25 +01:00
Benno Schulenberg 322120c980 undo: properly create separate items for deletes at different positions
That is: only extend the current Del or Backspace undo item when the
cursor is still (or again) at the same spot.

This fixes https://savannah.gnu.org/bugs/?50006.
2017-01-08 11:05:52 +01:00
Benno Schulenberg fd0589d8bc tweaks: remove the cluttering conditional compilation of a parameter
The conditionalizing saved negligible amounts of space, of memory, and
of speed.
2017-01-03 14:11:45 +01:00
Benno Schulenberg a381021ffc tweaks: when allow_tabs is FALSE, allow_files is irrelevant
In that case setting the latter to TRUE is misleading.  So don't do that.
2017-01-03 14:02:52 +01:00
David Lawrence Ramsey b1c20629f5 weeding: remove unnecessary settings of openfile->current_y
Many of the adjustments of the value of openfile->current_y appear to be
a holdover from the days when certain functions had to account for what
is now called STATIONARY scrolling mode, which depends on the value of
current_y.  Remove these adjustement where they are superfluous.

do_para_begin(), do_para_end(), and do_bracket_match() update the screen
through edit_redraw(), which uses either CENTERING or FLOWING scrolling
mode, so their setting of current_y is redundant and useless, as it will
be ignored and then overridden by the next call to reset_cursor().

findnextstr() is called by go_looking() [which calls edit_redraw(), see
above], and by do_replace_loop() and do_int_spell_fix(), which both call
edit_refresh(), which in this case only uses CENTERING scrolling mode
since focusing is TRUE.

(Additionally, the adjustments of current_y in findnextstr() and
do_bracket_match() use incorrect values when in softwrap mode.)

find_paragraph() doesn't need to save or restore current_y, because it
doesn't do any screen updates.  do_justify() calls edit_refresh() with
focusing set to TRUE, so it uses the CENTERING scrolling mode.

do_alt_speller() and do_formatter() do not need to save and restore
current_y, because they don't modify it in any way.

This addresses https://savannah.gnu.org/patch/?9197.
2017-01-02 12:40:21 +01:00
Benno Schulenberg 7373e4cd46 tweaks: fix compilation when configured with --disable-wrapping 2017-01-01 16:33:40 +01:00
Benno Schulenberg d3429a7a57 copy: properly set preferred x position when region was marked backwards
This fixes https://savannah.gnu.org/bugs/?49964.
2016-12-31 16:36:14 +01:00
Felix Janda fc89ac11d2 speller: fix build when tiny build is enabled
URL: https://bugs.gentoo.org/604000
2016-12-29 13:43:06 -05:00
Benno Schulenberg 588daf949e tweaks: condense the setting of three flags 2016-12-25 13:11:17 +01:00
Benno Schulenberg d21a9c8fc3 text: discard the undo stack after formatting and after spell checking
After a call to the Formatter or the Alternate spell checker, the data
on the undo stack could refer to line positions that don't exist any
more -- the chance is small, but it is there.  So... throw the whole
undo stack away, to prevent undoing things wrongly or even crashing.

(Changes made with the internal spell checker can be undone and redone
without a problem -- nano keeps full track of those.  But the changes
made with a formatter or an external spell checker happen in another
process, so nano has no record of them.)

This fixes https://savannah.gnu.org/bugs/?49920.
2016-12-24 12:22:50 +01:00
Benno Schulenberg edbc1e5950 text: avoid a crash when a spell-checked line has gotten shorter
When using an external spell checker or formatter, the line with
the cursor might become shorter, which might result in the stored
cursor position being beyond the end-of-line.  So, when restoring
the x position, make sure to limit it to the length of the line.

This fixes https://savannah.gnu.org/bugs/?49923.
2016-12-24 12:22:17 +01:00
Benno Schulenberg 6620acbff4 tweaks: use a faster comparison 2016-12-20 10:03:53 +01:00
Benno Schulenberg 1cb6619d6a undo: there are just two forms of deletion: backspacing and deleting
A third method does not exist.
2016-12-19 21:18:43 +01:00
Benno Schulenberg 79a4bf81dc tweaks: rename five variables, for uniformity with a few others 2016-12-19 19:58:15 +01:00
Benno Schulenberg 9fa95a3680 tweaks: put some prototypes in the proper order, and move a bit of code 2016-12-15 13:04:52 +01:00
Benno Schulenberg ea9f62fc0f tweaks: adjust some comments and indentation and ordering 2016-12-13 19:27:33 +01:00
Benno Schulenberg 13ec5d8ce9 spelling: correctly restore the selected region
An added magic linefeed should be removed again /before/ restoring
the x position, as the latter needs to be calculated from the real
last line of the region.

This fixes https://savannah.gnu.org/bugs/?49817.
Reported-by: Mike Frysinger <vapier@gentoo.org>
2016-12-11 09:55:38 +01:00
Benno Schulenberg 173bbe11ef tweaks: add a few translator hints 2016-12-07 21:05:41 +01:00
Benno Schulenberg 7531b71fa1 docs: note Sumedh as the author of the word-completion feature 2016-12-07 21:05:23 +01:00
Benno Schulenberg 964c10db17 tweaks: miscellaneous frobbings and rewrappings 2016-12-07 20:37:08 +01:00
Benno Schulenberg 68a0314500 build: add configure option --disable-wordcomp to disable word completion
(The variable 'pletion_line' is not conditionalized with this option, as
it would become messy.  The compiler will probably be able to elide it.)

When using --enable-tiny, it is not possible to use --enable-wordcomp,
because the word completion function uses the undo system.
2016-12-07 17:02:25 +01:00
Sumedh Pendurkar dca4ab5d8f new feature: complete a fragment to a longer word found in the buffer
Executing the 'complete_a_word' function will search from the start
of the current buffer for entire words that begin with the fragment
that is before the cursor, and will complete this fragment to the
first word that is found.  Each consecutive call of 'complete_a_word'
will search for the next matching word and will complete the fragment
to that.  By default the function is bound to the ^] keystroke.

Signed-off-by: Sumedh Pendurkar <sumedh.pendurkar@gmail.com>
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2016-12-07 16:42:39 +01:00
Benno Schulenberg 86121cf3fc tweaks: move a cursor-on switch to a more logical place (again)
But do it correctly this time: don't switch it on when replacing.
2016-12-05 15:47:44 +01:00
Benno Schulenberg f920e0d30c tweaks: replace some unneeded direct calls of edit_refresh() 2016-12-03 17:00:28 +01:00
Benno Schulenberg 0f3e303d1a tweaks: get rid of some spurious textual references to edit_refresh() 2016-12-02 18:13:10 +01:00
Benno Schulenberg e4b8d6fab5 tweaks: remove a bit of obscuring conditional compilation 2016-11-30 11:46:05 +01:00
Benno Schulenberg 7598b77e75 screen: use the correct width to determine whether a softwrap occurred
This fixes the two bugs reported by Anton Minaev
in https://savannah.gnu.org/bugs/?49511.
2016-11-13 19:20:38 +01:00
Benno Schulenberg 2cd8ca4eb1 tweaks: stop compiling the whole_word_only parameter conditionally
This make tiny nano slightly less tiny, but makes the code more readable.
2016-10-23 20:07:30 +02:00
Benno Schulenberg 01bbf7e82f tweaks: rename a function to better describe what it does
It does not update anything -- it just picks a new point from
where to start displaying the buffer.  All actual updating of
the screen is done by edit_refresh() and edit_redraw() and such.
2016-10-23 17:26:19 +02:00
Benno Schulenberg 43f35fc7a9 softwrap: ensure the current line is fully visible when moving in it
This fixes https://savannah.gnu.org/bugs/?49099,
and fixes the unreported corresponding bugs for
<End> and <Del> and typing extra characters.
2016-10-18 15:07:47 +02:00
Benno Schulenberg 3264d0c5be tweaks: move a variable that doesn't need to be global 2016-10-12 19:59:26 +02:00
Benno Schulenberg d9148e7b3f tweaks: elide an unneeded variable 2016-10-12 19:20:39 +02:00
Benno Schulenberg 08cd197bf1 general: include word-jumping and block-jumping into the tiny version
And also case-sensitive searches, backward searches, and searching again.
2016-09-13 09:27:04 +02:00