Consider headlines as sentences by themselves

* lisp/org.el (org-forward-sentence): Consider headlines as sentences
  by themselves.

* testing/lisp/test-org.el (test-org/forward-sentence): Add test.

Reported-by: Mat Vibrys <vibrysec@gmail.com>
<http://lists.gnu.org/archive/html/emacs-orgmode/2017-10/msg00130.html>
This commit is contained in:
Nicolas Goaziou 2017-10-08 10:35:22 +02:00
parent 6432fcd433
commit d747e51fbf
2 changed files with 10 additions and 4 deletions

View File

@ -23618,7 +23618,9 @@ depending on context."
(skip-chars-forward " \r\t\n"))))
(narrow-to-region (org-element-property :contents-begin element)
contents-end))
(call-interactively #'forward-sentence))))))
;; End of heading is considered as the end of a sentence.
(let ((sentence-end (concat (sentence-end) "\\|^\\*+ .*$")))
(call-interactively #'forward-sentence)))))))
(define-key org-mode-map "\M-a" 'org-backward-sentence)
(define-key org-mode-map "\M-e" 'org-forward-sentence)

View File

@ -3414,8 +3414,8 @@ SCHEDULED: <2017-05-06 Sat>
(org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
(org-forward-sentence)
(eobp)))
;; On a headline, stop at the end of the line, unless point is
;; already there.
;; Headlines are considered to be sentences by themselves, even if
;; they do not end with a full stop.
(should
(equal
"* Headline"
@ -3425,7 +3425,11 @@ SCHEDULED: <2017-05-06 Sat>
(should
(org-test-with-temp-text "* Headline<point>\nSentence."
(org-forward-sentence)
(eobp))))
(eobp)))
(should
(org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
(org-forward-sentence)
(and (org-at-heading-p) (eolp)))))
(ert-deftest test-org/backward-sentence ()
"Test `org-backward-sentence' specifications."