Closed fommil closed 8 years ago
Sure, I'd be happy to add an option for either of those. Which would you prefer? Could you describe your use case a little more?
Cool! This is something I've wanted for a while, but grep was always limited because it uses the compilation-mode buffers, e.g. see me asking here https://groups.google.com/forum/#!topic/gnu.emacs.help/glyhTwQVeiI
I think I'd prefer the first option: hide/replace the current buffer with the search results. Basically my use case is that every time I do a search, I always end up having to C-x 0
or C-x o
. When I want to search for something, I almost always want to change my attention to the results. In the rare cases where I want to keep the original buffer alive, I'm happy splitting the frame and navigating to it.
Yeah ditto - this behavior makes more sense to me
good option, I hope for this too.
Sorry for the delay on this. It's a good suggestion, I'll take a look at implementing it.
I think I can achieve what I want with something like this.
(use-package ag
:commands ag
:init
(setq ag-reuse-window 't)
:config
;; would be a lot better if the next-error had a hook for the first match
(add-hook 'ag-search-finished-hook 'next-match-jump))
(defun next-match-jump ()
"Jump the point and user's focus to first match in a `compile'."
(pop-to-buffer next-error-last-buffer)
(compilation-next-error 1))
so closing. I'm looking into using the compile
hooks directly to try and do this for when the search results start coming in (not waiting till the end)
actually, much better is this
(setq compilation-scroll-output 'first-error)
(use-package ag
:commands ag
:init
(setq ag-reuse-window 't)
:config
(add-hook 'ag-search-finished-hook (lambda () (pop-to-buffer next-error-last-buffer))))
Hallelujah, the above works beautifully. For years, I've been C-x o
ing zero to three times to focus on the results buffer. At least under ag-reuse-buffers
the focus would persist with the current window or jump to the other depending on where the results buffer was seen last. Many thanks to all.
The differing behaviors between M-x grep
and ag
was driving me insane for years. I think I've finally got some peace with the following. Maintain focus on my working window, and send the search results to the other window.
(use-package ag
:commands ag
:init
(setq ag-reuse-window nil)
:config
(add-function :around (symbol-function 'compilation-start)
(lambda (f &rest args)
(let ((inhibit-same-window
(lambda (args*)
(append (cons (first args*)
(list (append (second args*)
'((inhibit-same-window . t)))))
(nthcdr 2 args*)))))
(add-function :filter-args (symbol-function 'display-buffer)
inhibit-same-window)
(condition-case err
(prog1 (apply f args)
(remove-function (symbol-function 'display-buffer)
inhibit-same-window))
(error (remove-function (symbol-function 'display-buffer)
inhibit-same-window)
(error (error-message-string err))))))))
This is a really great extension!
Could you please add an option to replace the current buffer with the results buffer, or for the focus to go to the new buffer?