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