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: Tue, 13 Feb 2018 16:41:07 -0600
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0

On 2/13/2018 14:00, Emanuel Berg wrote:
(require 'cl-lib)

(defun replace-regexp-buffer (regexp replace)
   (save-excursion
     (goto-char (point-min))
     (while (re-search-forward regexp nil t)
       (replace-match replace) )))

(defun replace-list (list-pairs)
   (cl-loop for (search . replace) in list-pairs do
            (replace-regexp-buffer search replace) ))

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

;; james blish james blish



Thanks Emanuel but I need it to be more interactive. I want to look at each number that the query finds and press either space bar or n. The following produces argument "Args out of range" for no reason that I can ascertain. query-replace-regex has 5 args rexexp string, string, nil, int and int. Whence the error? Try my original function with query-replace-regexp-eval (the function I want to ditch) to see how it should work.


(defun num-to-supnum ( ) ;; M-x sup
    "Replace digits with superscript digits."
  (interactive)
  (let ((start (point)))
    (save-excursion
      (query-replace-regexp "[1234567890]"
                                 (cdr (assoc (match-string 0)
'(("1" . "¹") ("2" . "²") ("3" . "³") ("4" . "⁴") ("5" . "⁵") ("6" . "⁶") ("7" . "⁷") ("8" . "⁸") ("9" . "⁹") ("0" . "⁰"))

                                  ))
                                 nil start (point-max))
)))


Mutatis mutandis, it seems like I should be able to use query-replace-regexp but I can't get around the various errors it produces by trying different lisp idioms. If I evaluate different parts of the defun step-wise I see everything returned just as I expect. Could the fact that the superscripts are multi-byte cause a problem? Do I need backslashes someewhere?

Thanks anyway,

Ed


reply via email to

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