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

Go to next match after "ending" search #127

Open
ghosty141 opened this issue Oct 25, 2022 · 5 comments
Open

Go to next match after "ending" search #127

ghosty141 opened this issue Oct 25, 2022 · 5 comments

Comments

@ghosty141
Copy link

ghosty141 commented Oct 25, 2022

Hi,
I'm currently checking out ctrlf, fantastic package, but I'm missing one "key" functionality. I come from vim and I really like the way when searching with "/" you press enter, navigate around and edit some text, and then you can press "n" to go to the next occurence.

How do I replicate this behavior with ctrlf? In isearch I can do this via isearch-repeat-forward. I kinda need ctrlf-repeat-forward.

Thanks for the help in advance :)

@raxod502
Copy link
Member

The default binding for this would be C-s C-s. I suppose you want something shorter?

@ghosty141
Copy link
Author

Ah yes this comes close! isearch keeps the highlighting, that's quite neat, maybe there is a way to use the search term as input for the corresponding highlight-<...> function or ctrlf could implement similar behavior to isearch in that regard.

For now, how would I bind C-s C-s though? As "macro" ?

@raxod502
Copy link
Member

Sure, those things all seem like reasonable possibilities, however I'm not sure offhand what the best approach would be.

I don't think it would be possible to bind C-s C-s as a single command, directly, since each of the C-s instances are actually different commands.

I think what we'd probably want to do is copy this function but have it use the last search query rather than using symbol at point:

ctrlf/ctrlf.el

Lines 1414 to 1431 in 63d27a0

(defun ctrlf-forward-symbol-at-point ()
"Search forward for symbol at point.
If already in a search, replace the current input and change to a
symbol search, otherwise start the search. If no symbol is found,
display an error message and do not search."
(interactive)
(let ((initial-contents nil)
(position nil)
(skip-search nil))
(with-current-buffer (window-buffer (minibuffer-selected-window))
(setq position (car (find-tag-default-bounds)))
(setq initial-contents (thing-at-point 'symbol t))
(unless initial-contents
(setq skip-search t)
(let ((ctrlf--message-persist-p t))
(ctrlf--message "No symbol at point"))))
(unless skip-search
(ctrlf-forward 'symbol nil initial-contents position))))

@ghosty141
Copy link
Author

I think what we'd probably want to do is copy this function but have it use the last search query rather than using symbol at point:

I played around with this a little bit, what we basically need is use (car ctrlf-search-history) + the position of the next result if there is one. I didn't find a function that returns the position of the next match though, if that would exist this would be possible right?

@raxod502
Copy link
Member

Why do you need the position of the next match, rather than simply moving to it by invoking ctrlf-forward?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants