aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorEli Zaretskii2025-01-04 09:59:55 -0500
committerEli Zaretskii2025-01-04 09:59:55 -0500
commit6814ab06f2c7b5b271e6d78d4e05ce498ffc403d (patch)
treee28e9a577f3759cd9da0e487e1c5eb83740fde33 /doc
parenta1b687568fdf204f1e7e1244b60cf9d41c3ce7eb (diff)
parent6468c3f7a74133b130d15172d770c8b7eebfeac5 (diff)
downloademacs-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.texi120
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."
13810If you wish, you can also install this key binding by evaluating it: 13810If 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
13816To conduct the first test, set mark and point to the beginning and end 13816To 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
14762Let's reuse @kbd{C-c =} as a convenient key binding: 14762Let'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
14768Now we can try out @code{count-words-defun}: install both 14768Now 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.
17242This also shows how to set a key globally, for all modes. 17242This 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
17248The command is @code{global-set-key}. It is followed by the 17248The key setting command is @code{keymap-global-set}. It is followed by
17249key binding. In a @file{.emacs} file, the keybinding is written as 17249the key binding. In a @file{.emacs} file, the keybinding is written as
17250shown: @code{\C-c} stands for Control-C, which means to press the 17250shown: @code{C-c} stands for Control-C, which means to press the control
17251control key and the @kbd{c} key at the same time. The @code{w} means 17251key and the @kbd{c} key at the same time. The @code{w} means to press
17252to press the @kbd{w} key. The key binding is surrounded by double 17252the @kbd{w} key. The key binding is surrounded by double quotation
17253quotation marks. In documentation, you would write this as 17253marks. (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 17254key, 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, , 17256Emacs Manual}, for details.)
17257Rebinding Keys in Your Init File, emacs, The GNU Emacs Manual}, for
17258details.)
17259 17257
17260The command invoked by the keys is @code{compare-windows}. Note that 17258The 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.
17296Matching lines are shown in a buffer called @file{*Occur*}. 17294Matching lines are shown in a buffer called @file{*Occur*}.
17297That buffer serves as a menu to jump to occurrences. 17295That 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}
17336command, which not only lists the buffers, 17334command, which not only lists the buffers,
17337but moves point into that window. 17335but 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
17341Historically, keys are bound globally using a lower-level function,
17342@code{global-set-key}, which is now considered legacy. While you are
17343encouraged to use @code{keymap-global-set}, you likely would encounter
17344@code{global-set-key} in various places. The first example in this
17345section 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
17353It is very similar to @code{keymap-global-set}, with the keybinding
17354following a slightly different format. Control-C is represented by
17355@code{\C-c}, instead of @code{C-c}. There is no space between key
17356strokes, like @code{\C-c} and @code{w} in this example. Despite the
17357difference, in documentation, this is still written as @w{@kbd{C-c w}}
17358for readability.
17359
17360@findex global-unset-key
17361Historically, keys are unbound globally using a lower-function,
17362@code{global-unset-key}, which is now considered legacy. Its key
17363binding format follows that of @code{global-set-key}. The key unbinding
17364example 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
17344Emacs uses @dfn{keymaps} to record which keys call which commands. 17378Emacs uses @dfn{keymaps} to record which keys call which commands.
17345When you use @code{global-set-key} to set the key binding for a single 17379When you use @code{keymap-global-set} to set the key binding for a
17346command in all parts of Emacs, you are specifying the key binding in 17380single command in all parts of Emacs, you are specifying the key binding
17347@code{current-global-map}. 17381in @code{current-global-map}.
17348 17382
17349Specific modes, such as C mode or Text mode, have their own keymaps; 17383Specific modes, such as C mode or Text mode, have their own keymaps;
17350the mode-specific keymaps override the global map that is shared by 17384the mode-specific keymaps override the global map that is shared by
17351all buffers. 17385all buffers.
17352 17386
17353The @code{global-set-key} function binds, or rebinds, the global 17387The @code{keymap-global-set} function binds, or rebinds, the global
17354keymap. For example, the following binds the key @kbd{C-x C-b} to the 17388keymap. For example, the following binds the key @kbd{C-x C-b} to the
17355function @code{buffer-menu}: 17389function @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
17361Mode-specific keymaps are bound using the @code{define-key} function, 17395Mode-specific keymaps are bound using the @code{keymap-set} function,
17362which takes a specific keymap as an argument, as well as the key and 17396which takes a specific keymap as an argument, as well as the key and
17363the command. For example, my @file{.emacs} file contains the 17397the command. For example, the following expression binds the
17364following expression to bind the @code{texinfo-insert-@@group} command 17398@code{texinfo-insert-@@group} command to @kbd{C-c C-c g}:
17365to @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
17406Historically, keymaps are bound using a lower-level function,
17407@code{define-key}, which is now considered legacy. While you are
17408encouraged to use @code{keymap-set}, you likely would encounter
17409@code{define-key} in various places. The above key binding can be
17410rewritten 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:
17396write a function to insert a word; but I prefer key strokes consistent 17441write a function to insert a word; but I prefer key strokes consistent
17397with other Texinfo mode key bindings.) 17442with other Texinfo mode key bindings.)
17398 17443
17399You will see numerous @code{define-key} expressions in 17444You will see numerous @code{keymap-set} and @code{define-key}
17400@file{loaddefs.el} as well as in the various mode libraries, such as 17445expressions in @file{loaddefs.el} as well as in the various mode
17401@file{cc-mode.el} and @file{lisp-mode.el}. 17446libraries, 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
17404Manual}, and @ref{Keymaps, , Keymaps, elisp, The GNU Emacs Lisp 17449Manual}, and @ref{Keymaps, , Keymaps, elisp, The GNU Emacs Lisp
@@ -17440,13 +17485,12 @@ window.
17440 17485
17441@need 1250 17486@need 1250
17442To replace the key binding for the default 17487To 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
17444the 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
17608this: 17652this:
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
17614For more information, see @ref{Init Rebinding, , Rebinding Keys in 17658For 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