summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2012-05-20 16:54:45 +0200
committerNicolas Goaziou <n.goaziou@gmail.com>2012-05-20 17:33:36 +0200
commit42f7ba0d0238f88a1aad9e29958969fdee5e10c6 (patch)
treeebe357cc7377a63cdbc90cc644a3a74b2f0fda46
parent65c0e18892829ef2adb51ff3e486e7e239a615ab (diff)
downloadorg-mode-42f7ba0d0238f88a1aad9e29958969fdee5e10c6.tar.gz
org-element: Fix ill-defined keywords parsing
* contrib/lisp/org-element.el (org-element-comment-parser): Ill-defined keywords (without the colons) are treated as comments. (org-element-comment-interpreter): Apply changes to lexer. * testing/lisp/test-org-element.el: Add test.
-rw-r--r--contrib/lisp/org-element.el16
-rw-r--r--testing/lisp/test-org-element.el8
2 files changed, 15 insertions, 9 deletions
diff --git a/contrib/lisp/org-element.el b/contrib/lisp/org-element.el
index bb9d064..37bb04f 100644
--- a/contrib/lisp/org-element.el
+++ b/contrib/lisp/org-element.el
@@ -963,7 +963,12 @@ Assume point is at comment beginning."
(save-excursion
(let* ((keywords (org-element-collect-affiliated-keywords))
(begin (car keywords))
- value
+ ;; Match first line with a loose regexp since it might as
+ ;; well be an ill-defined keyword.
+ (value (progn
+ (looking-at "#\\+? ?")
+ (buffer-substring-no-properties
+ (match-end 0) (progn (forward-line) (point)))))
(com-end
;; Get comments ending. This may not be accurate if
;; commented lines within an item are followed by
@@ -977,9 +982,8 @@ Assume point is at comment beginning."
(setq value
(concat value
(buffer-substring-no-properties
- (or (match-end 2) (match-end 3)) (point-at-eol))
- "\n"))
- (forward-line))
+ (or (match-end 2) (match-end 3))
+ (progn (forward-line) (point))))))
(point)))
(end (progn (goto-char com-end)
(org-skip-whitespace)
@@ -994,9 +998,7 @@ Assume point is at comment beginning."
(defun org-element-comment-interpreter (comment contents)
"Interpret COMMENT element as Org syntax.
CONTENTS is nil."
- (replace-regexp-in-string
- "^" "#+ "
- (substring (org-element-property :value comment) 0 -1)))
+ (replace-regexp-in-string "^" "#+ " (org-element-property :value comment)))
;;;; Comment Block
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index 48621aa..c0d0dcc 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -195,7 +195,7 @@ CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] => 0:01"
:value
(org-test-with-temp-text "#+ No blank\n#+ One blank"
(org-element-map (org-element-parse-buffer) 'comment 'identity nil t)))
- "No blank\n One blank\n"))
+ "No blank\n One blank"))
;; Comment with blank lines.
(should
(equal
@@ -203,7 +203,11 @@ CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] => 0:01"
:value
(org-test-with-temp-text "#+ First part\n#+ \n#+\n#+ Second part"
(org-element-map (org-element-parse-buffer) 'comment 'identity nil t)))
- "First part\n\n\nSecond part\n")))
+ "First part\n\n\nSecond part"))
+ ;; Keywords without colons are treated as comments.
+ (should
+ (org-test-with-temp-text "#+wrong_keyword something"
+ (org-element-map (org-element-parse-buffer) 'comment 'identity))))
;;;; Comment Block