unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* help with regexp function
@ 2017-11-21 23:30 B. T. Raven
  2017-11-22 11:15 ` Stephen Berman
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: B. T. Raven @ 2017-11-21 23:30 UTC (permalink / raw)
  To: help-gnu-emacs

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-11-24 16:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-21 23:30 help with regexp function B. T. Raven
2017-11-22 11:15 ` Stephen Berman
2017-11-22 17:05 ` Kendall Shaw
     [not found] ` <mailman.4298.1511349362.27995.help-gnu-emacs@gnu.org>
2017-11-23  4:18   ` B. T. Raven
2017-11-23 15:20     ` Stephen Berman
     [not found]     ` <mailman.4372.1511450434.27995.help-gnu-emacs@gnu.org>
2017-11-24 14:46       ` B. T. Raven
2017-11-24 16:28         ` Stephen Berman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).