[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH] vi: searches in colon commands should wrap
From:       Ron Yorston <rmy () pobox ! com>
Date:       2021-08-21 13:02:43
Message-ID: 6120f973.Cg1auyXpcmBX+MtG%rmy () pobox ! com
[Download RAW message or body]

The '/' and '?' search commands wrap to the other end of the buffer
if the search target isn't found.  When searches are used to specify
addresses in colon commands they should do the same.

(In traditional vi and vim this behaviour is controlled by the
'wrapscan' option.  BusyBox vi doesn't have this option and always
uses the default behaviour.)

function                                             old     new   delta
colon                                               4033    4077     +44
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 44/0)               Total: 44 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
---
 editors/vi.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/editors/vi.c b/editors/vi.c
index 3e1bd0820..126780175 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -2526,8 +2526,13 @@ static char *get_one_address(char *p, int *result)	// get colon addr, if present
 				dir = ((unsigned)BACK << 1) | FULL;
 			}
 			q = char_search(q, last_search_pattern + 1, dir);
-			if (q == NULL)
-				return NULL;
+			if (q == NULL) {
+				// no match, continue from other end of file
+				q = char_search(dir > 0 ? text : end - 1,
+								last_search_pattern + 1, dir);
+				if (q == NULL)
+					return NULL;
+			}
 			new_addr = count_lines(text, q);
 		}
 # endif
-- 
2.31.1

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic