From 35ac6222ea2b5763859c9a35fac412dfa13c1d8e Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Sat, 21 Aug 2021 22:13:36 -0700 Subject: Buffer beautification. --- smart-documents.org | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/smart-documents.org b/smart-documents.org index 71404ea..1736c30 100644 --- a/smart-documents.org +++ b/smart-documents.org @@ -1463,9 +1463,9 @@ PDF. The binding is defined in Section [[Export to PDF]]. major-mode))))) #+END_SRC -** Whole buffer +** Operate on whole buffer -*** Indent +*** Fix indentation #+BEGIN_SRC emacs-lisp :tangle yes (defun sd-indent-buffer () @@ -1477,6 +1477,8 @@ PDF. The binding is defined in Section [[Export to PDF]]. *** Beautify +**** All types of buffers + #+BEGIN_SRC emacs-lisp :tangle yes (defun sd-beautify-buffer () "Clean up buffer in the most general sense. @@ -1488,9 +1490,27 @@ PDF. The binding is defined in Section [[Export to PDF]]. As well as a couple other things." (interactive) (sd-indent-buffer) - (delete-trailing-whitespace)) + (delete-trailing-whitespace) + (when (string-equal + major-mode "org-mode") + (sd-org-fix-headlines-spacing))) + + #+END_SRC +**** COMMENT For Org mode, specifically + +#+BEGIN_SRC emacs-lisp :tangle yes + (defun sd-org-fix-headlines-spacing () + "Insert the proper amount of newlines between Org headlines." + (save-excursion + (progn + (goto-char (point-min)) + (mark-whole-buffer) + (delete-blank-lines) + (org-next-visible-heading) + (re-search-backward "^$"))) +#+END_SRC ** Smart quitting -- cgit v1.2.3