emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

add INVERT to re-search-{forward, backward} (was: occur API change propo


From: Ted Zlatanov
Subject: add INVERT to re-search-{forward, backward} (was: occur API change proposal)
Date: Tue, 05 Aug 2008 13:49:52 -0500
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.60 (gnu/linux)

On Sat, 01 Dec 2007 02:34:35 +0200 Juri Linkov <address@hidden> 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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]