瀏覽代碼

Fix newline-issue with document property drawer

A bug was squashed where newlines after insertion of document property
drawers wasn't handled correctly.

* testing/lisp/test-org.el (test-org/insert-property-drawer):
Add test to verify that the document property drawer is
inserted above keyword lines.  Also fix the specification for
document property drawer so it doesn't remove existing blank
rows if inserted at the top of a buffer.

* lisp/org.el (org-insert-property-drawer): Make sure to add
newline after document property drawers.
Gustav Wikström 5 年之前
父節點
當前提交
00646ad817
共有 2 個文件被更改,包括 11 次插入7 次删除
  1. 3 5
      lisp/org.el
  2. 8 2
      testing/lisp/test-org.el

+ 3 - 5
lisp/org.el

@@ -13627,14 +13627,12 @@ drawer is immediately hidden."
      ;; next one.  It prevents extending text properties or overlays
      ;; belonging to the latter.
      (when (and (bolp) (> (point) (point-min))) (backward-char))
-     (let ((begin (if (= (point) (point-min))
-		      (point)
-		    (1+ (point))))
+     (let ((begin (if (bobp) (point) (1+ (point))))
 	   (inhibit-read-only t))
-       (unless (= begin (point-min)) (insert "\n"))
+       (unless (bobp) (insert "\n"))
        (insert ":PROPERTIES:\n:END:")
        (org-flag-drawer t nil (line-end-position 0) (point))
-       (when (eobp) (insert "\n"))
+       (when (or (eobp) (= begin (point-min))) (insert "\n"))
        (org-indent-region begin (point))))))
 
 (defun org-insert-drawer (&optional arg drawer)

+ 8 - 2
testing/lisp/test-org.el

@@ -481,6 +481,12 @@
 	  (org-test-with-temp-text "# C\n#+TITLE: T"
 	    (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
 	    (buffer-string))))
+  ;; Insert drawer in document header with existing keyword.
+  (should
+   (equal ":PROPERTIES:\n:END:\n#+TITLE: T"
+	  (org-test-with-temp-text "#+TITLE: T"
+	    (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
+	    (buffer-string))))
   (should
    (equal ":PROPERTIES:\n:END:"
 	  (org-test-with-temp-text ":PROPERTIES:\n:END:"
@@ -488,8 +494,8 @@
 	    (buffer-string))))
   ;; Insert drawer in document header with one existing heading in buffer.
   (should
-   (equal ":PROPERTIES:\n:END:\n* T\n"
-	  (org-test-with-temp-text "<point>\n* T\n"
+   (equal ":PROPERTIES:\n:END:\n\n* T\n"
+	  (org-test-with-temp-text "\n* T\n"
 	    (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
 	    (buffer-string))))
   ;; Insert drawer right after headline if there is no planning line,