Просмотр исходного кода

org-element: Fix parsing when a keyword follows the commented line

* lisp/org-element.el (org-element-comment-parser): Fix parsing when
  a keyword follows the commented line.
* testing/lisp/test-org-element.el: Add test.
Nicolas Goaziou 12 лет назад
Родитель
Сommit
eb2eacf91d
2 измененных файлов с 25 добавлено и 5 удалено
  1. 10 3
      lisp/org-element.el
  2. 15 2
      testing/lisp/test-org-element.el

+ 10 - 3
lisp/org-element.el

@@ -1358,17 +1358,24 @@ 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 (prog2 (looking-at "[ \t]*#\\+? ?")
+		      (buffer-substring-no-properties
+		       (match-end 0) (line-end-position))
+		    (forward-line)))
 	   (com-end
 	    ;; Get comments ending.
 	    (progn
-	      (while (and (< (point) limit) (looking-at "[ \t]*# ?"))
+	      (while (and (< (point) limit) (looking-at "[ \t]*#\\( \\|$\\)"))
 		;; Accumulate lines without leading hash and first
 		;; whitespace.
 		(setq value
 		      (concat value
+			      "\n"
 			      (buffer-substring-no-properties
-			       (match-end 0) (progn (forward-line) (point))))))
+			       (match-end 0) (line-end-position))))
+		(forward-line))
 	      (point)))
 	   (end (progn (goto-char com-end)
 		       (skip-chars-forward " \r\t\n" limit)

+ 15 - 2
testing/lisp/test-org-element.el

@@ -288,7 +288,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"))
+    "No blank\n One blank"))
   ;; Comment with blank lines.
   (should
    (equal
@@ -300,7 +300,20 @@ CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] =>  0:01"
   ;; 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))))
+     (org-element-map (org-element-parse-buffer) 'comment 'identity)))
+  ;; Do not mix comments and keywords.
+  (should
+   (eq 1
+       (org-test-with-temp-text "#+keyword: value\n# comment\n#+keyword: value"
+	 (length (org-element-map
+		  (org-element-parse-buffer) 'comment 'identity)))))
+  (should
+   (equal "comment"
+	  (org-test-with-temp-text "#+keyword: value\n# comment\n#+keyword: value"
+	    (org-element-property
+	     :value
+	     (org-element-map
+	      (org-element-parse-buffer) 'comment 'identity nil t))))))
 
 
 ;;;; Comment Block