f4eb89cd7d79738a9c6c45e29abdd9d15d22e4fd was partially wrong and
removed legitimate re-matches when two different matches ends at the
same position. Particularly, the replacement changes are reverted.
Interestingly, Perl and Python does not agree on how to do such
replacements. Python does what I did in the above-cited commit, e.g.
doesn't replace twice if the match end overlaps, but Perl does.
Perl looks more legitimate here since both Python and Perl does find
the overlapping matches when performing a search, so Python is the odd
guy here doing it differently on replace than it does upon search.
For example, replacing using the pattern "a?(?=b)" and the replacement
string "_":
Python: ababcdb -> _b_bcd_b
Perl: ababcdb -> __b__bcd_b
But finding using the same pattern on the same input gives the same
results on both:
Python: ababcdb -> ['a', '', 'a', '', '']
Perl: ababcdb -> ['a', '', 'a', '', '']
Anyway, GLib and us claim to support "Perl-compatible regular
expressions", so we gotta follow Perl, especially in such doubtful
situations.
Regular expressions might match empty ranges, which weren't handled
properly, but generally simply omitted.
For example, the regular expression "^$" (empty line) never matched
because we assumed empty results were not interesting, and actually
needed more care in the code. Alike, an expression matching only on
its lookahead part, like "a?(?=b)" against "b", would stop further
search, although it could even match a non-empty range if "ab" is
present later in the input. This last kind of expressions also lead
to double-replacement because they first matched "ab" and then "b"
alone when re-matching after the "a" replacement.
This commit fixes:
* searching when the matched range is empty;
* step-by-step search when matching an empty range;
* double replacement when the pattern re-matches an empty range
straight after a replacement;
* replacement to and empty string when the matching an empty range.
A know issue though is the step-by-step replacement that won't replace
an empty match but rather find the next match.
If a search matched the very last character of the document, next
search attempt started out of the document bounds. This even lead
to an infinite loop due to an improper sanity check.
By the way, this fixes matching of contiguous results, as the next
search used to improperly skip one character after the result.
Although this looks like a huge issue, it was actually visible almost
only on the match count since the whole matching line was printed.
Use the current document's directory unless the directory field has
already been edited and the current document has not changed.
Otherwise, prepend the current document's directory to the drop-down
history in case it is wanted.
This is useful to avoid losing the edited directory when it is less
likely the user wants to use the current document's directory.
Don't simply split the the extra options string on spaces to build the
grep argument list but rather split it in a shell-style fashion.
This is probably more intuitive for most users, is more consistent with
e.g. custom commands, and allows for spaces in an option or its
argument.
Closes#3516263.
The g_match_info_fetch_pos() function uses a signed value for the match_num
parameter, even though values less than 0 are not valid, so a cast is used.
This makes the code more readable, potentially more future-proof (if
the actual string changes) and better style (catches possible typos at
build-time).
Previously we could put into a message a string where escape sequences
were already translated.
In the code, now we pass the original text together with the one
that is actually searched for. New `original_text' field was added to
GeanySearchData. A bug was fixed in document.c:show_replace_summary(): it
did not escape the "No matches found for ..." string.
Patch by Eugene Arshinov, thanks.
git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5832 ea778897-0a13-0410-b9d1-a72fbfd435f5
grep's --include option doesn't filter files passed explicitly to grep,
so when we build the file list to search in, take the filters into
account.
Also drop the --include options in this case since they aren't useful.
git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5755 ea778897-0a13-0410-b9d1-a72fbfd435f5
User can now select what kind of file patterns should be used:
* all: all files are searched
* project: project patterns are used (only if a project is open)
* custom: manually entered custom patterns are used
Based on a patch by Jiří Techet, thanks.
git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5753 ea778897-0a13-0410-b9d1-a72fbfd435f5
G_(UN)?LIKELY() should be only used on whole conditional expressions,
and only if the branching is very highly predictable, not if it is only
more probable.
These macros should be used with care because a wrong prediction may
be a lot worst than what a good prediction can give.
git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5625 ea778897-0a13-0410-b9d1-a72fbfd435f5
* Don't use strlen(..) > 0 or == 0, simply check the first character
against 0;
* Fix a return without a value (my bad in last commit);
* Fix storing a literal in a non-const string.
git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5610 ea778897-0a13-0410-b9d1-a72fbfd435f5
search when there's no selection.
Change default Find Selection behaviour to not let the X selection
override the current word (can be confusing).
Add docs for Find Selection commands.
git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5253 ea778897-0a13-0410-b9d1-a72fbfd435f5