nroam is a supplementary package for org-roam that replaces the backlink side buffer of Org-roam. Instead, it displays org-roam backlinks at the end of org-roam buffers.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.7 KiB

  1. ;;; nroam-unlinked.el --- Unlinked references section for nroam.el -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2021 Nicolas Petton
  3. ;; Author: Nicolas Petton <nico@petton.fr>
  4. ;; This program is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;; You should have received a copy of the GNU General Public License
  13. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. ;;; Commentary:
  15. ;; This library provides an unlinked references nroam section for org-roam
  16. ;; buffers.
  17. ;;; Code:
  18. (require 'org-roam)
  19. (require 'nroam-utils)
  20. (declare-function nroam-register-section "nroam.el")
  21. (declare-function nroam-update "nroam.el")
  22. (defvar-local nroam-unlinked-show-references nil
  23. "When non-nil, show unlinked references for the current buffer.")
  24. (defun nroam-unlinked-register-section ()
  25. "Register `nroam-unlinked-section' as a section in nroam."
  26. (nroam-register-section #'nroam-unlinked-section))
  27. (defun nroam-unlinked-section ()
  28. "Insert `org-roam' unlinked references for the current buffer."
  29. (nroam-unlinked--insert-heading)
  30. (if nroam-unlinked-show-references
  31. (nroam-unlinked--insert-references)
  32. (nroam-unlinked--insert-toggle-button)))
  33. (defun nroam-unlinked--insert-heading ()
  34. "Insert the heading for unlinked references."
  35. (nroam--insert-heading 2 "Unlinked references"))
  36. (defun nroam-unlinked--insert-references ()
  37. "Insert unlinked references for the current buffer."
  38. (let (content)
  39. (save-window-excursion
  40. (org-roam-unlinked-references)
  41. (let ((buf (current-buffer)))
  42. (goto-char (point-min))
  43. (search-forward "* Unlinked References\n" nil t)
  44. (setq content (buffer-substring (point) (point-max)))
  45. (kill-buffer buf)))
  46. (insert content)))
  47. (defun nroam-unlinked--insert-toggle-button ()
  48. "Insert a button to show unlinked references."
  49. (let ((beg (point)))
  50. (insert "[Show unlinked references]")
  51. (make-text-button beg (point) 'action #'nroam-unlinked--show-references)))
  52. (defun nroam-unlinked--show-references (&rest _)
  53. "Search for and show unlinked references."
  54. (let ((inhibit-read-only t)
  55. (pos (point-at-bol)))
  56. (setq nroam-unlinked-show-references t)
  57. (nroam-update)
  58. (goto-char pos)
  59. (org-back-to-heading)))
  60. (provide 'nroam-unlinked)
  61. ;;; nroam-unlinked.el ends here