Commit Graph

5702 Commits (d88423eaae789ab64b64ce08a90839a03964d7db)

Author SHA1 Message Date
Benno Schulenberg 05238f31f4 search: elide an unneeded function
When we're spell checking, we don't need a special mechanism to detect
we have come full circle: reaching the end-of-buffer means we're done.
So don't bother to reset came_full_circle when we're spell checking
(when begin == NULL) but simply ignore its value.
2016-05-02 21:07:27 +02:00
Benno Schulenberg e21e954742 browser: add a binding for the refresh function
And make the function actually refresh the list.  Useful for when files
have been added or deleted since opening the browser.
2016-05-02 12:00:56 +02:00
Benno Schulenberg e2556274f7 browser: provide tab completion also outside of the working directory
Add a global variable, 'present_path', so that 'cwd_tab_completion()'
knows where the user is in the browser, so that it can try completions
against names in that directory instead of always against names in the
current working directory (where nano was invoked).

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

Signed-off-by: Rishabh Dave <rishabhddave@gmail.com>
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2016-05-02 12:00:18 +02:00
Benno Schulenberg e0c4f9c5fe input: give more detailed feedback when an unbound key is struck 2016-05-01 22:04:32 +02:00
Benno Schulenberg eb871e72f5 input: distinguish an unknown escape sequence from an unbound key
It is misleading to say "Unknown Command" when there is no way to rebind
the relevant key stroke do anything useful.
2016-05-01 22:04:17 +02:00
Benno Schulenberg 3c8647e713 search: terminate the loop a tiny bit earlier when spell checking
The internal spell checker starts searching/replacing always at the top
of the buffer, so reaching the end of the buffer means we're done with
the current search/replace.  This prevents the "Search Wrapped" message
from flashing over the statusbar at the end of a spelling replacement.
2016-05-01 13:00:30 +02:00
Benno Schulenberg ae8df00b92 search: rename a variable and a function, for clarity and contrast 2016-05-01 12:59:32 +02:00
Benno Schulenberg 9f1a44d9e3 replacing: properly detect when we've rereached the starting position
Commit 8704dde mistakenly removed this part of code -- it is not dead,
it is just that it will only fire when the user answered No at some of
the replacement prompts.  So... when we've rereached the starting line,
a found occurrence is invalid when it is beyond the starting x (either
after or before it, dependending on the direction of search).

This fixes https://savannah.gnu.org/bugs/?47816.
2016-05-01 12:44:58 +02:00
Benno Schulenberg 3ea8f42c7f browser: rearrange the search loop to elide two unneeded variables
Simply move to the next filename first before starting to match.
2016-04-29 17:50:53 +02:00
Benno Schulenberg 02153402ec browser: when nothing was found, restore the global search flags
Don't skip the end of the function: use break instead of return.
2016-04-29 17:03:45 +02:00
Benno Schulenberg b26aaa7e42 screen: fix compilation when configured with --enable-tiny 2016-04-27 17:45:36 +02:00
Benno Schulenberg 9330aa60a5 rcfile: disallow 'bind' and 'unbind' in an included file
Included files are meant to contain only syntax definitions; they may
not set or unset options, nor rebind keys, nor include other files.

This fixes https://savannah.gnu.org/bugs/?47391.
2016-04-27 10:07:45 +02:00
Benno Schulenberg 30f3c53305 tabbing: refresh the window also when Goto-Dir in browser was cancelled
This restores things to the way they were before commit 36ec76a.
Apparently all those refreshes are needed in some cases after all.
2016-04-26 17:55:56 +02:00
Benno Schulenberg 133ed4e21d tabbing: don't null-terminate a directory name on the slash but after it
This fixes https://savannah.gnu.org/bugs/?47786.
2016-04-26 14:28:01 +02:00
Benno Schulenberg 53f4a9f5a8 screen: rename 'edit_refresh_needed' to 'refresh_needed'
For a little contrast with the function edit_refresh() -- it's
annoying that when you search for the latter you get to see all
the settings of the flag too.
2016-04-25 21:14:18 +02:00
Benno Schulenberg b97c36c218 screen: don't always set 'edit_refresh_needed' when adjusting edittop
The function edit_update() is called by edit_refresh() itself, so it is
silly that the first sets 'edit_refresh_needed' to TRUE.  This setting
is needed only in a few cases -- in the others it's not needed because
the screen does not need to be refreshed (it was just about positioning
the cursor), or 'edit_refresh_needed' has already been set by a call to
goto_line_posx().  So, just set the flag in the five places that need it
and spare the other four calls.
2016-04-25 20:17:40 +02:00
Benno Schulenberg 3e1d2b9049 tabbing: make sure to refresh the edit window when returning to it
Since commit 41ed690, cancelling a prompt after tabbing would sometimes
leave the list of file names on the screen.  When testing this first,
it worked fine -- I was fooled again by 'edit_refresh_needed' already
being TRUE when nano has just started up and sits waiting for the first
key stroke.  I have to hunt this down and kill it.
2016-04-25 17:56:23 +02:00
Benno Schulenberg 907ba3a2e2 scrolling: catch the special case of reading a file from standard input
Since commit dac0aa1, nano would leave edittop at current after reading
data from standard input, meaning that everything that had been read in
was invisible, "scrolled off" the top of the screen.  Correct this by
explicitly setting edittop.

The above does not happen for ^R (^X) because it has a special mechanism
to save and restore edittop.  Nor does it happen for ^R ^X M-F because it
sets current to the top of the file and refreshing the screen will make
edittop follow, or -- in case just one unterminated line was read in --
edittop will already be equal to current.
2016-04-25 17:48:06 +02:00
Benno Schulenberg 981b414980 utils: distinguish between width (columns) and length (bytes) 2016-04-24 22:02:48 +02:00
Benno Schulenberg 06b1fcad13 tabbing: fix erroneous use of strnlenpt()
Names could be strings of multibyte characters, so they could be more
than COLS - 1 bytes long and still be less than COLS - 1 columns wide.
2016-04-24 21:44:11 +02:00
Benno Schulenberg 92b8d6fb24 files: miscellaneous tweaks of braces, comments, and variable names 2016-04-24 21:24:17 +02:00
Benno Schulenberg 0b33ab552b files: make an 'if' more transparent and snip an unneeded condition
Also unwrap or improve some comments.
2016-04-24 17:28:21 +02:00
Benno Schulenberg 2faad1230a locking: don't try to read more bytes than the buffer can hold
A normal lock file is apparently 1024 bytes in size, so the second
attempt at reading bytes from the file would try to read 8192 more
bytes into a buffer that has room for only 7168 left.  According to
valgrind, the read() function doesn't like that -- and true: if for
some reason the lock file had suddenly expanded, the buffer would
overflow.

This fixes https://savannah.gnu.org/bugs/?47156.
2016-04-23 20:41:23 +02:00
Benno Schulenberg bfe418febb files: when opening a buffer, make sure to expand a tilde in its name
When a tilde is used in the name given at the ^R or ^O prompts, nano
expands it, but /not/ when a tilde is given on the command line (in
such a way that the shell leaves it as is).  Correct that asymmetry.

This fixes https://savannah.gnu.org/bugs/?44929
and fixes https://savannah.gnu.org/bugs/?47702
and fixes https://savannah.gnu.org/bugs/?47771.
2016-04-23 18:17:48 +02:00
Benno Schulenberg 41ed690791 tabbing: refresh the edit window in case a previous tab listed names
Commit 36ec76a made the wrong change: after a tab that did not list any
file names on the screen, a refresh /is/ needed, because a previous tab
might have listed things on the screen.  But at the end of the prompt,
it is not necessary to refresh the edit window if things were listed,
because the window will be refreshed anyway after reading in a file.
2016-04-23 15:46:31 +02:00
Benno Schulenberg 553b7af355 files: do not use two variables for two different purposes each
Use 'slash' to point at a possible slash, use 'filename' just to
point at the real file name, and use 'wasdirname' just to point at
the dir's name before expanding it in order to be able to free it.

Also, remove two superfluous asserts: 'dirname' cannot be NULL
because it has just been mallocstrcpy'd, and checking 'num_matches'
is pointless as it would crash on the next statement anyway.
2016-04-23 15:03:39 +02:00
Benno Schulenberg 2815eaa5f8 files: rewrap en reindent some lines 2016-04-23 13:45:05 +02:00
Benno Schulenberg 5c5fefc8cf files: tweak the function tail() and rename two variables 2016-04-23 13:26:28 +02:00
Mike Frysinger 8aeb8434d6 more svn->git updates 2016-04-17 23:39:07 -04:00
Benno Schulenberg 36ec76a508 tabbing: don't refresh the edit window when nothing was printed on it
This is a remnant from 2001, when things were different.  Now, there
is no need to refresh the edit window when tabbing produced no list.
When it did produce a list, it is cleared off later.
2016-04-17 18:12:53 +02:00
Benno Schulenberg eb2661dc2d spelling: if rereading the file fails, don't destroy the current buffer
If for some reason opening the spell-checked or formatted file fails,
don't throw away the current contents of the buffer.

(It should also give proper feedback about the failure, but we'll leave
that for some other time.)
2016-04-17 17:33:18 +02:00
Benno Schulenberg c2518dd5f0 inserting: differentiate not finding a file from not finding a string
Because it is a little clearer, and it is what Pico does too.

