[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: killing the result of isearch
From: |
Stefan Monnier |
Subject: |
Re: killing the result of isearch |
Date: |
Tue, 07 Nov 2017 12:53:38 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
> I must be missing something big...
> I have an isearch that highlights a string, and I just want to delete
> that string.
> In other editors I'd just hit delete on that selection, but that won't
> work in Emacs...
It should be fairly easy to get what you want.
You could start with
(defun sm-isearch-done ()
;; Activate the region corresponding to the found string.
(unless (or isearch-mode-end-hook-quit ;; Leaving with C-g!
mark-active) ;; Already selecting a region!
(push-mark isearch-other-end nil t)
(when (eq transient-mark-mode t)
;; Mark the selected region in the same way as is done by S-right,
;; so that subsequent navigation commands automatically deactivate
;; the region.
(push 'only transient-mark-mode))))
(add-hook 'isearch-mode-end-hook #'sm-isearch-done)
so you can do `C-s foo <delete>` and it will delete the found `foo`.
You can also do `C-s foo RET DEL` to get the same result.
And if you use `delete-selection-mode`, then `C-s foo RET b` will
replace `foo` with `b'.
Many Emacs users rely on isearch for navigation, in which case the above
could prove annoying. Also, currently isearch pushes a mark at the
position where you started the search, so you can do
C-s foo RET C-w
to delete the text between point and the first occurrence of `foo`.
The above will break such usage (as well as various others).
Maybe something like the above code could be added to isearch.el but
I think it'll have to be made conditional on a config var, so users
can elect to use this behavior or not (since old-timers used to the
details of the current behavior will probably want to keep using that).
Feel free to use this code snippet in a feature request (via M-x
report-emacs-bug).
Stefan
- RE: killing the result of isearch, (continued)
- RE: killing the result of isearch, Drew Adams, 2017/11/10
- Re: killing the result of isearch, Marcin Borkowski, 2017/11/07
- RE: killing the result of isearch, Drew Adams, 2017/11/07
- Re: killing the result of isearch, Bob Proulx, 2017/11/07
- RE: killing the result of isearch, Drew Adams, 2017/11/07
- Re: killing the result of isearch, Bob Proulx, 2017/11/07
- Re: killing the result of isearch, Jean-Christophe Helary, 2017/11/07
- Re: killing the result of isearch, Bob Proulx, 2017/11/07
- Re: killing the result of isearch, Jean-Christophe Helary, 2017/11/08
- Re: killing the result of isearch, Bob Proulx, 2017/11/08
Re: killing the result of isearch,
Stefan Monnier <=
- Re: killing the result of isearch, Jean-Christophe Helary, 2017/11/07
- Re: killing the result of isearch, Tomas Nordin, 2017/11/12
- Re: killing the result of isearch, Emanuel Berg, 2017/11/12
- Re: killing the result of isearch, Tomas Nordin, 2017/11/13
- Re: killing the result of isearch, Emanuel Berg, 2017/11/13
- Re: killing the result of isearch, Emanuel Berg, 2017/11/19
Re: killing the result of isearch, Emanuel Berg, 2017/11/15