Kyle Meyer пре 4 година
родитељ
комит
3e39f82cd4
2 измењених фајлова са 66 додато и 4 уклоњено
  1. 5 4
      lisp/org.el
  2. 61 0
      testing/lisp/test-org.el

+ 5 - 4
lisp/org.el

@@ -7396,10 +7396,11 @@ Assume point is at a heading or an inlinetask beginning."
      (org-indent-region (match-beginning 0) (match-end 0)))
    (when (looking-at org-logbook-drawer-re)
      (let ((end-marker  (move-marker (make-marker) (match-end 0)))
-	   (ci (current-indentation)))
-       (while (and (not (> (point) end-marker)) (>= ci diff))
-	 (indent-line-to (+ ci diff))
-	 (forward-line))))
+	   (col (+ (current-indentation) diff)))
+       (when (wholenump col)
+	 (while (< (point) end-marker)
+	   (indent-line-to col)
+	   (forward-line)))))
    (catch 'no-shift
      (when (or (zerop diff) (not (eq org-adapt-indentation t)))
        (throw 'no-shift nil))

+ 61 - 0
testing/lisp/test-org.el

@@ -4710,6 +4710,32 @@ Text.
 	    (org-demote)
 	    (forward-line 2)
 	    (org-get-indentation))))))
+  ;; When `org-adapt-indentation' is non-nil, log drawers are
+  ;; adjusted.
+  (should
+   (equal
+    "** H\n   :LOGBOOK:\n   - a\n   :END:\n   b"
+    (org-test-with-temp-text "* H\n  :LOGBOOK:\n  - a\n  :END:\n  b"
+      (let ((org-odd-levels-only nil)
+	    (org-adapt-indentation t))
+	(org-demote))
+      (buffer-string))))
+  (should
+   (equal
+    "** H\n   :LOGBOOK:\n   - a\n   :END:\n  b"
+    (org-test-with-temp-text "* H\n  :LOGBOOK:\n  - a\n  :END:\n  b"
+      (let ((org-odd-levels-only nil)
+	    (org-adapt-indentation 'headline-data))
+	(org-demote))
+      (buffer-string))))
+  (should
+   (equal
+    "** H\n :LOGBOOK:\n - a\n :END:"
+    (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
+      (let ((org-odd-levels-only nil)
+	    (org-adapt-indentation t))
+	(org-demote))
+      (buffer-string))))
   ;; Ignore contents of source blocks or example blocks when
   ;; indentation should be preserved (through
   ;; `org-src-preserve-indentation' or "-i" flag).
@@ -4878,6 +4904,41 @@ Text.
 	  (org-promote))
 	(forward-line)
 	(org-get-indentation))))
+  ;; When `org-adapt-indentation' is non-nil, log drawers are
+  ;; adjusted.
+  (should
+   (equal
+    "* H\n  :LOGBOOK:\n  - a\n  :END:\n  b"
+    (org-test-with-temp-text "** H\n   :LOGBOOK:\n   - a\n   :END:\n   b"
+      (let ((org-odd-levels-only nil)
+	    (org-adapt-indentation t))
+	(org-promote))
+      (buffer-string))))
+  (should
+   (equal
+    "* H\n  :LOGBOOK:\n  - a\n  :END:\n   b"
+    (org-test-with-temp-text "** H\n   :LOGBOOK:\n   - a\n   :END:\n   b"
+      (let ((org-odd-levels-only nil)
+	    (org-adapt-indentation 'headline-data))
+	(org-promote))
+      (buffer-string))))
+  (should
+   (equal
+    "* H\n:LOGBOOK:\n- a\n:END:"
+    (org-test-with-temp-text "** H\n:LOGBOOK:\n- a\n:END:"
+      (let ((org-odd-levels-only nil)
+	    (org-adapt-indentation t))
+	(org-promote))
+      (buffer-string))))
+  (should
+   (equal
+    "# H\n:LOGBOOK:\n- a\n:END:"
+    (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
+      (let ((org-odd-levels-only nil)
+	    (org-allow-promoting-top-level-subtree t)
+	    (org-adapt-indentation t))
+	(org-promote))
+      (buffer-string))))
   ;; Ignore contents of source blocks or example blocks when
   ;; indentation should be preserved (through
   ;; `org-src-preserve-indentation' or "-i" flag).