From 11e2c4c383aeb54093a3258719f0de3fa6f84eb6 Mon Sep 17 00:00:00 2001 From: Michael Mikonos <127171689+mknos@users.noreply.github.com> Date: Thu, 24 Oct 2024 11:06:42 +0800 Subject: [PATCH] ed: allow repeated search with // and ?? (#768) * ed: allow repeated search with // and ?? * In commit 78d54294099cfab729e156e8a0f123939da14179, repeat search was only implemented for "/" and "?" * Add support for empty patterns specified as "??" and "//" (these may be followed by whitespace, but single "?" and "/" may not) * test1: "/\n" --> repeat search down * test2: "/ \n" --> start new search (down) for " " * test3: "// \n" --> repeat search down * test4: "?\n" --> repeat search up * test5: "? \n"--> start new search (up) for " " * test6: "?? \n --> repeat search up * Entering //n doesn't seem to work for repeating search then issuing n command (this could be supported later) * mention search features in pod manual --- bin/ed | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/bin/ed b/bin/ed index 59424c5b..4fb53878 100755 --- a/bin/ed +++ b/bin/ed @@ -886,14 +886,14 @@ sub edSetCurrentLine { sub edParse { s/\A\s+//; - if (m/\A(\/|\?)\z/) { + if (m/\A(\/|\?)\z/ || m/\A(\/{2}|\?{2})\s*\z/) { unless (defined $SearchPat) { edWarn(E_NOPAT); $command = 'nop'; return 1; } my $found; - if ($1 eq '/') { + if ($1 eq '/' || $1 eq '//') { $found = edSearchForward($SearchPat); } else { $found = edSearchBackward($SearchPat); @@ -1284,6 +1284,22 @@ Quit program Read named FILE into buffer +=item /PATTERN + +Search for PATTERN in the buffer, starting from the current line. +If no pattern is given the previous search is repeated. + +=item ?PATTERN + +Search backwards for PATTERN in the buffer, starting from the current line. +If no pattern is given the previous search is repeated. + +=item g/PATTERN/CMD + +Search globally in buffer for PATTERN and run command CMD on each matching line. +CMD is a single command letter of the following: 'l', 'n' and 'p'. +CMD can be omitted. + =item s/// Substitute text with a regular expression