This partly fixes https://savannah.gnu.org/bugs/?47721.
2016-04-17 17:30:52 +02:00
Benno Schulenberg 34a20f8839 prompt: properly save and restore the x position in the statusbar
This fixes https://savannah.gnu.org/bugs/?47720.
2016-04-17 15:24:05 +02:00
Benno Schulenberg 6f185d3022 inserting: strip a carriage return before copying the line
Also, store the input character earlier, so we don't have to use len - 1.
Furthermore, len increments in steps of 1, so it cannot pass the value of
bufx unnoticed, so use a comparison for equality.
2016-04-17 13:02:04 +02:00
Benno Schulenberg c5b8f52c07 inserting: don't bother zero-terminating every single character
Just let read_line() zero-terminate the intermediate buffer when
the line is complete.
2016-04-17 12:34:07 +02:00
Benno Schulenberg bcdc90e85f inserting: reshuffle some conditions for a teeny bit more speed
Most of the time NO_CONVERT will not be set, the number of lines will
not be zero, and the format of the file will be zero.  Rearrange the
conditions so that they will evaluate as FALSE as soon as possible.
2016-04-17 11:44:22 +02:00
Benno Schulenberg f5c6246433 inserting: prune a duplicate variable
Index i follows almost synchronously the value of len.  Since we're
adding characters to the intermediate buffer always only at the end,
just use len as the index.
2016-04-17 10:46:56 +02:00
Benno Schulenberg 086b85215f inserting: treat also the final \r of a Mac file as a newline
Until now (when not leaving files unconverted), nano would fumble and
drop the final carriage return of a Mac file, and would thus treat the
last line of such a file as an unterminated line and prepend it to the
current line of the buffer.  Correct that, and delete the dead piece
of code that was meant to do this.

This fixes https://savannah.gnu.org/bugs/?47716.
2016-04-17 10:19:02 +02:00
Benno Schulenberg dac0aa1d89 inserting: prune some superfluous settings, and do one differently
When we don't set edittop in read_line(), we don't need to readjust it in
read_file(), because in that particular case it will still be pointing at
current.  And since fileptr is a new, freshly created line, it can never
be equal to filebot, so there is no point in comparing them.

If more than one line was inserted at the beginning of the file, leave it
up to the screen handling to set edittop to what it should be.

Move the setting of fileage a bit down, to its sister setting: the line
at current gets "connected" either to the top-of-file pointer or to the
last line of the inserted file.
2016-04-16 21:38:17 +02:00
Benno Schulenberg 04013fb7fa search: untangle two lines and tweak two comments 2016-04-16 12:52:42 +02:00
Benno Schulenberg a101b30fa8 keyboard: reshuffle some lines to avoid an empty while 2016-04-16 11:57:05 +02:00
Benno Schulenberg 0bffd99dcb scrolling: elide a variable, to make clearer that edittop is being moved 2016-04-16 11:38:39 +02:00
Benno Schulenberg 4c075f3771 tabbing: rename four variables, snipping a redundant part 2016-04-16 11:32:37 +02:00
Benno Schulenberg 0ccdaff960 tabbing: avoid recalculating the length of the first match every time
Also don't zero-terminate the matches in order to compare them,
but just limit the length of the comparison.
2016-04-16 11:15:33 +02:00
Benno Schulenberg 2d50c4f257 softwrap: adjust for current_x when computing the amount to scroll
The number of lines to scroll is: the y position of the start of the
current line, plus the extra lines that this line occupies, plus the
extra lines that the next line occupies, plus one, minus the y position
of the last window line.

The y position of the start of the current line is current_y -
xplustabs() / COLS, the extra lines are strlenpt(data) / COLS,
and the y position of the last window line is editwinrows - 1.

Note that we first compute the amount to scroll before actually moving
to the next line, because we need the current value of current_x, not
the one that it will have in the next line.  The placewewant value is
not good either, because it might be beyond where we actually are.

This fixes https://savannah.gnu.org/bugs/?47665.
2016-04-15 17:16:28 +02:00
Benno Schulenberg 6a9e2a4d3e files: handle systems that disallow NULL as first parameter of getcwd
(This change will be made superfluous when we start using gnulib.)

This prevents getcwd() from failing on Android and thus completes the
fix for https://savannah.gnu.org/bugs/index.php?47659.

Reported-by: Chris Renshaw <osm0sis@outlook.com>
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2016-04-15 13:35:27 +02:00
Benno Schulenberg ff1bf88562 files: limit the number of attempts at climbing up the directory tree
Doing a chdir("..") will not fail when the root directory is reached,
and when getcwd() keeps failing too, we have no way of knowing when
to stop.  So, simply limit the number of attempted chdirs, to avoid
getting into an endless loop.

This avoids the hang in https://savannah.gnu.org/bugs/index.php?47659.

Reported-by: Chris Renshaw <osm0sis@outlook.com>
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2016-04-15 12:36:07 +02:00
Benno Schulenberg 6414f9f000 titlebar: snip two superfluous tests for having enough space
If nano has less than four columns available, it will die,
so there will always be room for at least four characters.
2016-04-13 17:54:06 +02:00
Benno Schulenberg 2246029447 screen: elide a variable and serialize some logic for clarity
Also, don't force a full refresh of the edit window simply because the
current line needs to be horizontally scrolled.  And further, when the
adjustment of edittop has determined that a full refresh is needed,
get out and don't bother scrolling some lines first.
2016-04-13 13:19:24 +02:00
Benno Schulenberg 503654e60e screen: don't redraw some lines when doing a full refresh anyway
When in softwrap mode and scrolling down a line, and thus going to
do a full refresh, get out and don't bother redrawing the current
and prior lines first.
2016-04-13 13:12:25 +02:00