aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPanagiotis Koutsourakis2023-01-17 20:57:41 +0200
committerEli Zaretskii2023-01-21 09:49:41 +0200
commita91b435d0d543f747bbdbd359ab708a3bab67c71 (patch)
treeeb026981ff26ab86b09d02f1dfc62de724e73efc
parentb3de81a6ee3b379fc1dfb9a071e469365081f438 (diff)
downloademacs-a91b435d0d543f747bbdbd359ab708a3bab67c71.tar.gz
emacs-a91b435d0d543f747bbdbd359ab708a3bab67c71.zip
; Reword user documentation on binding keys in Lisp
* doc/emacs/custom.texi (Init Rebinding): Move the description of 'kbd' farther down. (Bug#60859)
-rw-r--r--doc/emacs/custom.texi46
1 files changed, 36 insertions, 10 deletions
diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi
index 91df15a21d7..44c37d3ac83 100644
--- a/doc/emacs/custom.texi
+++ b/doc/emacs/custom.texi
@@ -1887,22 +1887,29 @@ command is less work to invoke when you really want to.
1887you can specify them in your initialization file by writing Lisp code. 1887you can specify them in your initialization file by writing Lisp code.
1888@xref{Init File}, for a description of the initialization file. 1888@xref{Init File}, for a description of the initialization file.
1889 1889
1890@findex kbd 1890@findex keymap-global-set
1891 There are several ways to write a key binding using Lisp. The 1891 The recommended way to write a key binding using Lisp is to use one
1892simplest is to use the @code{kbd} function, which converts a textual 1892of the @code{keymap-global-set}, or @code{keymap-set} functions. For
1893representation of a key sequence---similar to how we have written key 1893example, here's how to bind @kbd{C-z} to the @code{shell} command in
1894sequences in this manual---into a form that can be passed as an 1894the global keymap (@pxref{Interactive Shell}):
1895argument to @code{keymap-global-set}. For example, here's how to bind
1896@kbd{C-z} to the @code{shell} command (@pxref{Interactive Shell}):
1897 1895
1898@example 1896@example
1899(keymap-global-set "C-z" 'shell) 1897(keymap-global-set "C-z" 'shell)
1900@end example 1898@end example
1901 1899
1900@cindex key sequence syntax
1902@noindent 1901@noindent
1903The single-quote before the command name, @code{shell}, marks it as a 1902The second argument that describes the key sequence, is a string
1904constant symbol rather than a variable. If you omit the quote, Emacs 1903containing a series of characters separated by spaces with each
1905would try to evaluate @code{shell} as a variable. This probably 1904character corresponding to a key. Keys with modifiers can be
1905specified by prepending the modifier, such as @samp{C-} for Control,
1906or @samp{M-} for Meta. Special keys, such as @kbd{TAB} and @kbd{RET},
1907can be specified within angle brackets as in @kbd{@key{TAB}} and
1908@kbd{@key{RET}}.
1909
1910 The single-quote before the command name, @code{shell}, marks it as
1911a constant symbol rather than a variable. If you omit the quote,
1912Emacs would try to evaluate @code{shell} as a variable. This probably
1906causes an error; it certainly isn't what you want. 1913causes an error; it certainly isn't what you want.
1907 1914
1908 Here are some additional examples, including binding function keys 1915 Here are some additional examples, including binding function keys
@@ -1920,6 +1927,25 @@ and mouse events:
1920 Language and coding systems may cause problems with key bindings for 1927 Language and coding systems may cause problems with key bindings for
1921non-@acronym{ASCII} characters. @xref{Init Non-ASCII}. 1928non-@acronym{ASCII} characters. @xref{Init Non-ASCII}.
1922 1929
1930@findex global-set-key
1931@findex define-key
1932 Alternatively you can use the low level functions @code{define-key}
1933and @code{global-set-key}. For example to bind @kbd{C-z} to the
1934@code{shell} command as in the above example, use:
1935
1936@example
1937(global-set-key (kbd "C-z") 'shell)
1938@end example
1939
1940@findex kbd
1941@noindent
1942There are various ways to specify the key sequence but the simplest is
1943to use the function @code{kbd} as shown in the example above.
1944@code{kbd} takes a single string argument specifying a key sequence in
1945the syntax described earlier for @code{keymap-global-set}. For more
1946details about binding keys using Lisp @ref{Keymaps,,, elisp, The Emacs
1947Lisp Reference Manual}.
1948
1923@findex keymap-set 1949@findex keymap-set
1924@findex keymap-unset 1950@findex keymap-unset
1925 As described in @ref{Local Keymaps}, major modes and minor modes can 1951 As described in @ref{Local Keymaps}, major modes and minor modes can