Hi Jason,

Jason McIntyre wrote on Sun, Jul 07, 2019 at 08:56:43PM +0100:

> this is getting silly - we're mixing talking about how /re/ and ?re?
> work as addresses and as regular expressions in other places. dropping
> the trailing [/?] does not apply to regular expressions everywhere.

Actually, it does, though you are right in so far as the three
cases (addresses, global searches, and replacements) differ in
subtle ways.

> even if i have this wrong (to be fair, not that unlikely), we should
> just concentrate on one thing at a time.

We have now taken care of the case of addresses.

The case of replacements is already described correctly:

> regarding how dropping two delimiters works in an 's' command, although
> i'm not sure really of the reason, you can do:
>       1,$s/re
> which effectively drops /replacement/

Yes, this is described as follows:

   If one or two of the last delimiters is omitted, then the last line
   affected is printed as though the print suffix p were specified.

Admittedly, the grammar is awkward ("two of things is omitted"),
and it is not said explicitly that omitting both delimiters implies
deleting the re without a replacement - but one could argue that
is implicitly to be expected because omitting the middle delimiter
implies that the replacement can only be empty.  If you think this
should be improved, we can polish it later.


So what remains to be decsribed is the case of global searches (gGvV).

Here is what POSIX says about those:

  If the closing delimiter of an RE or of a replacement string (for
  example, '/' ) in a g, G, s, v, or V command would be the last
  character before a <newline>, that delimiter can be omitted, in
  which case the addressed line shall be written.

Our implementation appears to comply.

While documenting this, also fix a few glitches in the vicinity:

 * The wording "the current address is set to the last line affected
   by command-list" can easily be misunderstood.  The temporal sense
   of "last" is intended, but it can easily be read as the last (i.e.
   highest numbered) line in the file.  So let's better talk about
   the "last command executed", not about the "last line".
   You can easily see that this is correct with a command like

     g/.../+p\
     -p
     .

   which, for each matching line, first prints the following line,
   then the matching line itself, and leaves the matching line
   (printed by the last command) as the current line, not the
   following line, even though the following line was also "affected"
   and comes later in the file.

 * Avoid the confusing wording "a newline alone in command-list".
   The newline is not *in* the command list, but it comes after
   the command list, terminating it.

 * For G, explicitly say that an empty command list has a different
   effect compared to g: for g, it does the same as p, whereas for G,
   it does nothing at all.

There is nothing to do for v and V, which mostly point to g and G only.

OK for the patch below?

Yours,
  Ingo


Index: ed.1
===================================================================
RCS file: /cvs/src/bin/ed/ed.1,v
retrieving revision 1.72
diff -u -p -r1.72 ed.1
--- ed.1        12 Jul 2019 19:28:48 -0000      1.72
+++ ed.1        12 Jul 2019 22:17:47 -0000
@@ -377,7 +377,7 @@ The current address is set to the line c
 command-list is executed.
 At the end of the
 .Ic g
-command, the current address is set to the last line affected by command-list.
+command, the current address remains as set by the last command executed.
 If no lines were matched,
 the current line number remains unchanged.
 .Pp
@@ -392,22 +392,26 @@ Any commands are allowed, except for
 .Ic v ,
 and
 .Ic V .
-A newline alone in command-list is equivalent to a
+An empty
+.Ar command-list
+is equivalent to a
 .Ic p
 command.
+In this case, the trailing slash can be omitted.
 .Sm off
 .It (1,$) Ic G No / Ar re No /
 .Sm on
 Interactively edits the addressed lines matching a regular expression
 .Ar re .
+The trailing slash after
+.Ar re
+can be omitted.
 For each matching line, the line is printed, the current address is set,
 and the user is prompted to enter a
 .Ar command-list .
 At the end of the
 .Ic G
-command, the current address is set to the last line affected by
-.Pq the last
-command-list.
+command, the current address remains as set by the last command executed.
 If no lines were matched,
 the current line number remains unchanged.
 .Pp
@@ -415,11 +419,10 @@ The format of
 .Ar command-list
 is the same as that of the
 .Ic g
-command.
-A newline alone acts as a null command list.
+command, but an empty command list does nothing.
 A single
 .Sq &
-repeats the last non-null command list.
+repeats the last non-empty command list.
 .It Ic H
 Toggles the printing of error explanations.
 By default, explanations are not printed.

Reply via email to