Browse Source

Add support for unlinked references

* nroam-unlinked.el: New file.
* nroam.el: Setup unlinked references section.
master
Nicolas Petton 1 month ago
parent
commit
4fccc56fff
No known key found for this signature in database GPG Key ID: E8BCD7866AFCF978
2 changed files with 84 additions and 0 deletions
  1. +82
    -0
      nroam-unlinked.el
  2. +2
    -0
      nroam.el

+ 82
- 0
nroam-unlinked.el View File

@ -0,0 +1,82 @@
;;; nroam-unlinked.el --- Unlinked references section for nroam.el -*- lexical-binding: t; -*-
;; Copyright (C) 2021 Nicolas Petton
;; Author: Nicolas Petton <nico@petton.fr>
;; URL: https://github.com/NicolasPetton/nroam
;; Keywords: convenience, outlines
;; Version: 0.0.1
;; Package-Requires: ((emacs "26.1") (org-roam "1.2.3"))
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; This library provides an unlinked references nroam section for org-roam
;; buffers.
;;; Code:
(require 'org-roam)
(require 'nroam-utils)
(declare-function nroam-register-section "nroam.el")
(declare-function nroam-update "nroam.el")
(defvar-local nroam-unlinked-show-references nil
"When non-nil, show unlinked references for the current buffer.")
(defun nroam-unlinked-register-section ()
"Register `nroam-unlinked-section' as a section in nroam."
(nroam-register-section #'nroam-unlinked-section))
(defun nroam-unlinked-section ()
"Insert org-roam unlinked references for the current buffer."
(nroam-unlinked--insert-heading)
(if nroam-unlinked-show-references
(nroam-unlinked--insert-references)
(nroam-unlinked--insert-toggle-button)))
(defun nroam-unlinked--insert-heading ()
"Insert the heading for unlinked references."
(insert "* Unlinked references\n"))
(defun nroam-unlinked--insert-references ()
"Insert unlinked references for the current buffer."
(let (content)
(save-window-excursion
(org-roam-unlinked-references)
(let ((buf (current-buffer)))
(goto-char (point-min))
(search-forward "* Unlinked References\n" nil t)
(setq content (buffer-substring (point) (point-max)))
(kill-buffer buf)))
(insert content)))
(defun nroam-unlinked--insert-toggle-button ()
"Insert a button to show unlinked references."
(let ((beg (point)))
(insert "[Show unlinked references]")
(make-text-button beg (point) 'action #'nroam-unlinked--show-references)
(insert "\n")))
(defun nroam-unlinked--show-references (&rest _)
"Search for and show unlinked references."
(let ((inhibit-read-only t)
(pos (point-at-bol)))
(setq nroam-unlinked-show-references t)
(nroam-update)
(goto-char pos)
(org-back-to-heading)))
(provide 'nroam-unlinked)
;;; nroam-unlinked.el ends here

+ 2
- 0
nroam.el View File

@ -42,6 +42,7 @@
(require 'nroam-utils)
(require 'nroam-backlinks)
(require 'nroam-unlinked)
(defcustom nroam-sections nil
"List of functions to be called to insert sections in nroam buffers."
@ -200,6 +201,7 @@ Make the region inserted by BODY read-only, and marked with
(goto-char point))))
(nroam-backlinks-register-section)
(nroam-unlinked-register-section)
(provide 'nroam)
;;; nroam.el ends here

Loading…
Cancel
Save