From 4ff1c7d89b944ea9bdef4e9d47915e5f4fe56cc6 Mon Sep 17 00:00:00 2001 From: Nicolas Petton Date: Thu, 25 Feb 2021 09:58:01 +0100 Subject: Ensure one empty line between each heading in nroam sections * nroam.el (nroam--do-separated-by-newlines): New function. (nroam-backlinks-section): (nroam--insert): (nroam--insert-backlink-group): Call `nroam--do-separated-by-newlines' to ensure one empty line is inserted between headings. --- nroam.el | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'nroam.el') diff --git a/nroam.el b/nroam.el index 84af184..54a1a30 100644 --- a/nroam.el +++ b/nroam.el @@ -136,7 +136,7 @@ Make the region inserted by BODY read-only, and marked with (groups (seq-reverse (nroam--group-backlinks backlinks)))) (nroam--ensure-empty-line) (nroam--insert-backlinks-heading (seq-length backlinks)) - (seq-do #'nroam--insert-backlink-group groups) + (nroam--do-separated-by-newlines #'nroam--insert-backlink-group groups) (nroam--hide-drawers))) (defun nroam--org-roam-file-p () @@ -191,7 +191,7 @@ Make the region inserted by BODY read-only, and marked with (goto-char p) (nroam--ensure-empty-line) (with-nroam-markers - (seq-do #'funcall nroam-sections)) + (nroam--do-separated-by-newlines #'funcall nroam-sections)) (when (nroam--sections-inserted-p) (save-restriction (narrow-to-region p (point-max)) @@ -219,16 +219,12 @@ Make the region inserted by BODY read-only, and marked with "Insert all backlinks in GROUP." (let ((file (car group)) (backlinks (cdr group))) - (insert (format "\n** %s\n" + (insert (format "** %s\n" (org-roam-format-link file (org-roam-db--get-title file) "file"))) - (seq-do-indexed (lambda (backlink index) - (nroam--insert-backlink backlink) - (when (< index (1- (seq-length backlinks))) - (insert "\n"))) - backlinks))) + (nroam--do-separated-by-newlines #'nroam--insert-backlink backlinks))) (defun nroam--insert-backlink (backlink) "Insert a link to the org-roam BACKLINK." @@ -309,5 +305,15 @@ Temporary fix until `org-roam' v2 is out." (goto-char (point-max)) (unless (eq ?\n (char-before (1- (point)))) (insert "\n")))) +(defun nroam--do-separated-by-newlines (function sequence) + "Apply FUNCTION to each element of SEQUENCE. +Insert a single newline between each call to FUNCTION." + (seq-do-indexed (lambda (item index) + (unless (= index 0) + (delete-blank-lines) + (nroam--ensure-empty-line)) + (funcall function item)) + sequence)) + (provide 'nroam) ;;; nroam.el ends here -- cgit v1.2.3-54-g00ecf