diff options
| author | Panagiotis Koutsourakis | 2023-01-17 20:57:41 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2023-01-21 09:49:41 +0200 |
| commit | a91b435d0d543f747bbdbd359ab708a3bab67c71 (patch) | |
| tree | eb026981ff26ab86b09d02f1dfc62de724e73efc | |
| parent | b3de81a6ee3b379fc1dfb9a071e469365081f438 (diff) | |
| download | emacs-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.texi | 46 |
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. | |||
| 1887 | you can specify them in your initialization file by writing Lisp code. | 1887 | you 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 |
| 1892 | simplest is to use the @code{kbd} function, which converts a textual | 1892 | of the @code{keymap-global-set}, or @code{keymap-set} functions. For |
| 1893 | representation of a key sequence---similar to how we have written key | 1893 | example, here's how to bind @kbd{C-z} to the @code{shell} command in |
| 1894 | sequences in this manual---into a form that can be passed as an | 1894 | the global keymap (@pxref{Interactive Shell}): |
| 1895 | argument 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 |
| 1903 | The single-quote before the command name, @code{shell}, marks it as a | 1902 | The second argument that describes the key sequence, is a string |
| 1904 | constant symbol rather than a variable. If you omit the quote, Emacs | 1903 | containing a series of characters separated by spaces with each |
| 1905 | would try to evaluate @code{shell} as a variable. This probably | 1904 | character corresponding to a key. Keys with modifiers can be |
| 1905 | specified by prepending the modifier, such as @samp{C-} for Control, | ||
| 1906 | or @samp{M-} for Meta. Special keys, such as @kbd{TAB} and @kbd{RET}, | ||
| 1907 | can 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 | ||
| 1911 | a constant symbol rather than a variable. If you omit the quote, | ||
| 1912 | Emacs would try to evaluate @code{shell} as a variable. This probably | ||
| 1906 | causes an error; it certainly isn't what you want. | 1913 | causes 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 |
| 1921 | non-@acronym{ASCII} characters. @xref{Init Non-ASCII}. | 1928 | non-@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} | ||
| 1933 | and @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 | ||
| 1942 | There are various ways to specify the key sequence but the simplest is | ||
| 1943 | to use the function @code{kbd} as shown in the example above. | ||
| 1944 | @code{kbd} takes a single string argument specifying a key sequence in | ||
| 1945 | the syntax described earlier for @code{keymap-global-set}. For more | ||
| 1946 | details about binding keys using Lisp @ref{Keymaps,,, elisp, The Emacs | ||
| 1947 | Lisp 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 |