all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "B. T. Raven" <btraven@nihilo.net>
To: help-gnu-emacs@gnu.org
Subject: Re: help with regexp function
Date: Wed, 22 Nov 2017 22:18:14 -0600	[thread overview]
Message-ID: <ov5i620c1q@news4.newsguy.com> (raw)
In-Reply-To: <mailman.4298.1511349362.27995.help-gnu-emacs@gnu.org>

Thanks, Stephen and Kendall. Stephen's solution is exactly what I wanted 
except for the close-paren after the line number. What I needed to know 
about is the just discovered regexp-quote and re-builder functions. What 
I was relying on was the replace-match docs at C-hf whose syntax is much 
more complicated than your concatenation of match-strings 1 and 2.

Since my thinking about the problem was so tentative I won't try to 
remediate my code but just go with what Stephen wrote. Kendall wrote:
"
re-search-forward signals an error if the search string isn't matched. I 
don't know if that could explain the error you are seeing, but this 
would prevent a non-local exit:

(cond
   ((re-search-forward "^[0-9]+ " nil t)
    (setq num ...)
    (print num))
   (t
    (goto-char end)))
"

On 11/22/2017 05:15, Stephen Berman wrote:
 > 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:
 >>


[...]
 >
 > Here's a pretty direct translation of the interactive substitution:
This works correctly but it isn't exactly what regexp-quote returns.
Is there a function that produces "^\\([0-9]+\\) \\(.*\\)$" from 
"\(^[0-9]+ \)\(.+\)" ?  Did you replace .+ with .* just for greater 
generality?

 >
 > (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) ")"))))


[...]
 > 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?

No, I don't understand that notation. I started with other regexp 
functions like query-replace-regexp but was getting type errors and 
general confusion.

 >
 >> ;; 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.

Here is the function I was talking about:
(defun reverse-string (str)
   (apply #'string (nreverse (string-to-list str))))

It sounded like (append #'string ... was recasting a list to a string.

[...]
 >>
 >> Any help apppreciated.
 >>
 >> Ed
 >
 > Steve Berman
 >

Thanks again,

Ed


  parent reply	other threads:[~2017-11-23  4:18 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ov5i620c1q@news4.newsguy.com \
    --to=btraven@nihilo.net \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.