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

Allow call to swiper with initial-input to find the next closest value after point. #2930

Merged
merged 1 commit into from
Apr 30, 2022

Conversation

skempf
Copy link
Contributor

@skempf skempf commented Oct 20, 2021

When function swiper is called with an initial-input and the current point is on a line that does not contain a match, the current code returns nil for preselect, which then causes the first viable candidate to be used, which is the first candidate in the buffer.

This small change selects the first candidate following the current point, which allows for a simple repeat-search function to wrap a call to swiper.

##Background
I have a utility function to perform a repeat search after an initial search. The function is very simple

(defun search-repeat ()
  (interactive)
  (let ((a ""))
    (if swiper-history
        (setq a (first swiper-history)))
    (swiper a)))

The default behavior of this changed, some time ago (issue #2157 commit 50ead7e). This commit changed the preselect to return the candidate on the current line or to nil, which will cause the first candidate in the entire buffer to be chosen.

As can be in the change, if we modify this from equal to less than, it takes the first candidate with a line number greater than the current point. If this fails (nil) then it will choose the first candidate in the buffer.

Copy link
Collaborator

@basil-conto basil-conto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This small change selects the first candidate following the current point

Thanks, this seems like the correct behaviour to me, to be consistent with an interactive call to swiper without initial input.

@basil-conto
Copy link
Collaborator

Ping!

@skempf
Copy link
Contributor Author

skempf commented Apr 30, 2022

Thanks for the ping. I'll look at this on Monday.

@skempf
Copy link
Contributor Author

skempf commented Apr 30, 2022

Actually, I had a moment to look at it; see comment above.

When swiper is called with an initial-input and the current point is
on a line that does not contain a match, the previous code would
return nil for preselect, which would position the first viable
candidate as the first candidate in the buffer.

This small change selects the first candidate at or following the
current point, which allows for a simple repeat-search function to
wrap a call to swiper.

* swiper.el (swiper): Fix preselect search condition (PR abo-abo#2930).

Copyright-paperwork-exempt: yes
@basil-conto basil-conto force-pushed the allow-search-forward-at-point branch from 48281b9 to 8bf8027 Compare April 30, 2022 22:48
Copy link
Collaborator

@basil-conto basil-conto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@basil-conto basil-conto merged commit 8bf8027 into abo-abo:master Apr 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants