all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#74983: [PATCH] Use `keymap-set' instead of `define-key' in emacs lisp intro
@ 2024-12-19 22:36 Hong Xu
  2024-12-20  7:01 ` Eli Zaretskii
  0 siblings, 1 reply; 20+ messages in thread
From: Hong Xu @ 2024-12-19 22:36 UTC (permalink / raw)
  To: 74983

* Since `define-key' is considered legacy and we encourage `keymap-set'
  now.
---
 doc/lispintro/emacs-lisp-intro.texi | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/doc/lispintro/emacs-lisp-intro.texi b/doc/lispintro/emacs-lisp-intro.texi
index 49916235fbf9..32ad07785c20 100644
--- a/doc/lispintro/emacs-lisp-intro.texi
+++ b/doc/lispintro/emacs-lisp-intro.texi
@@ -17358,15 +17358,14 @@ 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
-(define-key texinfo-mode-map "\C-c\C-cg" 'texinfo-insert-@@group)
+(keymap-set texinfo-mode-map "C-c C-c g" 'texinfo-insert-@group)
 @end group
 @end smallexample
 
@@ -17396,7 +17395,7 @@ 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
+You will see numerous @code{keymap-set} expressions in
 @file{loaddefs.el} as well as in the various mode libraries, such as
 @file{cc-mode.el} and @file{lisp-mode.el}.
 
-- 
2.47.1






^ permalink raw reply related	[flat|nested] 20+ messages in thread

* bug#74983: [PATCH] Use `keymap-set' instead of `define-key' in emacs lisp intro
  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
                     ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Eli Zaretskii @ 2024-12-20  7:01 UTC (permalink / raw)
  To: Hong Xu, Stefan Kangas; +Cc: 74983

> From: Hong Xu <hong@topbug.net>
> Date: Thu, 19 Dec 2024 14:36:29 -0800
> 
> * Since `define-key' is considered legacy and we encourage `keymap-set'
>   now.

Thanks.  But the second chunk is not really right, since we have many
more define-key there than keymap-set.

So my suggestion is not to _replace_ define-key with keymap-set, but
instead describe _both_, explaining that as of Emacs 29 we are
migrating towards keymap-set, which is preferred.

Stefan, WDYT?





^ permalink raw reply	[flat|nested] 20+ messages in thread

* bug#74983: [PATCH] Use `keymap-set' instead of `define-key' in emacs lisp intro
  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-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
  2 siblings, 1 reply; 20+ messages in thread
From: Stefan Kangas @ 2024-12-20  9:35 UTC (permalink / raw)
  To: Eli Zaretskii, Hong Xu; +Cc: 74983

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Hong Xu <hong@topbug.net>
>> Date: Thu, 19 Dec 2024 14:36:29 -0800
>>
>> * Since `define-key' is considered legacy and we encourage `keymap-set'
>>   now.
>
> Thanks.  But the second chunk is not really right, since we have many
> more define-key there than keymap-set.
>
> So my suggestion is not to _replace_ define-key with keymap-set, but
> instead describe _both_, explaining that as of Emacs 29 we are
> migrating towards keymap-set, which is preferred.
>
> Stefan, WDYT?

I'd tend to agree.  Users will have to recognize define-key for a long
time indeed, not just in our sources (which are relatively easily
fixable in comparison) but also in online forums, third-party packages,
and so on.

I didn't yet look at the patch though.





^ permalink raw reply	[flat|nested] 20+ messages in thread

* bug#74983: [PATCH] Use `keymap-set' instead of `define-key' in emacs lisp intro
  2024-12-20  7:01 ` Eli Zaretskii
  2024-12-20  9:35   ` Stefan Kangas
@ 2024-12-20 15:43   ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-12-20 21:50   ` Hong Xu
  2 siblings, 0 replies; 20+ messages in thread
From: Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-12-20 15:43 UTC (permalink / raw)
  To: Eli Zaretskii, Hong Xu, Stefan Kangas; +Cc: 74983@debbugs.gnu.org

> So my suggestion is not to _replace_ define-key with keymap-set, but
> instead describe _both_, explaining that as of Emacs 29 we are
> migrating towards keymap-set, which is preferred.

+1.





^ permalink raw reply	[flat|nested] 20+ messages in thread

* bug#74999: [PATCH v2] Recommend `keymap-set' instead of `define-key' in emacs lisp intro
  2024-12-20  9:35   ` Stefan Kangas
@ 2024-12-20 21:42     ` Hong Xu
  2024-12-21  7:19       ` Eli Zaretskii
  0 siblings, 1 reply; 20+ messages in thread
From: Hong Xu @ 2024-12-20 21:42 UTC (permalink / raw)
  To: 74999

* 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






^ permalink raw reply related	[flat|nested] 20+ messages in thread

* bug#74983: [PATCH] Use `keymap-set' instead of `define-key' in emacs lisp intro
  2024-12-20  7:01 ` Eli Zaretskii
  2024-12-20  9:35   ` Stefan Kangas
  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
  2 siblings, 1 reply; 20+ messages in thread
From: Hong Xu @ 2024-12-20 21:50 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Stefan Kangas, 74983

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

>> From: Hong Xu <hong@topbug.net>
>> Date: Thu, 19 Dec 2024 14:36:29 -0800
>> 
>> * Since `define-key' is considered legacy and we encourage `keymap-set'
>>   now.
>
> Thanks.  But the second chunk is not really right, since we have many
> more define-key there than keymap-set.
>
> So my suggestion is not to _replace_ define-key with keymap-set, but
> instead describe _both_, explaining that as of Emacs 29 we are
> migrating towards keymap-set, which is preferred.

Thanks, I agree. I've made a followup patch. For some reason the
followup patch didn't attach to the Message ID of this thread and a new
bug 74999 was created.

-- 
Hong





^ permalink raw reply	[flat|nested] 20+ messages in thread

* bug#74999: [PATCH v2] Recommend `keymap-set' instead of `define-key' in emacs lisp intro
  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         ` bug#74999: [PATCH v2] " Hong Xu
  0 siblings, 2 replies; 20+ messages in thread
From: Eli Zaretskii @ 2024-12-21  7:19 UTC (permalink / raw)
  To: Hong Xu; +Cc: 74999

> 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...

Thanks.





^ permalink raw reply	[flat|nested] 20+ messages in thread

* bug#74983: [PATCH] Use `keymap-set' instead of `define-key' in emacs lisp intro
  2024-12-20 21:50   ` Hong Xu
@ 2024-12-21  7:20     ` Eli Zaretskii
  0 siblings, 0 replies; 20+ messages in thread
From: Eli Zaretskii @ 2024-12-21  7:20 UTC (permalink / raw)
  To: Hong Xu; +Cc: stefankangas, 74983

merge 74983 74999
thanks

> From: Hong Xu <hong@topbug.net>
> Cc: Stefan Kangas <stefankangas@gmail.com>,  74983@debbugs.gnu.org
> Date: Fri, 20 Dec 2024 13:50:15 -0800
> 
> On 2024-12-19 Thu 23:01 GMT-08, Eli Zaretskii <eliz@gnu.org> wrote:
> 
> >> From: Hong Xu <hong@topbug.net>
> >> Date: Thu, 19 Dec 2024 14:36:29 -0800
> >> 
> >> * Since `define-key' is considered legacy and we encourage `keymap-set'
> >>   now.
> >
> > Thanks.  But the second chunk is not really right, since we have many
> > more define-key there than keymap-set.
> >
> > So my suggestion is not to _replace_ define-key with keymap-set, but
> > instead describe _both_, explaining that as of Emacs 29 we are
> > migrating towards keymap-set, which is preferred.
> 
> Thanks, I agree. I've made a followup patch. For some reason the
> followup patch didn't attach to the Message ID of this thread and a new
> bug 74999 was created.

I've now merged them.





^ permalink raw reply	[flat|nested] 20+ messages in thread

* bug#74999: [PATCH v3] Recommend `keymap-set' instead of `define-key' in emacs lisp intro
  2024-12-21  7:19       ` Eli Zaretskii
@ 2024-12-21  8:03         ` Hong Xu
  2024-12-23 20:42           ` Hong Xu
  2024-12-26  8:20           ` Eli Zaretskii
  2024-12-21  8:06         ` bug#74999: [PATCH v2] " Hong Xu
  1 sibling, 2 replies; 20+ messages in thread
From: Hong Xu @ 2024-12-21  8:03 UTC (permalink / raw)
  To: 74999

* 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






^ permalink raw reply related	[flat|nested] 20+ messages in thread

* bug#74999: [PATCH v2] Recommend `keymap-set' instead of `define-key' in emacs lisp intro
  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
  1 sibling, 0 replies; 20+ messages in thread
From: Hong Xu @ 2024-12-21  8:06 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 74999

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





^ permalink raw reply	[flat|nested] 20+ messages in thread

* bug#74999: [PATCH v3] Recommend `keymap-set' instead of `define-key' in emacs lisp intro
  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
  1 sibling, 1 reply; 20+ messages in thread
From: Hong Xu @ 2024-12-23 20:42 UTC (permalink / raw)
  To: 74999, Eli Zaretskii

References: <86y1098pvj.fsf@gnu.org> <20241221080552.259664-1-hong@topbug.net>
User-Agent: mu4e 1.12.8; emacs 29.4
Date: Mon, 23 Dec 2024 12:42:29 -0800

On 2024-12-21 Sat 00:03 GMT-08, Hong Xu <hong@topbug.net> wrote:

> * 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(-)
>
> <...>

In case you missed this, are you still interested in reviewing this patch?


-- 
Hong





^ permalink raw reply	[flat|nested] 20+ messages in thread

* bug#74999: [PATCH v3] Recommend `keymap-set' instead of `define-key' in emacs lisp intro
  2024-12-23 20:42           ` Hong Xu
@ 2024-12-24  3:27             ` Eli Zaretskii
  0 siblings, 0 replies; 20+ messages in thread
From: Eli Zaretskii @ 2024-12-24  3:27 UTC (permalink / raw)
  To: Hong Xu; +Cc: 74999

> From: Hong Xu <hong@topbug.net>
> Date: Mon, 23 Dec 2024 12:42:34 -0800
> 
> References: <86y1098pvj.fsf@gnu.org> <20241221080552.259664-1-hong@topbug.net>
> User-Agent: mu4e 1.12.8; emacs 29.4
> Date: Mon, 23 Dec 2024 12:42:29 -0800
> 
> On 2024-12-21 Sat 00:03 GMT-08, Hong Xu <hong@topbug.net> wrote:
> 
> > * 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(-)
> >
> > <...>
> 
> In case you missed this, are you still interested in reviewing this patch?

I didn't miss it.  It's in my queue.





^ permalink raw reply	[flat|nested] 20+ messages in thread

* bug#74999: [PATCH v3] Recommend `keymap-set' instead of `define-key' in emacs lisp intro
  2024-12-21  8:03         ` bug#74999: [PATCH v3] " Hong Xu
  2024-12-23 20:42           ` Hong Xu
@ 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 21:58             ` bug#74999: [PATCH v3] Recommend `keymap-set' instead of `define-key' in emacs lisp intro Hong Xu
  1 sibling, 2 replies; 20+ messages in thread
From: Eli Zaretskii @ 2024-12-26  8:20 UTC (permalink / raw)
  To: Hong Xu; +Cc: 74999

> From: Hong Xu <hong@topbug.net>
> Date: Sat, 21 Dec 2024 00:03:54 -0800
> 
> * 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(-)

Thanks.  I tried to install this, but the git-commit hook rejected the
commit because Subject line is too long:

  Line longer than 78 characters in commit message
  Commit aborted; please see the file CONTRIBUTE

Please format the patch using "git format-patch", and please commit
the patch locally before you do so (assuming you have the hooks in
your local clone), to make sure these problems are corrected before
you send the patch here.

More generally, global-set-key, discussed earlier in this section, is
also obsolete, and we nowadays prefer keymap-global-set instead.  So,
if we want to modernize this part of the Emacs Lisp Intro manual, I
think we should replace all the key-binding examples and the
surrounding text in the manual to use the new keymap-* functions.  It
makes little sense to replace only define-key and leave the rest as
they were.

Would you like to submit a patch that takes care of these issues in a
more thorough manner?

> +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.

These two sentences should be in reverse order: first tell that
historically we used define-key, then say that the reader is
encouraged to use keymap-set.

Thanks.





^ permalink raw reply	[flat|nested] 20+ messages in thread

* bug#74999: [PATCH v4] Use `keymap*-set' over `global-set-key'/`define-key' in elisp intro
  2024-12-26  8:20           ` Eli Zaretskii
@ 2024-12-26 21:46             ` Hong Xu
  2024-12-26 22:05               ` Hong Xu
  2024-12-28 12:17               ` Eli Zaretskii
  2024-12-26 21:58             ` bug#74999: [PATCH v3] Recommend `keymap-set' instead of `define-key' in emacs lisp intro Hong Xu
  1 sibling, 2 replies; 20+ messages in thread
From: Hong Xu @ 2024-12-26 21:46 UTC (permalink / raw)
  To: 74999

* doc/lispintro/emacs-lisp-intro.texi (Key Bindings): Since
`global-set-key' and `define-key' are considered legacy, we encourage
`keymap-global-set' and `keymap-set' now.
---
 doc/lispintro/emacs-lisp-intro.texi | 119 +++++++++++++++++++---------
 1 file changed, 81 insertions(+), 38 deletions(-)

diff --git a/doc/lispintro/emacs-lisp-intro.texi b/doc/lispintro/emacs-lisp-intro.texi
index 49916235fbf9..daffd6386133 100644
--- a/doc/lispintro/emacs-lisp-intro.texi
+++ b/doc/lispintro/emacs-lisp-intro.texi
@@ -13810,7 +13810,7 @@ Whitespace Bug
 If you wish, you can also install this key binding by evaluating it:
 
 @smallexample
-(global-set-key "\C-c=" '@value{COUNT-WORDS})
+(keymap-global-set "C-c =" '@value{COUNT-WORDS})
 @end smallexample
 
 To conduct the first test, set mark and point to the beginning and end
@@ -14762,7 +14762,7 @@ count-words-in-defun
 Let's reuse @kbd{C-c =} as a convenient key binding:
 
 @smallexample
-(global-set-key "\C-c=" 'count-words-defun)
+(keymap-global-set "C-c =" 'count-words-defun)
 @end smallexample
 
 Now we can try out @code{count-words-defun}: install both
@@ -17229,7 +17229,7 @@ Key Bindings
 @smallexample
 @group
 ;;; Compare windows
-(global-set-key "\C-cw" 'compare-windows)
+(keymap-global-set "C-c w" 'compare-windows)
 @end group
 @end smallexample
 
@@ -17242,20 +17242,18 @@ Key Bindings
 This also shows how to set a key globally, for all modes.
 
 @cindex Setting a key globally
-@cindex Global set key
+@cindex Keymap global set
 @cindex Key setting globally
-@findex global-set-key
-The command is @code{global-set-key}.  It is followed by the
-key binding.  In a @file{.emacs} file, the keybinding is written as
-shown: @code{\C-c} stands for Control-C, which means to press the
-control key and the @kbd{c} key at the same time.  The @code{w} means
-to press the @kbd{w} key.  The key binding is surrounded by double
-quotation marks.  In documentation, you would write this as
-@w{@kbd{C-c w}}.  (If you were binding a @key{META} key, such as
-@kbd{M-c}, rather than a @key{CTRL} key, you would write
-@w{@code{\M-c}} in your @file{.emacs} file.  @xref{Init Rebinding, ,
-Rebinding Keys in Your Init File, emacs, The GNU Emacs Manual}, for
-details.)
+@findex keymap-global-set
+The key setting command is @code{keymap-global-set}.  It is followed by
+the key binding.  In a @file{.emacs} file, the keybinding is written as
+shown: @code{C-c} stands for Control-C, which means to press the control
+key and the @kbd{c} key at the same time.  The @code{w} means to press
+the @kbd{w} key.  The key binding is surrounded by double quotation
+marks.  (If you were binding a @key{META} key, rather than a @key{CTRL}
+key, you would write @w{@code{M-c}} in your @file{.emacs} file.
+@xref{Init Rebinding, , Rebinding Keys in Your Init File, emacs, The GNU
+Emacs Manual}, for details.)
 
 The command invoked by the keys is @code{compare-windows}.  Note that
 @code{compare-windows} is preceded by a single-quote; otherwise, Emacs
@@ -17284,7 +17282,7 @@ Key Bindings
 @group
 ;;; Key binding for 'occur'
 ; I use occur a lot, so let's bind it to a key:
-(global-set-key "\C-co" 'occur)
+(keymap-global-set "C-c o" 'occur)
 @end group
 @end smallexample
 
@@ -17296,7 +17294,7 @@ Key Bindings
 Matching lines are shown in a buffer called @file{*Occur*}.
 That buffer serves as a menu to jump to occurrences.
 
-@findex global-unset-key
+@findex keymap-global-unset
 @cindex Unbinding key
 @cindex Key unbinding
 @need 1250
@@ -17306,7 +17304,7 @@ Key Bindings
 @smallexample
 @group
 ;;; Unbind 'C-x f'
-(global-unset-key "\C-xf")
+(keymap-global-unset "C-x f")
 @end group
 @end smallexample
 
@@ -17324,7 +17322,7 @@ Key Bindings
 @smallexample
 @group
 ;;; Rebind 'C-x C-b' for 'buffer-menu'
-(global-set-key "\C-x\C-b" 'buffer-menu)
+(keymap-global-set "C-x C-b" 'buffer-menu)
 @end group
 @end smallexample
 
@@ -17336,33 +17334,79 @@ Key Bindings
 command, which not only lists the buffers,
 but moves point into that window.
 
+@subsection Legacy Global Key Binding Commands
+
+@findex global-set-key
+@cindex Global set key
+Historically, keys are bound globally using a lower-level function,
+@code{global-set-key}, which is now considered legacy.  While you are
+encouraged to use @code{keymap-global-set}, you likely would encounter
+@code{global-set-key} in various places.  The first example can be
+rewritten using @code{global-set-key} as:
+
+@smallexample
+@group
+(global-set-key "\C-cw" 'compare-windows)
+@end group
+@end smallexample
+
+It is very similar to @code{keymap-global-set}, with the keybinding
+following a slightly different format.  Control-C is represented by
+@code{\C-c}, instead of @code{C-c}.  There is no space between key
+strokes, like @code{\C-c} and @code{w} in this example.  Despite the
+difference, in documentation, this is still written as @w{@kbd{C-c w}}
+for readability.
+
+@findex global-unset-key
+Historically, keys are unbound globally using a lower-function,
+@code{global-unset-key}, which is now considered legacy.  Its key
+binding format follows that of @code{global-set-key}.  The above key
+unbinding example can be rewritten as:
+@smallexample
+@group
+;;; Unbind 'C-x f'
+(global-unset-key "\C-xf")
+@end group
+@end smallexample
+
 @node Keymaps
 @section Keymaps
 @cindex Keymaps
 @cindex Rebinding keys
 
 Emacs uses @dfn{keymaps} to record which keys call which commands.
-When you use @code{global-set-key} to set the key binding for a single
-command in all parts of Emacs, you are specifying the key binding in
-@code{current-global-map}.
+When you use @code{keymap-global-set} to set the key binding for a
+single command in all parts of Emacs, you are specifying the key binding
+in @code{current-global-map}.
 
 Specific modes, such as C mode or Text mode, have their own keymaps;
 the mode-specific keymaps override the global map that is shared by
 all buffers.
 
-The @code{global-set-key} function binds, or rebinds, the global
+The @code{keymap-global-set} function binds, or rebinds, the global
 keymap.  For example, the following binds the key @kbd{C-x C-b} to the
 function @code{buffer-menu}:
 
 @smallexample
-(global-set-key "\C-x\C-b" 'buffer-menu)
+(keymap-global-set "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
+
+Historically, keymaps are bound using a lower-level function,
+@code{define-key}, which is now considered legacy.  While you are
+encouraged to use @code{keymap-set}, you likely would encounter
+@code{define-key} in various places.  The above key binding can be
+rewritten using @code{define-key} as:
 
 @smallexample
 @group
@@ -17396,9 +17440,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
@@ -17440,13 +17484,12 @@ Loading Files
 
 @need 1250
 To replace the key binding for the default
-@code{split-window-vertically}, you must also unset that key and bind
-the keys to @code{split-window-quietly}, like this:
+@code{split-window-vertically}, you must bind the keys to
+@code{split-window-quietly}, like this:
 
 @smallexample
 @group
-(global-unset-key "\C-x2")
-(global-set-key "\C-x2" 'split-window-quietly)
+(keymap-global-set "C-x 2" 'split-window-quietly)
 @end group
 @end smallexample
 
@@ -17608,7 +17651,7 @@ Simple Extension
 this:
 
 @smallexample
-(global-set-key [f6] 'line-to-top-of-window)
+(keymap-global-set "<f6>" 'line-to-top-of-window)
 @end smallexample
 
 For more information, see @ref{Init Rebinding, , Rebinding Keys in
@@ -18791,7 +18834,7 @@ the-the
 
 @group
 ;; Bind 'the-the' to  C-c \
-(global-set-key "\C-c\\" 'the-the)
+(keymap-global-set "C-c \\" 'the-the)
 @end group
 @end smallexample
 
-- 
2.47.1






^ permalink raw reply related	[flat|nested] 20+ messages in thread

* bug#74999: [PATCH v3] Recommend `keymap-set' instead of `define-key' in emacs lisp intro
  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 21:58             ` Hong Xu
  2024-12-27  7:37               ` Eli Zaretskii
  1 sibling, 1 reply; 20+ messages in thread
From: Hong Xu @ 2024-12-26 21:58 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 74999


Thanks for reviewing. Please see my followup patch.

On 2024-12-26 Thu 00:20 GMT-08, Eli Zaretskii <eliz@gnu.org> wrote:

>> From: Hong Xu <hong@topbug.net>
>> Date: Sat, 21 Dec 2024 00:03:54 -0800
>> 
>> * 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(-)
>
> Thanks.  I tried to install this, but the git-commit hook rejected the
> commit because Subject line is too long:
>
>   Line longer than 78 characters in commit message
>   Commit aborted; please see the file CONTRIBUTE
>
> Please format the patch using "git format-patch", and please commit
> the patch locally before you do so (assuming you have the hooks in
> your local clone), to make sure these problems are corrected before
> you send the patch here.

I could apply these patches without line length complaints, and the
hooks were in effect. An inspection into the patch file also shows no
line is longer than 78 characters. Git is supposed to abandon the
"[Patch vN]" prefix when applying the patch.

> More generally, global-set-key, discussed earlier in this section, is
> also obsolete, and we nowadays prefer keymap-global-set instead.  So,
> if we want to modernize this part of the Emacs Lisp Intro manual, I
> think we should replace all the key-binding examples and the
> surrounding text in the manual to use the new keymap-* functions.  It
> makes little sense to replace only define-key and leave the rest as
> they were.
>
> Would you like to submit a patch that takes care of these issues in a
> more thorough manner?

Addressed.
>
>> +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.
>
> These two sentences should be in reverse order: first tell that
> historically we used define-key, then say that the reader is
> encouraged to use keymap-set.
>

Addressed.





^ permalink raw reply	[flat|nested] 20+ messages in thread

* bug#74999: [PATCH v4] Use `keymap*-set' over `global-set-key'/`define-key' in elisp intro
  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
  1 sibling, 1 reply; 20+ messages in thread
From: Hong Xu @ 2024-12-26 22:05 UTC (permalink / raw)
  To: 74999

On 2024-12-26 Thu 13:46 GMT-08, Hong Xu <hong@topbug.net> wrote:

> * doc/lispintro/emacs-lisp-intro.texi (Key Bindings): Since
> `global-set-key' and `define-key' are considered legacy, we encourage
> `keymap-global-set' and `keymap-set' now.
> ---
> <...>
>
> +@findex global-unset-key
> +Historically, keys are unbound globally using a lower-function,
> +@code{global-unset-key}, which is now considered legacy.  Its key
> +binding format follows that of @code{global-set-key}.  The above key
> +unbinding example can be rewritten as:
> +@smallexample
> +@group
> +;;; Unbind 'C-x f'
> +(global-unset-key "\C-xf")
> +@end group
> +@end smallexample
> +

I'm thinking about dropping this paragraph, because `global-unset-key'
isn't commonly seen, and there's no point to over fill an introduction
with less used functions.  Please advice.

-- 
Hong





^ permalink raw reply	[flat|nested] 20+ messages in thread

* bug#74999: [PATCH v3] Recommend `keymap-set' instead of `define-key' in emacs lisp intro
  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
  0 siblings, 0 replies; 20+ messages in thread
From: Eli Zaretskii @ 2024-12-27  7:37 UTC (permalink / raw)
  To: Hong Xu; +Cc: 74999

> From: Hong Xu <hong@topbug.net>
> Cc: 74999@debbugs.gnu.org
> Date: Thu, 26 Dec 2024 13:58:33 -0800
> 
> > Thanks.  I tried to install this, but the git-commit hook rejected the
> > commit because Subject line is too long:
> >
> >   Line longer than 78 characters in commit message
> >   Commit aborted; please see the file CONTRIBUTE
> >
> > Please format the patch using "git format-patch", and please commit
> > the patch locally before you do so (assuming you have the hooks in
> > your local clone), to make sure these problems are corrected before
> > you send the patch here.
> 
> I could apply these patches without line length complaints, and the
> hooks were in effect. An inspection into the patch file also shows no
> line is longer than 78 characters. Git is supposed to abandon the
> "[Patch vN]" prefix when applying the patch.

I'm guessing the problem on my side is because you sent the patch as a
complete email message, where the heading line is presumed to be taken
from Subject.  To avoid these problems, please in the future send the
patches as attachments, to allow me to pass to "git am" only the
actual patch, not any of the other email headers.





^ permalink raw reply	[flat|nested] 20+ messages in thread

* bug#74999: [PATCH v4] Use `keymap*-set' over `global-set-key'/`define-key' in elisp intro
  2024-12-26 22:05               ` Hong Xu
@ 2024-12-27  7:44                 ` Eli Zaretskii
  0 siblings, 0 replies; 20+ messages in thread
From: Eli Zaretskii @ 2024-12-27  7:44 UTC (permalink / raw)
  To: Hong Xu; +Cc: 74999

> From: Hong Xu <hong@topbug.net>
> Date: Thu, 26 Dec 2024 14:05:01 -0800
> 
> On 2024-12-26 Thu 13:46 GMT-08, Hong Xu <hong@topbug.net> wrote:
> 
> > * doc/lispintro/emacs-lisp-intro.texi (Key Bindings): Since
> > `global-set-key' and `define-key' are considered legacy, we encourage
> > `keymap-global-set' and `keymap-set' now.
> > ---
> > <...>
> >
> > +@findex global-unset-key
> > +Historically, keys are unbound globally using a lower-function,
> > +@code{global-unset-key}, which is now considered legacy.  Its key
> > +binding format follows that of @code{global-set-key}.  The above key
> > +unbinding example can be rewritten as:
> > +@smallexample
> > +@group
> > +;;; Unbind 'C-x f'
> > +(global-unset-key "\C-xf")
> > +@end group
> > +@end smallexample
> > +
> 
> I'm thinking about dropping this paragraph, because `global-unset-key'
> isn't commonly seen, and there's no point to over fill an introduction
> with less used functions.  Please advice.

I wouldn't remove it.  This manual is an extended tutorial of the
Emacs Lisp language, so it doesn't necessarily include only the
frequently-used functions.  We must trust the author of this manual,
who was a great expert in teaching Emacs Lisp, that his decision to
include this function had a good reason.





^ permalink raw reply	[flat|nested] 20+ messages in thread

* bug#74999: [PATCH v4] Use `keymap*-set' over `global-set-key'/`define-key' in elisp intro
  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-28 12:17               ` Eli Zaretskii
  2024-12-28 19:56                 ` Hong Xu
  1 sibling, 1 reply; 20+ messages in thread
From: Eli Zaretskii @ 2024-12-28 12:17 UTC (permalink / raw)
  To: Hong Xu; +Cc: 74999

> From: Hong Xu <hong@topbug.net>
> Date: Thu, 26 Dec 2024 13:46:39 -0800
> 
> * doc/lispintro/emacs-lisp-intro.texi (Key Bindings): Since
> `global-set-key' and `define-key' are considered legacy, we encourage
> `keymap-global-set' and `keymap-set' now.
> ---
>  doc/lispintro/emacs-lisp-intro.texi | 119 +++++++++++++++++++---------
>  1 file changed, 81 insertions(+), 38 deletions(-)

Thanks, I have a few minor comments:

>  @cindex Setting a key globally
> -@cindex Global set key
> +@cindex Keymap global set
>  @cindex Key setting globally
> -@findex global-set-key

Please add index entries for the new APIs, but do not remove the index
entries for old ones.  Readers could still need to look up the old
interfaces via index search.

> -@findex global-unset-key
> +@findex keymap-global-unset

Same here.

> +@subsection Legacy Global Key Binding Commands
> +
> +@findex global-set-key
> +@cindex Global set key
> +Historically, keys are bound globally using a lower-level function,
> +@code{global-set-key}, which is now considered legacy.  While you are
> +encouraged to use @code{keymap-global-set}, you likely would encounter
> +@code{global-set-key} in various places.  The first example can be
> +rewritten using @code{global-set-key} as:
> +
> +@smallexample
> +@group
> +(global-set-key "\C-cw" 'compare-windows)
> +@end group
> +@end smallexample

The text says "first example", but which example is that?  There are
no examples in this subsection.

> +Historically, keys are unbound globally using a lower-function,
> +@code{global-unset-key}, which is now considered legacy.  Its key
> +binding format follows that of @code{global-set-key}.  The above key
> +unbinding example can be rewritten as:

Same here: "the above key unbinding example" refers to an example in a
different subsection.

Thanks.





^ permalink raw reply	[flat|nested] 20+ messages in thread

* bug#74999: [PATCH v4] Use `keymap*-set' over `global-set-key'/`define-key' in elisp intro
  2024-12-28 12:17               ` Eli Zaretskii
@ 2024-12-28 19:56                 ` Hong Xu
  0 siblings, 0 replies; 20+ messages in thread
From: Hong Xu @ 2024-12-28 19:56 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 74999

[-- Attachment #1: Type: text/plain, Size: 2140 bytes --]

On 2024-12-28 Sat 04:17 GMT-08, Eli Zaretskii <eliz@gnu.org> wrote:

>> From: Hong Xu <hong@topbug.net>
>> Date: Thu, 26 Dec 2024 13:46:39 -0800
>> 
>> * doc/lispintro/emacs-lisp-intro.texi (Key Bindings): Since
>> `global-set-key' and `define-key' are considered legacy, we encourage
>> `keymap-global-set' and `keymap-set' now.
>> ---
>>  doc/lispintro/emacs-lisp-intro.texi | 119 +++++++++++++++++++---------
>>  1 file changed, 81 insertions(+), 38 deletions(-)
>
> Thanks, I have a few minor comments:
>
>>  @cindex Setting a key globally
>> -@cindex Global set key
>> +@cindex Keymap global set
>>  @cindex Key setting globally
>> -@findex global-set-key
>
> Please add index entries for the new APIs, but do not remove the index
> entries for old ones.  Readers could still need to look up the old
> interfaces via index search.
>
>> -@findex global-unset-key
>> +@findex keymap-global-unset
>
> Same here.

I moved these two indices to the legacy subsection, which is now the
place that describes these functions.

>
>> +@subsection Legacy Global Key Binding Commands
>> +
>> +@findex global-set-key
>> +@cindex Global set key
>> +Historically, keys are bound globally using a lower-level function,
>> +@code{global-set-key}, which is now considered legacy.  While you are
>> +encouraged to use @code{keymap-global-set}, you likely would encounter
>> +@code{global-set-key} in various places.  The first example can be
>> +rewritten using @code{global-set-key} as:
>> +
>> +@smallexample
>> +@group
>> +(global-set-key "\C-cw" 'compare-windows)
>> +@end group
>> +@end smallexample
>
> The text says "first example", but which example is that?  There are
> no examples in this subsection.
>
>> +Historically, keys are unbound globally using a lower-function,
>> +@code{global-unset-key}, which is now considered legacy.  Its key
>> +binding format follows that of @code{global-set-key}.  The above key
>> +unbinding example can be rewritten as:
>
> Same here: "the above key unbinding example" refers to an example in a
> different subsection.

The updated patch now adds an "in this section" qualifier. Please see
the attachment.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: v5-0001-Use-keymap-set-over-global-set-key-define-key-in-.patch --]
[-- Type: text/x-patch, Size: 9068 bytes --]

From b25a4cd7fedaec382b0d486493a1208276e618de Mon Sep 17 00:00:00 2001
From: Hong Xu <hong@topbug.net>
Date: Thu, 19 Dec 2024 14:33:35 -0800
Subject: [PATCH v5] Use `keymap*-set' over `global-set-key'/`define-key' in
 elisp intro

* doc/lispintro/emacs-lisp-intro.texi (Key Bindings): Since
`global-set-key' and `define-key' are considered legacy, we encourage
`keymap-global-set' and `keymap-set' now.
---
 doc/lispintro/emacs-lisp-intro.texi | 120 +++++++++++++++++++---------
 1 file changed, 82 insertions(+), 38 deletions(-)

diff --git a/doc/lispintro/emacs-lisp-intro.texi b/doc/lispintro/emacs-lisp-intro.texi
index 49916235fbf9..863e06346edc 100644
--- a/doc/lispintro/emacs-lisp-intro.texi
+++ b/doc/lispintro/emacs-lisp-intro.texi
@@ -13810,7 +13810,7 @@ Whitespace Bug
 If you wish, you can also install this key binding by evaluating it:
 
 @smallexample
-(global-set-key "\C-c=" '@value{COUNT-WORDS})
+(keymap-global-set "C-c =" '@value{COUNT-WORDS})
 @end smallexample
 
 To conduct the first test, set mark and point to the beginning and end
@@ -14762,7 +14762,7 @@ count-words-in-defun
 Let's reuse @kbd{C-c =} as a convenient key binding:
 
 @smallexample
-(global-set-key "\C-c=" 'count-words-defun)
+(keymap-global-set "C-c =" 'count-words-defun)
 @end smallexample
 
 Now we can try out @code{count-words-defun}: install both
@@ -17229,7 +17229,7 @@ Key Bindings
 @smallexample
 @group
 ;;; Compare windows
-(global-set-key "\C-cw" 'compare-windows)
+(keymap-global-set "C-c w" 'compare-windows)
 @end group
 @end smallexample
 
@@ -17242,20 +17242,18 @@ Key Bindings
 This also shows how to set a key globally, for all modes.
 
 @cindex Setting a key globally
-@cindex Global set key
+@cindex Keymap global set
 @cindex Key setting globally
-@findex global-set-key
-The command is @code{global-set-key}.  It is followed by the
-key binding.  In a @file{.emacs} file, the keybinding is written as
-shown: @code{\C-c} stands for Control-C, which means to press the
-control key and the @kbd{c} key at the same time.  The @code{w} means
-to press the @kbd{w} key.  The key binding is surrounded by double
-quotation marks.  In documentation, you would write this as
-@w{@kbd{C-c w}}.  (If you were binding a @key{META} key, such as
-@kbd{M-c}, rather than a @key{CTRL} key, you would write
-@w{@code{\M-c}} in your @file{.emacs} file.  @xref{Init Rebinding, ,
-Rebinding Keys in Your Init File, emacs, The GNU Emacs Manual}, for
-details.)
+@findex keymap-global-set
+The key setting command is @code{keymap-global-set}.  It is followed by
+the key binding.  In a @file{.emacs} file, the keybinding is written as
+shown: @code{C-c} stands for Control-C, which means to press the control
+key and the @kbd{c} key at the same time.  The @code{w} means to press
+the @kbd{w} key.  The key binding is surrounded by double quotation
+marks.  (If you were binding a @key{META} key, rather than a @key{CTRL}
+key, you would write @w{@code{M-c}} in your @file{.emacs} file.
+@xref{Init Rebinding, , Rebinding Keys in Your Init File, emacs, The GNU
+Emacs Manual}, for details.)
 
 The command invoked by the keys is @code{compare-windows}.  Note that
 @code{compare-windows} is preceded by a single-quote; otherwise, Emacs
@@ -17284,7 +17282,7 @@ Key Bindings
 @group
 ;;; Key binding for 'occur'
 ; I use occur a lot, so let's bind it to a key:
-(global-set-key "\C-co" 'occur)
+(keymap-global-set "C-c o" 'occur)
 @end group
 @end smallexample
 
@@ -17296,7 +17294,7 @@ Key Bindings
 Matching lines are shown in a buffer called @file{*Occur*}.
 That buffer serves as a menu to jump to occurrences.
 
-@findex global-unset-key
+@findex keymap-global-unset
 @cindex Unbinding key
 @cindex Key unbinding
 @need 1250
@@ -17306,7 +17304,7 @@ Key Bindings
 @smallexample
 @group
 ;;; Unbind 'C-x f'
-(global-unset-key "\C-xf")
+(keymap-global-unset "C-x f")
 @end group
 @end smallexample
 
@@ -17324,7 +17322,7 @@ Key Bindings
 @smallexample
 @group
 ;;; Rebind 'C-x C-b' for 'buffer-menu'
-(global-set-key "\C-x\C-b" 'buffer-menu)
+(keymap-global-set "C-x C-b" 'buffer-menu)
 @end group
 @end smallexample
 
@@ -17336,33 +17334,80 @@ Key Bindings
 command, which not only lists the buffers,
 but moves point into that window.
 
+@subsection Legacy Global Key Binding Commands
+
+@findex global-set-key
+@cindex Global set key
+Historically, keys are bound globally using a lower-level function,
+@code{global-set-key}, which is now considered legacy.  While you are
+encouraged to use @code{keymap-global-set}, you likely would encounter
+@code{global-set-key} in various places.  The first example in this
+section can be rewritten using @code{global-set-key} as:
+
+@smallexample
+@group
+(global-set-key "\C-cw" 'compare-windows)
+@end group
+@end smallexample
+
+It is very similar to @code{keymap-global-set}, with the keybinding
+following a slightly different format.  Control-C is represented by
+@code{\C-c}, instead of @code{C-c}.  There is no space between key
+strokes, like @code{\C-c} and @code{w} in this example.  Despite the
+difference, in documentation, this is still written as @w{@kbd{C-c w}}
+for readability.
+
+@findex global-unset-key
+Historically, keys are unbound globally using a lower-function,
+@code{global-unset-key}, which is now considered legacy.  Its key
+binding format follows that of @code{global-set-key}.  The key unbinding
+example in this section can be rewritten as:
+
+@smallexample
+@group
+;;; Unbind 'C-x f'
+(global-unset-key "\C-xf")
+@end group
+@end smallexample
+
 @node Keymaps
 @section Keymaps
 @cindex Keymaps
 @cindex Rebinding keys
 
 Emacs uses @dfn{keymaps} to record which keys call which commands.
-When you use @code{global-set-key} to set the key binding for a single
-command in all parts of Emacs, you are specifying the key binding in
-@code{current-global-map}.
+When you use @code{keymap-global-set} to set the key binding for a
+single command in all parts of Emacs, you are specifying the key binding
+in @code{current-global-map}.
 
 Specific modes, such as C mode or Text mode, have their own keymaps;
 the mode-specific keymaps override the global map that is shared by
 all buffers.
 
-The @code{global-set-key} function binds, or rebinds, the global
+The @code{keymap-global-set} function binds, or rebinds, the global
 keymap.  For example, the following binds the key @kbd{C-x C-b} to the
 function @code{buffer-menu}:
 
 @smallexample
-(global-set-key "\C-x\C-b" 'buffer-menu)
+(keymap-global-set "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
+
+Historically, keymaps are bound using a lower-level function,
+@code{define-key}, which is now considered legacy.  While you are
+encouraged to use @code{keymap-set}, you likely would encounter
+@code{define-key} in various places.  The above key binding can be
+rewritten using @code{define-key} as:
 
 @smallexample
 @group
@@ -17396,9 +17441,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
@@ -17440,13 +17485,12 @@ Loading Files
 
 @need 1250
 To replace the key binding for the default
-@code{split-window-vertically}, you must also unset that key and bind
-the keys to @code{split-window-quietly}, like this:
+@code{split-window-vertically}, you must bind the keys to
+@code{split-window-quietly}, like this:
 
 @smallexample
 @group
-(global-unset-key "\C-x2")
-(global-set-key "\C-x2" 'split-window-quietly)
+(keymap-global-set "C-x 2" 'split-window-quietly)
 @end group
 @end smallexample
 
@@ -17608,7 +17652,7 @@ Simple Extension
 this:
 
 @smallexample
-(global-set-key [f6] 'line-to-top-of-window)
+(keymap-global-set "<f6>" 'line-to-top-of-window)
 @end smallexample
 
 For more information, see @ref{Init Rebinding, , Rebinding Keys in
@@ -18791,7 +18835,7 @@ the-the
 
 @group
 ;; Bind 'the-the' to  C-c \
-(global-set-key "\C-c\\" 'the-the)
+(keymap-global-set "C-c \\" 'the-the)
 @end group
 @end smallexample
 
-- 
2.47.1


[-- Attachment #3: Type: text/plain, Size: 10 bytes --]


-- 
Hong

^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2024-12-28 19:56 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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-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

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.