[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: |
Wed, 14 Feb 2018 17:04:39 -0600 |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 |
Thanks, Joost and Emanuel. See below.
On 2/13/2018 17:19, Joost Kremers wrote:
On Tue, Feb 13 2018, B. T. Raven wrote:
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?
I suspect it's because you cannot use `match-string' to refer to the
match data of the regexp search still being executed.
This seems to be true of query-replace-regexp but not
query-replace-regexp-eval. The second argument of the deprecated
function is to-expr and it does work in my old defun. (I copy-pasted
that snippet from some code a few years ago. The second argument of
query-replace-regexp is a string.
This one works the same a my defun using query-replace-regexp-eval:
(defun num-to-supnum ( ) ;; M-x sup alias
"Replace digits with superscript digits."
(interactive)
(save-excursion
(setq pm (point-max))
(while (> pm (point))
(progn
(search-forward-regexp "[0-9]")
(backward-char)
(if (= (read-key) 32)
;; spacebar to preserve query-replace-regexp look and feel
(replace-match (cdr (assoc (match-string 0)
'(("1" . "¹") ("2" . "²")
("3" . "³") ("4" . "⁴") ("5" . "⁵")
("6" . "⁶") ("7" . "⁷")
("8" . "⁸") ("9" . "⁹") ("0" . "⁰")))))
(forward-char))
)
)))
Ed
p.s. This defun betrays my Quick-BASIC cognitive style but it seems to
work. What's mainly wrong with it?
The doc string of `query-replace-regexp-eval' says that in
non-interactive use, you should use a loop of `search-regexp-forward'
is this new synonym for search-forward.... ^
plus `replace-match'. You may be able to wrap the `replace-match' call
in y-or-n-p.
HTH
- replace deprecated function ?, B. T. Raven, 2018/02/13
- Re: replace deprecated function ?, Emanuel Berg, 2018/02/13
- Re: replace deprecated function ?, Emanuel Berg, 2018/02/13
- Re: replace deprecated function ?, B. T. Raven, 2018/02/13
- Re: replace deprecated function ?, Joost Kremers, 2018/02/13
- Re: replace deprecated function ?, Emanuel Berg, 2018/02/13
- Re: replace deprecated function ?, Emanuel Berg, 2018/02/13
- Re: replace deprecated function ?, Yuri Khan, 2018/02/13
- Message not available
- Re: replace deprecated function ?, Emanuel Berg, 2018/02/13
- Message not available
- Re: replace deprecated function ?,
B. T. Raven <=
- Re: replace deprecated function ?, Emanuel Berg, 2018/02/16
- Re: replace deprecated function ?, B. T. Raven, 2018/02/16
Re: replace deprecated function ?, Kaushal Modi, 2018/02/13
Message not available