all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Customize the key bindings in the org mode
@ 2024-03-07 10:41 Volker Wysk
  2024-03-07 12:59 ` Michel Verdier
  2024-03-08  0:37 ` Michael Heerdegen via Users list for the GNU Emacs text editor
  0 siblings, 2 replies; 7+ messages in thread
From: Volker Wysk @ 2024-03-07 10:41 UTC (permalink / raw)
  To: help-gnu-emacs

Hi!

I know how to change key bindings globally. But how can I customize the
bindings for just a specific major mode? More precisely, the org mode.

I found something on the web and adapted it:

(with-eval-after-load "org"  (define-key org-mode-map [M-down] #'absatz-vor)

But this doesn't work, because the org-mode-map is nil. Seems like that's
because org-mode hasn't been read yet, in the ~/.emacs file.

So how should I do it?

TIA

Cheers,
Volker



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

* Re: Customize the key bindings in the org mode
  2024-03-07 10:41 Customize the key bindings in the org mode Volker Wysk
@ 2024-03-07 12:59 ` Michel Verdier
  2024-03-07 13:13   ` Volker Wysk
  2024-03-08  0:37 ` Michael Heerdegen via Users list for the GNU Emacs text editor
  1 sibling, 1 reply; 7+ messages in thread
From: Michel Verdier @ 2024-03-07 12:59 UTC (permalink / raw)
  To: help-gnu-emacs

On 2024-03-07, Volker Wysk wrote:

> I know how to change key bindings globally. But how can I customize the
> bindings for just a specific major mode? More precisely, the org mode.

I do this for LaTeX mode

(defun my-latex-hook (&optional arg)
  "Custom hook for LaTeX mode."
  (interactive "P")
  (local-set-key [f5] 'TeX-command-run-all))
(add-hook 'LaTeX-mode-hook 'my-latex-hook)



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

* Re: Customize the key bindings in the org mode
  2024-03-07 12:59 ` Michel Verdier
@ 2024-03-07 13:13   ` Volker Wysk
  0 siblings, 0 replies; 7+ messages in thread
From: Volker Wysk @ 2024-03-07 13:13 UTC (permalink / raw)
  To: help-gnu-emacs

Am Donnerstag, dem 07.03.2024 um 13:59 +0100 schrieb Michel Verdier:
> On 2024-03-07, Volker Wysk wrote:
> 
> > I know how to change key bindings globally. But how can I customize the
> > bindings for just a specific major mode? More precisely, the org mode.
> 
> I do this for LaTeX mode
> 
> (defun my-latex-hook (&optional arg)
>   "Custom hook for LaTeX mode."
>   (interactive "P")
>   (local-set-key [f5] 'TeX-command-run-all))
> (add-hook 'LaTeX-mode-hook 'my-latex-hook)

Yes, this works. I've adapted it for my case. Thanks!

Volker



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

* Re: Customize the key bindings in the org mode
  2024-03-07 10:41 Customize the key bindings in the org mode Volker Wysk
  2024-03-07 12:59 ` Michel Verdier
@ 2024-03-08  0:37 ` Michael Heerdegen via Users list for the GNU Emacs text editor
  2024-03-08 11:35   ` Arash Esbati
  1 sibling, 1 reply; 7+ messages in thread
From: Michael Heerdegen via Users list for the GNU Emacs text editor @ 2024-03-08  0:37 UTC (permalink / raw)
  To: help-gnu-emacs

Volker Wysk <post@volker-wysk.de> writes:

> I found something on the web and adapted it:
>
> (with-eval-after-load "org"  (define-key org-mode-map [M-down] #'absatz-vor)
>
> But this doesn't work, because the org-mode-map is nil. Seems like that's
> because org-mode hasn't been read yet, in the ~/.emacs file.

Org consists of multiple source files, and at the moment where org.el
has been loaded the rest of org has not yet - including the file that
actually defines and fills the org-mode's keymap (note that C-h v
org-mode-map tells you org.el would define the variable, this is true
but only for internal technical reasons: the keymap is not yet created
by loading that file).

In such cases, either find a hook you can use, or find the file where
your stuff is defined - in this case, "org-keys".  It's not always
trivial to find that file, one must look at the source code.  In the
case of a major-mode using the mode hook is a good choice (or even the
best choice) to define key bindings for that mode.

Michael.




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

* Re: Customize the key bindings in the org mode
  2024-03-08  0:37 ` Michael Heerdegen via Users list for the GNU Emacs text editor
@ 2024-03-08 11:35   ` Arash Esbati
  2024-03-09  0:01     ` Michael Heerdegen via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 7+ messages in thread
From: Arash Esbati @ 2024-03-08 11:35 UTC (permalink / raw)
  To: Michael Heerdegen via Users list for the GNU Emacs text editor
  Cc: Michael Heerdegen

Michael Heerdegen via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> writes:

> Volker Wysk <post@volker-wysk.de> writes:
>
>> I found something on the web and adapted it:
>>
>> (with-eval-after-load "org"  (define-key org-mode-map [M-down] #'absatz-vor)
>>
>> But this doesn't work, because the org-mode-map is nil. Seems like that's
>> because org-mode hasn't been read yet, in the ~/.emacs file.
>
> Org consists of multiple source files, and at the moment where org.el
> has been loaded the rest of org has not yet - including the file that
> actually defines and fills the org-mode's keymap (note that C-h v
> org-mode-map tells you org.el would define the variable, this is true
> but only for internal technical reasons: the keymap is not yet created
> by loading that file).

Caveat emptor: I'm not an Org user.

Does the above mean that this example in Org manual[1] doesn't work
OOTB?

  C-c C-x C-n (org-next-link)
  C-c C-x C-p (org-previous-link)

    Move forward/backward to the next link in the buffer. At the limit
    of the buffer, the search fails once, and then wraps around. The key
    bindings for this are really too long; you might want to bind this
    also to M-n and M-p.

      (with-eval-after-load 'org
        (define-key org-mode-map (kbd "M-n") #'org-next-link)
        (define-key org-mode-map (kbd "M-p") #'org-previous-link))

Best, Arash

Footnotes:
[1]  https://orgmode.org/manual/Handling-Links.html



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

* Re: Customize the key bindings in the org mode
  2024-03-08 11:35   ` Arash Esbati
@ 2024-03-09  0:01     ` Michael Heerdegen via Users list for the GNU Emacs text editor
  2024-03-09 10:35       ` Arash Esbati
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Heerdegen via Users list for the GNU Emacs text editor @ 2024-03-09  0:01 UTC (permalink / raw)
  To: help-gnu-emacs

Arash Esbati <arash@gnu.org> writes:

> Caveat emptor: I'm not an Org user.
>
> Does the above mean that this example in Org manual[1] doesn't work
> OOTB?

>       (with-eval-after-load 'org
>         (define-key org-mode-map (kbd "M-n") #'org-next-link)
>         (define-key org-mode-map (kbd "M-p") #'org-previous-link))

It does work OOTB.

I only had a very quick look yesterday, but I now see that org.el does
require org-keys and all the other stuff, so I don't understand the
problem reported by the OP, which is described only very briefly.  AFAIU
there should not be a problem when defining keys in `org-mode-map'
inside a with-eval-after-load 'org.  I tried it in several Emacs
versions and everything was fine.

Michael.




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

* Re: Customize the key bindings in the org mode
  2024-03-09  0:01     ` Michael Heerdegen via Users list for the GNU Emacs text editor
@ 2024-03-09 10:35       ` Arash Esbati
  0 siblings, 0 replies; 7+ messages in thread
From: Arash Esbati @ 2024-03-09 10:35 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Heerdegen via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> writes:

> It does work OOTB.
>
> I only had a very quick look yesterday, but I now see that org.el does
> require org-keys and all the other stuff, so I don't understand the
> problem reported by the OP, which is described only very briefly.  AFAIU
> there should not be a problem when defining keys in `org-mode-map'
> inside a with-eval-after-load 'org.  I tried it in several Emacs
> versions and everything was fine.

Thanks for your response and checking, so there is no bug in the manual.
Maybe the OP can come up with a recipe to reproduce starting with 'emacs
-Q', otherwise we will never find out.

Best, Arash




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

end of thread, other threads:[~2024-03-09 10:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-07 10:41 Customize the key bindings in the org mode Volker Wysk
2024-03-07 12:59 ` Michel Verdier
2024-03-07 13:13   ` Volker Wysk
2024-03-08  0:37 ` Michael Heerdegen via Users list for the GNU Emacs text editor
2024-03-08 11:35   ` Arash Esbati
2024-03-09  0:01     ` Michael Heerdegen via Users list for the GNU Emacs text editor
2024-03-09 10:35       ` Arash Esbati

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.