vi: code shrink motion by paragraph
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>
This commit is contained in:
parent
d9d19896a9
commit
033fa3d5c6
27
editors/vi.c
27
editors/vi.c
@ -3636,21 +3636,24 @@ static void do_cmd(int c)
|
|||||||
break;
|
break;
|
||||||
case '{': // {- move backward paragraph
|
case '{': // {- move backward paragraph
|
||||||
case '}': // }- move forward paragraph
|
case '}': // }- move forward paragraph
|
||||||
|
dir = c == '}' ? FORWARD : BACK;
|
||||||
do {
|
do {
|
||||||
dir = c == '}' ? FORWARD : BACK;
|
int skip = TRUE; // initially skip consecutive empty lines
|
||||||
// skip over consecutive empty lines
|
while (dir == FORWARD ? dot < end - 1 : dot > text) {
|
||||||
while ((dir == FORWARD ? dot < end - 1 : dot > text) &&
|
if (*dot == '\n' && dot[dir] == '\n') {
|
||||||
*dot == '\n' && dot[dir] == '\n') {
|
if (!skip) {
|
||||||
|
if (dir == FORWARD)
|
||||||
|
++dot; // move to next blank line
|
||||||
|
goto dc2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
skip = FALSE;
|
||||||
|
}
|
||||||
dot += dir;
|
dot += dir;
|
||||||
}
|
}
|
||||||
q = char_search(dot, "\n\n", ((unsigned)dir << 1) | FULL);
|
goto dc6; // end of file
|
||||||
if (q != NULL) { // found blank line
|
dc2: continue;
|
||||||
dot = next_line(q); // move to next blank line
|
|
||||||
}
|
|
||||||
else { // blank line not found, move to end of file
|
|
||||||
dot = dir == FORWARD ? end - 1 : text;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while (--cmdcnt > 0);
|
} while (--cmdcnt > 0);
|
||||||
break;
|
break;
|
||||||
#endif /* FEATURE_VI_SEARCH */
|
#endif /* FEATURE_VI_SEARCH */
|
||||||
|
Loading…
Reference in New Issue
Block a user