~pkal/public-inbox

3 2

[QUESTION] setup.el: Why does :global use global-set-key and not define-key?

Details
Message ID
<CADS3Lq6Kj+CmK9A4GW=6nJShZ9C_CLFEsK0biXbUem5=HPYSaQ@mail.gmail.com>
DKIM signature
missing
Download raw message
Hi Philip,

Why does setup-define :global use

`(global-set-key ,key ,command)

and not something like

`(define-key global-map ,key ,command)?

My understanding is that `global-set-key' is just a thin wrapper around
`define-key' so would it not be better to use the more primitive
function within a macro definition?

No doubt there is a valid reason for your choice but I was just curious.

Kind regards,

Niall
Details
Message ID
<871qbgda5q.fsf@posteo.net>
In-Reply-To
<CADS3Lq6Kj+CmK9A4GW=6nJShZ9C_CLFEsK0biXbUem5=HPYSaQ@mail.gmail.com> (view parent)
DKIM signature
missing
Download raw message
Niall Dooley <dooleyn@gmail.com> writes:

> Hi Philip,

Hi,

> Why does setup-define :global use
>
> `(global-set-key ,key ,command)
>
> and not something like
>
> `(define-key global-map ,key ,command)?
>
> My understanding is that `global-set-key' is just a thin wrapper around
> `define-key' 

Just looking at the definition of global-set-key, it should be more or
less like:

  (define-key (current-global-map) key command)

>              so would it not be better to use the more primitive
> function within a macro definition?

I don't know of any such rule when writing macros.

> No doubt there is a valid reason for your choice but I was just curious.

Pretty much just that I was adding a macro for what I was previously
writing out in my init.el, and in my case I was using the user-facing
global-set-key -- and in fact still do.  IMO the :global local macro was
a mistake, since it doesn't really use any context, and admittedly was
inspired by `use-package', without sufficient introspection.  Since
Emacs 29, the proper function to use is `keymap-global-set' anyway.

> Kind regards,
>
> Niall
Details
Message ID
<CADS3Lq7MQMJi72Fo2ngV5vN99FKasM8sA6qbijG+1ZT1M-yMXQ@mail.gmail.com>
In-Reply-To
<871qbgda5q.fsf@posteo.net> (view parent)
DKIM signature
missing
Download raw message
On Wed, 20 Dec 2023 at 19:03, Philip Kaludercic <philipk@posteo.net> wrote:
> Just looking at the definition of global-set-key, it should be more or
> less like:
>
>   (define-key (current-global-map) key command)
>
> >              so would it not be better to use the more primitive
> > function within a macro definition?
>
> I don't know of any such rule when writing macros.

I didn't mean to suggest their was such a rule.

> > No doubt there is a valid reason for your choice but I was just curious.
>
> Pretty much just that I was adding a macro for what I was previously
> writing out in my init.el, and in my case I was using the user-facing
> global-set-key -- and in fact still do.  IMO the :global local macro was
> a mistake, since it doesn't really use any context, and admittedly was
> inspired by `use-package', without sufficient introspection.  Since
> Emacs 29, the proper function to use is `keymap-global-set' anyway.

Interesting.  Still on 27.1 myself but reading about these changes now
and `global-set-key' becoming a legacy function.
Details
Message ID
<87wmt8btiw.fsf@posteo.net>
In-Reply-To
<CADS3Lq7MQMJi72Fo2ngV5vN99FKasM8sA6qbijG+1ZT1M-yMXQ@mail.gmail.com> (view parent)
DKIM signature
missing
Download raw message
Niall Dooley <dooleyn@gmail.com> writes:

> On Wed, 20 Dec 2023 at 19:03, Philip Kaludercic <philipk@posteo.net> wrote:
>> Just looking at the definition of global-set-key, it should be more or
>> less like:
>>
>>   (define-key (current-global-map) key command)
>>
>> >              so would it not be better to use the more primitive
>> > function within a macro definition?
>>
>> I don't know of any such rule when writing macros.
>
> I didn't mean to suggest their was such a rule.

Heuristic, idiom or whatever; what I meant to say is that I have never
heard of anyone arguing this point.

>> > No doubt there is a valid reason for your choice but I was just curious.
>>
>> Pretty much just that I was adding a macro for what I was previously
>> writing out in my init.el, and in my case I was using the user-facing
>> global-set-key -- and in fact still do.  IMO the :global local macro was
>> a mistake, since it doesn't really use any context, and admittedly was
>> inspired by `use-package', without sufficient introspection.  Since
>> Emacs 29, the proper function to use is `keymap-global-set' anyway.
>
> Interesting.  Still on 27.1 myself but reading about these changes now
> and `global-set-key' becoming a legacy function.

The peculiar thing is that these functions all still boil down to
`define-key', which is also marked as a legacy function.
Reply to thread Export thread (mbox)