Commit Graph

1194 Commits (5f00b02f7cae365429bd0ebfa4ef3af4359554f5)

Author SHA1 Message Date
Benno Schulenberg 1f55c8819b tweaks: swap the names of two variables, to make more sense
An iterator should not be called "start_col", because it is only the
starting column at the very beginning.

Also, start_col (after the rename) can never be /larger/ than column.
2017-04-28 15:48:50 +02:00
Benno Schulenberg 03ecbf3d55 tweaks: remove a superfluous check
The mbwidth() function itself checks whether UTF-8 is being used
and does the right thing.
2017-04-28 15:47:53 +02:00
Benno Schulenberg 26fe2118c4 docs: update the list of who authored what
Also, mention that help texts can now be searched through, update
a copyright notice, and update and simplify a copyright year.
2017-04-25 20:32:05 +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 f9fea02fc5 help: suppress nano's name and number to make it clearer this is help
The top-left corner changing is far more conspicuous than the top right.
2017-04-25 17:21:02 +02:00
Rishabh Dave 90bd25c1bb new feature: add a search facility to the help viewer
Allow the user to search in a help text with ^W and M-W.

Achieve this by not writing the help text directly to the screen
but first writing it to a temporary file and then opening this file
in a new buffer, and treating it specially: the normal file-reading
feedback is suppressed, the titlebar shows the headline of the text,
the cursor is hidden, and the menu is limited to just the up and down
movements and searching.

This fulfills https://savannah.gnu.org/bugs/?28994.

Signed-off-by: Rishabh Dave <rishabhddave@gmail.com>
2017-04-25 17:20:34 +02:00
Benno Schulenberg ca6d7b6a46 input: avoid crashing when resizing the window during verbatim input
This fixes https://savannah.gnu.org/bugs/?50872.
2017-04-25 13:01:21 +02:00
Benno Schulenberg 861d81edba scrolling: don't bother to limit the number of lines to step back
The go_back_chunks() function will do this clipping.

This fixes https://savannah.gnu.org/bugs/?50866.
2017-04-24 19:48:55 +02:00
Benno Schulenberg 1fbe7596f8 options: allow -U (--quickblank) to be used in the tiny version
It takes almost no code and is a useful little improvement over Pico.
2017-04-19 13:47:40 +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 b98545f455 display: push the titlebar to the screen as soon as it has been drawn
To avoid an ncurses hiccup (miscoloring) when running on musl.

This fixes https://savannah.gnu.org/bugs/?50787.
Reported-by: Avi Halachmi <avihpit@yahoo.com>
2017-04-17 10:53:38 +02:00
Benno Schulenberg 5a741a0205 tweaks: remove some superfluous placements of the cursor
The cursor needs to be placed in its proper spot in the edit window
/only/ when nano is about to accept input from the user and needs to
show where this input will go.

