[Top][All Lists]

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

Re: recording-elisp.el - try recording commands as elisp code

From: Juri Linkov
Subject: Re: recording-elisp.el - try recording commands as elisp code
Date: Tue, 06 Nov 2007 02:45:47 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.50 (gnu/linux)

> Juri's approach get: (search-forward "abcdef")
> My implementation get: (search-forward "abc") (search-forward "abcdef"
> (search-forward "abcdef")
> rms's approach want: (isearch-forward) (isearch-append-string "abc")
> (isearch-yank-kill) (isearch-repeat-forward) (isearch-exit)
> What do we really want here?

Another case that might help us to decide to what level to record
Lisp code is converting M-% (`query-replace').  There are three basic
levels of "interactivity":

1. convert it to the call to `query-replace', e.g.

    (query-replace "from" "to" nil
                   (if (and transient-mark-mode mark-active) (region-beginning))
                   (if (and transient-mark-mode mark-active) (region-end)))

   That's how it is recorded now to `command-history'.

2. convert M-% to the call to `replace-string';

3. but the doc-string of this command says:

    This function is usually the wrong thing to use in a Lisp program.
    What you probably want is a loop like this:
      (while (search-forward FROM-STRING nil t)
        (replace-match TO-STRING nil t))
    which will run faster and will not set the mark or print anything.

So according to this guideline a Lisp program should use a loop with
search-forward and replace-match.

Juri Linkov

reply via email to

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