From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.devel Subject: add INVERT to re-search-{forward, backward} (was: occur API change proposal) Date: Tue, 05 Aug 2008 13:49:52 -0500 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <86myjrl2jz.fsf_-_@lifelogs.com> References: <861wa92g6a.fsf@lifelogs.com> <87fxyni898.fsf@jurta.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1217961939 19531 80.91.229.12 (5 Aug 2008 18:45:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 5 Aug 2008 18:45:39 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Aug 05 20:46:30 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KQRY7-0001Yr-Ly for ged-emacs-devel@m.gmane.org; Tue, 05 Aug 2008 20:46:23 +0200 Original-Received: from localhost ([127.0.0.1]:59657 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KQRXC-0006m2-IJ for ged-emacs-devel@m.gmane.org; Tue, 05 Aug 2008 14:45:26 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KQRX8-0006lj-0N for emacs-devel@gnu.org; Tue, 05 Aug 2008 14:45:22 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KQRX6-0006kL-7E for emacs-devel@gnu.org; Tue, 05 Aug 2008 14:45:21 -0400 Original-Received: from [199.232.76.173] (port=36285 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KQRX6-0006kI-1H for emacs-devel@gnu.org; Tue, 05 Aug 2008 14:45:20 -0400 Original-Received: from main.gmane.org ([80.91.229.2]:40926 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KQRX5-0007W0-G4 for emacs-devel@gnu.org; Tue, 05 Aug 2008 14:45:19 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1KQRWx-0006Kw-VG for emacs-devel@gnu.org; Tue, 05 Aug 2008 18:45:11 +0000 Original-Received: from 38.98.147.130 ([38.98.147.130]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 05 Aug 2008 18:45:11 +0000 Original-Received: from tzz by 38.98.147.130 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 05 Aug 2008 18:45:11 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 37 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 38.98.147.130 X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6; d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.60 (gnu/linux) Cancel-Lock: sha1:mH+LnsW9nJRVUS/WzxvPKvQ9PII= X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:102101 Archived-At: On Sat, 01 Dec 2007 02:34:35 +0200 Juri Linkov wrote: >> I propose changing the occur API to allow an optional predicate >> function. For example, this is useful to invert a regular expression so >> you don't have to run occur on the whole buffer matching everything, >> then limit the results. JL> The occur engine currently hard-codes the function call of JL> `re-search-forward'. Instead of this, we could do the same JL> as is done already in isearch for customization of the search JL> function using a variable `isearch-search-fun-function', and JL> add a new analogous variable `occur-fun-function'. JL> Even though such a variable will be useful for other purposes, JL> no simple function will allow inverting a regular expression. JL> Implementing this feature requires significant modification in JL> the logic of the occur engine: either changing the algorithm to JL> call `looking-at' at every line (very inefficient), or recording JL> a position of the previous match and outputing lines between it JL> and the current position (not easy to customize). After thinking about this (yes, it sat in my TODO queue for a while) I realize the problem is fundamental: Emacs doesn't have a way to invert at the re-search-{forward,backward} API level. There's no way to automatically invert a regular expression into another regular expression, so this change must happen at the API level to avoid unpleasant workarounds as Juri describes. I propose simply adding an optional INVERT parameter to those two functions. The API cost is small with an optional parameter, though I don't know if performance will be affected by the extra check on every search cycle. Once this API is in place, making the change in occur-mode and other places to use the new API is very easy. Ted