For Emacs 26.3 running in terminal mode, I am trying to map a my-command
to M-Z in org-mode by using the following code:
(with-eval-after-load org
(define-key org-mode-map (kbd "<M-Z>") #'my-command))
But this does not work.
It works if I do this instead:
(with-eval-after-load org
(define-key esc-map "Z" #'my-command))
But the latter binds my-command
in the global map making it available everywhere, and I do not want that.
This behaves as if the esc-map
takes precedence over the org-mode-map
. I looked in org.el and I don't see that code copying anything from the esc-map
defined in subr.el.
I thought it could because the org mode function has not yet run, so I tried adding the code inside a org-mode-hook
as well (in addition to the above code):
(defun pel--org-set-keys ()
"Set keys."
(if (boundp 'org-mode-map)
(progn
(define-key org-mode-map (kbd "<M-Z>") #'my-command))
(display-warning 'pel--org-set-keys
"org-mode-map not bound"
:error)))
(add-hook 'org-mode-hook (function pel--org-set-keys))
But that still does not work.
Why does the (define-key org-mode-map (kbd "<M-Z>") #'my-command)
not work?