unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Using re-builder
@ 2004-06-17 17:45 Phil_C
  2004-06-17 22:51 ` Michael Slass
  2004-06-18  9:03 ` martin
  0 siblings, 2 replies; 8+ messages in thread
From: Phil_C @ 2004-06-17 17:45 UTC (permalink / raw)


When I copy a regex to the kill ring and then try to use it in
something like "Query replace regex", I have to delete the extra "'s
and \'s before it will work. Is there a way to copy it from re-builder
without having to do that?

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

* Re: Using re-builder
  2004-06-17 17:45 Using re-builder Phil_C
@ 2004-06-17 22:51 ` Michael Slass
  2004-06-18 14:35   ` Phil_C
  2004-06-18  9:03 ` martin
  1 sibling, 1 reply; 8+ messages in thread
From: Michael Slass @ 2004-06-17 22:51 UTC (permalink / raw)


biff314@yahoo.com (Phil_C) writes:

>When I copy a regex to the kill ring and then try to use it in
>something like "Query replace regex", I have to delete the extra "'s
>and \'s before it will work. Is there a way to copy it from re-builder
>without having to do that?


Try this:

(defun reb-copy-unquoted ()
  "Copy current RE into the kill ring for later insertion as unquoted."
  (interactive)
  (reb-update-regexp)
  (let ((re (with-temp-buffer
	      (insert (reb-target-binding reb-regexp))
              (replace-string "\\\\" "\\" nil (point-min) (point-max))
              (buffer-substring (point-min) (point-max)))))
    (kill-new re)
    (message "Regexp copied to kill-ring")))

-- 
Mike Slass

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

* Re: Using re-builder
  2004-06-17 17:45 Using re-builder Phil_C
  2004-06-17 22:51 ` Michael Slass
@ 2004-06-18  9:03 ` martin
  1 sibling, 0 replies; 8+ messages in thread
From: martin @ 2004-06-18  9:03 UTC (permalink / raw)



"PC" == Phil C <biff314@yahoo.com> writes:
 PC> Date: 17 Jun 2004 10:45:37 -0700
 PC> 
 PC> When I copy a regex to the kill ring and then try to use it in
 PC> something like "Query replace regex", I have to delete the extra "'s
 PC> and \'s before it will work. Is there a way to copy it from re-builder
 PC> without having to do that?
 PC> 

hi,

i presume that you copy the regexp from some lisp source code.

another way could be to copy it from minibuffer after constructing the
regexp with incremental search.

-- 
martin dot fischer at boschrexroth dot de

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

* Re: Using re-builder
  2004-06-17 22:51 ` Michael Slass
@ 2004-06-18 14:35   ` Phil_C
  2004-06-18 16:05     ` Kevin Rodgers
  0 siblings, 1 reply; 8+ messages in thread
From: Phil_C @ 2004-06-18 14:35 UTC (permalink / raw)


Michael Slass <miknrene@drizzle.com> wrote in message news:<m3n031ol2b.fsf@eric.rossnet.com>...
> biff314@yahoo.com (Phil_C) writes:
> 
> >When I copy a regex to the kill ring and then try to use it in
> >something like "Query replace regex", I have to delete the extra "'s
> >and \'s before it will work. Is there a way to copy it from re-builder
> >without having to do that?
> 
> 
> Try this:
> 
> (defun reb-copy-unquoted ()
>   "Copy current RE into the kill ring for later insertion as unquoted."
>   (interactive)
>   (reb-update-regexp)
>   (let ((re (with-temp-buffer
> 	      (insert (reb-target-binding reb-regexp))
>               (replace-string "\\\\" "\\" nil (point-min) (point-max))
>               (buffer-substring (point-min) (point-max)))))
>     (kill-new re)
>     (message "Regexp copied to kill-ring")))

Thanks, that just about does it - except the beginning and ending
quotes are still there. Still, that's much better than it was before,
since now I don't have to go through the whole regex deleting "\"s.


Thanks again,

--Phil

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

* Re: Using re-builder
  2004-06-18 14:35   ` Phil_C
@ 2004-06-18 16:05     ` Kevin Rodgers
  2004-06-18 17:08       ` Michael Slass
  0 siblings, 1 reply; 8+ messages in thread
From: Kevin Rodgers @ 2004-06-18 16:05 UTC (permalink / raw)


Phil_C wrote:
 > Michael Slass <miknrene@drizzle.com> wrote in message news:<m3n031ol2b.fsf@eric.rossnet.com>...
 >>Try this:
 >>
 >>(defun reb-copy-unquoted ()
 >>  "Copy current RE into the kill ring for later insertion as unquoted."
 >>  (interactive)
 >>  (reb-update-regexp)
 >>  (let ((re (with-temp-buffer
 >>	      (insert (reb-target-binding reb-regexp))
 >>              (replace-string "\\\\" "\\" nil (point-min) (point-max))
 >>              (buffer-substring (point-min) (point-max)))))
 >>    (kill-new re)
 >>    (message "Regexp copied to kill-ring")))
 >
 > Thanks, that just about does it - except the beginning and ending
 > quotes are still there. Still, that's much better than it was before,
 > since now I don't have to go through the whole regex deleting "\"s.

Well, you could either replace "\\`\"" and "\"\\'" with "", or avoid
inserting them in the first place:

(let ((regexp (reb-target-binding reb-regexp)))
   (insert (substring regexp 1 (1- (length regexp)))))

Another approach would be to leave the regexp string in the kill ring,
but define a new command to yank the regexp itself into the minibuffer.

And instead of using replace-string to replace "\\\\" with "\\", you
might be able to get the lisp reader to do it for you (e.g. with
make-symbol).

-- 
Kevin Rodgers

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

* Re: Using re-builder
  2004-06-18 16:05     ` Kevin Rodgers
@ 2004-06-18 17:08       ` Michael Slass
  2004-06-18 18:54         ` Kevin Rodgers
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Slass @ 2004-06-18 17:08 UTC (permalink / raw)


Kevin Rodgers <ihs_4664@yahoo.com> writes:

>Phil_C wrote:
> > Thanks, that just about does it - except the beginning and ending
> > quotes are still there. Still, that's much better than it was before,
> > since now I don't have to go through the whole regex deleting "\"s.
>

That's really strange --- I'm not getting the quotes; in fact, I first
tried (buffer-substring (1+ (point-min)) (1- (point-max))) thinking it
would trim the quotes, and I lost the first and last chars of the RE.

Wierd.

>Well, you could either replace "\\`\"" and "\"\\'" with "", or avoid
>inserting them in the first place:
>
>(let ((regexp (reb-target-binding reb-regexp)))
>   (insert (substring regexp 1 (1- (length regexp)))))
>
>Another approach would be to leave the regexp string in the kill ring,
>but define a new command to yank the regexp itself into the minibuffer.

That's a great idea, but I think it would require a global keybinding
to that new command to be really useful, since you never know where
you're going to want to yank the RE.


>
>And instead of using replace-string to replace "\\\\" with "\\", you
>might be able to get the lisp reader to do it for you (e.g. with
>make-symbol).

Alas, that's deeper in the lisp pool than I can swim.

-- 
Mike Slass

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

* Re: Using re-builder
  2004-06-18 17:08       ` Michael Slass
@ 2004-06-18 18:54         ` Kevin Rodgers
  2004-06-18 20:09           ` Michael Slass
  0 siblings, 1 reply; 8+ messages in thread
From: Kevin Rodgers @ 2004-06-18 18:54 UTC (permalink / raw)


Michael Slass wrote:
 >>Another approach would be to leave the regexp string in the kill ring,
 >>but define a new command to yank the regexp itself into the minibuffer.
 >
 > That's a great idea, but I think it would require a global keybinding
 > to that new command to be really useful, since you never know where
 > you're going to want to yank the RE.

The OP specifically requested the ability to yank the regexp into the
minibuffer in response to C-M-%'s "Query replace regexp: " prompt.  For
that, you would only need a binding in minibuffer-local-map.  But what
would be wrong with a global binding e.g. `C-c y' which is reserved for
the user?

-- 
Kevin Rodgers

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

* Re: Using re-builder
  2004-06-18 18:54         ` Kevin Rodgers
@ 2004-06-18 20:09           ` Michael Slass
  0 siblings, 0 replies; 8+ messages in thread
From: Michael Slass @ 2004-06-18 20:09 UTC (permalink / raw)


Kevin Rodgers <ihs_4664@yahoo.com> writes:

>
>The OP specifically requested the ability to yank the regexp into the
>minibuffer in response to C-M-%'s "Query replace regexp: " prompt.  For
>that, you would only need a binding in minibuffer-local-map.  But what
>would be wrong with a global binding e.g. `C-c y' which is reserved for
>the user?

Absolutely nothing wrong; in fact I think it's a great idea.  I was
just pointing out that doing so increases the scope of the change
beyond simply extending the re-builder package.

-- 
Mike Slass

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

end of thread, other threads:[~2004-06-18 20:09 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-06-17 17:45 Using re-builder Phil_C
2004-06-17 22:51 ` Michael Slass
2004-06-18 14:35   ` Phil_C
2004-06-18 16:05     ` Kevin Rodgers
2004-06-18 17:08       ` Michael Slass
2004-06-18 18:54         ` Kevin Rodgers
2004-06-18 20:09           ` Michael Slass
2004-06-18  9:03 ` martin

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