unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Hong Xu <hong@topbug.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 74999@debbugs.gnu.org
Subject: bug#74999: [PATCH v2] Recommend `keymap-set' instead of `define-key' in emacs lisp intro
Date: Sat, 21 Dec 2024 00:06:53 -0800	[thread overview]
Message-ID: <87r0615ujm.fsf@topbug.net> (raw)
In-Reply-To: <86y1098pvj.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 21 Dec 2024 09:19:28 +0200")

On 2024-12-20 Fri 23:19 GMT-08, Eli Zaretskii <eliz@gnu.org> wrote:

>> From: Hong Xu <hong@topbug.net>
>> Date: Fri, 20 Dec 2024 13:42:29 -0800
>> 
>> -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.
>
> This should say that historically, Emacs used 'define-key', and
> therefore you are likely to see 'define-key' in various places etc.
> In addition "older function" is not really accurate: 'keymap-set'
> calls 'define-key' internally, so 'define-key' will not disappear from
> Emacs any time soon.  We just prefer using 'keymap-set' in Lisp
> programs because it is higher-level.  So instead of saying "older
> function", I think we should say "more low-level function".
>
> Also, please make sure to leave two spaces between sentences, per our
> conventions.
>
>>                                                             The
>> +above key map can be rewritten in @code{define-key} as:
>
> Not "key map", but "key binding".  The example doesn't show a complete
> key map, it only shows a single binding within a key map.  Since this
> is an introductory manual, we must be very accurate and clear in our
> text, to avoid confusing newcomers to Lisp, who are probably confused
> already to begin with...
>

I agree, please see my follow-up patch.

-- 
Thanks,
Hong





  parent reply	other threads:[~2024-12-21  8:06 UTC|newest]

Thread overview: 10+ 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     ` bug#74999: [PATCH v2] Recommend " Hong Xu
2024-12-21  7:19       ` Eli Zaretskii
2024-12-21  8:03         ` bug#74999: [PATCH v3] " Hong Xu
2024-12-21  8:06         ` Hong Xu [this message]
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=87r0615ujm.fsf@topbug.net \
    --to=hong@topbug.net \
    --cc=74999@debbugs.gnu.org \
    --cc=eliz@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).