From 8d09d1aaa9534d63d40f27c79737ab89664b4e3b Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sat, 1 Sep 2012 22:52:43 +0200 Subject: [PATCH] org-element: Fix section parsing * lisp/org-element.el (org-element-section-parser): Make sure section cannot contain an headline. (org-element--current-element): Fix bug requiring to parse a quote section even when point is at an headline. * testing/lisp/test-org-element.el: Add test. --- lisp/org-element.el | 29 ++++++++++++++--------------- testing/lisp/test-org-element.el | 8 +++++++- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index 7bcbcb61a..ebaf3f6f6 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -1184,18 +1184,18 @@ and `:post-blank' keywords." (save-excursion ;; Beginning of section is the beginning of the first non-blank ;; line after previous headline. - (org-with-limited-levels - (let ((begin (point)) - (end (progn (goto-char limit) (point))) - (pos-before-blank (progn (skip-chars-backward " \r\t\n") - (forward-line) - (point)))) - (list 'section - (list :begin begin - :end end - :contents-begin begin - :contents-end pos-before-blank - :post-blank (count-lines pos-before-blank end))))))) + (let ((begin (point)) + (end (progn (org-with-limited-levels (outline-next-heading)) + (point))) + (pos-before-blank (progn (skip-chars-backward " \r\t\n") + (forward-line) + (point)))) + (list 'section + (list :begin begin + :end end + :contents-begin begin + :contents-end pos-before-blank + :post-blank (count-lines pos-before-blank end)))))) (defun org-element-section-interpreter (section contents) "Interpret SECTION element as Org syntax. @@ -3333,15 +3333,14 @@ element it has to parse." ;; Item. ((eq special 'item) (org-element-item-parser limit structure raw-secondary-p)) - ;; Quote Section. - ((eq special 'quote-section) (org-element-quote-section-parser limit)) ;; Table Row. ((eq special 'table-row) (org-element-table-row-parser limit)) ;; Headline. ((org-with-limited-levels (org-at-heading-p)) (org-element-headline-parser limit raw-secondary-p)) - ;; Section (must be checked after headline). + ;; Sections (must be checked after headline). ((eq special 'section) (org-element-section-parser limit)) + ((eq special 'quote-section) (org-element-quote-section-parser limit)) ((eq special 'first-section) (org-element-section-parser (or (save-excursion (org-with-limited-levels (outline-next-heading))) diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index 7271cd349..eb0578d14 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -1325,7 +1325,13 @@ Outside list" ;; A section cannot be empty. (should-not (org-test-with-temp-text "* Headline 1\n* Headline 2" - (org-element-map (org-element-parse-buffer) 'section 'identity)))) + (org-element-map (org-element-parse-buffer) 'section 'identity))) + ;; A section doesn't contain sub-trees. + (should-not + (org-test-with-temp-text "* Head\nText\n** Sub-Head" + (org-element-map + (org-element-map (org-element-parse-buffer) 'section 'identity nil t) + 'headline 'identity)))) ;;;; Special Block