From 2de58df0522a0207958d5808c0ddfa92ece0bc05 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Fri, 3 Oct 2025 10:31:33 +0200 Subject: [PATCH] (Try to) fix indentation of Org headings converted from list items Not quite sure whether this is it, but looks better than before. --- site-lisp/db-org.el | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/site-lisp/db-org.el b/site-lisp/db-org.el index e600b53..7816705 100644 --- a/site-lisp/db-org.el +++ b/site-lisp/db-org.el @@ -430,6 +430,8 @@ history of the buffer." ;; Generate headline and store it somewhere (let* ((body (buffer-substring-no-properties (org-element-contents-begin last-seen-item) (org-element-end last-seen-item))) + (indent-offset (- (org-element-begin last-seen-item) + (org-element-contents-begin last-seen-item))) (first-line-of-body (seq-take-while #'(lambda (x) (not (= x ?\n))) body)) (rest-of-body (string-trim (seq-drop-while #'(lambda (x) (not (= x ?\n))) body)))) @@ -437,6 +439,12 @@ history of the buffer." (delete-region (org-element-begin last-seen-item) (org-element-end last-seen-item)) + ;; Adjust indentation of `rest-of-body' by `indent-offset' + (with-temp-buffer + (insert rest-of-body) + (indent-region (point-min) (point-max) indent-offset) + (setq rest-of-body (buffer-string))) + ;; Set up capture buffer (org-capture-put :key "") (org-capture-put :description "") @@ -461,10 +469,7 @@ Via %%(with-temp-buffer (db/org-add-link-to-current-clock) (string-trim (buffer- (org-capture-set-target-location) (org-capture-place-template) - (indent-region (point-min) (point-max)) - ;; Ensure that two line breaks are placed at the end of the heading - (goto-char (point-max)) (while (looking-back "\n" 1) (delete-char -1))