1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-29 07:58:21 +00:00

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.
This commit is contained in:
Nicolas Goaziou 2012-07-28 14:35:35 +02:00
parent b04f9e3268
commit 2227a17691
2 changed files with 26 additions and 11 deletions

View File

@ -124,7 +124,7 @@
;; process. ;; process.
(defconst org-element-paragraph-separate (defconst org-element-paragraph-separate
(concat "\f" "\\|" "^[ \t]*$" "\\|" (concat "^[ \t]*$" "\\|"
;; Headlines and inlinetasks. ;; Headlines and inlinetasks.
org-outline-regexp-bol "\\|" org-outline-regexp-bol "\\|"
;; Comments, blocks (any type), keywords and babel calls. ;; Comments, blocks (any type), keywords and babel calls.
@ -140,11 +140,7 @@
;; LaTeX environments. ;; LaTeX environments.
"^[ \t]*\\\\\\(begin\\|end\\)" "\\|" "^[ \t]*\\\\\\(begin\\|end\\)" "\\|"
;; Planning and Clock lines. ;; Planning and Clock lines.
"^[ \t]*\\(?:" org-planning-or-clock-line-re)
org-clock-string "\\|"
org-closed-string "\\|"
org-deadline-string "\\|"
org-scheduled-string "\\)")
"Regexp to separate paragraphs in an Org buffer.") "Regexp to separate paragraphs in an Org buffer.")
(defconst org-element-all-elements (defconst org-element-all-elements
@ -1691,15 +1687,16 @@ Assume point is at the beginning of the paragraph."
(let* ((contents-begin (point)) (let* ((contents-begin (point))
(keywords (org-element--collect-affiliated-keywords)) (keywords (org-element--collect-affiliated-keywords))
(begin (car keywords)) (begin (car keywords))
(contents-end (before-blank
(progn (end-of-line) (progn (end-of-line)
(if (re-search-forward org-element-paragraph-separate (if (re-search-forward org-element-paragraph-separate
limit limit
'm) 'm)
(progn (forward-line -1) (end-of-line) (point)) (goto-char (match-beginning 0))
(point)))) (point))))
(pos-before-blank (progn (forward-line) (point))) (contents-end (progn (skip-chars-backward " \r\t\n" contents-begin)
(end (progn (org-skip-whitespace) (line-end-position)))
(end (progn (skip-chars-forward " \r\t\n" limit)
(if (eobp) (point) (point-at-bol))))) (if (eobp) (point) (point-at-bol)))))
(list 'paragraph (list 'paragraph
;; If paragraph has no affiliated keywords, it may not begin ;; 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 :end end
:contents-begin contents-begin :contents-begin contents-begin
:contents-end contents-end :contents-end contents-end
:post-blank (count-lines pos-before-blank end)) :post-blank (count-lines before-blank end))
(cadr keywords)))))) (cadr keywords))))))
(defun org-element-paragraph-interpreter (paragraph contents) (defun org-element-paragraph-interpreter (paragraph contents)

View File

@ -1119,6 +1119,24 @@ e^{i\\pi}+1=0
(org-element-map (org-element-parse-buffer) 'macro 'identity)))) (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 ;;;; Plain List
(ert-deftest test-org-element/plain-list-parser () (ert-deftest test-org-element/plain-list-parser ()