From 2227a176910ae29a9e469b43b4a51e0cb3328aa7 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sat, 28 Jul 2012 14:35:35 +0200 Subject: [PATCH] org-element: Fix paragraph parsing * lisp/org-element.el (org-element-paragraph-separate): Refactor. (org-element-paragraph-parser): Fix paragraph parsing. * testing/lisp/test-org-element.el: Add test. --- lisp/org-element.el | 19 ++++++++----------- testing/lisp/test-org-element.el | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index 67b2c3b4b..f8cf1497d 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -124,7 +124,7 @@ ;; process. (defconst org-element-paragraph-separate - (concat "\f" "\\|" "^[ \t]*$" "\\|" + (concat "^[ \t]*$" "\\|" ;; Headlines and inlinetasks. org-outline-regexp-bol "\\|" ;; Comments, blocks (any type), keywords and babel calls. @@ -140,11 +140,7 @@ ;; LaTeX environments. "^[ \t]*\\\\\\(begin\\|end\\)" "\\|" ;; Planning and Clock lines. - "^[ \t]*\\(?:" - org-clock-string "\\|" - org-closed-string "\\|" - org-deadline-string "\\|" - org-scheduled-string "\\)") + org-planning-or-clock-line-re) "Regexp to separate paragraphs in an Org buffer.") (defconst org-element-all-elements @@ -1691,15 +1687,16 @@ Assume point is at the beginning of the paragraph." (let* ((contents-begin (point)) (keywords (org-element--collect-affiliated-keywords)) (begin (car keywords)) - (contents-end + (before-blank (progn (end-of-line) (if (re-search-forward org-element-paragraph-separate limit 'm) - (progn (forward-line -1) (end-of-line) (point)) + (goto-char (match-beginning 0)) (point)))) - (pos-before-blank (progn (forward-line) (point))) - (end (progn (org-skip-whitespace) + (contents-end (progn (skip-chars-backward " \r\t\n" contents-begin) + (line-end-position))) + (end (progn (skip-chars-forward " \r\t\n" limit) (if (eobp) (point) (point-at-bol))))) (list 'paragraph ;; If paragraph has no affiliated keywords, it may not begin @@ -1709,7 +1706,7 @@ Assume point is at the beginning of the paragraph." :end end :contents-begin contents-begin :contents-end contents-end - :post-blank (count-lines pos-before-blank end)) + :post-blank (count-lines before-blank end)) (cadr keywords)))))) (defun org-element-paragraph-interpreter (paragraph contents) diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index f4f0eb26e..e9df6e3af 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -1119,6 +1119,24 @@ e^{i\\pi}+1=0 (org-element-map (org-element-parse-buffer) 'macro 'identity)))) +;;;; Paragraph + +(ert-deftest test-org-element/paragraph-parser () + "Test `paragraph' parser." + ;; Standard test. + (should + (org-test-with-temp-text "Paragraph" + (org-element-map (org-element-parse-buffer) 'paragraph 'identity nil t))) + ;; Property find end of a paragraph stuck to another element. + (should + (eq ?# + (org-test-with-temp-text "Paragraph\n# Comment" + (org-element-map + (org-element-parse-buffer) 'paragraph + (lambda (p) (char-after (org-element-property :end p))) + nil t))))) + + ;;;; Plain List (ert-deftest test-org-element/plain-list-parser ()