Keyboard bindings in EMACS

Emacs offers several ways of adding keybindings for macros:

For quick hacks, such as repeatingly use a macro that you create with the macro recorder (which is a simple keyboard repeater), it is easiest to define a global keybinding without saving it in .emacs, that way the keybinding will disappear when you exit emacs. (In that case, name the macro and the invoke global-set-key using M-x, and follow the instructions).

To add a keybinding for a macro provided by a mode, you use the function local-set-key in the hook for the mode.

I want to bind two functions from ess-mode like this:

key macro description
<f5> ess-eval-chunk ess-eval-chunk
<f6> ess-noweb-next-chunk goto the next chunk

To achive this, I put the following in .emacs.

;; keybindings for ess
(defun my-ess-hook ()
  "Add my keybindings to ESS mode."
  (local-set-key (kbd "<f5>") 'ess-eval-chunk)
  (local-set-key (kbd "<f6>") 'ess-noweb-next-chunk)
)
(add-hook 'ess-mode-hook 'my-ess-hook)

comments powered by Disqus


Back to the index

Blog roll

R-bloggers, Debian Weekly
Valid XHTML 1.0 Strict [Valid RSS] Valid CSS! Emacs Muse Last modified: oktober 12, 2017