* occur API change proposal @ 2007-11-29 16:02 Ted Zlatanov 2007-12-01 0:34 ` Juri Linkov 0 siblings, 1 reply; 7+ messages in thread From: Ted Zlatanov @ 2007-11-29 16:02 UTC (permalink / raw To: emacs-devel This can wait until after the next release. 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. Ted ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: occur API change proposal 2007-11-29 16:02 occur API change proposal Ted Zlatanov @ 2007-12-01 0:34 ` Juri Linkov 2008-08-05 18:49 ` add INVERT to re-search-{forward, backward} (was: occur API change proposal) Ted Zlatanov 0 siblings, 1 reply; 7+ messages in thread From: Juri Linkov @ 2007-12-01 0:34 UTC (permalink / raw To: Ted Zlatanov; +Cc: emacs-devel > 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. The occur engine currently hard-codes the function call of `re-search-forward'. Instead of this, we could do the same as is done already in isearch for customization of the search function using a variable `isearch-search-fun-function', and add a new analogous variable `occur-fun-function'. Even though such a variable will be useful for other purposes, no simple function will allow inverting a regular expression. Implementing this feature requires significant modification in the logic of the occur engine: either changing the algorithm to call `looking-at' at every line (very inefficient), or recording a position of the previous match and outputing lines between it and the current position (not easy to customize). -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 7+ messages in thread
* add INVERT to re-search-{forward, backward} (was: occur API change proposal) 2007-12-01 0:34 ` Juri Linkov @ 2008-08-05 18:49 ` Ted Zlatanov 2008-08-25 15:45 ` Juri Linkov 0 siblings, 1 reply; 7+ messages in thread From: Ted Zlatanov @ 2008-08-05 18:49 UTC (permalink / raw To: emacs-devel On Sat, 01 Dec 2007 02:34:35 +0200 Juri Linkov <juri@jurta.org> 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: add INVERT to re-search-{forward, backward} (was: occur API change proposal) 2008-08-05 18:49 ` add INVERT to re-search-{forward, backward} (was: occur API change proposal) Ted Zlatanov @ 2008-08-25 15:45 ` Juri Linkov 2008-08-25 15:57 ` add INVERT to re-search-{forward, backward} Lennart Borgman (gmail) 0 siblings, 1 reply; 7+ messages in thread From: Juri Linkov @ 2008-08-25 15:45 UTC (permalink / raw To: Ted Zlatanov; +Cc: emacs-devel >>> 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/ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: add INVERT to re-search-{forward, backward} 2008-08-25 15:45 ` Juri Linkov @ 2008-08-25 15:57 ` Lennart Borgman (gmail) 2008-08-25 19:45 ` Juri Linkov 0 siblings, 1 reply; 7+ messages in thread From: Lennart Borgman (gmail) @ 2008-08-25 15:57 UTC (permalink / raw To: Juri Linkov; +Cc: Ted Zlatanov, emacs-devel Juri Linkov wrote: > 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. This is also similar to grep etc. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: add INVERT to re-search-{forward, backward} 2008-08-25 15:57 ` add INVERT to re-search-{forward, backward} Lennart Borgman (gmail) @ 2008-08-25 19:45 ` Juri Linkov 2008-08-25 20:07 ` Lennart Borgman (gmail) 0 siblings, 1 reply; 7+ messages in thread From: Juri Linkov @ 2008-08-25 19:45 UTC (permalink / raw To: Lennart Borgman (gmail); +Cc: Ted Zlatanov, emacs-devel >> 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. > > This is also similar to grep etc. Yes, as a line-oriented tool, grep's -v --invert-match option is what could be modelled in occur. Then a negative prefix argument of `occur' could mean inverting the regexp and displaying non-matching lines. -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: add INVERT to re-search-{forward, backward} 2008-08-25 19:45 ` Juri Linkov @ 2008-08-25 20:07 ` Lennart Borgman (gmail) 0 siblings, 0 replies; 7+ messages in thread From: Lennart Borgman (gmail) @ 2008-08-25 20:07 UTC (permalink / raw To: Juri Linkov; +Cc: Ted Zlatanov, emacs-devel Juri Linkov wrote: >>> 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. >> This is also similar to grep etc. > > Yes, as a line-oriented tool, grep's -v --invert-match option is what > could be modelled in occur. > > Then a negative prefix argument of `occur' could mean inverting the > regexp and displaying non-matching lines. Maybe it also would be practical to be able to access that function from within the occur window too? ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2008-08-25 20:07 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2007-11-29 16:02 occur API change proposal Ted Zlatanov 2007-12-01 0:34 ` Juri Linkov 2008-08-05 18:49 ` add INVERT to re-search-{forward, backward} (was: occur API change proposal) Ted Zlatanov 2008-08-25 15:45 ` Juri Linkov 2008-08-25 15:57 ` add INVERT to re-search-{forward, backward} Lennart Borgman (gmail) 2008-08-25 19:45 ` Juri Linkov 2008-08-25 20:07 ` Lennart Borgman (gmail)
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.