From 88dbb4f82b66ecb75cc2d2d6a0c190ae8c1a31b2 Mon Sep 17 00:00:00 2001 From: Nicolas Petton Date: Mon, 22 Feb 2021 15:38:58 +0100 Subject: Fix empty line before linked references Ensure one empty line before backlink section, but put the start marker on the heading line instead of the empty line above it. --- nroam.el | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'nroam.el') diff --git a/nroam.el b/nroam.el index 6fffa07..792f2fb 100644 --- a/nroam.el +++ b/nroam.el @@ -34,7 +34,7 @@ ;; ;; TODO: ;; - [x] Jump to reference on RET. -;; - [ ] Ensure one empty line before backlink section, but do put the start marker on the heading line. +;; - [x] Ensure one empty line before backlink section, but do put the start marker on the heading line. ;; - [x] Shift the level of headings in references ;; - [x] Hide drawers in the backlink sections. ;; - [x] Fix relative links (esp important with diaries that are in a subdirectory). @@ -59,6 +59,7 @@ Make the region inserted by BODY read-only, and marked with `(let ((beg (point))) (set-marker nroam-start-marker (point)) ,@body + (put-text-property beg (1+ beg) 'front-sticky '(read-only)) (put-text-property beg (point) 'read-only t) (set-marker nroam-end-marker (point)))) @@ -108,6 +109,7 @@ Make the region inserted by BODY read-only, and marked with (interactive) (nroam--setup-markers) (nroam--prune-backlinks) + (nroam--ensure-empty-line) (nroam--insert-backlinks)) (defun nroam--update-backlinks-maybe () @@ -144,7 +146,6 @@ Make the region inserted by BODY read-only, and marked with (save-excursion (goto-char (point-max)) (with-nroam-markers - (insert "\n") (nroam--insert-backlinks-heading (seq-length backlinks)) (seq-do #'nroam--insert-backlink-group groups))) (nroam--hide-drawers)))) @@ -253,5 +254,12 @@ Temporary fix until `org-roam' v2 is out." thing (if (> n 1) "s" ""))) +(defun nroam--ensure-empty-line () + "Insert a newline character if the buffer does not end with a newline." + (let ((inhibit-read-only t)) + (save-excursion + (goto-char (point-max)) + (unless (eq ?\n (char-before (1- (point)))) (insert "\n"))))) + (provide 'nroam) ;;; nroam.el ends here -- cgit v1.2.3-54-g00ecf