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.
This commit is contained in:
parent
65c0e18892
commit
42f7ba0d02
|
@ -963,7 +963,12 @@ Assume point is at comment beginning."
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(let* ((keywords (org-element-collect-affiliated-keywords))
|
(let* ((keywords (org-element-collect-affiliated-keywords))
|
||||||
(begin (car 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
|
(com-end
|
||||||
;; Get comments ending. This may not be accurate if
|
;; Get comments ending. This may not be accurate if
|
||||||
;; commented lines within an item are followed by
|
;; commented lines within an item are followed by
|
||||||
|
@ -977,9 +982,8 @@ Assume point is at comment beginning."
|
||||||
(setq value
|
(setq value
|
||||||
(concat value
|
(concat value
|
||||||
(buffer-substring-no-properties
|
(buffer-substring-no-properties
|
||||||
(or (match-end 2) (match-end 3)) (point-at-eol))
|
(or (match-end 2) (match-end 3))
|
||||||
"\n"))
|
(progn (forward-line) (point))))))
|
||||||
(forward-line))
|
|
||||||
(point)))
|
(point)))
|
||||||
(end (progn (goto-char com-end)
|
(end (progn (goto-char com-end)
|
||||||
(org-skip-whitespace)
|
(org-skip-whitespace)
|
||||||
|
@ -994,9 +998,7 @@ Assume point is at comment beginning."
|
||||||
(defun org-element-comment-interpreter (comment contents)
|
(defun org-element-comment-interpreter (comment contents)
|
||||||
"Interpret COMMENT element as Org syntax.
|
"Interpret COMMENT element as Org syntax.
|
||||||
CONTENTS is nil."
|
CONTENTS is nil."
|
||||||
(replace-regexp-in-string
|
(replace-regexp-in-string "^" "#+ " (org-element-property :value comment)))
|
||||||
"^" "#+ "
|
|
||||||
(substring (org-element-property :value comment) 0 -1)))
|
|
||||||
|
|
||||||
|
|
||||||
;;;; Comment Block
|
;;;; Comment Block
|
||||||
|
|
|
@ -195,7 +195,7 @@ CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] => 0:01"
|
||||||
:value
|
:value
|
||||||
(org-test-with-temp-text "#+ No blank\n#+ One blank"
|
(org-test-with-temp-text "#+ No blank\n#+ One blank"
|
||||||
(org-element-map (org-element-parse-buffer) 'comment 'identity nil t)))
|
(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.
|
;; Comment with blank lines.
|
||||||
(should
|
(should
|
||||||
(equal
|
(equal
|
||||||
|
@ -203,7 +203,11 @@ CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] => 0:01"
|
||||||
:value
|
:value
|
||||||
(org-test-with-temp-text "#+ First part\n#+ \n#+\n#+ Second part"
|
(org-test-with-temp-text "#+ First part\n#+ \n#+\n#+ Second part"
|
||||||
(org-element-map (org-element-parse-buffer) 'comment 'identity nil t)))
|
(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
|
;;;; Comment Block
|
||||||
|
|
Loading…
Reference in New Issue