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

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

help with regexp function


From: B. T. Raven
Subject: help with regexp function
Date: Tue, 21 Nov 2017 17:30:15 -0600
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0

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 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 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?)
...
(substring (match-string 0) 0 -1)
(replace-match "" nil t)


234 asentuhasneothu ;; example buffer-line

Any help apppreciated.

Ed


reply via email to

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