diff options
author | Nicolas Goaziou <n.goaziou@gmail.com> | 2013-09-18 21:15:04 +0200 |
---|---|---|
committer | Nicolas Goaziou <n.goaziou@gmail.com> | 2013-09-18 21:15:04 +0200 |
commit | 41cf6f2a3687a6edeccb9171e056d2017b17f7df (patch) | |
tree | a7a14a351e1f3c7308a475a7a7b8c57f1be9afdb | |
parent | 072f2abe4cdb57d01262e28858330f1e22de5e6f (diff) | |
download | org-mode-41cf6f2a3687a6edeccb9171e056d2017b17f7df.tar.gz |
org-element: Fix `org-element-at-point' at end of buffer
* lisp/org-element.el (org-element-at-point): If point is at the end
of the buffer, and that buffer ends with a list, and there's no
final newline, return last element in last item instead of plain
list.
* testing/lisp/test-org-element.el: Add test.
This fix allows to fill correctly the following construct:
- Item with a very long line ending at the end of buffer.
-rw-r--r-- | lisp/org-element.el | 17 | ||||
-rw-r--r-- | testing/lisp/test-org-element.el | 7 |
2 files changed, 19 insertions, 5 deletions
diff --git a/lisp/org-element.el b/lisp/org-element.el index 2dade91..807fdb4 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -4781,11 +4781,18 @@ first element of current section." ;; into elements with an explicit ending, but ;; return that element instead. (and (= cend origin) - (memq type - '(center-block - drawer dynamic-block inlinetask item - plain-list property-drawer quote-block - special-block)))) + (or (memq type + '(center-block + drawer dynamic-block inlinetask + property-drawer quote-block + special-block)) + ;; Corner case: if a list ends at the + ;; end of a buffer without a final new + ;; line, return last element in last + ;; item instead. + (and (memq type '(item plain-list)) + (progn (goto-char cend) + (or (bolp) (not (eobp)))))))) (throw 'exit (if keep-trail trail element)) (setq parent element) (case type diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index 76cdfda..ea4f649 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -2865,6 +2865,13 @@ Paragraph \\alpha." (org-test-with-temp-text "- Para1\n- Para2\n\nPara3" (progn (forward-line 2) (org-element-type (org-element-at-point)))))) + ;; Special case: when a list ends at the end of buffer and there's + ;; no final newline, return last element in last item. + (should + (eq 'paragraph + (org-test-with-temp-text "- a" + (end-of-line) + (org-element-type (org-element-at-point))))) ;; With an optional argument, return trail. (should (equal '(paragraph center-block) |