From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marco Wahl Subject: [RFC] org-style Date: Fri, 10 May 2019 13:55:08 +0200 Message-ID: <84k1eyv80z.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([209.51.188.92]:42654) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP47W-0006uM-Gd for emacs-orgmode@gnu.org; Fri, 10 May 2019 07:55:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP47V-00006f-DG for emacs-orgmode@gnu.org; Fri, 10 May 2019 07:55:22 -0400 Received: from [195.159.176.226] (port=55754 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hP47R-0008Bk-MA for emacs-orgmode@gnu.org; Fri, 10 May 2019 07:55:21 -0400 Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1hP47O-000mJ7-9B for emacs-orgmode@gnu.org; Fri, 10 May 2019 13:55:14 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org Hi all, For some time now I enforce a simple "style" for my org-mode files on save. Concretely the style is just assuring the number of blank lines immediately before a heading and the number of blank lines after the meta section, e.g. a property-drawer, in each subtree. This unifies my org files and I don't change blank lines by hand very often any more. What do you think about this? Is this worth to merge into org mode? Ciao, Marco P.S.: I have the code below in my init.el. #v+ (defcustom org-style-blanklines-num-before-heading 1 "Number of blank lines before each heading.") (defcustom org-style-blanklines-num-after-meta 1 "Number of blank lines after the heading meta section. If this happens to be a section before a heading the value of `num-blanklines-before-heading' is taken.") (defun org-style-blanklines-assure (num) "Assure exactly NUM blanklines and set point to the end of those. The buffer remains unchanged when the blanklines are already there." (skip-chars-backward "\t \n") (let ((numplusone-newlines (make-string (1+ num) ?\n))) (if (looking-at (concat numplusone-newlines "[^\n]")) (goto-char (1- (match-end 0))) (delete-region (point) (progn (skip-chars-forward "\t \n") (point))) (insert numplusone-newlines)))) (defun org-style-blanklines-at-headings () "Apply blank lines style. This is the number of blank lines: . before a heading`org-style-num-blanklines-before-heading' and . after the org meta data `org-style-num-blanklines-after-meta'." (goto-char (point-min)) (unless (org-at-heading-p) (outline-next-heading)) (while (and (not (eobp)) (< (point) (point-max))) (cl-assert (org-at-heading-p) "programming logic error. shoot a programmer, but not me") (org-style-blanklines-assure org-style-blanklines-num-before-heading) (org-style-blanklines-after-next-meta-data org-style-blanklines-num-after-meta) (unless (org-at-heading-p) (outline-next-heading)))) (defun org-style-blanklines-after-next-meta-data (num) "Assure exactly NUM blanklines after next meta data. When end of meta data is a headline, then leave point there and do nothing else." (org-end-of-meta-data t) (unless (org-at-heading-p) (org-style-blanklines-assure num))) ;; style the org-mode buffer before save. (add-hook 'before-save-hook (lambda () (when (equal 'org-mode major-mode) (save-excursion (org-style-blanklines-at-headings))))) #v-