-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enhance search API #3658
base: master
Are you sure you want to change the base?
enhance search API #3658
Conversation
8b80291
to
92b6fba
Compare
I've rebased the PR onto master and added |
92b6fba
to
72fcf50
Compare
The latest commit fixes a subtle bug related to the padding of the search region: In the presence of combining characters, one could end up with an infinite loop. (Try searching backwards for This bug is also present in #3575, hence in master. If you want, I can backport 88f3cf5 to master. This would require some modification of the commit, so let me know if that's necessary. |
0d14eae
to
88f3cf5
Compare
88f3cf5
to
1c1a35a
Compare
I've force-pushed a polished version and updated the list of functions at the top of this page. It still fixes the bug mentioned above. Also, locations returned for matches and submatches are now guaranteed to include the runes that matched. The underlying Go regexp functions match runes, which may be part of combining characters like This PR introduces many new functions. Maybe we don't need all of them. For example, do we need a submatch version on top of each non-submatch search or replace function? If we keep only the submatch version, we wouldn't lose any functionality because the additional elements in the slice for each match can be ignored. I nevertheless added all functions to this PR to show what's possible. |
This PR is based on #3575
and therefore a draft at present. It has the following components:RegexpGroup
that combines a regexp with its padded versions as used in match beginning and end of line correctly #3575,Deltas
inExecuteTextEvent
in reverse order. This makesreplaceall
easier to implement,LocVoid()
andLoc.IsVoid()
to deal with unused submatches.The new types and functions are as follows (UPDATED):
The method
FindNext
is kept.ReplaceRegex
is removed in favor ofReplaceAll
. The latter is easier to use in Lua scripts.Currently the simple search functions (
FindDown
etc.) take aRegexpGroup
as argument to avoid recompiling the regexps. In contrast,FindAll
,ReplaceAll
and friends take a string argument. Many other variants would be possible. Also, the new search functions ignore theignorecase
setting of the buffer and don't wrap around when they hit the end of the search region. I think they are more useful this way in Lua scripts.You will see that many new internal functions use callback functions. This avoids code duplication. (One has to somehow switch between
(*regexp.Regexp).FindIndex()
and(*regexp.Regexp).FindSubmatchIndex()
in the innermost function that searches each line of the buffer.)As said before, many details could be modified, but overall I think these functions are very useful for writing scripts. Please let me know what you think.