help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: replace deprecated function ?


From: B. T. Raven
Subject: Re: replace deprecated function ?
Date: Fri, 16 Feb 2018 14:19:23 -0600
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0

On 2/16/2018 10:57, Emanuel Berg wrote:
B. T. Raven wrote:

Thanks, Joost and Emanuel. See below.

Here is the best version [1] so far because
I got away with the redundant input data and
you then use the `query-replace' interface
(indeed the very function) which is better than
the crude `yes-or-no-p'.

(defun replace-list-ask-3 (dict)
   (let ((re (string-join (mapcar #'car dict) "\\|")))
     (save-excursion
       (goto-char (point-min))
       (while (re-search-forward re nil t)
         (let*((match-string (match-string-no-properties 0))
               (default (cdr (assoc match-string dict))) )
           (when default
             (query-replace match-string default nil
                            (match-beginning 0)
                            (match-end       0) )))))))

;; (replace-list-ask-3 '(("james" . "James") ("blish" . "Blish")))

[1] http://user.it.uu.se/~embe8573/emacs-init/replace-list.el


Thanks, Emanuel. In order to conserve muscle memory I used the (read-key) kludge instead of y-or-n-p. My only goal was to get rid of query-replace-regexp-eval so the only thing I used from your code was re-search-forward (C function) instead of search-forward-regexp. It looks like your solution is more general but I don't currently have any application for it other than superscripting numerals (footnotes) here and there.

Ed


reply via email to

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