diff --git a/contrib/lisp/org-element.el b/contrib/lisp/org-element.el index bb9d064c9..37bb04f88 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 48621aad6..c0d0dcc21 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