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
|
||||
(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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue