diff options
| author | Eli Zaretskii | 2025-01-04 09:59:55 -0500 |
|---|---|---|
| committer | Eli Zaretskii | 2025-01-04 09:59:55 -0500 |
| commit | 6814ab06f2c7b5b271e6d78d4e05ce498ffc403d (patch) | |
| tree | e28e9a577f3759cd9da0e487e1c5eb83740fde33 /doc | |
| parent | a1b687568fdf204f1e7e1244b60cf9d41c3ce7eb (diff) | |
| parent | 6468c3f7a74133b130d15172d770c8b7eebfeac5 (diff) | |
| download | emacs-6814ab06f2c7b5b271e6d78d4e05ce498ffc403d.tar.gz emacs-6814ab06f2c7b5b271e6d78d4e05ce498ffc403d.zip | |
Merge from origin/emacs-30
6468c3f7a74 Update doc string of 'insert'
6d8c3c0cbe4 Use `keymap*-set' over `global-set-key'/`define-key' in e...
4b2bb63b7ac Fix documentation and prompt in 'package-isolate'
55f43f5b220 ; Fix typo in treesit-explore-mode
921f454f508 Update fontification for attribute values in heex-ts-mode
ae2589ea7a5 Add expression handling to heex-ts-mode
0cacf806391 ; * etc/NEWS: Document change of 'make-cursor-line-fully-...
f47a29da5c4 * lisp/man.el (Man-mode): Improve docstring.
# Conflicts:
# etc/NEWS
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/lispintro/emacs-lisp-intro.texi | 120 |
1 files changed, 82 insertions, 38 deletions
diff --git a/doc/lispintro/emacs-lisp-intro.texi b/doc/lispintro/emacs-lisp-intro.texi index 3e3febaf162..2c94e7f407e 100644 --- a/doc/lispintro/emacs-lisp-intro.texi +++ b/doc/lispintro/emacs-lisp-intro.texi | |||
| @@ -13810,7 +13810,7 @@ syntax table determines which characters these are." | |||
| 13810 | If you wish, you can also install this key binding by evaluating it: | 13810 | If you wish, you can also install this key binding by evaluating it: |
| 13811 | 13811 | ||
| 13812 | @smallexample | 13812 | @smallexample |
| 13813 | (global-set-key "\C-c=" '@value{COUNT-WORDS}) | 13813 | (keymap-global-set "C-c =" '@value{COUNT-WORDS}) |
| 13814 | @end smallexample | 13814 | @end smallexample |
| 13815 | 13815 | ||
| 13816 | To conduct the first test, set mark and point to the beginning and end | 13816 | To conduct the first test, set mark and point to the beginning and end |
| @@ -14762,7 +14762,7 @@ almost the same code as for the recursive version of | |||
| 14762 | Let's reuse @kbd{C-c =} as a convenient key binding: | 14762 | Let's reuse @kbd{C-c =} as a convenient key binding: |
| 14763 | 14763 | ||
| 14764 | @smallexample | 14764 | @smallexample |
| 14765 | (global-set-key "\C-c=" 'count-words-defun) | 14765 | (keymap-global-set "C-c =" 'count-words-defun) |
| 14766 | @end smallexample | 14766 | @end smallexample |
| 14767 | 14767 | ||
| 14768 | Now we can try out @code{count-words-defun}: install both | 14768 | Now we can try out @code{count-words-defun}: install both |
| @@ -17229,7 +17229,7 @@ Now for some personal key bindings: | |||
| 17229 | @smallexample | 17229 | @smallexample |
| 17230 | @group | 17230 | @group |
| 17231 | ;;; Compare windows | 17231 | ;;; Compare windows |
| 17232 | (global-set-key "\C-cw" 'compare-windows) | 17232 | (keymap-global-set "C-c w" 'compare-windows) |
| 17233 | @end group | 17233 | @end group |
| 17234 | @end smallexample | 17234 | @end smallexample |
| 17235 | 17235 | ||
| @@ -17242,20 +17242,18 @@ each window as far as they match. I use this command all the time. | |||
| 17242 | This also shows how to set a key globally, for all modes. | 17242 | This also shows how to set a key globally, for all modes. |
| 17243 | 17243 | ||
| 17244 | @cindex Setting a key globally | 17244 | @cindex Setting a key globally |
| 17245 | @cindex Global set key | 17245 | @cindex Keymap global set |
| 17246 | @cindex Key setting globally | 17246 | @cindex Key setting globally |
| 17247 | @findex global-set-key | 17247 | @findex keymap-global-set |
| 17248 | The command is @code{global-set-key}. It is followed by the | 17248 | The key setting command is @code{keymap-global-set}. It is followed by |
| 17249 | key binding. In a @file{.emacs} file, the keybinding is written as | 17249 | the key binding. In a @file{.emacs} file, the keybinding is written as |
| 17250 | shown: @code{\C-c} stands for Control-C, which means to press the | 17250 | shown: @code{C-c} stands for Control-C, which means to press the control |
| 17251 | control key and the @kbd{c} key at the same time. The @code{w} means | 17251 | key and the @kbd{c} key at the same time. The @code{w} means to press |
| 17252 | to press the @kbd{w} key. The key binding is surrounded by double | 17252 | the @kbd{w} key. The key binding is surrounded by double quotation |
| 17253 | quotation marks. In documentation, you would write this as | 17253 | marks. (If you were binding a @key{META} key, rather than a @key{CTRL} |
| 17254 | @w{@kbd{C-c w}}. (If you were binding a @key{META} key, such as | 17254 | key, you would write @w{@code{M-c}} in your @file{.emacs} file. |
| 17255 | @kbd{M-c}, rather than a @key{CTRL} key, you would write | 17255 | @xref{Init Rebinding, , Rebinding Keys in Your Init File, emacs, The GNU |
| 17256 | @w{@code{\M-c}} in your @file{.emacs} file. @xref{Init Rebinding, , | 17256 | Emacs Manual}, for details.) |
| 17257 | Rebinding Keys in Your Init File, emacs, The GNU Emacs Manual}, for | ||
| 17258 | details.) | ||
| 17259 | 17257 | ||
| 17260 | The command invoked by the keys is @code{compare-windows}. Note that | 17258 | The command invoked by the keys is @code{compare-windows}. Note that |
| 17261 | @code{compare-windows} is preceded by a single-quote; otherwise, Emacs | 17259 | @code{compare-windows} is preceded by a single-quote; otherwise, Emacs |
| @@ -17284,7 +17282,7 @@ Here is another key binding, with a comment: | |||
| 17284 | @group | 17282 | @group |
| 17285 | ;;; Key binding for 'occur' | 17283 | ;;; Key binding for 'occur' |
| 17286 | ; I use occur a lot, so let's bind it to a key: | 17284 | ; I use occur a lot, so let's bind it to a key: |
| 17287 | (global-set-key "\C-co" 'occur) | 17285 | (keymap-global-set "C-c o" 'occur) |
| 17288 | @end group | 17286 | @end group |
| 17289 | @end smallexample | 17287 | @end smallexample |
| 17290 | 17288 | ||
| @@ -17296,7 +17294,7 @@ uses the entire buffer. | |||
| 17296 | Matching lines are shown in a buffer called @file{*Occur*}. | 17294 | Matching lines are shown in a buffer called @file{*Occur*}. |
| 17297 | That buffer serves as a menu to jump to occurrences. | 17295 | That buffer serves as a menu to jump to occurrences. |
| 17298 | 17296 | ||
| 17299 | @findex global-unset-key | 17297 | @findex keymap-global-unset |
| 17300 | @cindex Unbinding key | 17298 | @cindex Unbinding key |
| 17301 | @cindex Key unbinding | 17299 | @cindex Key unbinding |
| 17302 | @need 1250 | 17300 | @need 1250 |
| @@ -17306,7 +17304,7 @@ work: | |||
| 17306 | @smallexample | 17304 | @smallexample |
| 17307 | @group | 17305 | @group |
| 17308 | ;;; Unbind 'C-x f' | 17306 | ;;; Unbind 'C-x f' |
| 17309 | (global-unset-key "\C-xf") | 17307 | (keymap-global-unset "C-x f") |
| 17310 | @end group | 17308 | @end group |
| 17311 | @end smallexample | 17309 | @end smallexample |
| 17312 | 17310 | ||
| @@ -17324,7 +17322,7 @@ The following rebinds an existing key: | |||
| 17324 | @smallexample | 17322 | @smallexample |
| 17325 | @group | 17323 | @group |
| 17326 | ;;; Rebind 'C-x C-b' for 'buffer-menu' | 17324 | ;;; Rebind 'C-x C-b' for 'buffer-menu' |
| 17327 | (global-set-key "\C-x\C-b" 'buffer-menu) | 17325 | (keymap-global-set "C-x C-b" 'buffer-menu) |
| 17328 | @end group | 17326 | @end group |
| 17329 | @end smallexample | 17327 | @end smallexample |
| 17330 | 17328 | ||
| @@ -17336,33 +17334,80 @@ window, I prefer the @code{buffer-menu} | |||
| 17336 | command, which not only lists the buffers, | 17334 | command, which not only lists the buffers, |
| 17337 | but moves point into that window. | 17335 | but moves point into that window. |
| 17338 | 17336 | ||
| 17337 | @subsection Legacy Global Key Binding Commands | ||
| 17338 | |||
| 17339 | @findex global-set-key | ||
| 17340 | @cindex Global set key | ||
| 17341 | Historically, keys are bound globally using a lower-level function, | ||
| 17342 | @code{global-set-key}, which is now considered legacy. While you are | ||
| 17343 | encouraged to use @code{keymap-global-set}, you likely would encounter | ||
| 17344 | @code{global-set-key} in various places. The first example in this | ||
| 17345 | section can be rewritten using @code{global-set-key} as: | ||
| 17346 | |||
| 17347 | @smallexample | ||
| 17348 | @group | ||
| 17349 | (global-set-key "\C-cw" 'compare-windows) | ||
| 17350 | @end group | ||
| 17351 | @end smallexample | ||
| 17352 | |||
| 17353 | It is very similar to @code{keymap-global-set}, with the keybinding | ||
| 17354 | following a slightly different format. Control-C is represented by | ||
| 17355 | @code{\C-c}, instead of @code{C-c}. There is no space between key | ||
| 17356 | strokes, like @code{\C-c} and @code{w} in this example. Despite the | ||
| 17357 | difference, in documentation, this is still written as @w{@kbd{C-c w}} | ||
| 17358 | for readability. | ||
| 17359 | |||
| 17360 | @findex global-unset-key | ||
| 17361 | Historically, keys are unbound globally using a lower-function, | ||
| 17362 | @code{global-unset-key}, which is now considered legacy. Its key | ||
| 17363 | binding format follows that of @code{global-set-key}. The key unbinding | ||
| 17364 | example in this section can be rewritten as: | ||
| 17365 | |||
| 17366 | @smallexample | ||
| 17367 | @group | ||
| 17368 | ;;; Unbind 'C-x f' | ||
| 17369 | (global-unset-key "\C-xf") | ||
| 17370 | @end group | ||
| 17371 | @end smallexample | ||
| 17372 | |||
| 17339 | @node Keymaps | 17373 | @node Keymaps |
| 17340 | @section Keymaps | 17374 | @section Keymaps |
| 17341 | @cindex Keymaps | 17375 | @cindex Keymaps |
| 17342 | @cindex Rebinding keys | 17376 | @cindex Rebinding keys |
| 17343 | 17377 | ||
| 17344 | Emacs uses @dfn{keymaps} to record which keys call which commands. | 17378 | Emacs uses @dfn{keymaps} to record which keys call which commands. |
| 17345 | When you use @code{global-set-key} to set the key binding for a single | 17379 | When you use @code{keymap-global-set} to set the key binding for a |
| 17346 | command in all parts of Emacs, you are specifying the key binding in | 17380 | single command in all parts of Emacs, you are specifying the key binding |
| 17347 | @code{current-global-map}. | 17381 | in @code{current-global-map}. |
| 17348 | 17382 | ||
| 17349 | Specific modes, such as C mode or Text mode, have their own keymaps; | 17383 | Specific modes, such as C mode or Text mode, have their own keymaps; |
| 17350 | the mode-specific keymaps override the global map that is shared by | 17384 | the mode-specific keymaps override the global map that is shared by |
| 17351 | all buffers. | 17385 | all buffers. |
| 17352 | 17386 | ||
| 17353 | The @code{global-set-key} function binds, or rebinds, the global | 17387 | The @code{keymap-global-set} function binds, or rebinds, the global |
| 17354 | keymap. For example, the following binds the key @kbd{C-x C-b} to the | 17388 | keymap. For example, the following binds the key @kbd{C-x C-b} to the |
| 17355 | function @code{buffer-menu}: | 17389 | function @code{buffer-menu}: |
| 17356 | 17390 | ||
| 17357 | @smallexample | 17391 | @smallexample |
| 17358 | (global-set-key "\C-x\C-b" 'buffer-menu) | 17392 | (keymap-global-set "C-x C-b" 'buffer-menu) |
| 17359 | @end smallexample | 17393 | @end smallexample |
| 17360 | 17394 | ||
| 17361 | Mode-specific keymaps are bound using the @code{define-key} function, | 17395 | Mode-specific keymaps are bound using the @code{keymap-set} function, |
| 17362 | which takes a specific keymap as an argument, as well as the key and | 17396 | which takes a specific keymap as an argument, as well as the key and |
| 17363 | the command. For example, my @file{.emacs} file contains the | 17397 | the command. For example, the following expression binds the |
| 17364 | following expression to bind the @code{texinfo-insert-@@group} command | 17398 | @code{texinfo-insert-@@group} command to @kbd{C-c C-c g}: |
| 17365 | to @kbd{C-c C-c g}: | 17399 | |
| 17400 | @smallexample | ||
| 17401 | @group | ||
| 17402 | (keymap-set texinfo-mode-map "C-c C-c g" 'texinfo-insert-@@group) | ||
| 17403 | @end group | ||
| 17404 | @end smallexample | ||
| 17405 | |||
| 17406 | Historically, keymaps are bound using a lower-level function, | ||
| 17407 | @code{define-key}, which is now considered legacy. While you are | ||
| 17408 | encouraged to use @code{keymap-set}, you likely would encounter | ||
| 17409 | @code{define-key} in various places. The above key binding can be | ||
| 17410 | rewritten using @code{define-key} as: | ||
| 17366 | 17411 | ||
| 17367 | @smallexample | 17412 | @smallexample |
| 17368 | @group | 17413 | @group |
| @@ -17396,9 +17441,9 @@ Here is the @code{texinfo-insert-@@group} function definition: | |||
| 17396 | write a function to insert a word; but I prefer key strokes consistent | 17441 | write a function to insert a word; but I prefer key strokes consistent |
| 17397 | with other Texinfo mode key bindings.) | 17442 | with other Texinfo mode key bindings.) |
| 17398 | 17443 | ||
| 17399 | You will see numerous @code{define-key} expressions in | 17444 | You will see numerous @code{keymap-set} and @code{define-key} |
| 17400 | @file{loaddefs.el} as well as in the various mode libraries, such as | 17445 | expressions in @file{loaddefs.el} as well as in the various mode |
| 17401 | @file{cc-mode.el} and @file{lisp-mode.el}. | 17446 | libraries, such as @file{cc-mode.el} and @file{lisp-mode.el}. |
| 17402 | 17447 | ||
| 17403 | @xref{Key Bindings, , Customizing Key Bindings, emacs, The GNU Emacs | 17448 | @xref{Key Bindings, , Customizing Key Bindings, emacs, The GNU Emacs |
| 17404 | Manual}, and @ref{Keymaps, , Keymaps, elisp, The GNU Emacs Lisp | 17449 | Manual}, and @ref{Keymaps, , Keymaps, elisp, The GNU Emacs Lisp |
| @@ -17440,13 +17485,12 @@ window. | |||
| 17440 | 17485 | ||
| 17441 | @need 1250 | 17486 | @need 1250 |
| 17442 | To replace the key binding for the default | 17487 | To replace the key binding for the default |
| 17443 | @code{split-window-vertically}, you must also unset that key and bind | 17488 | @code{split-window-vertically}, you must bind the keys to |
| 17444 | the keys to @code{split-window-quietly}, like this: | 17489 | @code{split-window-quietly}, like this: |
| 17445 | 17490 | ||
| 17446 | @smallexample | 17491 | @smallexample |
| 17447 | @group | 17492 | @group |
| 17448 | (global-unset-key "\C-x2") | 17493 | (keymap-global-set "C-x 2" 'split-window-quietly) |
| 17449 | (global-set-key "\C-x2" 'split-window-quietly) | ||
| 17450 | @end group | 17494 | @end group |
| 17451 | @end smallexample | 17495 | @end smallexample |
| 17452 | 17496 | ||
| @@ -17608,7 +17652,7 @@ I bind @code{line-to-top-of-window} to my @key{F6} function key like | |||
| 17608 | this: | 17652 | this: |
| 17609 | 17653 | ||
| 17610 | @smallexample | 17654 | @smallexample |
| 17611 | (global-set-key [f6] 'line-to-top-of-window) | 17655 | (keymap-global-set "<f6>" 'line-to-top-of-window) |
| 17612 | @end smallexample | 17656 | @end smallexample |
| 17613 | 17657 | ||
| 17614 | For more information, see @ref{Init Rebinding, , Rebinding Keys in | 17658 | For more information, see @ref{Init Rebinding, , Rebinding Keys in |
| @@ -18791,7 +18835,7 @@ Here is the @code{the-the} function, as I include it in my | |||
| 18791 | 18835 | ||
| 18792 | @group | 18836 | @group |
| 18793 | ;; Bind 'the-the' to C-c \ | 18837 | ;; Bind 'the-the' to C-c \ |
| 18794 | (global-set-key "\C-c\\" 'the-the) | 18838 | (keymap-global-set "C-c \\" 'the-the) |
| 18795 | @end group | 18839 | @end group |
| 18796 | @end smallexample | 18840 | @end smallexample |
| 18797 | 18841 | ||