Commit Graph

720 Commits (86f7bc18685732d0a7bf744e004a0c751d07ad61)

Author SHA1 Message Date
David Lawrence Ramsey 86f7bc1868 files: revamp the insertion of a file, to be more like pasting text
Move buffer handling and '\r' stripping from read_line() to read_file(),
so that the file gets its format determined and gets stored in its own
buffer entirely in one function.  Then use ingraft_buffer() to insert
this new buffer into the current one.

In addition to pasting the file at current[current_x], ingraft_buffer()
also deals with renumbering, the updating of totsize, and the handling
of a magicline, so read_file() doesn't need to do those anymore.

Note that all this makes read_file() depend on the position of
current[current_x] to know where to insert the file.  Accordingly,
set current_x to zero in initialize_buffer_text() instead of in
make_new_buffer(), so that replace_buffer() keeps working properly.
2017-02-28 14:35:44 +01:00
Benno Schulenberg 9e6e1ebe58 tweaks: remove a disabled warning, and adjust a translator hint 2017-02-24 12:06:15 +01:00
Benno Schulenberg 330741b650 tweaks: adjust two comments, to be more accurate 2017-02-17 19:59:34 +01:00
David Lawrence Ramsey f773d715e8 tweaks: rewrap two lines and fix two typos 2017-02-17 19:55:54 +01:00
Benno Schulenberg 605f031833 files: leave out the confusing "[from ./]" when prompting for a command
This fixes https://savannah.gnu.org/bugs/?49892.
2017-01-19 10:31:55 +01:00
Benno Schulenberg c0aa5ad258 tweaks: miscellaneous frobbings 2017-01-09 18:25:25 +01:00
Benno Schulenberg 5ca765f107 tweaks: discard some conditional compilation 2017-01-09 15:09:06 +01:00
David Lawrence Ramsey f35c3dbd57 softwrap: ensure the current line is fully visible after inserting a file
This fixes https://savannah.gnu.org/bugs/?49994.
Reported-by: David Lawrence Ramsey <pooka109@gmail.com>
2017-01-06 14:01:47 +01:00
David Lawrence Ramsey acb394aec0 screen: properly place the cursor after inserting a file
Instead of setting openfile->current_y (and wrongly so), just call
reset_cursor() to recompute current_y and place the cursor on that
line (if it is not offscreen).
2017-01-06 14:00:37 +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 5f30775d62 inserting: adjust the desired x position (don't restore the old one)
This makes nano's cursor behavior consistent across 1) typing text by
hand; 2) pasting in text with ^U; 3) inserting text from a file; and
4) redoing with M-E that same typing or pasting or inserting.

This fixes https://savannah.gnu.org/bugs/?49968.
2017-01-01 15:32:25 +01:00
Benno Schulenberg 69bd4d1f06 tweaks: slightly condense a function and its comment 2017-01-01 15:06:39 +01:00
Benno Schulenberg 32719d64a1 locking: disable an annoying warning
The warning is wrong when the user has just saved a buffer under a
new name.  And when --quickblank is used, the warning most likely
gets cleared off before it is seen, and the user would just hear
the beep and be left wondering what happened.

This avoids https://savannah.gnu.org/bugs/?49875.
2016-12-28 12:04:55 +01:00
Benno Schulenberg e72db0e350 files: show newlines in filenames as ^J also in error messages
When a given file is, for example, unreadable or unwritable, the
error message should use ^J instead of ^@ in its name.
2016-12-26 12:35:50 +01:00
Benno Schulenberg c24caf5fb8 tweaks: rename four variables, for density and aptness 2016-12-26 11:01:40 +01:00
Benno Schulenberg 8db21b68d5 tweaks: use memory on the stack instead of calling malloc() and free() 2016-12-26 10:39:48 +01:00
Benno Schulenberg dc18746cbd tweaks: retype, rename, and reshuffle a function 2016-12-23 13:51:58 +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 d49d4f7b56 history: search items *can* contain newlines -- encoded NUL bytes
Decode 0x0A bytes to 0x00 when saving the search history, and encode
them again when reading the file back in, to prevent nano from hanging
or aborting when encountering 0x00 on a line by itself.
2016-12-23 10:54:09 +01:00
Benno Schulenberg 66356ec7e2 screen: draw new content immediately, to prevent color flashes
After updating the color palette, the corresponding new window content
should be drawn immediately, before some other part of the code calls
doupdate(), to prevent the old content being shown in the new colors.

This fixes https://savannah.gnu.org/bugs/?49912.
Reported-by: Mike Frysinger <vapier@gentoo.org>
2016-12-23 09:25:29 +01:00
Benno Schulenberg e6350aaba4 prompt: do not treat a leading newline in a filename specially
This fixes https://savannah.gnu.org/bugs/?49884.
2016-12-22 13:46:53 +01:00
Benno Schulenberg 90b959a677 history: avoid crashing when the positionlog file is malformed 2016-12-21 17:28:09 +01:00
Benno Schulenberg 2bcc6d7f66 tweaks: start searching at a better place
Taking the terminating newline into account, and that there is
at least one digit per number.
2016-12-19 09:57:31 +01:00
Benno Schulenberg ecd18c1694 history: search for the two position numbers from EOL instead of BOL
A filename might contain spaces, so we can't look for the numbers
(the second and third elements) starting from the head of the line
-- we have to start at the tail and work backward.

