Comments (14)
Implemented the rg-finish-functions
solution for now.
from rg.el.
Probably the define-compilation-mode
inner workings. If defined it's picked up by compilation mode and handled from there. So the defvar
isn't strictly needed (any setq
would work) but will allow for more flexible usage plus visibility in the package.
from rg.el.
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 next-error-last-buffer
should be set so you can use that in an rg-mode-hook
to do what you need.
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.
from rg.el.
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 compilation-mode
feature, though I'd want this for rg
but not for M-x compile
where next-error
would be fine for me.
Your suggestion didn't work for me as next-error-last-buffer
wasn't correct, also the add-hook call should be:
(add-hook 'rg-mode-hook #'select-rg-buffer)
from rg.el.
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))
from rg.el.
I guess I can add an rg-finish-functions
variable that can be used instead of compilation-finish-functions
. In that way the last example should work without finding the rg buffer. Something like this:
(add-to-list 'rg-finish-functions (lambda (buffer _) (pop-to-buffer buffer)))
Would this work for your use cases?
I guess one problem for long running searches is that the buffer will not be selected until the search is finished.
from rg.el.
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 rg-finish-functions
could be run at the end of rg-run
like my advice? I don't have another use for such a hook so if rg itself could select the buffer via user option I'm fine with that.
from rg.el.
I see the defvar in the commit but I don't see where they are called. Am I missing something?
from rg.el.
Seems to be working :)
from rg.el.
Related Issues (20)
- default-directory is not updated when using rg from an rg-mode buffer HOT 1
- Keep multiple search results' buffers HOT 3
- `M-x rg` never finds matches using Emacs 28.1 on Mac HOT 8
- rg.el not works under fish shell HOT 1
- IPv6 addresses often mistaken as line/column numbers HOT 4
- ignore user-specified built-in aliases HOT 2
- Only rg-use-old-defaults seems to work with result buffer HOT 6
- Would be nice if DWIM modes prompt for search string if no word at point HOT 3
- Question on searching and removing the whole line HOT 1
- Wgrep fails with "There are n unapplied changes. (0 changed)" HOT 1
- Result-based navigation fails HOT 3
- Question about using glob pattern with rg HOT 1
- Feature request: search symlinked file, but make the file path in "*rg*" buffer the path of the symlink HOT 6
- Comparison with Deadgrep? HOT 1
- Expose search history more prominently HOT 1
- project.el issue HOT 2
- support project.el external roots HOT 1
- When copying from buffer `*rg*`, some internal text is included HOT 1
- How to make "enter" key open target file at the location of the searched keyword? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rg.el.