[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: help with regexp function
From: |
Stephen Berman |
Subject: |
Re: help with regexp function |
Date: |
Wed, 22 Nov 2017 12:15:51 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
On Tue, 21 Nov 2017 17:30:15 -0600 "B. T. Raven" <btraven@nihilo.net> wrote:
> Dear Emacs gurus:
>
> I can perform this inteactive substitution
> CM-%: \(^[0-9]+ \)\(.+\) -> \2 \1)
> in order to change a buffer line prefixed with a number into one post-fixed
> with the same number but I can't figue out how to do the same programatically
> to a whole region. I started with this code:
>
> (defun verse-num-move-beg-to-end (beg end)
> "Move int-string and following space from beginning of line to end of line
> throughout region."
> (interactive "r")
> (goto-char beg)
> (while (<= (point) end)
> (re-search-forward "^[0-9]+ ")
> (setq num (substring (match-string 0) 0 -1)) ;; should be a string of
> ;;digits without trailing space
> (print num)
Here's a pretty direct translation of the interactive substitution:
(defun verse-num-move-beg-to-end (beg end)
"Move int-string and following space from beginning of line to
end of line throughout region."
(interactive "r")
(goto-char beg)
(while (<= (point) end)
(re-search-forward "^\\([0-9]+\\) \\(.*\\)$")
(replace-match (concat (match-string 2) " " (match-string 1) ")"))))
> ;; here the value generates a wrong argument error:
> setq: Wrong type argument: listp, #("234" 0 3 (fontified t))
> (type-of #("234" 0 3 (fontified t)))
I can't tell what the problem without seeing the code that causes it.
Were you trying to treat the propertized string as a list because of the
#(...) notation?
> ;; I have a function which is a black box to to me but it works in the larger
> context I have it in. Does match-string do something like this implicitly
> (casting a list as a string?)
Not AFAIK.
> (substring (match-string 0) 0 -1)
> (replace-match "" nil t)
>
>
> 234 asentuhasneothu ;; example buffer-line
>
> Any help apppreciated.
>
> Ed
Steve Berman