Skip to content

Commit

Permalink
ed: allow repeated search with // and ?? (#768)
Browse files Browse the repository at this point in the history
* ed: allow repeated search with // and ??

* In commit 78d5429, 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
  • Loading branch information
mknos authored Oct 24, 2024
1 parent 9f891d0 commit 11e2c4c
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions bin/ed
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 11e2c4c

Please sign in to comment.