3

Org mode overrides paragraph movement to replace forward-paragraph with org-forward-paragraph. How do I access the normal forward-paragraph command?

I'm happy to rebind the org-forward-paragraph if I have to change code somewhere. I just want to have access to both functions. org-forward-paragraph is great, but sometimes I want forward-paragraph in an org document.

Even if you call M-x forward-paragraph, org-forward-paragraph is executed. I want to be able to bind forward paragraph. I have a logging package that shows that org-forward-paragraph is being called for these below bindings (instead of the bound forward-paragraph).

I've tried this:

(bind-key "<f5> 3" 'forward-paragraph org-mode-map)

and this:

(defun my-org-forward-paragraph-override ()
  (interactive)
  (forward-paragraph))
(bind-key "<f5> 3" 'my-org-forward-paragraph-override org-mode-map)

With the following org doc, and the cursor at the beginning, I expect M-x forward-paragraph to move to the first empty line (the end of the first paragraph). Instead, it moves to the end of the file and tells me to call forward-paragraph with C-<down> (which calls org-forward-paragraph).

* heading 1
* heading 2

* heading 3

The issue can be replicated in emacs -q by creating the above org doc, switching to scratch and executing the below binding; C-h k C-c 2 then shows that org-forward-paragraph is being called instead of the bound forward-paragraph

(define-key org-mode-map (kbd "C-c 2") #'forward-paragraph)
6
  • 1
    What would you consider to be adequate access to forward-paragraph in an org document? Are you looking for something more than M-x forward-paragraph?
    – Malle Yeno
    Oct 25, 2022 at 0:27
  • 1
    The question could be clearer. Are you just asking how to bind forward-paragraph to a key, in an Org mode keymap?
    – Drew
    Oct 25, 2022 at 3:29
  • Even if you call M-x forward-paragraph, org-forward-paragraph is executed. I want to execute forward-paragraph. Oct 25, 2022 at 10:04
  • 1
    I am not able to replicate the behaviour you are experiencing. Calling M-x forward-paragraph within an org doc works as expected, not as org-forward-paragraph. (Checked through messages log, command log, and by seeing how the command treats "org units" like lists and tables.) Have you checked if anything in your config could be causing problems here?
    – Malle Yeno
    Oct 25, 2022 at 15:12
  • 1
    I understand your confusion. org-mode is really confusing about certain special org- functions, and doesn't bind them in the conventional way!
    – Tyler
    Oct 25, 2022 at 21:18

2 Answers 2

2

@Tyler's diagnosis is correct, but there is no need to define a renamed function just to do this. All you have to do is undo the remapping of forward-paragraph that Org mode did. The remapping section of the manual tells you how to do that:

;;; traditional
(define-key my-mode-map [remap forward-paragraph] nil)
;;; ... or recent Emacsen(?)
(keymap-set org-mode-map "<remap> <forward-paragraph>" nil)

You just remap it to nil.

The current online manual shows the first version, but the 29.0.50 manual shows the second one: they are equivalent but the second version may not be available if your version of Emacs is older.

The two functions can now independently be bound to keys. Note that forward-paragraph is still bound to C-<down>, so only the Org variant key binding needs to be defined.

2
  • This is great and makes my config look a little nicer than the other answer (the other answer is fine, though, like you said). Nov 1, 2022 at 17:49
  • Credit where credit is due: without @Tyler's answer, this answer would probably not exist. He pointed out the remapping - since I didn't know anything about it, I followed up in the manual and saw the above mentioned.
    – NickD
    Nov 1, 2022 at 17:56
4

orgmode defines special 'super' functions that take over many typical Emacs functions, and binds them in a way that makes it difficult to override them. You can look into the details in the function org-remap, in the file org-keys.el. The main point is, any key you bind to one of these super functions, and forward-paragraph is one of them, will actually get bound to the org version instead.

If you want to use one of these normal functions, you need to give it a different name to call, so org's remapping won't catch it. In your case, the following worked for me:

(defun my-org-forward-paragraph-override ()
  (interactive)
  (forward-paragraph))


(define-key org-mode-map "\M-p" 'my-org-forward-paragraph-override)

With this config, M-p gives you the regular behaviour of forward-paragraph.

By contrast, the following doesn't work:

(define-key org-mode-map "\M-o" 'forward-paragraph)

With this config, M-o calls org-forward-paragraph, even though you (thought you) told it to call forward-paragraph.

1
  • Thanks. I was on the right trail but got wrapped around the axle with a compounding issue not realizing I bound again later differently. This clarification was what I was looking for. Oct 25, 2022 at 21:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.