all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* New define-key syntax with custom keymap
@ 2021-10-19  5:53 Manuel Uberti
  2021-10-19 13:52 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 10+ messages in thread
From: Manuel Uberti @ 2021-10-19  5:53 UTC (permalink / raw)
  To: emacs-devel

Hi,

following the recent changes on master, I am trying to use the new syntax to 
define key bindings. The following works as expected:

(global-set-key ["C-M-z"] #'mu-indent-defun)

But these do not work:

(define-key mu-keys-mode-map ["C-<return>"] #'mu-open-line-below)
(define-key mu-keys-mode-map ["C-c C-n"] #'mu-cleanup-buffer)

Whereas these work as expected:

(define-key mu-keys-mode-map (kbd "C-<return>") #'mu-open-line-below)
(define-key mu-keys-mode-map "\C-c\C-n" #'mu-cleanup-buffer)

For reference, mu-keys-mode-map comes from this code in my init.el:

(defvar mu-keys-mode-map (make-keymap)
   "Keymap for command `mu-keys-mode'.")

(define-minor-mode mu-keys-mode
   "Minor mode for my personal key bindings."
   :init-value t
   :global t
   :keymap mu-keys-mode-map
   :group 'local)

(push `((mu-keys-mode . ,mu-keys-mode-map)) emulation-mode-map-alists)

I am probably missing something, but I don't know what.

-- 
Manuel Uberti
www.manueluberti.eu



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

* Re: New define-key syntax with custom keymap
  2021-10-19  5:53 New define-key syntax with custom keymap Manuel Uberti
@ 2021-10-19 13:52 ` Lars Ingebrigtsen
  2021-10-19 13:54   ` Manuel Uberti
  2021-10-19 13:59   ` Manuel Uberti
  0 siblings, 2 replies; 10+ messages in thread
From: Lars Ingebrigtsen @ 2021-10-19 13:52 UTC (permalink / raw)
  To: Manuel Uberti; +Cc: emacs-devel

Manuel Uberti <manuel.uberti@inventati.org> writes:

> following the recent changes on master, I am trying to use the new
> syntax to define key bindings. The following works as expected:
>
> (global-set-key ["C-M-z"] #'mu-indent-defun)
>
> But these do not work:
>
> (define-key mu-keys-mode-map ["C-<return>"] #'mu-open-line-below)
> (define-key mu-keys-mode-map ["C-c C-n"] #'mu-cleanup-buffer)

I don't have the mu mode, but I tried:

(define-key gnus-summary-mode-map ["C-c C-n"] #'mu-cleanup-buffer)
C-h c C-n C-n

=>

C-c C-n runs the command mu-cleanup-buffer

So it works for me.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



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

* Re: New define-key syntax with custom keymap
  2021-10-19 13:52 ` Lars Ingebrigtsen
@ 2021-10-19 13:54   ` Manuel Uberti
  2021-10-19 13:59   ` Manuel Uberti
  1 sibling, 0 replies; 10+ messages in thread
From: Manuel Uberti @ 2021-10-19 13:54 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: emacs-devel

On 19/10/21 15:52, Lars Ingebrigtsen wrote:
> I don't have the mu mode, but I tried:
> 
> (define-key gnus-summary-mode-map ["C-c C-n"] #'mu-cleanup-buffer)
> C-h c C-n C-n
> 
> =>
> 
> C-c C-n runs the command mu-cleanup-buffer
> 
> So it works for me.

I see, thanks for trying. I'll check what is wrong with my minor mode, then, 
although the code I wrote in the previous mail is all that I have for it.

-- 
Manuel Uberti
www.manueluberti.eu



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

* Re: New define-key syntax with custom keymap
  2021-10-19 13:52 ` Lars Ingebrigtsen
  2021-10-19 13:54   ` Manuel Uberti
@ 2021-10-19 13:59   ` Manuel Uberti
  2021-10-19 14:14     ` Lars Ingebrigtsen
  1 sibling, 1 reply; 10+ messages in thread
From: Manuel Uberti @ 2021-10-19 13:59 UTC (permalink / raw)
  To: emacs-devel

On 19/10/21 15:52, Lars Ingebrigtsen wrote:
> So it works for me.

Out of curiosity, did you try restarting Emacs with:

(define-key gnus-summary-mode-map ["C-c C-n"] #'mu-cleanup-buffer)

somewhere in your init file?

Because if I evaluate:

(define-key mu-keys-mode-map ["C-c C-n"] #'mu-cleanup-buffer)

it works for me as well. But upon restart C-c C-n is not bound to anything.

-- 
Manuel Uberti
www.manueluberti.eu



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

* Re: New define-key syntax with custom keymap
  2021-10-19 13:59   ` Manuel Uberti
@ 2021-10-19 14:14     ` Lars Ingebrigtsen
  2021-10-19 14:19       ` Manuel Uberti
  0 siblings, 1 reply; 10+ messages in thread
From: Lars Ingebrigtsen @ 2021-10-19 14:14 UTC (permalink / raw)
  To: Manuel Uberti; +Cc: emacs-devel

Manuel Uberti <manuel.uberti@inventati.org> writes:

> Because if I evaluate:
>
> (define-key mu-keys-mode-map ["C-c C-n"] #'mu-cleanup-buffer)
>
> it works for me as well. But upon restart C-c C-n is not bound to anything.

I'm not sure I understand what you mean.  `define-key' only works in the
current session -- what it does isn't saved anywhere (no matter what
syntax you use for the key binding).

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



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

* Re: New define-key syntax with custom keymap
  2021-10-19 14:14     ` Lars Ingebrigtsen
@ 2021-10-19 14:19       ` Manuel Uberti
  2021-10-19 14:22         ` Lars Ingebrigtsen
  0 siblings, 1 reply; 10+ messages in thread
From: Manuel Uberti @ 2021-10-19 14:19 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: emacs-devel

On 19/10/21 16:14, Lars Ingebrigtsen wrote:
> I'm not sure I understand what you mean.  `define-key' only works in the
> current session -- what it does isn't saved anywhere (no matter what
> syntax you use for the key binding).

What I mean is that I have this in my init.el:

(define-key mu-keys-mode-map "\C-c\C-n" #'mu-cleanup-buffer)

And I'd like to change it to this:

(define-key mu-keys-mode-map ["C-c C-n"] #'mu-cleanup-buffer)

But, with the first syntax every time I start/restart Emacs, C-c C-n is bound to 
mu-cleanup-buffer. Whereas with the second approach, on start/restart 
mu-cleanup-buffer is not bound to anything until I explicitly evaluate that 
second define-key statement above.

-- 
Manuel Uberti
www.manueluberti.eu



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

* Re: New define-key syntax with custom keymap
  2021-10-19 14:19       ` Manuel Uberti
@ 2021-10-19 14:22         ` Lars Ingebrigtsen
  2021-10-19 14:27           ` Manuel Uberti
  0 siblings, 1 reply; 10+ messages in thread
From: Lars Ingebrigtsen @ 2021-10-19 14:22 UTC (permalink / raw)
  To: Manuel Uberti; +Cc: emacs-devel

Manuel Uberti <manuel.uberti@inventati.org> writes:

> What I mean is that I have this in my init.el:
>
> (define-key mu-keys-mode-map "\C-c\C-n" #'mu-cleanup-buffer)
>
> And I'd like to change it to this:
>
> (define-key mu-keys-mode-map ["C-c C-n"] #'mu-cleanup-buffer)
>
> But, with the first syntax every time I start/restart Emacs, C-c C-n
> is bound to mu-cleanup-buffer. Whereas with the second approach, on
> start/restart mu-cleanup-buffer is not bound to anything until I
> explicitly evaluate that second define-key statement above.

Ah, I see.

I put:

(require 'gnus-sum)
(define-key gnus-summary-mode-map ["C-c C-n"] #'mu-cleanup-buffer)

in my ~/.emacs and started an Emacs and Gnus, and the key was bound in
Gnus summary buffers.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



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

* Re: New define-key syntax with custom keymap
  2021-10-19 14:22         ` Lars Ingebrigtsen
@ 2021-10-19 14:27           ` Manuel Uberti
  2021-10-19 14:32             ` Lars Ingebrigtsen
  0 siblings, 1 reply; 10+ messages in thread
From: Manuel Uberti @ 2021-10-19 14:27 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: emacs-devel

On 19/10/21 16:22, Lars Ingebrigtsen wrote:
> Ah, I see.
> 
> I put:
> 
> (require 'gnus-sum)
> (define-key gnus-summary-mode-map ["C-c C-n"] #'mu-cleanup-buffer)
> 
> in my ~/.emacs and started an Emacs and Gnus, and the key was bound in
> Gnus summary buffers.

I see, thanks. But I am already using:

(require 'mu-lib)

At the top of my init.el, which requires the file where everything mu-* is 
defined. That's why I don't understand why it does not work with the new syntax 
but it does with the old one.

-- 
Manuel Uberti
www.manueluberti.eu



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

* Re: New define-key syntax with custom keymap
  2021-10-19 14:27           ` Manuel Uberti
@ 2021-10-19 14:32             ` Lars Ingebrigtsen
  0 siblings, 0 replies; 10+ messages in thread
From: Lars Ingebrigtsen @ 2021-10-19 14:32 UTC (permalink / raw)
  To: Manuel Uberti; +Cc: emacs-devel

Manuel Uberti <manuel.uberti@inventati.org> writes:

> That's why I don't understand why it does not work with the new syntax
> but it does with the old one.

Me neither.  There should be no difference.  Perhaps you can instrument
`kbd-valid-p' (with edebug or something) and see that it's actually
called?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



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

* Re: New define-key syntax with custom keymap
@ 2021-11-23  6:51 Manuel Uberti
  0 siblings, 0 replies; 10+ messages in thread
From: Manuel Uberti @ 2021-11-23  6:51 UTC (permalink / raw)
  To: larsi, emacs-devel

Sorry if I haven't replied before on this, but on a recent version of Emacs 
master (I built 2955d46c00 this morning) I switched to the new keymap-* commands 
and everything is working as expected.

-- 
Manuel Uberti
www.manueluberti.eu



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

end of thread, other threads:[~2021-11-23  6:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-19  5:53 New define-key syntax with custom keymap Manuel Uberti
2021-10-19 13:52 ` Lars Ingebrigtsen
2021-10-19 13:54   ` Manuel Uberti
2021-10-19 13:59   ` Manuel Uberti
2021-10-19 14:14     ` Lars Ingebrigtsen
2021-10-19 14:19       ` Manuel Uberti
2021-10-19 14:22         ` Lars Ingebrigtsen
2021-10-19 14:27           ` Manuel Uberti
2021-10-19 14:32             ` Lars Ingebrigtsen
  -- strict thread matches above, loose matches on Subject: below --
2021-11-23  6:51 Manuel Uberti

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.