unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Sparse key maps garbage?
@ 2008-08-30 23:44 Lennart Borgman (gmail)
  2008-08-31  6:18 ` Stefan Monnier
  0 siblings, 1 reply; 11+ messages in thread
From: Lennart Borgman (gmail) @ 2008-08-30 23:44 UTC (permalink / raw)
  To: Emacs Devel

If you do

 (defvar my-sparse-map (make-sparse-keymap))
 (define-key my-sparse-map [f4] nil)

then there will be an entry with f4 in my-sparse-keymap. I do not think
that is used for anything. Is it? Should it be there?






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

* Re: Sparse key maps garbage?
  2008-08-30 23:44 Sparse key maps garbage? Lennart Borgman (gmail)
@ 2008-08-31  6:18 ` Stefan Monnier
  2008-08-31 12:17   ` Lennart Borgman (gmail)
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2008-08-31  6:18 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: Emacs Devel

> If you do

>  (defvar my-sparse-map (make-sparse-keymap))
>  (define-key my-sparse-map [f4] nil)

> then there will be an entry with f4 in my-sparse-keymap. I do not think
> that is used for anything. Is it? Should it be there?

Actually, IIRC it's (been) used at some places to create a place holder
in the keymap which is later on replaced with the actual binding.
But I do wonder why you care,


        Stefan


PS: Some other issues have to do with the delicate treatment of nil
bindings w.r.t inheritance: a nil binding will hide any other binding in
the parent(s).




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

* Re: Sparse key maps garbage?
  2008-08-31  6:18 ` Stefan Monnier
@ 2008-08-31 12:17   ` Lennart Borgman (gmail)
  2008-08-31 12:55     ` Stefan Monnier
  0 siblings, 1 reply; 11+ messages in thread
From: Lennart Borgman (gmail) @ 2008-08-31 12:17 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs Devel

Stefan Monnier wrote:
>> If you do
> 
>>  (defvar my-sparse-map (make-sparse-keymap))
>>  (define-key my-sparse-map [f4] nil)
> 
>> then there will be an entry with f4 in my-sparse-keymap. I do not think
>> that is used for anything. Is it? Should it be there?
> 
> Actually, IIRC it's (been) used at some places to create a place holder
> in the keymap which is later on replaced with the actual binding.
> But I do wonder why you care,

I was looking a bit at how to undefine a key, for example at
local-unset-key. So what I really wondered was how do you undefine a
key? Is there a standard way to do that?

> PS: Some other issues have to do with the delicate treatment of nil
> bindings w.r.t inheritance: a nil binding will hide any other binding in
> the parent(s).
> 




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

* Re: Sparse key maps garbage?
  2008-08-31 12:17   ` Lennart Borgman (gmail)
@ 2008-08-31 12:55     ` Stefan Monnier
  2008-08-31 13:05       ` Lennart Borgman (gmail)
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2008-08-31 12:55 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: Emacs Devel

>>> If you do
>> 
>>> (defvar my-sparse-map (make-sparse-keymap))
>>> (define-key my-sparse-map [f4] nil)
>> 
>>> then there will be an entry with f4 in my-sparse-keymap. I do not think
>>> that is used for anything. Is it? Should it be there?
>> 
>> Actually, IIRC it's (been) used at some places to create a place holder
>> in the keymap which is later on replaced with the actual binding.
>> But I do wonder why you care,

> I was looking a bit at how to undefine a key, for example at
> local-unset-key. So what I really wondered was how do you undefine a
> key? Is there a standard way to do that?

Depends how you define "un define a key".  Binding it to nil is such
a way.  Binding it to `undefined' is another.  Removing the binding from
the keymap is yet another (one that does not come with a ready-to-use
function for it).


        Stefan




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

* Re: Sparse key maps garbage?
  2008-08-31 12:55     ` Stefan Monnier
@ 2008-08-31 13:05       ` Lennart Borgman (gmail)
  2008-08-31 18:19         ` Stefan Monnier
  0 siblings, 1 reply; 11+ messages in thread
From: Lennart Borgman (gmail) @ 2008-08-31 13:05 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs Devel

Stefan Monnier wrote:
> Depends how you define "un define a key".  Binding it to nil is such
> a way.  Binding it to `undefined' is another.  Removing the binding from
> the keymap is yet another (one that does not come with a ready-to-use
> function for it).


I am thinking of the last case. Shouldn't there be one for this case?
Using exactly the same parameters as define-key (minus the binding)?




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

* Re: Sparse key maps garbage?
  2008-08-31 13:05       ` Lennart Borgman (gmail)
@ 2008-08-31 18:19         ` Stefan Monnier
  2008-08-31 20:09           ` Lennart Borgman (gmail)
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2008-08-31 18:19 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: Emacs Devel

>> Depends how you define "un define a key".  Binding it to nil is such
>> a way.  Binding it to `undefined' is another.  Removing the binding from
>> the keymap is yet another (one that does not come with a ready-to-use
>> function for it).

> I am thinking of the last case. Shouldn't there be one for this case?
> Using exactly the same parameters as define-key (minus the binding)?

What do you need it for?


        Stefan




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

* Re: Sparse key maps garbage?
  2008-08-31 18:19         ` Stefan Monnier
@ 2008-08-31 20:09           ` Lennart Borgman (gmail)
  2008-09-01  3:00             ` Stefan Monnier
  0 siblings, 1 reply; 11+ messages in thread
From: Lennart Borgman (gmail) @ 2008-08-31 20:09 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs Devel

Stefan Monnier wrote:
>>> Depends how you define "un define a key".  Binding it to nil is such
>>> a way.  Binding it to `undefined' is another.  Removing the binding from
>>> the keymap is yet another (one that does not come with a ready-to-use
>>> function for it).
> 
>> I am thinking of the last case. Shouldn't there be one for this case?
>> Using exactly the same parameters as define-key (minus the binding)?
> 
> What do you need it for?