(This might cause a scrolling issue to appear, because reset_cursor()
does not just place the cursor, it also recomputes current_y, which
is used in several places to determine whether and how much to scroll.
If it so happens, we'll deal with that fallout later.)
2017-04-17 10:35:05 +02:00
Benno Schulenberg 6723ac6fcc tweaks: add three warnings for conditions that should never occur 2017-04-17 10:17:47 +02:00
Benno Schulenberg 999d99c6e4 tweaks: delete a function that hasn't been used since 2005 2017-04-09 13:33:25 +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
David Lawrence Ramsey 23ae7bfbbf input: support escape sequences for ^Home and ^End
Make nano recognize the escape sequences for Ctrl-Home, Ctrl-End,
Shift-Ctrl-Home, and Shift-Ctrl-End on xterm, rxvt, and Eterm.
2017-04-06 21:25:41 +02:00
Benno Schulenberg cb0806b2a0 bindings: make ^Home and ^End go to top and tail of buffer
On some terminal emulators, Ctrl+Home and Ctrl+End produce special
keycodes, distinct from plain Home and End.  Make the users of those
emulators (and of the Linux console) glad by making ^Home and ^End
do the obvious thing, and the combinations with Shift too.
2017-04-06 21:19:00 +02:00
Benno Schulenberg f3e2ad945d display: with softwrap, show the cursor where the eye expects it
When a multi-column character straddles a chunk boundary, and the
preferred column (placewewant) for the cursor is zero, cheat: show
the cursor not where the character starts but on the beginning of
the next row.  This makes the cursor move smoothly in the leftmost
column of the screen when using <Up> and <Down> and such, instead
of jumping around.

In this way the scrolling logic won't get confused and the screen
will scroll properly when stepping beyond the top or bottom row.

This fixes https://savannah.gnu.org/bugs/?50687.
2017-04-06 19:51:07 +02:00
Benno Schulenberg 6ec65d5500 display: check the correct character for being double-width
This fixes https://savannah.gnu.org/bugs/?50741.
2017-04-06 17:39:58 +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
David Lawrence Ramsey f9a8d6ff4e scrolling: properly compensate for the onscreen chunks
If edittop is partially offscreen before we scroll, and it gets
scrolled more offscreen, we do need to compensate for the chunks
between firstcolumn and leftedge -- that is: the chunks between
the top row and the cursor row.

This fixes https://savannah.gnu.org/bugs/?50691.
2017-04-04 10:55:24 +02:00
David Lawrence Ramsey c3830517cc display: show '<' and '>' placeholders for characters that get split
When a two-column character cannot be shown because it straddles the
boundary between two chunks of a line, show the '>' placeholder for
its left "half", and '<' for its right "half".

This mitigates https://savannah.gnu.org/bugs/?49440.
2017-04-03 21:51:46 +02:00
Benno Schulenberg 33cefa9208 tweaks: elide an intermediate variable 2017-03-29 10:20:41 +02:00
Benno Schulenberg 873e3d6fa6 tweaks: don't loop over an initializer 2017-03-29 10:13:08 +02:00
Benno Schulenberg 54e4505b2f tweaks: frob a couple of comments 2017-03-28 19:44:41 +02:00
Benno Schulenberg 8091d0a574 tweaks: simplify and correct a computation
The leftedge variable is a column number, not an x position.
2017-03-28 19:24:37 +02:00
David Lawrence Ramsey 93c6248956 display: don't compensate for chunks before firstcolumn
The number of rows to draw shouldn't be compensated for the chunks
of edittop that are before firstcolumn, because they are offscreen.

This completes the fix for https://savannah.gnu.org/bugs/?50621.
2017-03-28 19:10:45 +02:00
David Lawrence Ramsey 66ef8f45a3 display: don't draw more chunks than the screen can hold
There is no need to always increase nrows by 1 or 2 -- an increase
of 1 is only needed when the line that borders on the scrolled region
needs to redrawn too: when this line was horizontally scrolled or when
the mark is on.

This fixes https://savannah.gnu.org/bugs/?50621.
Reported-by: David Lawrence Ramsey <pooka109@gmail.com>
2017-03-28 12:32:51 +02:00
Benno Schulenberg 58faff50ae tweaks: shorten a bit of logic 2017-03-24 21:37:06 +01:00
David Lawrence Ramsey 87a7c2e42d tweaks: fix a comment typo 2017-03-24 21:21:51 +01:00
Benno Schulenberg e46c6c9607 tweaks: ehm... the warning is more important for the softwrap case
But apparently none of these cases occur, because I can't trigger them.
2017-03-22 11:05:22 +01:00
Benno Schulenberg 8b7bbebeeb tweaks: add a warning for a condition that should never occur 2017-03-22 10:50:59 +01:00
Benno Schulenberg 55159b7b39 painting: don't try to start highlighting before column zero
This could happen when a tab or a double-width character straddles
the boundary between two softwrapped chunks.
2017-03-22 10:44:06 +01:00
David Lawrence Ramsey 0389a1d939 softwrap: adjust firstcolumn when the window width changes
If the number of columns in the edit window changes (which currently
only happens in two places: in regenerate_screen(), called when the
window is resized; and in main(), when line numbering mode is toggled),
the display will break if we're in softwrap mode and firstcolumn is
nonzero.  This is because the column width of softwrapped chunks has
changed, and firstcolumn is no longer the starting column of a chunk,
an assumption that all code using firstcolumn relies on.

To fix this problem, add a new function, ensure_firstcolumn_is_aligned(),
to adjust firstcolumn to the starting column of the chunk it's on, and
use it when the number of columns in the edit window changes.

(Note that this function uses the simplest possible fix, and could
probably be made more sophisticated.)
2017-03-22 10:44:06 +01:00
David Lawrence Ramsey 2f6c8987ea softwrap: move the updating of a softwrapped line to a new function
The new function, update_softwrapped_line(), is called from inside
update_line() when softwrap mode is on, so that existing calls remain
unchanged.  It takes no index, instead displaying edittop from column
firstcolumn, and all other lines from column zero.

If current is on edittop, it's displayed using the edittop rules, but
this is not a problem: if current[current_x] is above edittop at column
firstcolumn, it's offscreen, and that should be handled before calling
update_line() anyway.

Together with the preceding bunch of changes,
this fixes https://savannah.gnu.org/bugs/?47667.
2017-03-22 10:44:05 +01:00
David Lawrence Ramsey 98b029cf3e softwrap: account for firstcolumn in reset_cursor()
When counting rows in softwrap mode, reset_cursor() should compensate for
the number of softwrapped chunks that edittop takes up before firstcolumn.
2017-03-22 10:44:05 +01:00
David Lawrence Ramsey c0fa3f04b1 softwrap: account for firstcolumn when checking for offscreen current
Make current_is_above_screen() check for current[current_x] being above
edittop at column firstcolumn, and make current_is_below_screen() start
counting down from edittop at column firstcolumn instead of edittop at
column zero.  This means that both functions now account for softwrapped
chunks properly.
2017-03-22 10:44:05 +01:00
David Lawrence Ramsey e52d5b0672 softwrap: remove and replace workarounds for firstcolumn
Actually enable scrolling edittop partially off the screen by making
edit_scroll() and adjust_viewport() use firstcolumn properly when
iterating through softwrapped chunks in softwrap mode, or lines in
non-softwrap mode.

In non-softwrap mode, firstcolumn should still always be zero, because
it's initially set to that, and because passing it through the iterators
will maintain it at that.

This fixes https://savannah.gnu.org/bugs/?49100.
Reported-by: David Lawrence Ramsey <pooka109@gmail.com>
2017-03-22 10:44:05 +01:00
David Lawrence Ramsey 812ecaeb0c weeding: remove maxlines and related code
Since all lines can be partially scrolled off the screen now
(except for edittop, which is forthcoming), the maxlines global
variable and its computation mechanism are no longer needed.
2017-03-22 10:44:05 +01:00
David Lawrence Ramsey 2abf7b755b softwrap: iterate through softwrapped chunks in adjust_viewport()
Use go_back_chunks() to adjust edittop, instead of special casing
the computation of goal when softwrapping.  Now softwrap mode and
non-softwrap mode will behave the same way when edittop can be
partially scrolled off the screen, which is forthcoming.

(Note that the top line of the screen can't be partially scrolled
yet, so we have to work around that for now.)
2017-03-22 10:44:04 +01:00
David Lawrence Ramsey ba4858de83 softwrap: iterate through softwrapped chunks in edit_scroll()
Use go_back_chunks() and go_forward_chunks() to adjust edittop and to
move up or down to the scrolled region before updating the rows there.
Now softwrap mode and non-softwrap mode will behave the same way when
we can scroll the top line of the screen partially off the screen,
which is forthcoming.

(Note that the top line of the screen can't be partially scrolled yet,
so we have to work around that for now.)
2017-03-22 10:44:04 +01:00
David Lawrence Ramsey fa025f0ca3 display: limit an optimization to non-softwrap mode
Not drawing a line on a row if we're on the top row and scrolled down,
or if we're on the bottom row and scrolled up, will only work properly
if the line on that row takes up only that row.  The latter might not
be the case in softwrap mode: if the line occupies multiple chunks and
begins on that row -- in that case none of the chunks would be drawn.
2017-03-22 10:44:04 +01:00
David Lawrence Ramsey eb369c0e00 tweaks: rename need_horizontal_scroll() to line_needs_update()
The old name made it sound as if it didn't apply in softwrap mode.  But
it does: in softwrap mode a line needs updating  when the mark is on.
2017-03-22 10:44:04 +01:00
David Lawrence Ramsey 380ad30a53 softwrap: account for softwrap when checking whether current is offscreen
Add the new functions current_is_above_screen() (which doesn't account
for softwrapped chunks yet, but will when we can scroll edittop partially
off the screen, which is forthcoming), current_is_below_screen() (which
determines whether current[current_x] is past the softwrapped chunk at
the bottom of the screen), and current_is_offscreen() (the union of the
previous two functions).

edit_redraw() and edit_refresh() now use current_is_offscreen() to check
whether they should adjust the viewport, and adjust_viewport() now uses
current_is_above_screen() to determine whether current is on or below
the screen in FLOWING mode.
2017-03-22 10:44:04 +01:00
David Lawrence Ramsey 4f9c563e6b softwrap: count softwrapped chunks properly in do_uncut_text()
Add the new function less_than_a_screenful() to accomplish this.
It uses go_back_chunks() to count the number of softwrapped chunks
between the end point and the starting point of the paste.

Now softwrap mode and non-softwrap mode behave the same way when
uncutting fewer than editwinrows rows of text.  Accordingly, remove
the call to ensure_line_is_visible(), as it no longer applies.
2017-03-22 10:44:04 +01:00
David Lawrence Ramsey 456d66b904 softwrap: add two chunk-iterator functions
These functions, go_back_chunks() and go_forward_chunks(), take a number
of softwrapped chunks (screen rows) to move, a pointer to a buffer, and
a location (specifically, a starting column of a softwrapped chunk).  If
they move successfully, they will update the buffer pointer and location
to point to the beginning of the softwrapped chunk they moved to.

Since non-softwrap mode is effectively just a subset of softwrap mode
in which every line takes up one chunk, these functions also work in
non-softwrap mode.  In this case, their starting column will always be
zero, as it would be in softwrap mode on a line that takes up one chunk.

Nothing uses these functions yet, but that is forthcoming.
2017-03-22 10:44:04 +01:00
Benno Schulenberg 6d873d3760 startup: add option 'nopauses' to disable pausing after a warning
This addresses a followup of https://savannah.gnu.org/bugs/?50362.
Reported-by: Mike Frysinger <vapier@gentoo.org>
2017-03-16 19:26:39 +01:00
Benno Schulenberg 5283acdcf3 tweaks: trim a displayable string in a more efficient manner
Instead of redetermining the entire span of the converted string,
simply move one character left, and then bite it off to make place
for the trailing $.
2017-03-14 21:20:50 +01:00
Benno Schulenberg 69784d51db screen: don't push the longer-line indicator ($) to the next row
If the last two columns of a row would be taken up by a double-width
character (and the line is longer than that), don't print it, because
it wouldn't leave any room for the $ character.

This fixes https://savannah.gnu.org/bugs/?50491.
Reported-by: David Lawrence Ramsey <pooka109@gmail.com>
2017-03-08 21:24:13 +01:00
Benno Schulenberg 355a07bbce tweaks: don't optimize for the wrong case
Running strlenpt() on a string that takes up more than 80 columns
(the width of an average terminal) takes /more/ time than simply
converting an extra character (the one that will be overwritten
by the "$" at the edge of the terminal).  So... just convert one
more character than necessary when the line is overlong.  In the
most common case, however, the line will fit fully onscreen, and
we save a whole call of strlenpt().
2017-02-28 17:07:38 +01:00
David Lawrence Ramsey 0404474ec2 tweaks: stop converting text once we overshoot span columns
Since we only need span columns of the string, stop scanning the string
as soon as we have that many columns, instead of scanning the string all
the way to the end.  This speeds up the conversion of very long lines.
2017-02-28 16:50:22 +01:00
Benno Schulenberg a80ade38d7 tweaks: rename two variables, to be more distinctive 2017-02-28 15:17:03 +01:00
Benno Schulenberg 48643cbdf3 tweaks: elide a small intermediate buffer 2017-02-28 15:05:02 +01:00
Benno Schulenberg aa013aa007 tweaks: elide a variable 2017-02-28 14:53:10 +01:00
Benno Schulenberg 91910b2364 input: count a manually entered unicode as one character
This fixes https://savannah.gnu.org/bugs/?50403.
Reported-by: David Lawrence Ramsey <pooka109@gmail.com>
2017-02-28 14:47:45 +01:00
Benno Schulenberg efdd73922e oops -- that's what you get when you don't test things before pushing
Of course 'row' needs to be initialized to zero for the softwrap case.
2017-02-26 18:29:18 +01:00
Benno Schulenberg 2e53ed2928 tweaks: use two extra variables to make it clearer what is being done
This addresses https://savannah.gnu.org/patch/?9215.
Inspired-by: David Lawrence Ramsey <pooka109@gmail.com>
2017-02-26 17:33:10 +01:00
Benno Schulenberg 0378146add tweaks: rename a variable, drop a false assert, and reshuffle a bit 2017-02-24 15:07:04 +01:00
David Lawrence Ramsey 6e9d6a08b9 replacing: fix spotlight() to highlight words properly in softwrap mode
In softwrap mode, the entire line is onscreen, so the word is never
partially offscreen, so we always have enough columns to show it.

This fixes https://savannah.gnu.org/bugs/?50389.
Reported-by: David Lawrence Ramsey <pooka109@gmail.com>
2017-02-24 15:06:44 +01:00
Benno Schulenberg 07ebba5e99 tweaks: rename a variable and invert its logic 2017-02-24 12:21:59 +01:00
David Lawrence Ramsey f1d214c0ef tweaks: slightly optimize an allocation in display_string()
Instead of allocating enough space to convert the entire passed string,
just allocate space for converting the part that will be converted --
that is: starting from start_index.  This still allocates far too much
(if the passed string is very long and its tail part won't fit on the
screen), but it's better than before.
2017-02-24 10:52:04 +01:00
Benno Schulenberg 1d3f3a6e25 tweaks: mark a message for translation 2017-02-23 15:22:07 +01:00
Benno Schulenberg 23c3fd9bcd statusbar: display at most three consecutive alert messages
Cap the number of pauses when displaying ALERT messages, to avoid
making the user wait for ages when tens or hundreds of files were
specified on the command line.

This fixes https://savannah.gnu.org/bugs/?50362.
Reported-by: Mike Frysinger <vapier@gentoo.org>
2017-02-22 10:48:26 +01:00
Benno Schulenberg c118397a14 tweaks: update some copyright years
Reflect the significant changes in painting and regex searching
in the copyright notices.
2017-02-21 20:27:49 +01:00
Benno Schulenberg 407f2d5bcf tweaks: move a comment and rewrap a line 2017-02-17 12:01:25 +01:00
David Lawrence Ramsey 61e8b3d542 screen: don't hide two-column characters at left edge in softwrap mode
When in softwrap mode, no "$" continuation characters are displayed,
so the code that reserves space for them should be skipped then.

This fixes https://savannah.gnu.org/bugs/?50335.
2017-02-17 11:39:37 +01:00
Benno Schulenberg fccfcccd37 tweaks: reshuffle an assignment and trim some comments 2017-02-13 19:46:51 +01:00
Benno Schulenberg 03148804e6 tweaks: scrap some debugging stuff 2017-02-13 19:46:41 +01:00
Benno Schulenberg 7ef5c53263 painting: mark an unpaired start match as CWOULDBE
The lines that come after an unpaired start have to know about this.

This fixes https://savannah.gnu.org/bugs/?50293.
2017-02-13 11:18:54 +01:00
Benno Schulenberg 6bd94040df painting: don't look at the current multidata when coloring a line
When coloring a line, look only at the multidata of the preceding
line, and based on that determine what to seek in the current line.

This fixes https://savannah.gnu.org/bugs/?50292.
2017-02-13 10:03:07 +01:00
Benno Schulenberg b3bcc8eeac painting: make use of the multidata of the preceding line
When painting a line, the multidata of the line /before/ it is valid
in most cases: it was determined just a moment ago.  And it tells us
all we need to know: whether there is an unpaired start match before
the current line or not.

The only exception is when painting the first line of the screen:
the multidata of the line before it might be stale.  So for the
first screen line we will always have to do some backtracking.
But that is left for later.

This fixes https://savannah.gnu.org/bugs/?50121.
2017-02-12 18:24:49 +01:00
David Lawrence Ramsey b1b9770c57 tweaks: rename a variable and adjust some types in edit_scroll()
Scrolling works on rows, not on lines.  Accordingly, rename the nlines
variable to nrows.  And rows should be of the type int, not ssize_t.
2017-02-05 20:04:31 +01:00
David Lawrence Ramsey 78037831f8 tweaks: rename a variable in edit_scroll(), to make sense 2017-02-05 19:44:42 +01:00
David Lawrence Ramsey 34e086f038 tweaks: rename a variable in edit_redraw(), to make sense 2017-02-05 12:30:09 +01:00
David Lawrence Ramsey f2ac20114e tweaks: adjust and correct some comments 2017-02-05 12:29:43 +01:00
Benno Schulenberg 1d10d79860 painting: account for index maybe being zero after the preceding change 2017-01-22 10:12:27 +01:00
Benno Schulenberg 8441887ec0 painting: advance only when both start /and/ end match are zero-length 2017-01-22 10:07:48 +01:00
Benno Schulenberg 775f007348 tweaks: use a cheaper way to detect an end-of-line
There is no need to compute the line length: just avoid overstepping
the terminating NUL byte when being forced to advance the index.
2017-01-21 19:44:48 +01:00
Benno Schulenberg 9a4a5454f2 painting: properly look for a new start match only after the end match 2017-01-21 12:30:56 +01:00
Benno Schulenberg af7201f9a0 tweaks: reshuffle three variables 2017-01-21 12:30:51 +01:00
Benno Schulenberg 2f80193d96 tweaks: reshuffle a test to a better place 2017-01-21 12:30:44 +01:00
Benno Schulenberg 23595c8376 tweaks: differentiate single-regex matches from paired-regex matches
Don't use the 'startmatch' variable when the corresponding match is
not the start of anything but is the entire match by itself.
2017-01-21 12:30:38 +01:00
Benno Schulenberg 669453506c painting: when skipping a zero-length match, skip a character, not a byte 2017-01-21 12:29:27 +01:00
Benno Schulenberg 9de376deed painting: stay within the line when skipping zero-length matches
Don't blithely overshoot the end of a line when both start regex and
end regex match an empty string.  Overshooting would let the matching
run on into uncharted country and thus ultimately cause a segfault.

This fixes https://savannah.gnu.org/bugs/?50056.
Reported-by: Elia Geretto <elia.f.geretto@gmail.com>
2017-01-20 17:03:10 +01:00
Benno Schulenberg 94907aa534 painting: do not bluntly ignore zero-length start matches -- handle them
The segmentation fault that this causes when both start and end match are
zero-length will be tackled later (https://savannah.gnu.org/bugs/?50056).

This fixes https://savannah.gnu.org/bugs/?50078.
Inspired-by: Elia Geretto <elia.f.geretto@gmail.com>
2017-01-20 14:00:14 +01:00
Benno Schulenberg 7e5524bb66 painting: do not let a match for 'end' overlap a match for 'start'
During precalculation and in step_two, we begin looking for an end
match only after the full start match, not merely one byte beyond
its starting point.  So do that too when searching backward for an
unpaired start match.

Also, index can never be zero here, because if the match was of length
zero, this piece of code will have been skipped by the preceding goto.
So we can always use REG_NOTBOL here.

(That goto is wrong, by the way: https://savannah.gnu.org/bugs/?50078,
but that will follow later.)
2017-01-20 13:17:10 +01:00
Benno Schulenberg 9f884810b6 tweaks: use a subtraction instead of a counter
And return a better value, so that less calculation is needed.
2017-01-13 19:33:32 +01:00
Benno Schulenberg 5d5666fba6 tweaks: swap two blocks of code to reduce the number of #ifdefs 2017-01-13 19:29:39 +01:00
Benno Schulenberg 980e334e37 tweaks: rearrange some code to separate softwrap and normal mode more
(Ignore the indentation for the moment.)
2017-01-13 19:17:59 +01:00
Benno Schulenberg 9bb64fccef tweaks: chuck some obscuring debugging stuff 2017-01-13 17:47:55 +01:00
David Lawrence Ramsey 6e3adf31b8 tweaks: let update_line() return the correct value on error
If the given line is out of range of editwinrows, we don't display it
at all, so we obviously don't display more than one line of it.  Thus,
the return value in this case should be zero, not one.
2017-01-13 17:41:26 +01:00
David Lawrence Ramsey c67c431239 tweaks: improve comments and formatting in update_line() 2017-01-13 17:36:02 +01:00
Benno Schulenberg bf0268d41d tweaks: condense a comment, rename a variable, and use a while loop 2017-01-12 21:31:08 +01:00
Benno Schulenberg b7c2513f7d tweaks: rename some variables, to better distinguish rows from lines
And columns from indexes -- columns are places on the screen, while
indexes point to characters in a line in the current buffer.
2017-01-12 19:32:21 +01:00
Benno Schulenberg 892762d99c tweaks: rename some variables, to show they refer to screen rows 2017-01-12 18:03:36 +01:00
Benno Schulenberg f7d320d932 tweaks: rename a function, to show it refers to screen rows 2017-01-12 17:48:33 +01:00
Benno Schulenberg 0208ae7149 tweaks: rename a variable -- lines refers to buffer, rows to screen 2017-01-12 17:33:46 +01:00
Benno Schulenberg 26fb907aa6 screen: ehm... no, that was wrong: page_start /is/ a column position
(The mistake becomes visible when you go to the end of a very long line
of double-width characters: the $ will be shown on the right edge, even
though you're already at line's end.)

This reverts commit 16a7fd4b from yesterday.
2017-01-12 10:29:20 +01:00
Benno Schulenberg 16a7fd4bfc screen: don't compare a character index with a column position
This addresses part of https://savannah.gnu.org/patch/?9216.
Reported-by: David Lawrence Ramsey <pooka109@gmail.com>
2017-01-11 17:22:46 +01:00
Benno Schulenberg a898fa5dcc tweaks: if there is no end match, there is nothing to paint
When there is no end match after a start, it is pointless to look
for any more starts because also they will not have any end match,
so nothing will get painted -- just cut the loop short.
2017-01-09 19:14:51 +01:00
Benno Schulenberg c0aa5ad258 tweaks: miscellaneous frobbings 2017-01-09 18:25:25 +01:00
Benno Schulenberg f6fbc1572d tweaks: adjust whitespace after the previous change 2017-01-09 12:01:27 +01:00
Benno Schulenberg 38d7362f20 tweaks: rename two variables to be just one as they play the same role
The renamed variable 'index' is not the start of a match (as some comment
mistakenly said), but from where in the line we start looking for a next
match.

Also, use one more goto to allow unindenting a big piece of code, and
shortcircuit two while loops for two more small unindents.
2017-01-09 11:39:37 +01:00
Benno Schulenberg 26683a9e5f tweaks: frob some comments, and transform one variable 2017-01-08 21:31:49 +01:00
Benno Schulenberg a89437219d tweaks: don't use a variable for two different purposes
At first paintlen was computed as a column span, and then converted
to a character count...  Confusing.
2017-01-08 13:34:10 +01:00
Benno Schulenberg aa28441071 tweaks: the starting point for painting /cannot/ be offscreen
The top_x variable has already been forced to become equal to from_x
if it was before it.  So start_col will be at least zero.
2017-01-08 13:34:04 +01:00
Benno Schulenberg 5dbd288254 tweaks: rename another variable, to show it refers to columns not chars 2017-01-08 13:12:40 +01:00
Benno Schulenberg 8f21d256fb tweaks: rename two variables, for distinguishing characters from columns 2017-01-08 13:12:36 +01:00
Benno Schulenberg 08cfdbcbdb tweaks: don't compare a character offset with a column position
It is the misuse of "x_" to mean a column position on screen, and the
misuse of "_col" to mean a character position in a string that causes
this confusion.
2017-01-08 13:12:11 +01:00
Benno Schulenberg 6103c47f1c tweaks: rename three painting variables, to be more distinct
All these different "start"s and "end"s are confusing.  Use instead
'from_x and 'till_x' to remember which part of the current line is
visible now on screen and is thus represented in 'converted'.
2017-01-08 11:35:07 +01:00
Benno Schulenberg 88cf22f804 tweaks: rearrange and reindent some lines in the painting routines
Also adjust a few comments.
2017-01-08 11:33:57 +01:00
Benno Schulenberg 8177e62c18 screen: examine the whole line when painting, to set the correct info
In order to determine the correct multidata for a line that doesn't
have such data yet, the whole line must be examined, not just the
part that fits within the screen width.

This fixes https://savannah.gnu.org/bugs/?49978.
2017-01-08 11:33:57 +01:00
Benno Schulenberg 908663e8fc input: discard a verbatim 0x0A or 0x00 byte, depending on the mode
This disallows entering a verbatim ^J (0x0A) when typing text or
search terms, and disallows a verbatim ^@ (0x00) when typing a
filename.  Nano beeps when the disallowed code is attempted.

This addresses https://savannah.gnu.org/bugs/?49897.
2016-12-27 16:46:09 +01:00
Benno Schulenberg c92b9be6cd tweaks: rename three variables, to be more fitting 2016-12-23 13:01:15 +01:00
Benno Schulenberg eef7d1047a screen: display byte value 0x0A in the right places as ^@ or as ^J
In path names and file names, 0x0A means an embedded newline and
should be shown as ^J, but in anything related to the file's data,
0x0A is an encoded NUL and should be displayed as ^@.

So... switch mode at the two main entry points into the "file system"
(reading in a file, and writing out a file), and also when drawing the
titlebar.  Switch back to the default mode in the main loop.

This fixes https://savannah.gnu.org/bugs/?49893.
2016-12-23 11:00:55 +01:00
Benno Schulenberg a9b5a0e029 tweaks: rename a function to something less abbrevy
Also, swap the logic around, to use less braces.
2016-12-22 12:04:10 +01:00
Benno Schulenberg 026393a91a binding: use plain codes instead of function calls for the jumping keys
Which is possible because those keycodes are hard-bound to the relevant
functions.
2016-12-22 11:50:24 +01:00
Benno Schulenberg db897b574f input: detect again when both Shift and Ctrl are being held on a VT
In nano 2.7.1 and 2.7.2, pressing Shift+Ctrl+Arrow on a Linux console
would behave as if Shift wasn't held.  It got broken three months ago,
by commit 08cd197b, messing up the proper order of the checks.

This fixes https://savannah.gnu.org/bugs/?49906.
2016-12-22 11:13:39 +01:00
Benno Schulenberg 2b1bc6866a input: don't crash when receiving a KEY_CANCEL
On some systems, typing ^C apparently results in a KEY_CANCEL in
the input stream, which gets hard-bound to the do_cancel function.
But in the main menu there is no Cancel function.  So... in that
case, let it fall back to the plain old Ctrl-C code: 0x03.

Reported-by: Liam Gretton <liam.gretton@leicester.ac.uk>
2016-12-21 17:42:15 +01:00
Benno Schulenberg b77e6bd99d general: simplify the detection of a SIGWINCH
There is no need for a counter, nor an old counter to compare it with.
2016-12-19 10:04:01 +01:00
Benno Schulenberg eafae5d417 screen: show an embedded newline in filenames as ^J instead of ^@
The byte 0x0A means 0x00 *only* when it is found in nano's internal
representation of a file's data, not when it occurs in a file name.

This fixes the second part of https://savannah.gnu.org/bugs/?49867.
2016-12-18 11:13:50 +01:00
Benno Schulenberg dfff78dffe titlebar: always pass a pathname through display_string()
So that embedded control characters will be represented
instead of acted upon.

This fixes the first part of https://savannah.gnu.org/bugs/?49867.
2016-12-18 11:13:49 +01:00
Benno Schulenberg eb88ad980a tweaks: use a slightly faster comparison 2016-12-15 13:15:46 +01:00
Benno Schulenberg a772194102 tweaks: rename two variables, for self-documentation 2016-12-13 17:13:38 +01:00
Benno Schulenberg faf77fb1ec tweaks: don't bother making the next line of an end point NULL 2016-12-13 17:12:52 +01:00
David Lawrence Ramsey c9f743f676 tweaks: elide two unneeded variables from line numbering mode
Instead compute directly whether we're at a softwrapped part or not.
2016-12-13 17:01:39 +01:00
David Lawrence Ramsey bd920b1f49 tweaks: adjust the type of two arguments
Convert digits() to take a ssize_t instead of an int, since it's
used on ssize_t line numbers.  And properly use the long modifier
when displaying a line number.

Also, conditionalize the digits() prototype.
2016-12-13 13:06:20 +01:00
Benno Schulenberg 2fa93ae999 tweaks: rename two variables to make more sense 2016-12-09 12:47:00 +01:00
David Lawrence Ramsey c8c6340ce8 tweaks: conditionalize a bit of softwrap code
This addresses https://savannah.gnu.org/bugs/?49803.
2016-12-09 12:34:56 +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 372bd0f7dd screen: switch the cursor back on only in the main loop
This fixes https://savannah.gnu.org/bugs/?49750.
2016-12-03 18:03:11 +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 c9680b8b64 input: add the shifted PageUp and PageDown keycodes produced by VTE
Modern VTE-based terminals now produce codes for those keys and
no longer swallow them when nano is active.

This addresses https://savannah.gnu.org/bugs/?49746.
2016-12-01 17:34:57 +01:00
Benno Schulenberg c6512a9717 screen: don't request an update of the edit window for every yesno prompt
Only when doing replacements does the edit window need a refresh: for
every new spotlight.  So, do the update request in the latter routine.
2016-12-01 15:20:05 +01:00
Benno Schulenberg ac41587d4e oops: the yesno prompt for replacing does not want a visible cursor 2016-11-30 13:47:50 +01:00
Benno Schulenberg 72e8bcb027 tweaks: move a switching on of the cursor to a more logical place 2016-11-30 11:11:06 +01:00
Benno Schulenberg 7401670d58 tweaks: fix compilation when configured with --enable-tiny 2016-11-30 11:05:07 +01:00
David Lawrence Ramsey e4d452424b files: give feedback when restricted mode prevents overwriting a file
Achieve this by reusing the code that gives feedback when trying to
save a buffer while using --tempfile and the file has no name yet.

This fixes https://savannah.gnu.org/bugs/?48622.
2016-11-29 12:08:39 +01:00
David Lawrence Ramsey d48071b2b2 input: properly check the full escape sequences for all keys
Also for Delete, End, PageUp and PageDown (on some terminals)
the last byte in the sequence needs to be checked.

This fixes https://savannah.gnu.org/bugs/?49710.
2016-11-27 20:31:12 +01:00
Benno Schulenberg 3cc561e36e input: distinguish <Shift+Home> from <Home> on an rxvt terminal
That is: when --rebindkeypad is in effect -- without this option
they were already getting distinguished.
2016-11-26 12:25:36 +01:00
Benno Schulenberg 0333b87ad7 input: distinguish <Alt+Left> from <Alt+Right> on an rxvt terminal
Both would jump a word to the left -- now each jumps a word in the
proper direction.
2016-11-26 12:07:33 +01:00
David Lawrence Ramsey 059c8efb44 input: make Shift+Alt+Arrow work properly on rxvt and Eterm terminals
This fixes https://savannah.gnu.org/bugs/?49636.
2016-11-26 11:57:39 +01:00
Benno Schulenberg 55b1403542 tweaks: adjust some whitespace and a comment 2016-10-23 17:26:19 +02:00
Benno Schulenberg 9d5ee16614 tweaks: don't bother redrawing some lines when whole screen will be redrawn 2016-10-23 17:26:19 +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 023edffe3d screen: move the margin determination to the main loop
There is no need to look at this for every painted line, because
the margin can only change when some key is struck.
2016-10-21 14:56:56 +02:00
Benno Schulenberg 2789bb0813 screen: repaint the edit window in a single place -- the main loop
Instead of doing this in two places: after interpreting shortcuts,
and after injecting characters.
2016-10-21 14:56:53 +02:00
Benno Schulenberg 4d996e4c39 screen: suppress line numbers when the terminal is very narrow
To prevent the display from getting messed up, making nano unusable.
2016-10-21 14:55:43 +02:00
Benno Schulenberg de2aa4f24a rcfile: add an option to customize the color of line numbers 2016-10-20 16:48:45 +02:00
Faissal Bensefia de95ca68f7 new feature: the ability to show line numbers before the text
It can be activated with --linenumbers on the command line or with
'set linenumbers' in a nanorc file, and it can be toggled with M-#.

Signed-off-by: Faissal Bensefia <faissaloo@gmail.com>
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2016-10-20 16:47:52 +02:00
Benno Schulenberg fdee0df849 input: keep the Ctrl+Arrow keys working when their synonyms are unbound
This fixes https://savannah.gnu.org/bugs/?49058 reported by Rishabh Dave.
2016-10-15 17:03:10 +02:00
Benno Schulenberg 0a18d8912b screen: defeat a VTE bug by doing an extra cursor move and update
This fixes https://savannah.gnu.org/bugs/?49106.
2016-10-12 13:56:48 +02:00
Benno Schulenberg 598e0af7af softwrap: scroll the current line fully into view when jumping words
This fixes https://savannah.gnu.org/bugs/?47710
and fixes https://savannah.gnu.org/bugs/?49088.
2016-09-20 12:29:10 +02:00
Benno Schulenberg 8ba57cf87b input: don't return zero when some function is completely unbound
Returning a zero would mean returning a ^Space -- the keycode that
by default is bound to the Next-Word function.  So, unbinding the
keys to which the modified Arrow keys are hard bound would cause
the latter ones to mysteriously jump to the next word.

This partially fixes https://savannah.gnu.org/bugs/?49058.
2016-09-20 11:11:44 +02:00
Benno Schulenberg fc9c7b4917 softwrap: scroll when searching lands on an overlong bottom line
This fixes https://savannah.gnu.org/bugs/index.php?42189.
2016-09-14 11:02:36 +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
Benno Schulenberg ad83ed22d9 input: handle the "resize key" in a better way
And correct a comment: the key /does/ occur also in the tiny version.
2016-09-06 12:09:18 +02:00
Benno Schulenberg acd8809d71 tweaks: use hard-baked keycodes where possible
These keycodes have non-rebindable entries in the list of shortcuts, so
they will always be there -- no need for a function call to find them.
2016-09-02 12:04:29 +02:00
Benno Schulenberg 272a953889 tweaks: fix compilation when configured with --with-slang 2016-08-30 10:12:02 +02:00
Benno Schulenberg db310ac9b6 input: ignore the resize "key", to prevent reporting an unbound key
In the tiny version it would beep and report an unbound key for every
window resize.
2016-08-30 09:40:51 +02:00
Benno Schulenberg 514cd9a099 update the license text to the preferred version
Mentioning "GNU nano" instead of "This program" and referring to the
website instead of to a postal address.
2016-08-29 21:27:16 +02:00
Benno Schulenberg 406e5242a3 update the copyright notices 2016-08-29 21:27:05 +02:00
Benno Schulenberg 382c9d792d new feature: allow text selection by holding Shift with the cursor keys
Add the keycodes and routines to allow the user to forego setting the
mark explicitly (with M-A / ^6) and instead quickly select a few words
or lines by holding down Shift together with the movement keys.

(Some combinations with Shift are swallowed by some terminal emulators.
To work around some of those, the combinations Shift+Alt+Left/Right work
as Shift+Home/End and Shift+Alt+Up/Down work as Shift+PageUp/PageDown.)
2016-08-28 11:29:28 +02:00
Benno Schulenberg c05c914eee tweaks: rename three variables 2016-08-27 12:10:18 +02:00
Benno Schulenberg c19f0c732e tweaks: simplify the determination of the number of shown help items 2016-08-27 12:06:08 +02:00
Benno Schulenberg 21cb01e543 tweaks: rename two variables, to make some sense
And move a statement to a better place.
2016-08-25 11:45:05 +02:00
Benno Schulenberg ea9aaee8c7 statusbar: leave out the brackets when the message is very long
This also prevents the message from spilling into the help lines
when the terminal is less than four columns wide.  (Not that one
can read anything then, but it looks better.)
2016-08-25 11:45:01 +02:00
Benno Schulenberg 76a960d73d screen: continue to function also in a terminal with very few lines
This fixes https://savannah.gnu.org/bugs/?48787.
2016-08-17 10:13:22 +02:00
Benno Schulenberg 0dd2a55284 screen: don't die when the window is narrower than four columns
This fixes https://savannah.gnu.org/bugs/?48520.
2016-08-15 17:25:33 +02:00
Benno Schulenberg 928a24c204 input: look at the modifier keys only when compiled on Linux
This fixes https://savannah.gnu.org/bugs/?48751 reported by Andrew Ho.

This also fixes compilation when configured with --enable-tiny.
2016-08-14 21:42:08 +02:00
Benno Schulenberg 290d278f68 input: make the Ctrl+Arrow keys work on a Linux console
If this breaks your build, please send report or instructions or patch.
2016-08-07 18:20:34 +02:00
Benno Schulenberg 8edb096821 input: after an Esc, don't discard starter byte of a multibyte sequence
This fixes https://savannah.gnu.org/bugs/?48711.
2016-08-07 17:40:38 +02:00
Benno Schulenberg faa46a3c71 screen: remove redundant redrawings of the entire edit window
(It may have been necessary in the past; there is no need for it now.)

This fixes https://savannah.gnu.org/bugs/?48633.
2016-08-01 19:41:13 +02:00
Benno Schulenberg 2f6647687a tweaks: rename a function, and adjust some comments 2016-08-01 19:41:13 +02:00
Benno Schulenberg c9e9964207 screen: don't look at placewewant but at where we actually were and are
For horizontal scrolling, it is not the /desired/ column position that
is relevant for determining whether a line needs to be redrawn after a
cursor movement, but the /actual/ column positions before and after.

This fixes https://savannah.gnu.org/bugs/?48627,
and fixes https://savannah.gnu.org/bugs/?48629.
2016-08-01 19:41:13 +02:00
Benno Schulenberg 08c51cfd45 input: ingest as verbatim just one control code or one or two escapes
Leave the rest of any escape sequence to be processed normally, which
should be possible because those characters are all in ASCII range.

This fixes https://savannah.gnu.org/bugs/?48318.
2016-08-01 14:47:02 +02:00
Benno Schulenberg b472f5a633 tweaks: remove some unnecessary keycodes from a switch statement
These codes are the basic codes that get assigned for the movement keys
in the list of shortcuts -- they don't need any translation.
2016-08-01 14:07:21 +02:00
Benno Schulenberg 5806bf5249 tweaks: normalize some whitespace and adjust several comments 2016-08-01 14:05:42 +02:00
Benno Schulenberg 90a90365a8 tweaks: rename three constants, for clarity, and hardcode two others 2016-08-01 12:56:05 +02:00
Benno Schulenberg f33d8cae30 tweaks: don't use a function call when reference to the variable will do 2016-07-31 18:30:53 +02:00
Benno Schulenberg e471e2d462 tweaks: move the modified editing keys again 2016-07-31 18:29:57 +02:00
Benno Schulenberg fe38b78486 tweaks: adjust indentation after the previous changes 2016-07-31 18:22:07 +02:00
Benno Schulenberg 1af1f5c9f4 tweaks: return quicker from the key parsing routine 2016-07-31 18:19:17 +02:00
Benno Schulenberg b9e83fe9f8 tweaks: move some debugging stuff, and move modified editing keys too
Again, just for preapring an easier return from the parsing routine.
2016-07-31 18:17:06 +02:00
Benno Schulenberg cb10b2b908 tweaks: elide the global variable 'func_key'
There is no need to specially flag a function key or editing key --
the keycode is indication enough in itself: outside of byte range.
2016-07-31 18:13:05 +02:00
Benno Schulenberg 19dfd20a88 tweaks: add a variable, in preparation for making returning easier 2016-07-31 18:10:31 +02:00
Benno Schulenberg d12fdda15b tweaks: replace a three-case switch with an if and an else 2016-07-31 18:10:01 +02:00
Benno Schulenberg 1c9ab8bf16 tweaks: rename a struct element, to be more fitting
The keycode is not a sequence; it is a single integer value.
2016-07-30 12:24:35 +02:00
Benno Schulenberg e295070193 shortcuts: group the setting of key string and keycode into one function
And instead of using two key types, just use a bool to indicate whether
a keystroke involves Meta.
2016-07-30 12:21:42 +02:00
Benno Schulenberg 91951ab22a input: don't bother putting a keycode into byte range
A keycode is either already in byte range (so there is nothing to do)
or it is not and it shouldn't be (so there is nothing to do either).
2016-07-30 12:19:47 +02:00
Benno Schulenberg 5b0ab8be62 shortcuts: remove any unnecessary classifying of keys
After initialization, the type of a key is never used nor needed
(other than for meta keys).
2016-07-30 12:13:47 +02:00
Benno Schulenberg ecef093def tweaks: adjust indentation after previous changes 2016-07-29 09:33:28 +02:00
Benno Schulenberg 6d6f5bd4a7 tweaks: check earlier on for sufficient length of the sequence 2016-07-29 09:33:28 +02:00
Benno Schulenberg e3dbffc9f7 input: be more strict in recognizing certain escape sequences
Accept the "Esc [ 1 n ~" and "Esc [ 2 n ~" sequences only when they
end with the "~" character, not with any character.
2016-07-29 09:33:28 +02:00
Benno Schulenberg 2225d54126 input: don't use a function call when a literal value will do 2016-07-29 09:33:28 +02:00
Benno Schulenberg 9115828e76 input: fix a pasto from eight years ago, from commit e347efb 2016-07-29 09:33:16 +02:00
Benno Schulenberg f3e8991206 credits: don't bother blanking the second line nor the help lines
Those lines don't exist in that mode -- the relevant subwindows are
smaller, or have been made smaller just before.
2016-07-27 12:40:11 +02:00
Benno Schulenberg 68cfb08888 tweaks: fix compilation with --enable-tiny 2016-07-25 17:29:24 +02:00
Benno Schulenberg a472f480a7 tweaks: trim some comments, and simplify a condition 2016-07-24 13:44:16 +02:00