-
Notifications
You must be signed in to change notification settings - Fork 0
/
org-roam-plugin-ok.el
109 lines (95 loc) · 3.73 KB
/
org-roam-plugin-ok.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
;;; org-roam-plugin-ok.el --- Org Roam Plugin -*- lexical-binding: t -*-
;;
;; Copyright (C) 2024 Taro Sato
;;
;; Author: Taro Sato <[email protected]>
;; URL: https://github.com/okomestudio/org-roam-plugin-ok
;; Version: 0.2
;; Keywords: org-mode, roam, plug-in
;; Package-Requires: ((emacs "29.1") (org "9.7") (org-roam "2.2.2") (adaptive-wrap "0.8") (dash "2.13") (marginalia "1.6") (ok-plural "0.1") (org-roam-timestamps "1.0.0") (s "1.13.1"))
;;
;;; License:
;;
;; 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:
;;
;; The `org-roam-plugin-ok' mode is a plugin to enhance `org-roam' in
;; several ways. See the repository README for detail.
;;
;;; Code:
(defgroup org-roam-plugin-ok nil
"Group for `org-roam-plugin-ok'."
:group 'org
:prefix "org-roam-plugin-ok-")
(defvar org-roam-plugin-ok-version "0.1"
"Package version.")
(defcustom org-roam-plugin-ok-on-idle-delay 60
"Idle delay before running on-idle initializer."
:group 'org)
;; On-idle initialization
(defvar org-roam-plugin-ok--on-idle-timer nil
"Timer object used by on-idle init scheduler.")
(defun org-roam-plugin-ok--init-on-idle ()
"Initialize `org-roam' on idle."
(when org-roam-plugin-ok--on-idle-timer
(cancel-timer org-roam-plugin-ok--on-idle-timer))
(remove-hook 'post-command-hook #'org-roam-plugin-ok--on-idle-init-scheduler)
(when (not (and (boundp 'orp-ok-node--cache-in-memory)
(> (hash-table-count orp-ok-node--cache-in-memory) 0)))
(message "Starting org-roam-init-on-idle...")
(require 'org-roam)
(org-roam-node-list)
(org-roam-plugin-ok-mode 1)
(orp-ok-node-project-org-file--load #'orp-ok-node-fill-caches)
(message "Finished org-roam-init-on-idle")))
(defun org-roam-plugin-ok--on-idle-init-scheduler ()
"Schedule on-idle initializer."
(when org-roam-plugin-ok--on-idle-timer
(cancel-timer org-roam-plugin-ok--on-idle-timer))
(setq org-roam-plugin-ok--on-idle-timer
(run-with-idle-timer org-roam-plugin-ok-on-idle-delay
nil
#'org-roam-plugin-ok--init-on-idle)))
;;;###autoload
(defun org-roam-plugin-ok-on-idle-init-setup ()
"Set up on-idle initializer."
(org-roam-plugin-ok--on-idle-init-scheduler)
(add-hook 'post-command-hook #'org-roam-plugin-ok--on-idle-init-scheduler))
(defun org-roam-plugin-ok-activate ()
"Activate `org-roam-plugin-ok-mode'."
(require 'orp-ok-utils)
(require 'orp-ok-capture)
(require 'orp-ok-mode)
(require 'orp-ok-node)
(with-eval-after-load 'org-roam-gt
(require 'orp-ok-node-gt))
(require 'orp-ok-ja)
(advice-add #'org-roam-node-find
:around #'orp-ok-node-project-org-file--load)
(advice-add #'org-roam-node-insert
:around #'orp-ok-node-project-org-file--load))
(defun org-roam-plugin-ok-deactivate ()
"Deactivate `org-roam-plugin-ok-mode'."
nil)
;;;###autoload
(define-minor-mode org-roam-plugin-ok-mode
"The `org-roam-plugin-ok-mode' minor mode."
:global nil
:group 'org-roam-plugin-ok-mode
(if org-roam-plugin-ok-mode
(org-roam-plugin-ok-activate)
(org-roam-plugin-ok-deactivate)))
(provide 'org-roam-plugin-ok)
;;; org-roam-plugin-ok.el ends here