Make line addresses behave more like vi:
- Vi allows the user to enter an arbitrary number of addresses,
though only the last two are used. This simplifies get_address()
by reducing the amount of state that needs to be carried.
- When a command requires a single address the last one entered is
used.
- If addresses are separated by a ';' instead of a ',' the current
line is updated to the left address. This may be useful when a
search is used to specify a range, e.g. ':/first/;/last/d'.
- When the last address is empty it should refer to the current line.
function old new delta
colon 3855 3834 -21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-21) Total: -21 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
A CR in the gcc output would cause the following to show throughout build:
: invalid numberbox-1.32.1/scripts/gcc-version.sh: line 12: printf: 9
Signed-off-by: Chris Renshaw <osm0sis@outlook.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Commit ac6495f6f (vi: allow ctrl-D to reduce indentation) treated
ctrl-D during autoindent as a backspace. This was adequate for
indentation using tabs but doesn't work well with the expandtab
option. In the latter case it's necessary to backspace over all
the spaces.
Make ctrl-D work correctly when spaces are present in the indent.
Also, make it behave more like vim:
- ctrl-D is independent of autoindent;
- indentation is reduced even when the cursor isn't positioned at
the end of the indent.
function old new delta
char_insert 679 717 +38
get_column - 37 +37
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 75/0) Total: 75 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This implements the vim option expandtab in BusyBox vi. From
vim help:
In Insert mode: Use the appropriate number of spaces to insert a
<Tab>. Spaces are used in indents with the '>' and '<' commands and
when 'autoindent' is on. To insert a real tab when 'expandtab' is
on, use CTRL-V<Tab>.
This implementation doesn't change how BusyBox vi handles autoindent:
it continues to copy the indentation from a neighbouring line. If
that line has tabs in its indentation so too will the new line.
function old new delta
char_insert 563 679 +116
next_column - 48 +48
.rodata 105211 105236 +25
colon 3844 3855 +11
refresh 1000 982 -18
move_to_col 83 59 -24
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/2 up/down: 200/-42) Total: 158 bytes
Signed-off-by: Peter D <urmum69@snopyta.org>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Line addresses in colon commands can be defined using an expression
that includes '+' or '-' operators. The implementation follows
traditional vi:
- The first term in the expression defines an address. It can be
an absolute line number, '.', '$', a search or a marker.
- The second and subsequent terms must be non-negative integers.
- If the first term is missing '.' is assumed. If the operator is
missing addition is assumed. If the final term in missing an
offset of 1 is assumed.
Thus the following are valid addresses:
.+1 .+ + .1
.-1 .- -
The following are not valid (though they are in vim):
.+$ .$ 2+.
function old new delta
colon 3701 3844 +143
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 143/0) Total: 143 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
It should be possible to use a backward search as a line address
in colon commands.
function old new delta
colon 3661 3701 +40
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 40/0) Total: 40 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
BusyBox vi didn't have proper handling for invalid markers or
unsuccessful searches in colon line addresses. This could result
in the wrong lines being affected by a change.
Detect when an invalid address is specified, propagate an error
indicator up the call chain and issue a warning.
function old new delta
colon 3604 3661 +57
.rodata 105195 105211 +16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 73/0) Total: 73 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
The context marks that are automatically updated and can be used
with the "''" command didn't behave the same as in vi. Marks
were only being set for certain editing commands when they should
have been set on successful movement commands.
Make BusyBox vi behave more like vi.
function old new delta
.rodata 105179 105194 +15
do_cmd 4723 4668 -55
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 15/-55) Total: -40 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Opening a line above the current line with the 'O' command should
use the current, not previous, line to determine how much to
autoindent.
function old new delta
char_insert 531 563 +32
do_cmd 4746 4723 -23
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 32/-23) Total: 9 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
When whitespace has been automatically added to a new line due to
autoindent entering ctrl-D should reduce the level of indentation.
Implement an approximation of this by treating ctrl-D as backspace.
For the common case of indentation using tabs this is good enough.
My attempt at a full implementation was three times bigger.
function old new delta
char_insert 476 531 +55
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 55/0) Total: 55 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
When whole lines are yanked using 'yy' or 'Y' vi doesn't change the
cursor position. Make BusyBox vi do the same.
function old new delta
do_cmd 4776 4786 +10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 10/0) Total: 10 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Since commit a54450248 (vi: allow the '.' command to have a
repetition count) using '0' to specify a range doesn't work with
a non-zero repeat count, e.g. '1d0'. Users wouldn't normally try
to do that but the '.' command does.
Add a special case in get_motion_char() to handle this.
function old new delta
find_range 737 746 +9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 9/0) Total: 9 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Use a hand-coded loop to search for paragraph boundaries instead
of calling char_search(). We were using a loop anyway to skip
consecutive newlines.
function old new delta
do_cmd 4792 4752 -40
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-40) Total: -40 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Vi places the cursor on the last column of a tab character whereas
BusyBox vi puts it on the first. This is disconcerting for
experienced vi users and makes it impossible to distinguish
visually between an empty line and one containing just a tab.
It wasn't always this way. Prior to commit e3cbfb91d (vi: introduce
FEATURE_VI_8BIT) BusyBox vi also put the cursor on the last column.
However there were problems with cursor positioning when text was
inserted before a tab. Commit eaabf0675 (vi: multiple fixes by
Natanael Copa) includes a partial attempt to fix this. (The code is
still present but it's never executed. Clever compilers optimise it
away.)
Revert the changes of commit e3cbfb91d and fix the insert problem
for all tabs, not just the first.
To quote Natanael: "Costs a few bytes but its worth it imho".
function old new delta
refresh 974 1000 +26
move_to_col 81 83 +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 28/0) Total: 28 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
The undo queue didn't record deleted characters properly. For
example, insert some text, backspace over a couple of characters
then exit insert mode. At this point undo will restore two nulls
instead of the deleted characters.
The fix is in undo_push(): record the state of the UNDO_USE_SPOS
flag and clear it before using 'u_type'.
Also, update the comments to reflect the fact that UNDO_QUEUED_FLAG
isn't actually used.
function old new delta
undo_push 443 435 -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-8) Total: -8 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>