GNU bug report logs -
#74999
[PATCH v2] Recommend `keymap-set' instead of `define-key' in emacs lisp intro
Previous Next
Reported by: Hong Xu <hong <at> topbug.net>
Date: Fri, 20 Dec 2024 21:45:02 UTC
Severity: wishlist
Tags: patch
Merged with 74983
Done: Eli Zaretskii <eliz <at> gnu.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
* Since `define-key' is considered legacy and we encourage `keymap-set'
now.
---
doc/lispintro/emacs-lisp-intro.texi | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/doc/lispintro/emacs-lisp-intro.texi b/doc/lispintro/emacs-lisp-intro.texi
index 49916235fbf9..ba671e60ffcf 100644
--- a/doc/lispintro/emacs-lisp-intro.texi
+++ b/doc/lispintro/emacs-lisp-intro.texi
@@ -17358,11 +17358,21 @@ Keymaps
(global-set-key "\C-x\C-b" 'buffer-menu)
@end smallexample
-Mode-specific keymaps are bound using the @code{define-key} function,
+Mode-specific keymaps are bound using the @code{keymap-set} function,
which takes a specific keymap as an argument, as well as the key and
-the command. For example, my @file{.emacs} file contains the
-following expression to bind the @code{texinfo-insert-@@group} command
-to @kbd{C-c C-c g}:
+the command. For example, the following expression binds the
+@code{texinfo-insert-@@group} command to @kbd{C-c C-c g}:
+
+@smallexample
+@group
+(keymap-set texinfo-mode-map "C-c C-c g" 'texinfo-insert-@@group)
+@end group
+@end smallexample
+
+While you are encouraged to use @code{keymap-set}, you likely would
+encounter @code{define-key} in various places. @code{define-key} is an
+older function to create keymaps, and is now considered legacy. The
+above key map can be rewritten in @code{define-key} as:
@smallexample
@group
@@ -17396,9 +17406,9 @@ Keymaps
write a function to insert a word; but I prefer key strokes consistent
with other Texinfo mode key bindings.)
-You will see numerous @code{define-key} expressions in
-@file{loaddefs.el} as well as in the various mode libraries, such as
-@file{cc-mode.el} and @file{lisp-mode.el}.
+You will see numerous @code{keymap-set} and @code{define-key}
+expressions in @file{loaddefs.el} as well as in the various mode
+libraries, such as @file{cc-mode.el} and @file{lisp-mode.el}.
@xref{Key Bindings, , Customizing Key Bindings, emacs, The GNU Emacs
Manual}, and @ref{Keymaps, , Keymaps, elisp, The GNU Emacs Lisp
--
2.47.1
This bug report was last modified 136 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.