From 2eef05cb801826015c7818737ebe0b10344b0fb7 Mon Sep 17 00:00:00 2001 From: contrapunctus Date: Sun, 6 Feb 2022 17:38:19 +0530 Subject: [PATCH] Create helper command my-org-fix-newlines --- init.org | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/init.org b/init.org index 24c1c0b..8305e1b 100644 --- a/init.org +++ b/init.org @@ -4096,6 +4096,29 @@ From https://emacs.stackexchange.com/questions/20577/org-babel-load-all-language ad-do-it)) #+END_SRC +*** my-org-fix-newlines +#+BEGIN_SRC emacs-lisp +(defun my-org-fix-newlines () + "Insert newlines around Org headings. +Newlines are inserted before headings (unless immediately +preceded by another heading) and after headings." + (interactive) + (org-map-tree + (lambda () + (save-excursion + (forward-line -1) + (goto-char (point-at-bol)) + (unless (or (looking-at-p "^$") + (org-at-heading-p)) + (goto-char (point-at-eol)) + (insert "\n"))) + (save-excursion + (forward-line) + (goto-char (point-at-bol)) + (when (looking-at-p "^$") + (join-line)))))) +#+END_SRC + *** org-html-themify #+BEGIN_SRC emacs-lisp (use-package org-html-themify