I have no need for it now. It just came to my mind because Xah asked how
to undow a (define-key map [remap ...] ...) binding.

You can do that of course, but having an undefine-key make the data
abstraction (is it called so?) better.




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

* Re: Sparse key maps garbage?
  2008-08-31 20:09           ` Lennart Borgman (gmail)
@ 2008-09-01  3:00             ` Stefan Monnier
  2008-09-01  7:34               ` Lennart Borgman (gmail)
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2008-09-01  3:00 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: Emacs Devel

>>>> Depends how you define "un define a key".  Binding it to nil is such
>>>> a way.  Binding it to `undefined' is another.  Removing the binding from
>>>> the keymap is yet another (one that does not come with a ready-to-use
>>>> function for it).
>> 
>>> I am thinking of the last case. Shouldn't there be one for this case?
>>> Using exactly the same parameters as define-key (minus the binding)?
>> 
>> What do you need it for?

> I have no need for it now.

Thought so.  That's the reason why it doesn't exist.

> It just came to my mind because Xah asked how
> to undow a (define-key map [remap ...] ...) binding.

The answer is: (define-key map [remap ...] nil).

If you're worried that this will not quite undo it (i.e. in the case
that map's parent already had a [remap ...] binding), then you need to
do something like:

   (setq orig-map map)
   (setq map (make-sparse-keymap))
   (set-keymap-parent map orig-map)
   (define-key map [remap ...] ...))

so that you can undo the binding(s) with

   (setq map orig-map)     

> You can do that of course, but having an undefine-key make the data
> abstraction (is it called so?) better.

`undo' is not the same as `undefine-key'.


        Stefan




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

* Re: Sparse key maps garbage?
  2008-09-01  3:00             ` Stefan Monnier
@ 2008-09-01  7:34               ` Lennart Borgman (gmail)
  2008-09-01 18:25                 ` Stefan Monnier
  0 siblings, 1 reply; 11+ messages in thread
From: Lennart Borgman (gmail) @ 2008-09-01  7:34 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs Devel

Stefan Monnier wrote:
>>>>> Depends how you define "un define a key".  Binding it to nil is such
>>>>> a way.  Binding it to `undefined' is another.  Removing the binding from
>>>>> the keymap is yet another (one that does not come with a ready-to-use
>>>>> function for it).
>>>> I am thinking of the last case. Shouldn't there be one for this case?
>>>> Using exactly the same parameters as define-key (minus the binding)?
>>> What do you need it for?
> 
>> I have no need for it now.
> 
> Thought so.  That's the reason why it doesn't exist.
> 
>> It just came to my mind because Xah asked how
>> to undow a (define-key map [remap ...] ...) binding.
> 
> The answer is: (define-key map [remap ...] nil).
> 
> If you're worried that this will not quite undo it (i.e. in the case
> that map's parent already had a [remap ...] binding), then you need to
> do something like:
> 
>    (setq orig-map map)
>    (setq map (make-sparse-keymap))
>    (set-keymap-parent map orig-map)
>    (define-key map [remap ...] ...))
> 
> so that you can undo the binding(s) with
> 
>    (setq map orig-map)     

What Xah wanted was to remove some (define-key map [remap ...] ...)
bindings in an existing map. (Some map in cua-mode.)

This can not be done as above since you do not know for sure where that
keymap variable is used. You have to use your knowledge of the data
structures for sparse keymaps.

>> You can do that of course, but having an undefine-key make the data
>> abstraction (is it called so?) better.
> 
> `undo' is not the same as `undefine-key'.





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

* Re: Sparse key maps garbage?
  2008-09-01  7:34               ` Lennart Borgman (gmail)
@ 2008-09-01 18:25                 ` Stefan Monnier
  2008-09-01 22:28                   ` Lennart Borgman (gmail)
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2008-09-01 18:25 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: Emacs Devel

> What Xah wanted was to remove some (define-key map [remap ...] ...)
> bindings in an existing map. (Some map in cua-mode.)

And why didn't he want to use (define-key map [remap ...] nil)?


        Stefan




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

* Re: Sparse key maps garbage?
  2008-09-01 18:25                 ` Stefan Monnier
@ 2008-09-01 22:28                   ` Lennart Borgman (gmail)
  0 siblings, 0 replies; 11+ messages in thread
From: Lennart Borgman (gmail) @ 2008-09-01 22:28 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs Devel

Stefan Monnier wrote:
>> What Xah wanted was to remove some (define-key map [remap ...] ...)
>> bindings in an existing map. (Some map in cua-mode.)
> 
> And why didn't he want to use (define-key map [remap ...] nil)?

Not sure what he did. And I did not test but I thought that one above
would end remapping to something like 'ignore.




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

end of thread, other threads:[~2008-09-01 22:28 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-30 23:44 Sparse key maps garbage? Lennart Borgman (gmail)
2008-08-31  6:18 ` Stefan Monnier
2008-08-31 12:17   ` Lennart Borgman (gmail)
2008-08-31 12:55     ` Stefan Monnier
2008-08-31 13:05       ` Lennart Borgman (gmail)
2008-08-31 18:19         ` Stefan Monnier
2008-08-31 20:09           ` Lennart Borgman (gmail)
2008-09-01  3:00             ` Stefan Monnier
2008-09-01  7:34               ` Lennart Borgman (gmail)
2008-09-01 18:25                 ` Stefan Monnier
2008-09-01 22:28                   ` Lennart Borgman (gmail)

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