From 253872c03ddd5f28c0b27895f01d07c1f7a38c41 Mon Sep 17 00:00:00 2001 From: Chris Barrett Date: Thu, 1 Sep 2022 21:02:17 +1200 Subject: [PATCH] Apply formatting correctly to text in headline --- lisp/org-format.el | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lisp/org-format.el b/lisp/org-format.el index 372e053..55c846b 100644 --- a/lisp/org-format.el +++ b/lisp/org-format.el @@ -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