Wilfred / ag.el

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

Bind the 'n' 'p' to next-error-no-select and previous-error-no-select by default #86

Closed casch-at closed 9 years ago

casch-at commented 9 years ago

Hey,

first off all, thank you for this extension for _the_silversearcher.

It would be great if the key n and p in the ag search buffer are bound to next-error-no-select and previous-error-no-select by default, as it is in grep search buffer.

In grep search buffer you can move right to the location with n and p (no leaving of the buffer) whereas in ag search buffer you would have to press C-c C-c or Enter to jump to the location and than you would have to go back. Of course as the parent mode is compiliation-mode you could also press C-x `` to jump to next "error" orM-g pto jump to the previous "error". But I think if you usegreporag` you usually want to investigate the hits quickly with less key strokes.

Just my opinion, let me know what you think.

regards, Christian

UPDATE:

For now I have added this to my emacs init file.

;;; Rebind 'n' and 'p' of *ag search* buffer
(define-key ag-mode-map (kbd "n") 'next-error-no-select)
(define-key ag-mode-map (kbd "p") 'previous-error-no-select)

Would be nice if this would be the default bindings.

Wilfred commented 9 years ago

OK, so the default behaviour of n and p in the results buffer is to simply move point to the next search result.

If I've understood correctly, you're proposing n to move point in the search buffer and to open the relevant result.

I think this is the same as next-error-follow-minor-mode, which you can enable with C-c C-f in a results buffer. If you want this behaviour on by default, try this:

(add-hook 'ag-mode-hook #'next-error-follow-minor-mode)

Does that meet your needs?

(If so, we should probably clarify this in the docs.)

kaushalmodi commented 9 years ago

@Wilfred Looks like next-error-follow-minor-mode enables only the follow mode that syncs the ag results with the corresponding locations in files.

As @cslux updated, those bindings will have to be added to the ag-mode-map, just as grep.el does:

(defvar grep-mode-map
  (let ((map (make-sparse-keymap)))
    (set-keymap-parent map compilation-minor-mode-map)
    (define-key map " " 'scroll-up-command)
    (define-key map [?\S-\ ] 'scroll-down-command)
    (define-key map "\^?" 'scroll-down-command)
    (define-key map "\C-c\C-f" 'next-error-follow-minor-mode)

    (define-key map "\r" 'compile-goto-error)  ;; ?
    (define-key map "n" 'next-error-no-select)
    (define-key map "p" 'previous-error-no-select)

Thanks for the pointer @cslux, I have remapped those bindings in ag-mode-map in my config.

casch-at commented 9 years ago

@Wilfred yes that meet my needs, didn't know that.

Thank you! Chris