unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Hong Xu <hong@topbug.net>
To: 74999@debbugs.gnu.org
Subject: bug#74999: [PATCH v2] Recommend `keymap-set' instead of `define-key' in emacs lisp intro
Date: Fri, 20 Dec 2024 13:42:29 -0800	[thread overview]
Message-ID: <20241220214351.57036-1-hong@topbug.net> (raw)
In-Reply-To: <CADwFkmnmWHjies57ptvWL+hPeHfmATnxvHb7hrKP_vbYiNHNTA@mail.gmail.com>

* 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






  reply	other threads:[~2024-12-20 21:42 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-19 22:36 bug#74983: [PATCH] Use `keymap-set' instead of `define-key' in emacs lisp intro Hong Xu
2024-12-20  7:01 ` Eli Zaretskii
2024-12-20  9:35   ` Stefan Kangas
2024-12-20 21:42     ` Hong Xu [this message]
2024-12-21  7:19       ` bug#74999: [PATCH v2] Recommend " Eli Zaretskii
2024-12-21  8:03         ` bug#74999: [PATCH v3] " Hong Xu
2024-12-23 20:42           ` Hong Xu
2024-12-24  3:27             ` Eli Zaretskii
2024-12-26  8:20           ` Eli Zaretskii
2024-12-26 21:46             ` bug#74999: [PATCH v4] Use `keymap*-set' over `global-set-key'/`define-key' in elisp intro Hong Xu
2024-12-26 22:05               ` Hong Xu
2024-12-27  7:44                 ` Eli Zaretskii
2024-12-28 12:17               ` Eli Zaretskii
2024-12-28 19:56                 ` Hong Xu
2024-12-26 21:58             ` bug#74999: [PATCH v3] Recommend `keymap-set' instead of `define-key' in emacs lisp intro Hong Xu
2024-12-27  7:37               ` Eli Zaretskii
2024-12-21  8:06         ` bug#74999: [PATCH v2] " Hong Xu
2024-12-20 15:43   ` bug#74983: [PATCH] Use " Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-20 21:50   ` Hong Xu
2024-12-21  7:20     ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241220214351.57036-1-hong@topbug.net \
    --to=hong@topbug.net \
    --cc=74999@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).