Go to the first, previous, next, last section, table of contents.


Keymaps

Emacs uses keymaps to record which keys call which commands. Specific modes, such as C mode or Text mode, have their own keymaps; the mode-specific keymaps override the global map that is shared by all buffers.

The global-set-key function binds, or rebinds, the global keymap. For example, the following binds the key C-c C-l to the function line-to-top-of-window:

(global-set-key "\C-c\C-l" 'line-to-top-of-window))

Mode-specific keymaps are bound using the define-key function, which takes a specific keymap as an argument, as well as the key and the command. For example, my `.emacs' file contains the following expression to bind the texinfo-insert-@group command to C-c C-c g:

(define-key texinfo-mode-map "\C-c\C-cg"
  'texinfo-insert-@group)

The texinfo-insert-@group function itself is a little extension to Texinfo mode that inserts `@group' into a Texinfo file. I use this command all the time and prefer to type the three strokes C-c C-c g rather than the six strokes @ g r o u p. (`@group' and its matching `@end group' are commands that keep all enclosed text together on one page; many multi-line examples in this book are surrounded by `@group ... @end group'.)

Here is the texinfo-insert-@group function definition:

(defun texinfo-insert-@group ()
  "Insert the string @group in a Texinfo buffer."
  (interactive)
  (beginning-of-line)
  (insert "@group\n"))

(Of course, I could have used Abbrev mode to save typing, rather than write a function to insert a word; but I prefer key strokes consistent with other Texinfo mode key bindings.)

You will see numerous define-key expressions in `loaddefs.el' as well as in the various mode libraries, such as `c-mode.el' and `lisp-mode.el'.

See section `Customizing Key Bindings' in The GNU Emacs Manual, and section `Keymaps' in The GNU Emacs Lisp Reference Manual, for more information about keymaps.


Go to the first, previous, next, last section, table of contents.