summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorGravatar Damien Pollet2021-03-14 17:48:20 +0100
committerGravatar Damien Pollet2021-03-14 17:48:20 +0100
commit6b5fd99e2e3cc40e564e76ed568807d87221e745 (patch)
tree74f89504148f8229641a51076f86d112fcf5e1e0
parent7ae549a22225eb1dd099cd63726dc164109c92d7 (diff)
downloadnroam-6b5fd99e2e3cc40e564e76ed568807d87221e745.tar.gz
nroam-6b5fd99e2e3cc40e564e76ed568807d87221e745.zip
Organize backlinks under single heading
-rw-r--r--nroam-backlinks.el18
-rw-r--r--nroam-unlinked.el2
-rw-r--r--nroam-utils.el10
-rw-r--r--nroam.el1
4 files changed, 21 insertions, 10 deletions
diff --git a/nroam-backlinks.el b/nroam-backlinks.el
index ff948fe..3d1cb3f 100644
--- a/nroam-backlinks.el
+++ b/nroam-backlinks.el
@@ -56,19 +56,19 @@
(defun nroam-backlinks--insert-heading (count)
"Insert the heading for the backlinks section with a COUNT."
- (insert (format "* %s %s :noexport:\n"
- (if (= count 0) "No" count)
- (nroam--pluralize count "linked reference"))))
+ (let ((title (format "%s %s"
+ (if (= count 0) "No" count)
+ (nroam--pluralize count "linked reference"))))
+ (nroam--insert-heading 2 title)))
(defun nroam-backlinks--insert-group (group)
"Insert all backlinks in GROUP."
(let ((file (car group))
- (backlinks (cdr group)))
- (insert (format "** %s\n"
- (org-roam-format-link
- file
- (org-roam-db--get-title file)
- "file")))
+ (backlinks (cdr group))
+ (title (org-roam-format-link file
+ (org-roam-db--get-title file)
+ "file")))
+ (nroam--insert-heading 3 title)
(nroam--do-separated-by-newlines #'nroam-backlinks--insert-backlink backlinks)))
(defun nroam-backlinks--insert-backlink (backlink)
diff --git a/nroam-unlinked.el b/nroam-unlinked.el
index b989de3..5f511a4 100644
--- a/nroam-unlinked.el
+++ b/nroam-unlinked.el
@@ -44,7 +44,7 @@
(defun nroam-unlinked--insert-heading ()
"Insert the heading for unlinked references."
- (insert "* Unlinked references :noexport:\n"))
+ (nroam--insert-heading 2 "Unlinked references"))
(defun nroam-unlinked--insert-references ()
"Insert unlinked references for the current buffer."
diff --git a/nroam-utils.el b/nroam-utils.el
index e94bdff..a4e58fc 100644
--- a/nroam-utils.el
+++ b/nroam-utils.el
@@ -34,6 +34,16 @@
(let ((inhibit-read-only t))
(unless (eq ?\n (char-before (1- (point)))) (insert "\n"))))
+(defun nroam--insert-heading (level title &optional tags)
+ "Insert a section heading"
+ (let ((pos (point))
+ (stars (make-string level ?*)))
+ (insert stars " " title "\n")
+ (when tags
+ (save-excursion
+ (goto-char pos)
+ (org-set-tags tags)))))
+
(defun nroam--do-separated-by-newlines (function sequence)
"Apply FUNCTION to each element of SEQUENCE.
Insert a single newline between each call to FUNCTION."
diff --git a/nroam.el b/nroam.el
index b5bb4ab..26ab3be 100644
--- a/nroam.el
+++ b/nroam.el
@@ -186,6 +186,7 @@ Make the region inserted by BODY read-only, and marked with
(unless (bobp)
(nroam--ensure-empty-line))
(with-nroam-markers
+ (nroam--insert-heading 1 "Backlinks" "noexport")
(nroam--do-separated-by-newlines #'funcall nroam-sections))
(nroam--set-sections-visibility))))