GNU bug report logs -
#73723
31.0.50; Add copy/kill/mark commands to isearch
Previous Next
To reply to this bug, email your comments to 73723 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#73723
; Package
emacs
.
(Wed, 09 Oct 2024 20:37:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Phil Sainty <psainty <at> orcon.net.nz>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Wed, 09 Oct 2024 20:37:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
I find the following useful, and sometimes see others asking for
the same thing. Shall we add these to Emacs?
(defun isearch-copy-match ()
"Copy the currently-matched text to the kill ring."
(interactive)
(kill-new (buffer-substring (min (point) isearch-other-end)
(max (point) isearch-other-end))))
(defun isearch-kill-match ()
"Kill the currently-matched text."
(interactive)
(kill-region (min (point) isearch-other-end)
(max (point) isearch-other-end)))
(defun isearch-mark-match ()
"Exit isearch, marking the last match."
(interactive)
(set-mark isearch-other-end)
(isearch-exit)
(activate-mark))
(define-key isearch-mode-map (kbd "M-s M-w") #'isearch-copy-match)
(define-key isearch-mode-map (kbd "M-s C-w") #'isearch-kill-match)
(define-key isearch-mode-map (kbd "M-s C-SPC") #'isearch-mark-match)
(define-key isearch-mode-map (kbd "M-s C-@") #'isearch-mark-match)
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#73723
; Package
emacs
.
(Wed, 09 Oct 2024 23:50:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 73723 <at> debbugs.gnu.org (full text, mbox):
Phil Sainty <psainty <at> orcon.net.nz> writes:
> I find the following useful, and sometimes see others asking for
> the same thing. Shall we add these to Emacs?
>
> (defun isearch-copy-match ()
> "Copy the currently-matched text to the kill ring."
> (interactive)
> (kill-new (buffer-substring (min (point) isearch-other-end)
> (max (point) isearch-other-end))))
>
> (defun isearch-kill-match ()
> "Kill the currently-matched text."
> (interactive)
> (kill-region (min (point) isearch-other-end)
> (max (point) isearch-other-end)))
>
> (defun isearch-mark-match ()
> "Exit isearch, marking the last match."
> (interactive)
> (set-mark isearch-other-end)
> (isearch-exit)
> (activate-mark))
>
> (define-key isearch-mode-map (kbd "M-s M-w") #'isearch-copy-match)
> (define-key isearch-mode-map (kbd "M-s C-w") #'isearch-kill-match)
> (define-key isearch-mode-map (kbd "M-s C-SPC") #'isearch-mark-match)
> (define-key isearch-mode-map (kbd "M-s C-@") #'isearch-mark-match)
It looks like a fine addition to me. We'd need the usual documentation,
NEWS entry, etc., though.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#73723
; Package
emacs
.
(Thu, 10 Oct 2024 04:49:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 73723 <at> debbugs.gnu.org (full text, mbox):
> Date: Thu, 10 Oct 2024 09:33:41 +1300
> From: Phil Sainty <psainty <at> orcon.net.nz>
>
> I find the following useful, and sometimes see others asking for
> the same thing. Shall we add these to Emacs?
>
> (defun isearch-copy-match ()
> "Copy the currently-matched text to the kill ring."
> (interactive)
> (kill-new (buffer-substring (min (point) isearch-other-end)
> (max (point) isearch-other-end))))
>
> (defun isearch-kill-match ()
> "Kill the currently-matched text."
> (interactive)
> (kill-region (min (point) isearch-other-end)
> (max (point) isearch-other-end)))
>
> (defun isearch-mark-match ()
> "Exit isearch, marking the last match."
> (interactive)
> (set-mark isearch-other-end)
> (isearch-exit)
> (activate-mark))
>
> (define-key isearch-mode-map (kbd "M-s M-w") #'isearch-copy-match)
> (define-key isearch-mode-map (kbd "M-s C-w") #'isearch-kill-match)
> (define-key isearch-mode-map (kbd "M-s C-SPC") #'isearch-mark-match)
> (define-key isearch-mode-map (kbd "M-s C-@") #'isearch-mark-match)
Sounds useful, but "M-x M-w" is already taken, unfortunately.
For isearch-kill-match, should there also be a command to kill _all_
the matches?
Thanks.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#73723
; Package
emacs
.
(Thu, 10 Oct 2024 06:40:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 73723 <at> debbugs.gnu.org (full text, mbox):
> I find the following useful, and sometimes see others asking for
> the same thing. Shall we add these to Emacs?
>
> (defun isearch-copy-match ()
> "Copy the currently-matched text to the kill ring."
> (interactive)
> (kill-new (buffer-substring (min (point) isearch-other-end)
> (max (point) isearch-other-end))))
>
> (defun isearch-kill-match ()
> "Kill the currently-matched text."
> (interactive)
> (kill-region (min (point) isearch-other-end)
> (max (point) isearch-other-end)))
>
> (defun isearch-mark-match ()
> "Exit isearch, marking the last match."
> (interactive)
> (set-mark isearch-other-end)
> (isearch-exit)
> (activate-mark))
>
> (define-key isearch-mode-map (kbd "M-s M-w") #'isearch-copy-match)
> (define-key isearch-mode-map (kbd "M-s C-w") #'isearch-kill-match)
> (define-key isearch-mode-map (kbd "M-s C-SPC") #'isearch-mark-match)
> (define-key isearch-mode-map (kbd "M-s C-@") #'isearch-mark-match)
I have a patch that I'm using for a long time every day.
It allows exiting Isearch with 'S-RET' that activates
the region on the current match. This allows using
the standard keys afterwards: 'M-w' to copy the match,
'C-w' to kill the match, etc. Does this eliminate the need
to add more Isearch commands?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#73723
; Package
emacs
.
(Thu, 10 Oct 2024 07:42:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 73723 <at> debbugs.gnu.org (full text, mbox):
> Cc: 73723 <at> debbugs.gnu.org
> From: Juri Linkov <juri <at> linkov.net>
> Date: Thu, 10 Oct 2024 09:37:37 +0300
>
> > (define-key isearch-mode-map (kbd "M-s M-w") #'isearch-copy-match)
> > (define-key isearch-mode-map (kbd "M-s C-w") #'isearch-kill-match)
> > (define-key isearch-mode-map (kbd "M-s C-SPC") #'isearch-mark-match)
> > (define-key isearch-mode-map (kbd "M-s C-@") #'isearch-mark-match)
>
> I have a patch that I'm using for a long time every day.
> It allows exiting Isearch with 'S-RET' that activates
> the region on the current match.
S-RET will not work on text terminals.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#73723
; Package
emacs
.
(Thu, 10 Oct 2024 12:11:01 GMT)
Full text and
rfc822 format available.
Message #20 received at 73723 <at> debbugs.gnu.org (full text, mbox):
On 2024-10-10 17:48, Eli Zaretskii wrote:
>> Date: Thu, 10 Oct 2024 09:33:41 +1300
>> From: Phil Sainty <psainty <at> orcon.net.nz>
>> (define-key isearch-mode-map (kbd "M-s M-w") #'isearch-copy-match)
>> (define-key isearch-mode-map (kbd "M-s C-w") #'isearch-kill-match)
>> (define-key isearch-mode-map (kbd "M-s C-SPC") #'isearch-mark-match)
>> (define-key isearch-mode-map (kbd "M-s C-@") #'isearch-mark-match)
>
> Sounds useful, but "M-x M-w" is already taken, unfortunately.
"M-s M-w" does have a binding to `eww-search-words' in the global
keymap,
but I'm not sure that needs to prevent us using it here?
Certainly `eww-search-words' doesn't react to the current isearch match,
so I think there's not currently a particular reason why one would
invoke
the global binding whilst isearching. (You *could* set the mark and
then
search to extend the region before calling `eww-search-words' for that
region; but you could trivially still do that simply by exiting the
isearch explicitly.)
> For isearch-kill-match, should there also be a command to kill _all_
> the matches?
Potentially, although there's a library iedit.el which provides that
kind of functionality. It has an `iedit-mode-from-isearch' command
to invoke iedit on the matched text. (Although to specifically kill
all matches, it looks like you'd need to follow that command by
restarting the isearch and *then* call `isearch-kill-match'.
-Phil
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#73723
; Package
emacs
.
(Thu, 10 Oct 2024 16:59:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 73723 <at> debbugs.gnu.org (full text, mbox):
> > I find the following useful, and sometimes see others asking for
> > the same thing. Shall we add these to Emacs?
> >
> > (defun isearch-copy-match ()
> > "Copy the currently-matched text to the kill ring."
> > (interactive)
> > (kill-new (buffer-substring (min (point) isearch-other-end)
> > (max (point) isearch-other-end))))
> >
> > (defun isearch-kill-match ()
> > "Kill the currently-matched text."
> > (interactive)
> > (kill-region (min (point) isearch-other-end)
> > (max (point) isearch-other-end)))
> >
> > (defun isearch-mark-match ()
> > "Exit isearch, marking the last match."
> > (interactive)
> > (set-mark isearch-other-end)
> > (isearch-exit)
> > (activate-mark))
> >
> > (define-key isearch-mode-map (kbd "M-s M-w") #'isearch-copy-match)
> > (define-key isearch-mode-map (kbd "M-s C-w") #'isearch-kill-match)
> > (define-key isearch-mode-map (kbd "M-s C-SPC") #'isearch-mark-match)
> > (define-key isearch-mode-map (kbd "M-s C-@") #'isearch-mark-match)
>
> I have a patch that I'm using for a long time every day.
> It allows exiting Isearch with 'S-RET' that activates
> the region on the current match. This allows using
> the standard keys afterwards: 'M-w' to copy the match,
> 'C-w' to kill the match, etc. Does this eliminate the need
> to add more Isearch commands?
FWIW, in isearch+.el I define `isearchp-kill-ring-save'
and bind it to `M-w'.
This has been the case since 2013.
(defun isearchp-kill-ring-save () ; Bound to `M-w' in `isearch-mode-map'.
"Copy the current search string to the kill ring."
(interactive)
(kill-new isearch-string)
(let ((message-log-max nil)) (message "Copied search string as kill"))
(sit-for 1)
(isearch-update))
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#73723
; Package
emacs
.
(Thu, 10 Oct 2024 17:38:02 GMT)
Full text and
rfc822 format available.
Message #26 received at 73723 <at> debbugs.gnu.org (full text, mbox):
>> > (define-key isearch-mode-map (kbd "M-s M-w") #'isearch-copy-match)
>> > (define-key isearch-mode-map (kbd "M-s C-w") #'isearch-kill-match)
>> > (define-key isearch-mode-map (kbd "M-s C-SPC") #'isearch-mark-match)
>> > (define-key isearch-mode-map (kbd "M-s C-@") #'isearch-mark-match)
>>
>> I have a patch that I'm using for a long time every day.
>> It allows exiting Isearch with 'S-RET' that activates
>> the region on the current match.
>
> S-RET will not work on text terminals.
I see that S-left and S-right arrows work on text terminals
via 'this-command-keys-shift-translated', but S-RET
doesn't set 'this-command-keys-shift-translated'.
Then isearch-exit could support a prefix argument to
activate the region on exit like Gregory proposed in
https://debbugs.gnu.org/47599#34
with three values of prefix arguments to isearch-exit:
C-u RET moves point to the other end,
C-u C-u RET activates region around match,
C-u C-u C-u RET moves point to the other end
and activate region around match.
But then Ergus proposed M-RET or M-s RET.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#73723
; Package
emacs
.
(Thu, 10 Oct 2024 17:38:02 GMT)
Full text and
rfc822 format available.
Message #29 received at 73723 <at> debbugs.gnu.org (full text, mbox):
>> It allows exiting Isearch with 'S-RET' that activates
>> the region on the current match. This allows using
>> the standard keys afterwards: 'M-w' to copy the match,
>> 'C-w' to kill the match, etc.
>
> FWIW, in isearch+.el I define `isearchp-kill-ring-save'
> and bind it to `M-w'.
> This has been the case since 2013.
>
> (defun isearchp-kill-ring-save () ; Bound to `M-w' in `isearch-mode-map'.
> "Copy the current search string to the kill ring."
> (interactive)
> (kill-new isearch-string)
> (let ((message-log-max nil)) (message "Copied search string as kill"))
> (sit-for 1)
> (isearch-update))
Since `M-w' can't be used according to the comments in
https://old.reddit.com/r/emacs/comments/1fzvwig/copy_search_string_to_killring/
what remains is `M-s M-w'.
OTOH, `S-RET M-w' is shorter than `M-s M-w RET'.
But since `S-RET' is not available on text terminals
what remains is still `M-s M-w RET' or `M-s RET M-w'.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#73723
; Package
emacs
.
(Thu, 10 Oct 2024 18:21:02 GMT)
Full text and
rfc822 format available.
Message #32 received at 73723 <at> debbugs.gnu.org (full text, mbox):
> >> It allows exiting Isearch with 'S-RET' that activates
> >> the region on the current match. This allows using
> >> the standard keys afterwards: 'M-w' to copy the match,
> >> 'C-w' to kill the match, etc.
> >
> > FWIW, in isearch+.el I define `isearchp-kill-ring-save'
> > and bind it to `M-w'.
> > This has been the case since 2013.
>
> Since `M-w' can't be used according to the comments in
> https://urldefense.com/v3/__https://old.reddit.com/r/emacs/comments/1fzv
> wig/copy_search_string_to_killring/__;!!ACWV5N9M2RV99hQ!L5HGxhm07QP4heBq
> z0oZG6Hs1DF2e5hty8aAHJG_sxr39y7pRCFJPoP2E_m9P8iyv-lGni4NgqrGZg$
I don't see anything there that says why `M-w' can't
be used. What's the reason you think is given there?
Is it this?
"I have muscle memory for pressing M-w to end the
search and save the region from where point was
before starting isearch to the location where the
search string was found."
?
There are other ways to get the region to be from the
initial position to the end (if forward) or the start
(if backward) of the search match.
In any case, we are (should be) talking about default
key bindings (in `isearch-mode-map'). Both copying
the search match as a kill and setting the region to
origin-to-search-end are useful, and they can both have
default key bindings. Which should be `M-w' by default
is something to decide.
You know what my recommendation is: copy the match.
IME, if someone wants to set the region from the initial
position they usually know that _before_ searching - in
which case it's enough to do `C-SPC' before searching.
* `M-w' _during_ search should copy the search match
because it can be done anytime _during_ a search. It
can even be done multiple times _during_ a search, and
for the _same or different search patterns_. It's a
very useful, versatile operation.
* `M-w' _after_ a search is something else, whether or
not you want to extend the region to initial position.
It makes no sense to use a key to set the region from
the initial position more than once during a search.
At most once per search is all you need, for that.
The question is whether to have a `isearch-mode-map'
key to _set the mark_ at the initial position (instead
of someone setting mark there before searching).
If we have such a key, then `M-w' _after_ the search
is just the _normal_ `M-w': `kill-ring-save'. IOW,
we need not have a search-map key to set that region,
since that's done after searching (and once only).
To implement a command to _set mark_ at init position
during search we can always let-bind that position at
the outset, and then use it only when a user hits the
key to set the mark there (and that key shouldn't be
`M-w'.)
> what remains is `M-s M-w'.
Lots of possibilities remain. But you might want to
use `M-s M-w' not for copying search matches but for
setting mark at the initial position.
Why? See above: You only do that once, and you might
want to copy multiple (different) search matches to
the kill ring during the same search. The key for
copying search matches should be `M-w' (IMO).
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#73723
; Package
emacs
.
(Thu, 10 Oct 2024 18:32:02 GMT)
Full text and
rfc822 format available.
Message #35 received at 73723 <at> debbugs.gnu.org (full text, mbox):
Sorry, I misspoke. I was thinking that my `M-w'
copies the current search _match_, but it copies
the search string (input pattern), `isearch-string'.
The argument that it's better to use `M-w' during
search for that because you can use it multiple
times still holds, but only because you can change
the search pattern (during search) - not _also_
because the same pattern can match different text.
It probably makes sense to also have a command
that copies the current search match. And maybe
that's the best candidate for `M-w' (not a command
that copies `isearch-string').
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#73723
; Package
emacs
.
(Thu, 10 Oct 2024 18:44:01 GMT)
Full text and
rfc822 format available.
Message #38 received at 73723 <at> debbugs.gnu.org (full text, mbox):
> Sorry, I misspoke. I was thinking that my `M-w'
> copies the current search _match_, but it copies
> the search string (input pattern), `isearch-string'.
But it's easy to copy the search string with just
'M-e C-a C-k'.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#73723
; Package
emacs
.
(Thu, 10 Oct 2024 18:44:02 GMT)
Full text and
rfc822 format available.
Message #41 received at 73723 <at> debbugs.gnu.org (full text, mbox):
>> > FWIW, in isearch+.el I define `isearchp-kill-ring-save'
>> > and bind it to `M-w'.
>> > This has been the case since 2013.
>>
>> Since `M-w' can't be used according to the comments in
>> https://urldefense.com/v3/__https://old.reddit.com/r/emacs/comments/1fzv
>> wig/copy_search_string_to_killring/__;!!ACWV5N9M2RV99hQ!L5HGxhm07QP4heBq
>> z0oZG6Hs1DF2e5hty8aAHJG_sxr39y7pRCFJPoP2E_m9P8iyv-lGni4NgqrGZg$
>
> I don't see anything there that says why `M-w' can't
> be used. What's the reason you think is given there?
> Is it this?
>
> "I have muscle memory for pressing M-w to end the
> search and save the region from where point was
> before starting isearch to the location where the
> search string was found."
>
> ?
Yes, I meant exactly this feedback.
> There are other ways to get the region to be from the
> initial position to the end (if forward) or the start
> (if backward) of the search match.
Like 'C-x C-x' etc. But 'C-x C-x' can't activate the region
on the last match. Therefore we need another key binding.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#73723
; Package
emacs
.
(Thu, 10 Oct 2024 18:55:01 GMT)
Full text and
rfc822 format available.
Message #44 received at 73723 <at> debbugs.gnu.org (full text, mbox):
> > Sorry, I misspoke. I was thinking that my `M-w'
> > copies the current search _match_, but it copies
> > the search string (input pattern), `isearch-string'.
>
> But it's easy to copy the search string with just
> 'M-e C-a C-k'.
Not as easy as `M-w'.
But I do think it makes sense to _also_ have a key
to copy the current _match_. Both of those should
be short keys.
The use case of wanting to set mark at the initial
position, so you can get back there or activate the
region back to there (actions that take place when
you're _done_ searching), can be on a longer key
sequence. Why? Because it's useful at most _once_
during search.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#73723
; Package
emacs
.
(Thu, 10 Oct 2024 22:05:01 GMT)
Full text and
rfc822 format available.
Message #47 received at 73723 <at> debbugs.gnu.org (full text, mbox):
> (defun isearch-copy-match ()
> "Copy the currently-matched text to the kill ring."
> (interactive)
> (kill-new (buffer-substring (min (point) isearch-other-end)
> (max (point) isearch-other-end))))
>
> (defun isearch-kill-match ()
> "Kill the currently-matched text."
> (interactive)
> (kill-region (min (point) isearch-other-end)
> (max (point) isearch-other-end)))
Two minor suggestions:
. Neither buffer-substring nor kill-region needs the
positions in any particular order - don't need min/max.
E.g., just (kill-region (point) isearch-other-end)
. Show a message at the end of `isearch-copy-match':
(let ((message-log-max nil))
(message "Copied search match as kill"))
(sit-for 1)
(isearch-update)
Severity set to 'wishlist' from 'normal'
Request was from
Stefan Kangas <stefankangas <at> gmail.com>
to
control <at> debbugs.gnu.org
.
(Sat, 12 Oct 2024 14:03:02 GMT)
Full text and
rfc822 format available.
Added tag(s) patch.
Request was from
Stefan Kangas <stefankangas <at> gmail.com>
to
control <at> debbugs.gnu.org
.
(Sat, 01 Mar 2025 01:38:02 GMT)
Full text and
rfc822 format available.
This bug report was last modified 161 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.