Question

How can I navigate through text found by M-x grep using C-x ` and M-g p? These are normally bound to next-error and previous-error but in Auctex's LaTeX-mode they are re-bound to TeX-next-error and TeX-previous-error. I have tried using both local-set-key and global-set-key to rebind these keystrokes, but neither method works.

MWE: install Auctex, make a tex file, grep for something, and try the above keystrokes from within the tex buffer. Using M-x next-error will work, so will using the keystrokes from inside the *grep* buffer.

Was it helpful?

Solution

(defun jpk/LaTeX-mode-hook ()
  (local-set-key [remap next-error] nil)
  (local-set-key [remap previous-error] nil))

(add-hook 'LaTeX-mode-hook 'jpk/LaTeX-mode-hook)

OTHER TIPS

You can alias next-error to a command name of your own via fset and then use that in a rebinding. For example, the following may be used in an emacs init file (init.el or .emacs), to retain the M-g n binding for next-error without removing TeX-next-error from C-x `:

(fset #'afs-next-error #'next-error)
(fset #'afs-previous-error #'previous-error)
(with-eval-after-load "tex"
  (progn
    (define-key TeX-mode-map (kbd "M-g n") #'afs-next-error)
    (define-key TeX-mode-map (kbd "M-g p") #'afs-previous-error)))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top