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 v2] Recommend `keymap-set' instead of `define-key' in emacs lisp intro Date: Fri, 20 Dec 2024 13:42:29 -0800 Message-ID: <20241220214351.57036-1-hong@topbug.net> References: Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8028"; 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 Fri Dec 20 22:45:14 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 1tOko5-0001sg-Se for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 20 Dec 2024 22:45:14 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOkny-0005TA-0Q; Fri, 20 Dec 2024 16:45:06 -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 1tOknv-0005RY-W4 for bug-gnu-emacs@gnu.org; Fri, 20 Dec 2024 16:45:04 -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 1tOknv-0003Xu-Mt for bug-gnu-emacs@gnu.org; Fri, 20 Dec 2024 16:45:03 -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=+hqSqYOkASyZa7DdTkKYd+TlThk9CtS12aArCb0lYvc=; b=andKhColY2xd5aZ/QCSCtSgszX4ntXmf+vSJI0eJmwI83VVpSo0zcnaUuCNln89ALksttYV859yd+e6FrPe6raF3IB/OsH0n+j4wcXLypClLE2AUmUGKoPfqt9Xs/pKluZrBj8xppUJtSfuxh63T+OH7PE+gU+DTP7Nj/M4qhKHIdHbKz7hxEmA1Ma44KJ3fVzasHOe5YF1hYn6H3gg08W9Hbh469thSbrMamVJ9DrXMILX81LIm88SI6Ddc0mQntW7IOAECQSLGwYmrrFoMWUWRSIJbTm3v0XbwtpHKm00Yn94cOOwUVgD1HKuXrDZFsyaGOsfDoTDuZGFP11K/xA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tOknu-000852-HR for bug-gnu-emacs@gnu.org; Fri, 20 Dec 2024 16:45: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: Fri, 20 Dec 2024 21:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 74999 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.173473104330957 (code B ref -1); Fri, 20 Dec 2024 21:45:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 20 Dec 2024 21:44:03 +0000 Original-Received: from localhost ([127.0.0.1]:44294 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tOkmx-00083F-AB for submit@debbugs.gnu.org; Fri, 20 Dec 2024 16:44:03 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:50412) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tOkmt-00082f-8t for submit@debbugs.gnu.org; Fri, 20 Dec 2024 16:44:02 -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 1tOkms-000527-Vz for bug-gnu-emacs@gnu.org; Fri, 20 Dec 2024 16:43:59 -0500 Original-Received: from sender4-of-o52.zoho.com ([136.143.188.52]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOkmr-0003Pb-51 for bug-gnu-emacs@gnu.org; Fri, 20 Dec 2024 16:43:58 -0500 ARC-Seal: i=1; a=rsa-sha256; t=1734731034; cv=none; d=zohomail.com; s=zohoarc; b=ddT5qcLsQz9PQhNOL63Kn8nVL2Gth9OGeqlrXUvbGV2xZXgZHbI+0caQkKF/Pwr/tjYHLfUpNyXGoxEwLmMK5l9YDB+FmOLU2wbO8xXEg1QtGR4k+gVlVv/aeJrB+EGWbhkjQuoV6CAb7CWStvyKRd1Z71SwPyYGoJiFRngJ3L0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734731034; 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=+hqSqYOkASyZa7DdTkKYd+TlThk9CtS12aArCb0lYvc=; b=GVJMtN+CvNUmKXMt4WwryCNYA+VeIyp1z8I/0BiBVpJv1vepTf21zHq8rJ/1MMLAaC64T+N6JHei1pUwzD9wXKgyxv8cvXD5Qe2NhRAAmhU0UBM8PGx6/Su8yfNlmGl/ssk2GpeN6UCOFthv7q7lo9VNjz7NIl82gyOTcWQqRWQ= 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=1734731034; 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=+hqSqYOkASyZa7DdTkKYd+TlThk9CtS12aArCb0lYvc=; b=B49GsNdbAhtJ/RFKFdyXdXktSBM1DmN0GreuuY+2YFxOjBOltyxGBIoMRBnXGkBY CGQ2Yu7x3xfHQIUY98xfzyJDiDSCbURCH5fLd5EkTIRM59uAgRb8bcS2UxUvfsq/ELJ E2BXtwQKWevh+Mh0xHmul3+q7BG6wYFSv+/sHtPs= Original-Received: by mx.zohomail.com with SMTPS id 1734731031891799.9926349286576; Fri, 20 Dec 2024 13:43:51 -0800 (PST) X-Mailer: git-send-email 2.47.1 In-Reply-To: X-ZohoMailClient: External Received-SPF: pass client-ip=136.143.188.52; envelope-from=hong@topbug.net; helo=sender4-of-o52.zoho.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:297478 Archived-At: * 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