Wilfred / ag.el

An Emacs frontend to The Silver Searcher
http://agel.readthedocs.org/en/latest/
525 stars 61 forks source link

give focus to the results window #85

Closed fommil closed 8 years ago

fommil commented 9 years ago

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?

Wilfred commented 9 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?

fommil commented 9 years ago

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.

gone commented 9 years ago

Yeah ditto - this behavior makes more sense to me

stardiviner commented 9 years ago

good option, I hope for this too.

Wilfred commented 9 years ago

Sorry for the delay on this. It's a good suggestion, I'll take a look at implementing it.

fommil commented 8 years ago

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)

fommil commented 8 years ago

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))))
dickmao commented 6 years ago

Hallelujah, the above works beautifully. For years, I've been C-x oing 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.

dickmao commented 5 years ago

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))))))))