Alex Rivera | Logout

Set custom keybinding for specific Emacs mode

Asked 2011-03-31T12:45:29.013
65

Though I know how to set a global key-binding in Emacs, I find it hard to even Google out the code for a local (minor-mode specific) key-binding. For instance, I have this code in my .emacs:

;; PDFLaTeX from AucTeX
(global-set-key (kbd "C-c M-p")
        (lambda ()
          (interactive)
          (shell-command (concat "pdflatex " buffer-file-name))))

I don't want to set it globally. Is there a function like local-set-key?

Edit
Report

1 Answer

51

To bind a key in a mode, you need to wait for the mode to be loaded before defining the key. One could require the mode, or use eval-after-load

   (eval-after-load 'latex 
                    '(define-key LaTeX-mode-map [(tab)] 'outline-cycle))

Don't forget either '—eval-after-load is not a macro, so it needs them.

answered 2011-03-31T20:24:44.703

Your Answer