Jelajahi Sumber

lint: Catch misleading drawers within drawers

* lisp/org-lint.el (org-lint-incomplete-drawer): Catch misleading
drawers within drawers.
* testing/lisp/test-org-lint.el (test-org-lint/incomplete-drawer): Add
test.
Nicolas Goaziou 4 tahun lalu
induk
melakukan
516c038e5f
2 mengubah file dengan 17 tambahan dan 4 penghapusan
  1. 14 4
      lisp/org-lint.el
  2. 3 0
      testing/lisp/test-org-lint.el

+ 14 - 4
lisp/org-lint.el

@@ -794,15 +794,25 @@ Use \"export %s\" instead"
       (let ((name (org-trim (match-string-no-properties 0)))
 	    (element (org-element-at-point)))
 	(pcase (org-element-type element)
-	  ((or `drawer `property-drawer)
-	   (goto-char (org-element-property :end element))
-	   nil)
+	  (`drawer
+	   ;; Find drawer opening lines within non-empty drawers.
+	   (let ((end (org-element-property :contents-end element)))
+	     (when end
+	       (while (re-search-forward org-drawer-regexp end t)
+		 (let ((n (org-trim (match-string-no-properties 0))))
+		   (push (list (line-beginning-position)
+			       (format "Possible misleading drawer entry %S" n))
+			 reports))))
+	     (goto-char (org-element-property :end element))))
+	  (`property-drawer
+	   (goto-char (org-element-property :end element)))
 	  ((or `comment-block `example-block `export-block `src-block
 	       `verse-block)
 	   nil)
 	  (_
+	   ;; Find drawer opening lines outside of any drawer.
 	   (push (list (line-beginning-position)
-		       (format "Possible incomplete drawer \"%s\"" name))
+		       (format "Possible incomplete drawer %S" name))
 		 reports)))))
     reports))
 

+ 3 - 0
testing/lisp/test-org-lint.el

@@ -393,6 +393,9 @@ SCHEDULED: <2012-03-29 thu.>"
   (should
    (org-test-with-temp-text ":DRAWER:"
      (org-lint '(incomplete-drawer))))
+  (should
+   (org-test-with-temp-text ":DRAWER:\n:ODD:\n:END:"
+     (org-lint '(incomplete-drawer))))
   (should-not
    (org-test-with-temp-text ":DRAWER:\n:END:"
      (org-lint '(incomplete-drawer)))))