From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: add INVERT to re-search-{forward, backward} (was: occur API change proposal) Date: Mon, 25 Aug 2008 18:45:18 +0300 Organization: JURTA Message-ID: <878wumj8zx.fsf@jurta.org> References: <861wa92g6a.fsf@lifelogs.com> <87fxyni898.fsf@jurta.org> <86myjrl2jz.fsf_-_@lifelogs.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1219679754 12663 80.91.229.12 (25 Aug 2008 15:55:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 25 Aug 2008 15:55:54 +0000 (UTC) Cc: emacs-devel@gnu.org To: Ted Zlatanov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Aug 25 17:56:48 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 1KXeQk-0002uN-Pe for ged-emacs-devel@m.gmane.org; Mon, 25 Aug 2008 17:56:35 +0200 Original-Received: from localhost ([127.0.0.1]:55602 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KXePm-00064c-V6 for ged-emacs-devel@m.gmane.org; Mon, 25 Aug 2008 11:55:34 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KXeOM-0005TU-OX for emacs-devel@gnu.org; Mon, 25 Aug 2008 11:54:06 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KXeOM-0005T9-5d for emacs-devel@gnu.org; Mon, 25 Aug 2008 11:54:06 -0400 Original-Received: from [199.232.76.173] (port=56919 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KXeOL-0005T4-Qj for emacs-devel@gnu.org; Mon, 25 Aug 2008 11:54:05 -0400 Original-Received: from relay02.kiev.sovam.com ([62.64.120.197]:62624) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KXeOL-0008Vm-Fr for emacs-devel@gnu.org; Mon, 25 Aug 2008 11:54:05 -0400 Original-Received: from [83.170.232.243] (helo=smtp.svitonline.com) by relay02.kiev.sovam.com with esmtp (Exim 4.67) (envelope-from ) id 1KXeOJ-0000EI-BT; Mon, 25 Aug 2008 18:54:03 +0300 In-Reply-To: <86myjrl2jz.fsf_-_@lifelogs.com> (Ted Zlatanov's message of "Tue, 05 Aug 2008 13:49:52 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu) X-Scanner-Signature: 565941832c2f675ae953af64aa3a5396 X-DrWeb-checked: yes X-SpamTest-Envelope-From: juri@jurta.org X-SpamTest-Group-ID: 00000000 X-SpamTest-Header: Trusted X-SpamTest-Info: Profiles 4896 [Aug 24 2008] X-SpamTest-Info: {received from trusted relay: common white list} X-SpamTest-Info: {HEADERS: header Content-Type found without required header Content-Transfer-Encoding} X-SpamTest-Method: white ip list X-SpamTest-Rate: 10 X-SpamTest-Status: Trusted X-SpamTest-Status-Extended: trusted X-SpamTest-Version: SMTP-Filter Version 3.0.0 [0278], KAS30/Release X-detected-kernel: by monty-python.gnu.org: FreeBSD 6.x (1) 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:102954 Archived-At: >>> 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. It seems such an API with a new INVERT parameter will be useless because these two character-based search functions will find too much matches. For example, calling it with the parameter "def" on the string "abcdefghi" will match in it 6 places, i.e. everywhere except the position under the character "d". Thus this will provide no useful information to occur. Instead of this, I think the change should be done at the occur level, since occur's algorithm is line-based and can skip lines that contain a given regexp. This could be similar to the algorithm used by the command `flush-lines' in the same file. `occur' currently works like the command `keep-lines' that keeps lines containing the specified regexp. But with a new INVERT argument, `occur' could work like `flush-lines' that keep everything except lines containing the specified regexp. -- Juri Linkov http://www.jurta.org/emacs/