Apply formatting correctly to text in headline

This commit is contained in:
Chris Barrett
2022-09-01 21:02:17 +12:00
parent bca4034ae7
commit 253872c03d

View File

@@ -12,6 +12,7 @@
;;; Code:
(require 'org)
(require 'thingatpt)
(defgroup org-format nil
"Automatically format org buffers on save."
@@ -53,6 +54,12 @@ Only applies to level-1 headings in the document."
(defun org-format--delete-empty-lines ()
(goto-char (line-beginning-position))
(while (thing-at-point-looking-at (rx bol (* space) eol))
(delete-region (line-beginning-position) (1+ (line-end-position)))))
(defun org-format--ensure-empty-lines (n)
(save-excursion
(goto-char (line-beginning-position))
@@ -95,11 +102,11 @@ Only applies to level-1 headings in the document."
org-format-blank-lines-before-subheadings))))
(org-format--ensure-empty-lines headline-spacing)))
(unless (or (org-at-heading-p)
(when (fboundp 'org-transclusion-within-transclusion-p)
(org-transclusion-within-transclusion-p)))
(unless (and (fboundp 'org-transclusion-within-transclusion-p)
(org-transclusion-within-transclusion-p))
(forward-line 1)
(org-format--delete-empty-lines)
(org-format--ensure-empty-lines org-format-blank-lines-before-meta)
(org-end-of-meta-data t)
(org-format--ensure-empty-lines org-format-blank-lines-before-content)))
t