summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2017-10-06 19:34:28 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2017-10-06 19:34:28 +0200
commitfb403ca34ee87118683d4f5a64f0caac0168d95c (patch)
tree8cecc51d0592172879f8574364d1fe7fc36cb48f
parentce536f637554c630ae81598bca2481c01fa3d697 (diff)
downloadorg-mode-fb403ca34ee87118683d4f5a64f0caac0168d95c.tar.gz
Fix `org-backward-paragraph' on an empty heading
* lisp/org.el (org-backward-paragraph): Fix behavior on greater elements without contents. * testing/lisp/test-org.el (test-org/backward-paragraph): Add test. Reported-by: Omar Antolin <omar.antolin@gmail.com> <http://lists.gnu.org/archive/html/emacs-orgmode/2017-10/msg00099.html>
-rw-r--r--lisp/org.el12
-rw-r--r--testing/lisp/test-org.el5
2 files changed, 11 insertions, 6 deletions
diff --git a/lisp/org.el b/lisp/org.el
index 35405b4..3120fae 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -24230,10 +24230,11 @@ convenience:
(backward-char)
(org-backward-paragraph))
((<= (point) post-affiliated) (goto-char begin))
+ ;; Special behavior: on a table or a property drawer, move to
+ ;; its beginning.
((memq type '(node-property table-row))
(goto-char (org-element-property
:post-affiliated (org-element-property :parent element))))
- ((memq type '(property-drawer table)) (goto-char begin))
(special?
(if (<= (point) contents-begin) (goto-char post-affiliated)
;; Inside a verse block, see blank lines as paragraph
@@ -24244,8 +24245,7 @@ convenience:
(skip-chars-forward " \r\t\n" origin)
(if (= (point) origin) (goto-char contents-begin)
(beginning-of-line))))))
- ((eq type 'paragraph)
- (goto-char contents-begin)
+ ((eq type 'paragraph) (goto-char contents-begin)
;; When at first paragraph in an item or a footnote definition,
;; move directly to beginning of line.
(let ((parent-contents
@@ -24253,9 +24253,9 @@ convenience:
:contents-begin (org-element-property :parent element))))
(when (and parent-contents (= parent-contents contents-begin))
(beginning-of-line))))
- ;; At the end of a greater element, move to the beginning of the
- ;; last element within.
- ((>= (point) contents-end)
+ ;; At the end of a greater element, move to the beginning of
+ ;; the last element within.
+ ((and contents-end (>= (point) contents-end))
(goto-char (1- contents-end))
(org-backward-paragraph))
(t (goto-char (or post-affiliated begin))))
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 4023ec4..0ac3e60 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -3607,6 +3607,11 @@ SCHEDULED: <2017-05-06 Sat>
(should
(org-test-with-temp-text "#+BEGIN_<point>EXAMPLE\nL1\n#+END_EXAMPLE"
(org-backward-paragraph)
+ (bobp)))
+ ;; Pathological case: on an empty heading, move to its beginning.
+ (should
+ (org-test-with-temp-text "* <point>H"
+ (org-backward-paragraph)
(bobp))))
(ert-deftest test-org/forward-element ()