From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.devel Subject: RE: Occur should use the region as input if it's active Date: Thu, 16 Jan 2014 11:23:38 -0800 (PST) Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1389900240 29559 80.91.229.3 (16 Jan 2014 19:24:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 16 Jan 2014 19:24:00 +0000 (UTC) To: Tom , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jan 16 20:24:06 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1W3sXs-00039e-Ro for ged-emacs-devel@m.gmane.org; Thu, 16 Jan 2014 20:24:04 +0100 Original-Received: from localhost ([::1]:34640 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W3sXs-0006MO-BZ for ged-emacs-devel@m.gmane.org; Thu, 16 Jan 2014 14:24:04 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58272) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W3sXh-0006LL-GN for emacs-devel@gnu.org; Thu, 16 Jan 2014 14:24:02 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W3sXY-0000kU-Ub for emacs-devel@gnu.org; Thu, 16 Jan 2014 14:23:53 -0500 Original-Received: from userp1040.oracle.com ([156.151.31.81]:41418) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W3sXY-0000kQ-O1 for emacs-devel@gnu.org; Thu, 16 Jan 2014 14:23:44 -0500 Original-Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s0GJNecH023849 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 16 Jan 2014 19:23:40 GMT Original-Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s0GJNd7T014427 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 16 Jan 2014 19:23:39 GMT Original-Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s0GJNdmf006279; Thu, 16 Jan 2014 19:23:39 GMT In-Reply-To: X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.8 (707110) [OL 12.0.6680.5000 (x86)] X-Source-IP: acsinet21.oracle.com [141.146.126.237] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 156.151.31.81 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:168566 Archived-At: > If often happens to me that I'm perusing a buffer and I want to > search for some word or phrase in it. To do this I simply select the > text and use this code to instantly get occur matches of it: >=20 > (defun my-occur () > (interactive) > (if (use-region-p) > (occur (buffer-substring-no-properties > (region-beginning) (region-end))) > (call-interactively 'occur))) >=20 > Shouldn't the builtin occur do this? It's quite convenient and > efficient and in my experience most of the occur searches are > of these kind (searching for something I see) and it's less > often that I actualy need to type in the search term. Yes and no. The region can also be useful to delimit the search without narrowing. FWIW, in my code, a user option decides this: ,---- | search/replace-region-as-default-flag is a variable defined in `replace+.= el'. | Its value is nil |=20 | Documentation: | Non-nil means use the active region text as default for search/replace. | That is, if the region is currently active then use its text as the | default input. All text properties are removed from the text. |=20 | Note that in this case the active region is not used to limit the | search/replacement scope. But in that case you can of course just | narrow the buffer temporarily to restrict the operation scope. |=20 | A non-nil value of this option takes precedence over the use of option | `search/replace-2nd-sel-as-default-flag'. To give that option | precedence over using the active region, you can set this option to | nil and use `region-or-non-nil-symbol-name-nearest-point' as the value | of option `search/replace-default-fn'. |=20 | You can customize this variable. `----