[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Search/Replace manual changes.

From: David Kastrup
Subject: Re: Search/Replace manual changes.
Date: 25 Jun 2004 00:00:47 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

Juri Linkov <address@hidden> writes:

> David Kastrup <address@hidden> writes:
> >  @example
> > -M-x query-replace @key{RET} x @key{RET} @@TEMP@@ @key{RET}
> > -M-x query-replace @key{RET} y @key{RET} x @key{RET}
> > -M-x query-replace @key{RET} @@TEMP@@ @key{RET} y @key{RET}
> > +M-x replace-string @key{RET} x @key{RET} @@TEMP@@ @key{RET}
> > +M-< M-x replace-string @key{RET} y @key{RET} x @key{RET}
> > +M-< M-x replace-string @key{RET} @@TEMP@@ @key{RET} y @key{RET}
> >  @end example
> I think this example should be removed from the Emacs manual
> completely.  Using three commands to exchange words is too clumsy.
> When reading the Emacs manual the users will mis-spend their time at
> understanding and remembering this example not knowing that a better
> method to do this is shown in the next chapter.

But the method in the next chapter requires a basic Lisp
understanding.  It is an advanced technique.  Granted, probably one of
the easiest, and probably a nice incentive for learning, but it is
still an advanced technique.  I don't think we should remove an
example for swapping strings that is accessible also to the beginner.

> > > +  You can also use arbitrary Lisp expressions evaluated at replacement
> > +time by placing @samp{\,} before them in the replacement string.  Inside
> > +of those expressions, the symbols @samp{\&} and @address@hidden refer to
> > +match and submatch strings like described above (a submatch not matching
> > +anything will be @samp{nil}), and @samp{\&#} and @address@hidden to
> This looks like a typo: this should be @samp{\#&} and
> @address@hidden

Right.  I'll fix that.

> > +As another example, to add consecutively numbered strings like
> > address@hidden to column 73 to~80 (unless they are already occupied),
> > +you can use
> > +
> > address@hidden
> > +M-x replace-regexp @key{RET} address@hidden,address@hidden @key{RET}
> > +\,(format "%-72sABC%05d" \& \#) @key{RET}
> > address@hidden example
> Do we really need this ancient punched card 80-column filling example?

It is a non-trivial, yet short example for using "format", which is
certainly another highlight to utilize in the context of `\,'.  In
particular because of the possibilities for using the field widths.

Apart from which I find the example amusing.  It's so "wouldn't it
have been nice if we had this 40 years ago"ish.  And you recognized
it immediately...

> M-x replace-regexp @key{RET} address@hidden @key{RET}
> \&address@hidden:\,(format "%05d" (1+ \#))address@hidden @key{RET}

I prefer having two quite easy examples rather than cramming
everything into one.  If people see a lot of weirdness all too early
and at once, they will just skip it and think "that's rocket science,

David Kastrup, Kriemhildstr. 15, 44793 Bochum

reply via email to

[Prev in Thread] Current Thread [Next in Thread]