2

I wanted to use hl-sentences module and discovered in the process that the sentence detection, and thus move between sentence is buggy inside org-mode.

* Title

some text:

- bullet 1
- bullet 2
- bullet 3

** sub-title

If I do an org-forward-sentence when my cursor is positioned in the second bullet for instance. I'm jumping to the end of sub-title.

Worse if I do a org-backward-sentence when I'm in the middle of bullet 2, the first time I'm going back to the beginning (the b) of bullet 2 (which is ok) but if I do another org-backward-sentence I'm jumping back to the start of some text:.

This feel very wrong as by intuition I would imagine that org-backward-sentence should be a projection.

I would prefer that org-mode treat each bullet as a single sentence. And also that starting a new "heading" means the end of any previous sentence.

So perhaps there are good reason for these behaviour if not I would appreciate a pointer on how to fix that problem. Perhaps even propose a PR to org-mode.

2 Answers 2

1

The actual problem is that org-mode uses org-forward-paragraph as replacement for forward-paragraph but forward-paragraph is still used in elisp functions.

For an instance forward-sentence directly uses forward-paragraph and org-forward-sentence directly uses forward-sentence.

A hacky solution is to override forward-paragraph with org-forward-paragraph in an advice of forward-sentence:

(defun forward-sentence-with-org-forward-paragraph (oldfun &rest args)
  (if (derived-mode-p 'org-mode)
      (unwind-protect
          (progn
            (advice-add #'forward-paragraph :override (lambda (&optional _arg) (org-forward-paragraph)) '((name . "org-forward-paragraph")))
            (apply oldfun args))
        (advice-remove #'forward-paragraph "org-forward-paragraph"))
    (apply oldfun args)))

(with-current-buffer "test.org"
  (advice-add #'forward-sentence :around #'forward-sentence-with-org-forward-paragraph))

The general solution would be to avoid forward-sentence in org-forward-sentence and to use org-forward-paragraph in org-forward-sentence. But that is quite a bit of work...

0

emacs-sentence-navigation.el is dedicated to sentence navigation, and will help in most cases... but not in yours, because it lacks "standard" sentences (capitalized word following a period). If your bullets contained "real" sentences, this package would detect them.

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.