From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Bob Proulx Newsgroups: gmane.emacs.help Subject: Re: killing the result of isearch Date: Tue, 7 Nov 2017 13:59:06 -0700 Message-ID: <20171107132316472375613@bob.proulx.com> References: <433bd3d0-a506-4d89-9d10-dcbfb0e23be0@default> <852BAA28-2A50-4AD9-B8D6-9F06905A4395@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1510088387 585 195.159.176.226 (7 Nov 2017 20:59:47 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 7 Nov 2017 20:59:47 +0000 (UTC) User-Agent: NeoMutt/20170609 (1.8.3) 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 21:59:41 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 1eCAyD-0008Iw-5W for geh-help-gnu-emacs@m.gmane.org; Tue, 07 Nov 2017 21:59:41 +0100 Original-Received: from localhost ([::1]:55821 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eCAyK-0000z1-6r for geh-help-gnu-emacs@m.gmane.org; Tue, 07 Nov 2017 15:59:48 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36003) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eCAxj-0000wm-VO for help-gnu-emacs@gnu.org; Tue, 07 Nov 2017 15:59:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eCAxg-0003Rk-Tn for help-gnu-emacs@gnu.org; Tue, 07 Nov 2017 15:59:12 -0500 Original-Received: from havoc.proulx.com ([96.88.95.61]:35490) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eCAxg-0003Qg-Lg for help-gnu-emacs@gnu.org; Tue, 07 Nov 2017 15:59:08 -0500 Original-Received: from joseki.proulx.com (localhost [127.0.0.1]) by havoc.proulx.com (Postfix) with ESMTP id 1D7D088F for ; Tue, 7 Nov 2017 13:59:07 -0700 (MST) Original-Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id DE5D6217E5 for ; Tue, 7 Nov 2017 13:59:06 -0700 (MST) Original-Received: by hysteria.proulx.com (Postfix, from userid 1000) id CB22C2DC5E; Tue, 7 Nov 2017 13:59:06 -0700 (MST) Mail-Followup-To: help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: <852BAA28-2A50-4AD9-B8D6-9F06905A4395@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 96.88.95.61 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:114792 Archived-At: Jean-Christophe Helary wrote: > I have an isearch that highlights a string, and I just want to delete > that string. ... > But, isn't it something emacs users do normally? Search for a string > and just delete it? Doesn't it look like a function that could be > useful in vanilla emacs? I have been using emacs for a very long time and that isn't a feature I have ever missed. However I will say that language shapes the way you think. If the language you use does or does not have a construct then it shapes the way one thinks about it. Emacs doesn't intrinsically have that feature but has other features and therefore I think and use those other features. The answers suggesting M-% are excellent suggestions. I think they are the best suggestions. But exploring other options are good for learning how to do things in emacs too. That is what I want to do at this moment. Here you see that in the default emacs configuration the search string is highlighted (in what looks like purple on my testing, I will call it purple) in the search face. (Your colors may be different.) But the highlighted region face is what looks like brown to me. Brown hightlight means a region and pressing DEL (Backspace) would delete it. Purple is the search string. They are different. In fact if you have a text like this with the point at the 'N' in the word "Now". Now is the time for all good men to come to the aid of their party. And then type in "C-s party" it will set the mark at the 'N' and then move the point to the '.' immedately after "party". The "party" will be highlighted in purple. If you terminate the search then and there with RET then the point is at the '.' and the mark is at the 'N' and the region is not active. The region is always the text between the point and the mark. You can use C-x C-x to exchange-point-and-mark to show the region. Doing that will activate the region. At that time you will see that the region covers the entire text fron 'N' to the 'y' of "party". (But not the '.' after party since that wasn't between mark and point.) The typical deletions (killing text in emacs speak) act upon either single characters or the region. The region between the point and the mark. In order to make the search string a region one wants to make the point and mark to be placed surrounding the text to be deleted. How would someone do that. How would *I* do that. I would do it like this. I would "C-s party" to move point to the end of party. Seeing that it is a single word I would simply use M-DEL backward-kill-word to delete the word behind. It will terminate the search and then delete the word behind. Voil=E0! The task is done exactly as you wish. But then one might ask, "What about strings that are more than one word?" In that case I would do tihs. I would "C-s party" to move point to the end of party. Knowing that mark was left at the previous location of the point I would then use C-r to reverse search the same string. That will move the point to the start of the search string. The point would be at the 'p' in "party". I would press RET to terminate the search. The mark is still far away at the previous location of the point. But the search has been saved. I would then press C-s C-s twice. Once to start a new search and again a second time for isearch-repeat-forward to recall the previous search. That will move the point to the end of the search string and will set a new mark at the previous location at the start of the search string. At that point the point and mark are around the text to be deleted. Then I will use C-x C-x to exchange-point-and-mark and to activate the region showing it. Then C-w to kill-region it. (Killing text puts it into the kill ring.) Let's change "One-two, Buckle my shoe" to something else. C-s one-two, buckle my shoe C-r RET C-s C-s RET C-x C-x C-w It's more keys than M-% but the above are all mainstream keys that an emacs user would press a zillion times a day. I don't even think about them. They just happen reflexively. And at each step along the way I have positive feedback from the editor telling me what is highlighted, what is happening, and what will be deleted when I delete it. No stress editing. Personally I never use the highlighted region. Using C-x C-x to exchange-point-and-mark is perfect for me to know what is the region that will be deleted. This means that instead of using DEL to delete a highlighted region that I will use C-w to kill-region instead. Shrug. Personally I always bind C-s to isearch-forward-regexp instead of leaving it at isearch-forward. Regular expressions are so much more powerful and useful. "C-s one.*shoe" matches the entire string I want to change with much fewer characters. Learning regular expressions makes for powerful editing capability. Again using M-% seems perfect here but hopefully at least some of you enjoyed seeing the thought process another person might use to perform this task using the mainstream commands. Bob