-
Notifications
You must be signed in to change notification settings - Fork 38
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
select the *rg* buffer after running a search #142
Comments
This should be a compilation-mode feature since that is what is used in rg. I have not seen any way of customizing that in compilation-mode itself unfortunately but I think A naive setup may be: (defun select-rg-buffer ()
(switch-to-buffer next-error-last-buffer))
(add-hook 'rg-mode-hook select-rg-buffer) Not sure how you get that to play well with how compilation buffers are displayed in general but works ok for me that have the default setup. |
This is what I have been using: (with-eval-after-load 'rg
(advice-add 'rg-run :after
#'(lambda (_pattern _files _dir &optional _literal _confirm _flags) (pop-to-buffer (rg-buffer-name))))) It's seems reasonable that it should be a Your suggestion didn't work for me as (add-hook 'rg-mode-hook #'select-rg-buffer) |
Here's another variant: (eval-after-load 'rg
(defun maybe-pop-to-rg-buffer(&optional buffer _)
"Switch to BUFFER (default: rg buffer) and select first match."
(with-current-buffer (or buffer (rg-buffer-name))
(when (string= mode-name "rg")
(pop-to-buffer (current-buffer))
(condition-case nil
(compilation-next-error 1 nil (point-min))
(error nil)))))
(add-to-list 'compilation-finish-functions #'maybe-pop-to-rg-buffer)) |
I guess I can add an (add-to-list 'rg-finish-functions (lambda (buffer _) (pop-to-buffer buffer))) Would this work for your use cases? |
Yeah, with the advice I'm using, it switches to the rg buffer at the start of a long running search, which is nice. Maybe |
This would allow the same functionality as compilation-finish-functions, i.e. add hooks called when the ripgrep process finishes. Could for instance be used to select the *rg* buffer after a search: (add-to-list 'rg-finish-functions (lambda (buffer _) (pop-to-buffer buffer)))
Implemented the |
I see the defvar in the commit but I don't see where they are called. Am I missing something? |
Probably the |
Seems to be working :) |
I just verified with the |
I think so. It has been working fine for me though I have one minor issue, but I don't think this has to stay open for it. I have |
Also, should |
Possibly. I have followed conventions of |
For me the |
After running an rg search, I'd like an option to have the results buffer (typically
*rg*
) be selected. I know about usingnext-error
, but this way I could easily navigate and also quit, edit (via wgrep) or rerun the search.The text was updated successfully, but these errors were encountered: