unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* yank-match.el -- yank matches for a regexp from kill-ring
@ 2007-07-15 23:38 Karl Fogel
  2007-07-17 18:44 ` Mathias Dahl
  2008-03-02 16:17 ` Karl Fogel
  0 siblings, 2 replies; 13+ messages in thread
From: Karl Fogel @ 2007-07-15 23:38 UTC (permalink / raw)
  To: Emacs-Devel

I've had this code for ten years or so.  I use it every day; I think
Noah Friedman uses it too.  I'm not sure who else even knows about it.
See doc string for `yank-match' to grok what it does.

It might be useful to have in Emacs.  Comments welcome.

;;; -*- Mode: Emacs-Lisp -*-
;;; File: yank-match.el
;;; 
;;; Yanks matches for REGEXP from kill-ring.
;;; Copyright (C) 1997 Karl Fogel <kfogel@red-bean.com>
;;; 
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;; 
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;; 
;;; You should have received a copy of the GNU General Public License along
;;; with this program; if not, write to the Free Software Foundation, Inc.,
;;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
;;;
;;; USAGE:
;;;
;;; Just call yank-match ("M-x yank-match" or whatever keybinding you 
;;; have installed for it) and supply a regular expression at the prompt.
;;; See documentation for `yank-match' for more details.

(defvar yank-match-modify-kill-ring nil "*Non-nil means place matches 
at the front of the kill-ring, thus making it not behave like a ring for
yank-match functions.  Instead you'd \"bounce back\" from one end of
the kill-ring to the other with repeated yank-matches.  However, each
match would then be available for immediate yanking with \\[yank].

If that was at all confusing, just leave this set to nil.")

(defvar yank-match-count 0 "Which match in kill ring yank-match will 
yank.")

(defvar yank-match-last-regexp nil "Last regexp used by yank-match.")

(defvar yank-match-inserted nil "Did we insert on last yank match?")

(defun yank-match (re)
  "Yank the first item in the kill-ring that contains a match for RE
\(a regular expression\).  Set point and mark just as \\[yank] does.

Repeated invocations with no intervening commands will run
successively through the matches for RE in the kill-ring,
replacing the previously-yanked text with the new match each
time, without prompting for a new regular expression,

See variable `yank-match-modify-kill-ring' for a way to make matches
automatically be put at the front of the kill-ring \(and thus be available
for immediate yanking\).  Normally, matches are not put at the front
of the kill ring, but if you do \\[copy-region-as-kill] or
\\[kill-ring-save] immediately after finding the match you wanted, it
will then be put at the front of the ring, and \\[yank] will default
to that match.

Because the kill-ring is a ring \(or a dead ringer for one, at
least\), it is okay to repeat this command more times than the number
of matches in the kill-ring.  It just means that previous matches will
come back to haunt you."
  (interactive (if (equal last-command 'yank-match)
		   (list yank-match-last-regexp)
		 (list (read-from-minibuffer "Yank match (regexp): "))))
  (let ((repeating (equal last-command 'yank-match)))
    (if repeating
	(progn
	  ;; if inserted on last yank, kill that region before yanking new
	  (if yank-match-inserted 
	      (progn
		(setq yank-match-inserted nil)
		(delete-region (mark) (point))))

	  ;; if repeating and successful match this time
	  (if (do-yank-match re yank-match-count)
		(setq yank-match-count (1+ yank-match-count))

	    ;; if repeating and unsuccessful match this time
	    (progn
	      (setq yank-match-count 1)
	      (do-yank-match re 0))))
		      
      ;; if not repeating
      (if (do-yank-match re 0)
	  (setq yank-match-count 1)
	(error 
	 (concat "No match found for \"" re "\" in kill-ring.")))))
  (setq yank-match-last-regexp re)
  (setq this-command 'yank-match))


(defun do-yank-match (re num)
  (let ((found-one t))
    (catch 'done
      (let ((index 0)
	    (len (1- (length kill-ring))))
	(progn
	  (while (<= index len)
	    (let ((str (nth index kill-ring)))
	      (if (string-match re str)
		  (if (= num 0)
		      (progn (setq found-one nil)
			     (setq yank-match-inserted t)
			     (push-mark (point))
			     (insert str)
			     (if yank-match-modify-kill-ring
				 (setq 
				  kill-ring
				  (cons str (delq str kill-ring))))
			     (throw 'done nil))
		    (progn (setq found-one t)
			   (setq num (1- num))
			   (setq index (1+ index))))
		(setq index (1+ index))))))))
    (not found-one))) ; so it returns t on success! 

;;; yank-match.el ends here

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

* Re: yank-match.el -- yank matches for a regexp from kill-ring
  2007-07-15 23:38 yank-match.el -- yank matches for a regexp from kill-ring Karl Fogel
@ 2007-07-17 18:44 ` Mathias Dahl
  2007-07-17 18:46   ` Karl Fogel
  2008-03-02 16:17 ` Karl Fogel
  1 sibling, 1 reply; 13+ messages in thread
From: Mathias Dahl @ 2007-07-17 18:44 UTC (permalink / raw)
  To: Karl Fogel; +Cc: Emacs-Devel

> ...
> (defun yank-match (re)
>   "Yank the first item in the kill-ring that contains a match for RE
> \(a regular expression\).  Set point and mark just as \\[yank] does.
>
> Repeated invocations with no intervening commands will run
> successively through the matches for RE in the kill-ring,
> replacing the previously-yanked text with the new match each
> time, without prompting for a new regular expression,
> ...

This sounds very handy. I cannot say I have been longing for such a
command, but now that I know it exist I will probably find uses for
it. Taking advantage of what is in the kill ring is something I have
mostly underestimated.

There isn't any other way to do this in standard Emacs, is it?

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

* Re: yank-match.el -- yank matches for a regexp from kill-ring
  2007-07-17 18:44 ` Mathias Dahl
@ 2007-07-17 18:46   ` Karl Fogel
  2007-07-17 19:29     ` Drew Adams
  2007-07-28 20:32     ` T. V. Raman
  0 siblings, 2 replies; 13+ messages in thread
From: Karl Fogel @ 2007-07-17 18:46 UTC (permalink / raw)
  To: Mathias Dahl; +Cc: Emacs-Devel

"Mathias Dahl" <mathias.dahl@gmail.com> writes:
> This sounds very handy. I cannot say I have been longing for such a
> command, but now that I know it exist I will probably find uses for
> it. Taking advantage of what is in the kill ring is something I have
> mostly underestimated.
>
> There isn't any other way to do this in standard Emacs, is it?

I don't know of any existing feature that does this.  Part of my
purpose in posting here was to find out.

If there is no such feature, I would like to install this code.  But
I'll wait a bit longer for comments.

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

* RE: yank-match.el -- yank matches for a regexp from kill-ring
  2007-07-17 18:46   ` Karl Fogel
@ 2007-07-17 19:29     ` Drew Adams
  2007-07-17 20:40       ` Mathias Dahl
  2007-07-28 20:32     ` T. V. Raman
  1 sibling, 1 reply; 13+ messages in thread
From: Drew Adams @ 2007-07-17 19:29 UTC (permalink / raw)
  To: Karl Fogel, Mathias Dahl; +Cc: Emacs-Devel

> > This sounds very handy. I cannot say I have been longing for such a
> > command, but now that I know it exist I will probably find uses for
> > it. Taking advantage of what is in the kill ring is something I have
> > mostly underestimated.
> >
> > There isn't any other way to do this in standard Emacs, is it?
>
> I don't know of any existing feature that does this.  Part of my
> purpose in posting here was to find out.
>
> If there is no such feature, I would like to install this code.  But
> I'll wait a bit longer for comments.

Sounds good to me.

This falls into the category of things that complement the cycling of `M-y',
which is mainly useful for only the first several items of the kill-ring.

Here are two other approaches in the same category.

* browse-kill-ring.el - see
http://www.emacswiki.org/cgi-bin/wiki/BrowseKillRing

* In Icicles, `C-y' with a negative prefix arg uses completion to let you
yank a kill-ring entry (actually, any number of such entries, any number of
times). The completion can be regexp/substring-based.

yank-match.el uses an approach analogous to that of `M-r' for matching a
regexp against the minibuffer history. It can require some cycling to get
the right match. The Icicles approach uses completion instead, so you can
pick a matching candidate directly without cycling.

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

* Re: yank-match.el -- yank matches for a regexp from kill-ring
  2007-07-17 19:29     ` Drew Adams
@ 2007-07-17 20:40       ` Mathias Dahl
  0 siblings, 0 replies; 13+ messages in thread
From: Mathias Dahl @ 2007-07-17 20:40 UTC (permalink / raw)
  To: Drew Adams; +Cc: Karl Fogel, Emacs-Devel

> yank-match.el uses an approach analogous to that of `M-r' for matching a
> regexp against the minibuffer history. It can require some cycling to get
> the right match. The Icicles approach uses completion instead, so you can
> pick a matching candidate directly without cycling.

IMHO the Icicles approach sounds even more useful.

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

* Re: yank-match.el -- yank matches for a regexp from kill-ring
  2007-07-17 18:46   ` Karl Fogel
  2007-07-17 19:29     ` Drew Adams
@ 2007-07-28 20:32     ` T. V. Raman
  1 sibling, 0 replies; 13+ messages in thread
From: T. V. Raman @ 2007-07-28 20:32 UTC (permalink / raw)
  To: kfogel; +Cc: emacs-devel, mathias.dahl


There is no direct way of doing what your code enables I use
browse-kill-ring at  present to   find things in the kill ring, 

>>>>> "Karl" == Karl Fogel <kfogel@red-bean.com> writes:
    Karl> "Mathias Dahl" <mathias.dahl@gmail.com> writes:
    >> This sounds very handy. I cannot say I have been longing
    >> for such a command, but now that I know it exist I will
    >> probably find uses for it. Taking advantage of what is in
    >> the kill ring is something I have mostly underestimated.
    >> 
    >> There isn't any other way to do this in standard Emacs, is
    >> it?
    Karl> 
    Karl> I don't know of any existing feature that does this.
    Karl> Part of my purpose in posting here was to find out.
    Karl> 
    Karl> If there is no such feature, I would like to install
    Karl> this code.  But I'll wait a bit longer for comments.
    Karl> 
    Karl> 
    Karl> _______________________________________________
    Karl> Emacs-devel mailing list Emacs-devel@gnu.org
    Karl> http://lists.gnu.org/mailman/listinfo/emacs-devel

-- 
Best Regards,
--raman

      
Email:  raman@users.sf.net
WWW:    http://emacspeak.sf.net/raman/
AIM:    emacspeak       GTalk: tv.raman.tv@gmail.com
PGP:    http://emacspeak.sf.net/raman/raman-almaden.asc
Google: tv+raman 
IRC:    irc://irc.freenode.net/#emacs

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

* yank-match.el -- yank matches for a regexp from kill-ring
  2007-07-15 23:38 yank-match.el -- yank matches for a regexp from kill-ring Karl Fogel
  2007-07-17 18:44 ` Mathias Dahl
@ 2008-03-02 16:17 ` Karl Fogel
  2008-03-02 17:59   ` Juri Linkov
  1 sibling, 1 reply; 13+ messages in thread
From: Karl Fogel @ 2008-03-02 16:17 UTC (permalink / raw)
  To: emacs-devel

Yidong and Stefan (and everyone else),

A while ago, I posted suggesting that I install 'yank-match' (see
below) into Emacs.  There was some discussion of whether it overlaps
with any other functionality, but the general sentiment seemed to be
in favor of installing.  It would not be attached to a keybinding by
default, just available for people to custom bind.  The original
thread starts here:

   http://lists.gnu.org/archive/html/emacs-devel/2007-07/msg00778.html

For various reasons, I didn't get a chance to install it, and then
overall maintainership changed from RMS to Stefan and Yidong.  I'm now
ready to install it -- but it's been so long that I thought I should
check once more first.

Rather than stuffing it into simple.el, I guess I'd create a new file
yank-match.el (suggestions for other destinations welcome).

The FSF already has my papers; naturally I'd adjust the copyright
notice before installing.

-Karl

--------------------8-<-------cut-here---------8-<-----------------------
;;; -*- Mode: Emacs-Lisp -*-
;;; File: yank-match.el
;;; 
;;; Yanks matches for REGEXP from kill-ring.
;;; Copyright (C) 1997 Karl Fogel <kfogel@red-bean.com>
;;; 
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;; 
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;; 
;;; You should have received a copy of the GNU General Public License along
;;; with this program; if not, write to the Free Software Foundation, Inc.,
;;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
;;;
;;; USAGE:
;;;
;;; Just call yank-match ("M-x yank-match" or whatever keybinding you 
;;; have installed for it) and supply a regular expression at the prompt.
;;; See documentation for `yank-match' for more details.

(defvar yank-match-modify-kill-ring nil "*Non-nil means place matches 
at the front of the kill-ring, thus making it not behave like a ring for
yank-match functions.  Instead you'd \"bounce back\" from one end of
the kill-ring to the other with repeated yank-matches.  However, each
match would then be available for immediate yanking with \\[yank].

If that was at all confusing, just leave this set to nil.")

(defvar yank-match-count 0 "Which match in kill ring yank-match will 
yank.")

(defvar yank-match-last-regexp nil "Last regexp used by yank-match.")

(defvar yank-match-inserted nil "Did we insert on last yank match?")

(defun yank-match (re)
  "Yank the first item in the kill-ring that contains a match for RE
\(a regular expression\).  Set point and mark just as \\[yank] does.

Repeated invocations with no intervening commands will run
successively through the matches for RE in the kill-ring,
replacing the previously-yanked text with the new match each
time, without prompting for a new regular expression,

See variable `yank-match-modify-kill-ring' for a way to make matches
automatically be put at the front of the kill-ring \(and thus be available
for immediate yanking\).  Normally, matches are not put at the front
of the kill ring, but if you do \\[copy-region-as-kill] or
\\[kill-ring-save] immediately after finding the match you wanted, it
will then be put at the front of the ring, and \\[yank] will default
to that match.

Because the kill-ring is a ring \(or a dead ringer for one, at
least\), it is okay to repeat this command more times than the number
of matches in the kill-ring.  It just means that previous matches will
come back to haunt you."
  (interactive (if (equal last-command 'yank-match)
		   (list yank-match-last-regexp)
		 (list (read-from-minibuffer "Yank match (regexp): "))))
  (let ((repeating (equal last-command 'yank-match)))
    (if repeating
	(progn
	  ;; if inserted on last yank, kill that region before yanking new
	  (if yank-match-inserted 
	      (progn
		(setq yank-match-inserted nil)
		(delete-region (mark) (point))))

	  ;; if repeating and successful match this time
	  (if (do-yank-match re yank-match-count)
		(setq yank-match-count (1+ yank-match-count))

	    ;; if repeating and unsuccessful match this time
	    (progn
	      (setq yank-match-count 1)
	      (do-yank-match re 0))))
		      
      ;; if not repeating
      (if (do-yank-match re 0)
	  (setq yank-match-count 1)
	(error "No match found for `%s' in kill ring." re))))
  (setq yank-match-last-regexp re)
  (setq this-command 'yank-match))


(defun do-yank-match (re num)
  (let ((found-one t))
    (catch 'done
      (let ((index 0)
	    (len (1- (length kill-ring))))
	(progn
	  (while (<= index len)
	    (let ((str (nth index kill-ring)))
	      (if (string-match re str)
		  (if (= num 0)
		      (progn (setq found-one nil)
			     (setq yank-match-inserted t)
			     (push-mark (point))
			     (insert str)
			     (if yank-match-modify-kill-ring
				 (setq 
				  kill-ring
				  (cons str (delq str kill-ring))))
			     (throw 'done nil))
		    (progn (setq found-one t)
			   (setq num (1- num))
			   (setq index (1+ index))))
		(setq index (1+ index))))))))
    (not found-one))) ; so it returns t on success! 

;;; yank-match.el ends here




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

* Re: yank-match.el -- yank matches for a regexp from kill-ring
  2008-03-02 16:17 ` Karl Fogel
@ 2008-03-02 17:59   ` Juri Linkov
  2008-03-02 19:25     ` Stefan Monnier
  2008-03-02 23:50     ` Karl Fogel
  0 siblings, 2 replies; 13+ messages in thread
From: Juri Linkov @ 2008-03-02 17:59 UTC (permalink / raw)
  To: Karl Fogel; +Cc: emacs-devel

> Rather than stuffing it into simple.el, I guess I'd create a new file
> yank-match.el (suggestions for other destinations welcome).

May I make some remarks?  Usually a good function is harder to find
in a separate small file.  Also it is more difficult to incorporate a
separate file into the core functionality.  But this would be useful:
when I tried using your `yank-match' at the first try it yanked the
first match but I needed one of the next matches.  Then I typed M-y
to cycle next matches, but this method failed.  I think just like a
sequence of `C-y M-y M-y M-y' cycles the kill-ring it would be good to
do the same for `yank-match' as `M-x yank-match RET regexp RET M-y M-y'
to cycle matches from the kill-ring.

BTW, I have a command for similar purposes:

(defun insert-yank-from-kill-ring (string)
  "Insert the selected item from the kill-ring in the minibuffer history.
Use minibuffer navigation and search commands to browse the kill-ring
in the minibuffer history."
  (interactive (list (read-string "Yank from kill-ring: " nil 'kill-ring)))
  (insert-for-yank string))

Comparing to your approach, it has one drawback: multi-line elements
in the kill-ring will resize the minibuffer, but in other respects
those are complementing approaches.

-- 
Juri Linkov
http://www.jurta.org/emacs/




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

* Re: yank-match.el -- yank matches for a regexp from kill-ring
  2008-03-02 17:59   ` Juri Linkov
@ 2008-03-02 19:25     ` Stefan Monnier
  2008-03-02 20:07       ` Juri Linkov
  2008-03-02 23:50     ` Karl Fogel
  1 sibling, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2008-03-02 19:25 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Karl Fogel, emacs-devel

>> Rather than stuffing it into simple.el, I guess I'd create a new file
>> yank-match.el (suggestions for other destinations welcome).

Your file uses ";;;" incorrectly.  Most of those should be ";;" (the
";;;" should be used to separate sections).

But in any case, there's no need for a separate file for such
a small function.

> (defun insert-yank-from-kill-ring (string)
>   "Insert the selected item from the kill-ring in the minibuffer history.
> Use minibuffer navigation and search commands to browse the kill-ring
> in the minibuffer history."
>   (interactive (list (read-string "Yank from kill-ring: " nil 'kill-ring)))
>   (insert-for-yank string))

This looks good.


        Stefan




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

* Re: yank-match.el -- yank matches for a regexp from kill-ring
  2008-03-02 19:25     ` Stefan Monnier
@ 2008-03-02 20:07       ` Juri Linkov
  0 siblings, 0 replies; 13+ messages in thread
From: Juri Linkov @ 2008-03-02 20:07 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Karl Fogel, emacs-devel

>>> Rather than stuffing it into simple.el, I guess I'd create a new file
>>> yank-match.el (suggestions for other destinations welcome).
>
> Your file uses ";;;" incorrectly.  Most of those should be ";;" (the
> ";;;" should be used to separate sections).
>
> But in any case, there's no need for a separate file for such
> a small function.
>
>> (defun insert-yank-from-kill-ring (string)
>>   "Insert the selected item from the kill-ring in the minibuffer history.
>> Use minibuffer navigation and search commands to browse the kill-ring
>> in the minibuffer history."
>>   (interactive (list (read-string "Yank from kill-ring: " nil 'kill-ring)))
>>   (insert-for-yank string))
>
> This looks good.

To avoid possible confusion I want to reiterate that a new command
`yank-match' proposed by Karl is useful on its own, and would be more
useful with some improvements (to behave like `yank-pop', but using
a predicate to match patterns on the elements of the kill-ring to select
the next element).

OTOH, a simple command I presented is not a replacement for the command
`yank-match'.

-- 
Juri Linkov
http://www.jurta.org/emacs/




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

* Re: yank-match.el -- yank matches for a regexp from kill-ring
  2008-03-02 17:59   ` Juri Linkov
  2008-03-02 19:25     ` Stefan Monnier
@ 2008-03-02 23:50     ` Karl Fogel
  2008-03-04  0:35       ` Juri Linkov
  1 sibling, 1 reply; 13+ messages in thread
From: Karl Fogel @ 2008-03-02 23:50 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel

Juri Linkov <juri@jurta.org> writes:
> May I make some remarks?  Usually a good function is harder to find
> in a separate small file.  Also it is more difficult to incorporate a
> separate file into the core functionality.  But this would be useful:
> when I tried using your `yank-match' at the first try it yanked the
> first match but I needed one of the next matches.  Then I typed M-y
> to cycle next matches, but this method failed.  I think just like a
> sequence of `C-y M-y M-y M-y' cycles the kill-ring it would be good to
> do the same for `yank-match' as `M-x yank-match RET regexp RET M-y M-y'
> to cycle matches from the kill-ring.

Thank you, this is a good idea.

Repeated invocations of `yank-match' will have this effect.  It never
occurred to me to make M-y DTRT, but it seems obvious in retrospect:
M-y (that is, `yank-pop') should cycle through the kill-ring in the
usual way if the initial command was `yank', but cycle matches if the
initial command was `yank-match'.

> BTW, I have a command for similar purposes:
>
> (defun insert-yank-from-kill-ring (string)
>   "Insert the selected item from the kill-ring in the minibuffer history.
> Use minibuffer navigation and search commands to browse the kill-ring
> in the minibuffer history."
>   (interactive (list (read-string "Yank from kill-ring: " nil 'kill-ring)))
>   (insert-for-yank string))
>
> Comparing to your approach, it has one drawback: multi-line elements
> in the kill-ring will resize the minibuffer, but in other respects
> those are complementing approaches.

Yes, that seems useful -- but big matches have a problem, as you
pointed out.  Also, sometimes one just knows the right regexp (usually
just a substring), in which case `yank-match' is the fastest way to
get there.

Stefan Monnier <monnier@iro.umontreal.ca> writes:
> Your file uses ";;;" incorrectly.  Most of those should be ";;" (the
> ";;;" should be used to separate sections).

*nod* Can fix.

> But in any case, there's no need for a separate file for such
> a small function.

Okay.  Shall I make the changes Juri suggests above re M-y, and put
both the `yank-match' code and his code above into simple.el?

-Karl




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

* Re: yank-match.el -- yank matches for a regexp from kill-ring
  2008-03-02 23:50     ` Karl Fogel
@ 2008-03-04  0:35       ` Juri Linkov
  2008-03-04  1:16         ` Karl Fogel
  0 siblings, 1 reply; 13+ messages in thread
From: Juri Linkov @ 2008-03-04  0:35 UTC (permalink / raw)
  To: Karl Fogel; +Cc: emacs-devel

>> May I make some remarks?  Usually a good function is harder to find
>> in a separate small file.  Also it is more difficult to incorporate a
>> separate file into the core functionality.  But this would be useful:
>> when I tried using your `yank-match' at the first try it yanked the
>> first match but I needed one of the next matches.  Then I typed M-y
>> to cycle next matches, but this method failed.  I think just like a
>> sequence of `C-y M-y M-y M-y' cycles the kill-ring it would be good to
>> do the same for `yank-match' as `M-x yank-match RET regexp RET M-y M-y'
>> to cycle matches from the kill-ring.
>
> Thank you, this is a good idea.
>
> Repeated invocations of `yank-match' will have this effect.  It never
> occurred to me to make M-y DTRT, but it seems obvious in retrospect:
> M-y (that is, `yank-pop') should cycle through the kill-ring in the
> usual way if the initial command was `yank', but cycle matches if the
> initial command was `yank-match'.
>
>> But in any case, there's no need for a separate file for such
>> a small function.
>
> Okay.  Shall I make the changes Juri suggests above re M-y, and put
> both the `yank-match' code and his code above into simple.el?

Modifying `yank-pop' in simple.el to take into account the initial
command `yank-match' has also benefits of using the recent and more
correct code to do this.  For instance, your command uses `delete-region'
to replace the previously-yanked text, but `yank-pop' has more advanced
code that calls (funcall (or yank-undo-function 'delete-region) ...)

Also your command uses `insert' to insert the previously-yanked text,
but `yank-pop' uses `insert-for-yank' to strip text properties from the
inserted text according to `yank-excluded-properties'.  I guess your patch
was written when there was no such functions in Emacs?

I think it would be safer to reuse code in `yank-pop' and just find
places in it that differ from `yank-match' functionality, like
`current-kill'.  Maybe you could just add a new match-string argument
to `current-kill' that will rotate the yanking point by N matching
places?

-- 
Juri Linkov
http://www.jurta.org/emacs/




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

* Re: yank-match.el -- yank matches for a regexp from kill-ring
  2008-03-04  0:35       ` Juri Linkov
@ 2008-03-04  1:16         ` Karl Fogel
  0 siblings, 0 replies; 13+ messages in thread
From: Karl Fogel @ 2008-03-04  1:16 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel

Juri Linkov <juri@jurta.org> writes:
> Modifying `yank-pop' in simple.el to take into account the initial
> command `yank-match' has also benefits of using the recent and more
> correct code to do this.  For instance, your command uses `delete-region'
> to replace the previously-yanked text, but `yank-pop' has more advanced
> code that calls (funcall (or yank-undo-function 'delete-region) ...)
>
> Also your command uses `insert' to insert the previously-yanked text,
> but `yank-pop' uses `insert-for-yank' to strip text properties from the
> inserted text according to `yank-excluded-properties'.  I guess your patch
> was written when there was no such functions in Emacs?

Probably -- the code is a bit over ten years old now.

> I think it would be safer to reuse code in `yank-pop' and just find
> places in it that differ from `yank-match' functionality, like
> `current-kill'.  Maybe you could just add a new match-string argument
> to `current-kill' that will rotate the yanking point by N matching
> places?

All these are good ideas, yup.  I grok your general message here:
*really* incorporate 'yank-match' into the existing yank code, don't
just stitch it in in the quickest way possible :-).  I will make sure
to DTRT.  (I wish we were in bzr already, it would make this slightly
easier... But only slightly, not a big deal either way.)

Thanks for the help!

-Karl




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

end of thread, other threads:[~2008-03-04  1:16 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-15 23:38 yank-match.el -- yank matches for a regexp from kill-ring Karl Fogel
2007-07-17 18:44 ` Mathias Dahl
2007-07-17 18:46   ` Karl Fogel
2007-07-17 19:29     ` Drew Adams
2007-07-17 20:40       ` Mathias Dahl
2007-07-28 20:32     ` T. V. Raman
2008-03-02 16:17 ` Karl Fogel
2008-03-02 17:59   ` Juri Linkov
2008-03-02 19:25     ` Stefan Monnier
2008-03-02 20:07       ` Juri Linkov
2008-03-02 23:50     ` Karl Fogel
2008-03-04  0:35       ` Juri Linkov
2008-03-04  1:16         ` Karl Fogel

Code repositories for project(s) associated with this public inbox

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

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