From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Hong Xu Newsgroups: gmane.emacs.bugs Subject: bug#74999: [PATCH v3] Recommend `keymap-set' instead of `define-key' in emacs lisp intro Date: Sat, 21 Dec 2024 00:03:54 -0800 Message-ID: <20241221080552.259664-1-hong@topbug.net> References: <86y1098pvj.fsf@gnu.org> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20592"; mail-complaints-to="usenet@ciao.gmane.io" To: 74999@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 21 09:07:23 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tOuWA-0005El-IG for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 21 Dec 2024 09:07:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOuVr-00069l-TL; Sat, 21 Dec 2024 03:07:03 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOuVq-00069b-VR for bug-gnu-emacs@gnu.org; Sat, 21 Dec 2024 03:07:03 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tOuVq-0004Tw-N3 for bug-gnu-emacs@gnu.org; Sat, 21 Dec 2024 03:07:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=wVENP7nTAdK0vwplHgr/Ufv9xjDULgWJPKnKg2Vmnbw=; b=rlmDjLT2ZJ3KErfxUFkOgn1XzI10zBGMlB3eR2SvynnS5DFqmBm0HOS1a7cVMlY7Djy3K9RXfrwB640mdH8o7HYN0lcHB72cinA1xA62fD8gdZnBuiXtW3ih4ENSNhnFjz17hIJir9N9c/Lll59QEbH6DJuA4CyRoj/2Q9oWqCkdH5jTCaK36OGlAWT3ihzyvzveEV5R7FWZfIDslVjlvxXId2ZMr9A9sF1o48V8uyk9z15uTpk5jZ9hloYeMVYYJE6oouOWVTG03bRYaTHp/KdUoEDg0fsbXKOmdSdNN8Ayn8dDgxWkySLwTj2cCTTZaoyL+EZOpsK6uK3PbDZeQA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tOuVq-0003Jd-8H for bug-gnu-emacs@gnu.org; Sat, 21 Dec 2024 03:07:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Hong Xu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 21 Dec 2024 08:07:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74999 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 74999-submit@debbugs.gnu.org id=B74999.173476836212659 (code B ref 74999); Sat, 21 Dec 2024 08:07:02 +0000 Original-Received: (at 74999) by debbugs.gnu.org; 21 Dec 2024 08:06:02 +0000 Original-Received: from localhost ([127.0.0.1]:45109 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tOuUr-0003I7-Vm for submit@debbugs.gnu.org; Sat, 21 Dec 2024 03:06:02 -0500 Original-Received: from sender4-of-o52.zoho.com ([136.143.188.52]:21286) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tOuUo-0003Hd-E6 for 74999@debbugs.gnu.org; Sat, 21 Dec 2024 03:06:01 -0500 ARC-Seal: i=1; a=rsa-sha256; t=1734768355; cv=none; d=zohomail.com; s=zohoarc; b=X0+Puec/zPTAC9YpBGJ4hrlMWxAuQ+lGIjU9zg/vxpYtP6+kKc1fLHtFmE9r8ROoz/Uiv+HKAq83XG6KLMf9nnpPyLKNkxbjA+E2+dVjqH3ASR38BCpLJv9bEw4sWJ594o5RQpqAMh5jPPJ2FE9jlRGrzFfNw0mVQkZZCZ+Yu0E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734768355; h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=wVENP7nTAdK0vwplHgr/Ufv9xjDULgWJPKnKg2Vmnbw=; b=aZCdk7BqPOXHTGmmbiPqeMPcKlLN1s5JW6THIMCkw74ODGHAuw17mz/9HXNE5xYc67FVLKRWVNTAqHjiFY7kE8JDtjKe+l/iq5a8qtTPxS1vciC+lIPdpC0EAy3iXAupqjR8DXjPiEaWZGD1VVhXpnT3XKF5qFHNpx/tXYRn2oo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=topbug.net; spf=pass smtp.mailfrom=hong@topbug.net; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1734768355; s=zoho; d=topbug.net; i=hong@topbug.net; h=From:From:To:To:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To:Cc; bh=wVENP7nTAdK0vwplHgr/Ufv9xjDULgWJPKnKg2Vmnbw=; b=Jd/8NcnDfSJ+3jx4qtMwRv5CjR4qldNWmp/nqhcEr2sDacKNwXxFYvaNUFceHtl+ 0fs9MjQFxpPaGGdtiNRrAcpSwaWEqEZlbNjwJtI6HIhG4/122TkAY4f4/zHvMy7DDaq iKznVCcykhm9ya6iqGWfMWKWa9ZXuYu9dT3ZWDm4= Original-Received: by mx.zohomail.com with SMTPS id 1734768352997620.4018781471116; Sat, 21 Dec 2024 00:05:52 -0800 (PST) X-Mailer: git-send-email 2.47.1 In-Reply-To: <86y1098pvj.fsf@gnu.org> X-ZohoMailClient: External X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:297495 Archived-At: * Since `define-key' is considered legacy and we encourage `keymap-set' now. --- doc/lispintro/emacs-lisp-intro.texi | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/doc/lispintro/emacs-lisp-intro.texi b/doc/lispintro/emacs-lisp-intro.texi index 49916235fbf9..b3b4141a3c5f 100644 --- a/doc/lispintro/emacs-lisp-intro.texi +++ b/doc/lispintro/emacs-lisp-intro.texi @@ -17358,11 +17358,22 @@ 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. Historically, keymaps +are bound using a lower-level function, @code{define-key}, which +is now considered legacy. The above key binding can be rewritten using +@code{define-key} as: @smallexample @group @@ -17396,9 +17407,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