From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: killing the result of isearch Date: Tue, 07 Nov 2017 12:53:38 -0500 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1510077273 11653 195.159.176.226 (7 Nov 2017 17:54:33 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 7 Nov 2017 17:54:33 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Nov 07 18:54:29 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eC84x-0002qf-Uc for geh-help-gnu-emacs@m.gmane.org; Tue, 07 Nov 2017 18:54:28 +0100 Original-Received: from localhost ([::1]:55155 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eC855-0003kS-Af for geh-help-gnu-emacs@m.gmane.org; Tue, 07 Nov 2017 12:54:35 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40615) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eC84T-0003hY-Ou for help-gnu-emacs@gnu.org; Tue, 07 Nov 2017 12:53:58 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eC84P-0003Av-OW for help-gnu-emacs@gnu.org; Tue, 07 Nov 2017 12:53:57 -0500 Original-Received: from [195.159.176.226] (port=33280 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eC84P-0003A2-HO for help-gnu-emacs@gnu.org; Tue, 07 Nov 2017 12:53:53 -0500 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1eC84E-0000yG-JN for help-gnu-emacs@gnu.org; Tue, 07 Nov 2017 18:53:42 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 46 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:/7udvvOH3dtIg+Y2Xe/DkU5IJzA= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:114788 Archived-At: > 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 ` 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