This fixes https://savannah.gnu.org/bugs/?49879.
2016-12-18 19:57:33 +01:00
Benno Schulenberg bc8a3a50a4 tweaks: rename three variables, for visibility
(I don't /see/ single-letter variables -- they are too small.)
2016-12-18 19:31:11 +01:00
Benno Schulenberg 9b90ec877a tweaks: drive closer to the edge 2016-12-18 17:56:18 +01:00
Benno Schulenberg 8b483c10ba history: don't bother encoding search items -- they cannot contain newlines 2016-12-18 17:55:39 +01:00
Benno Schulenberg f915a28d30 tweaks: don't bother trimming the final newline from a position item
It is irrelevant -- the line is discarded as soon as the data has been
extracted.
2016-12-18 16:44:39 +01:00
Benno Schulenberg cb3fc8892a tweaks: rename a variable and rewrap two lines 2016-12-18 16:34:19 +01:00
Benno Schulenberg 06d9ee89e5 history: encode newlines in filenames as nulls
So they will not break a line in the positionlog file in two.

(Strangely, the reading in of such a log file already decodes
nulls back into newlines.)

This fixes https://savannah.gnu.org/bugs/?49877.
2016-12-18 12:27:55 +01:00
Benno Schulenberg 0b0b812206 files: don't change embedded newlines into nulls in filenames
Because changing anything to a null effectively means to truncate
the name.

This fixes https://savannah.gnu.org/bugs/?49868
and fixes https://savannah.gnu.org/bugs/?49874.
2016-12-18 11:37:57 +01:00
Benno Schulenberg 40acb8714c oops: forgot to add and amend this to the previous commit 2016-12-18 11:12:04 +01:00
Benno Schulenberg d7af590c6b memory: don't bother making a snug fit for things that will be freed soon
Most full paths are needed only temporarily and will be freed within
milliseconds.  Only 'full_operating_dir' and 'backup_dir' continue to
exist for the whole current session.  Any partition, too, will soon be
unpartitioned, so the extra reallocation is just a waste of time.
2016-12-18 10:33:30 +01:00
Benno Schulenberg 8c7e4f5108 tweaks: rename a function to describe what it does
It doesn't align anything -- any allocations are already aligned to
whatever multiple is required -- it just shrinks the allocated space.
2016-12-18 10:30:35 +01:00
Benno Schulenberg 1144d38316 tweaks: don't bother reallocating a string of which there is only one
And which normally is just some ten or twenty characters long, and
never gets wildly overallocated.
2016-12-18 10:28:30 +01:00
Benno Schulenberg 0562d27b9c tweaks: delete a bunch of unneeded asserts
Nano would crash straight afterward if any of these asserts would fail,
so they don't add anything.  A few others are simply superfluous.
2016-12-15 21:15:32 +01:00
David Lawrence Ramsey 84d6f1a5b6 tweaks: adjust the type of four lockfile variables
The functions read() and fwrite() take size_t, not ssize_t.

And line numbers in the file should be displayed as a long type instead
of an int, since the effective type of ssize_t is not int, but long.
2016-12-09 10:05:33 +01:00
Benno Schulenberg 173bbe11ef tweaks: add a few translator hints 2016-12-07 21:05:41 +01:00
Benno Schulenberg 964c10db17 tweaks: miscellaneous frobbings and rewrappings 2016-12-07 20:37:08 +01:00
Benno Schulenberg 4eac699df3 tweaks: remove some more annoying conditional compilation 2016-12-04 12:26:33 +01:00
David Lawrence Ramsey b5400ffe65 general: gettextize three overlooked statusbar messages
This fixes https://savannah.gnu.org/bugs/?48622.
2016-12-01 13:02:43 +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
Benno Schulenberg 281a56fb74 tweaks: reshuffle some things in a more linear manner
Also improve or correct some comments.
2016-11-26 17:42:27 +01:00
Benno Schulenberg 592d0d6c9a files: trying to open a non-existent file will never succeed
If it would, the returned file descriptor would make nano crash,
because the corresponding stream has not been opened.  And when
returning zero instead (as the code did originally), nano would
open an empty buffer, although it claims to be reading the file.

In short: I think this is a leftover of an attempted fix of
https://savannah.gnu.org/bugs/?25297, from commit 2823c99.
2016-11-26 17:00:41 +01:00
Benno Schulenberg 0eef5610eb files: mark a new buffer as modified after inserting command output
This fixes https://savannah.gnu.org/bugs/?49423.
2016-10-27 20:05:05 +02:00
Benno Schulenberg 2a55d2b29a tweaks: adjust some comments and reduce the scope of some variables
Also remove some cluttering conditional compilation.
2016-10-27 20:04:50 +02:00
Benno Schulenberg 702b09c859 tweaks: elide a parameter that is always FALSE 2016-10-23 20:07:39 +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 4de0a5049b tweaks: reshuffle an if statement 2016-09-11 21:43:47 +02:00
Benno Schulenberg dc76e84657 files: alert about an unwritable file also in the tiny version 2016-09-11 21:40:50 +02:00