Skip to content
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

isearch - End highlight when no range found #1725

Merged
merged 2 commits into from
Dec 31, 2024

Conversation

Encryptoid
Copy link
Contributor

@Encryptoid Encryptoid commented Dec 31, 2024

Background

I started looking into this from: In vi mode :'<,'>s/^/;;/ leads to a crash.
It was a windy road to find this small code change, but I think this has the smallest impact, and works. I learned a lot about vi-mode ex-commands and isearch.

Cause

When using the isearch mode: *isearch-search-forward-function* = lem:search-forward-regexp, which vi-mode ex-command substitute does, the editor freezes when attempting to highlight regex that evaluates to an empty string. Eg. "^", "$", both can be searched for, but should not highlight anything.

This is because in isearch:highlight-region, for example with "^", the loop searches backward for "^", then the end loop clause searches forward in the line for "^" and does not find it, so it loops infinitely, and causes Lem to freeze. Same with "$", ".*", etc.

Fix

Add to the loop end clause, that if after the points have been moved by these above checks, if the mutable moving start-point = end-point still, then end the highlighting loop as there is nothing to highligh.

Testing

I added tests to vi-mode and verified the isearch ones still pass.

Tested myself via vi-mode subs, and verified isearch still works.
Vi-mode "/" and "?" still highlight correctly.

image

@cxxxr cxxxr merged commit b15c5bb into lem-project:main Dec 31, 2024
2 checks passed
@Encryptoid Encryptoid deleted the isearch-fix-highlight-with-regex branch January 1, 2025 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants