forked from protesilaos/denote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
denote-silo-extras.el
102 lines (80 loc) · 3.9 KB
/
denote-silo-extras.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
;;; denote-silo-extras.el --- Convenience functions for using Denote in multiple silos -*- lexical-binding: t; -*-
;; Copyright (C) 2023-2024 Free Software Foundation, Inc.
;; Author: Protesilaos Stavrou <[email protected]>
;; Maintainer: Protesilaos Stavrou <[email protected]>
;; URL: https://github.com/protesilaos/denote
;; This file is NOT part of GNU Emacs.
;; 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 is a set of convenience functions that used to be provided in
;; the Denote manual. A "silo" is a `denote-directory' that is
;; self-contained. Users can maintain multiple silos. Consult the
;; manual for the details. With the Denote package installed,
;; evaluate the following to read the relevant node:
;;
;; (info "(denote) Maintain separate directory silos for notes")
;;; Code:
(require 'denote)
(defgroup denote-silo-extras nil
"Make it easier to use Denote across Silos."
:group 'denote
:link '(info-link "(denote) Top")
:link '(url-link :tag "Homepage" "https://protesilaos.com/emacs/denote"))
(defcustom denote-silo-extras-directories
`(,denote-directory)
"List of file paths pointing to Denote silos.
Each file path points to a directory, which takes the same value
as the variable `denote-directory'."
:group 'denote-silo-extras
:link '(info-link "(denote) Maintain separate directories for notes")
:type '(repeat directory))
(defvar denote-silo-extras-directory-history nil
"Minibuffer history for `denote-silo-extras--directory-prompt'.")
(defalias 'denote-silo-extras--directory-history 'denote-silo-extras-directory-history
"Compatibility alias for `denote-silo-extras-directory-history'.")
(defun denote-silo-extras--directory-prompt ()
"Prompt for directory among `denote-silo-extras-directories'."
(let ((default (car denote-silo-extras-directory-history)))
(completing-read
(format-prompt "Select a silo" default)
denote-silo-extras-directories nil :require-match
nil 'denote-silo-extras-directory-history)))
;;;###autoload
(defun denote-silo-extras-create-note (silo)
"Select SILO and run `denote' in it.
SILO is a file path from `denote-silo-extras-directories'.
When called from Lisp, SILO is a file system path to a directory."
(interactive (list (denote-silo-extras--directory-prompt)))
(let ((denote-user-enforced-denote-directory silo))
(call-interactively #'denote)))
;;;###autoload
(defun denote-silo-extras-open-or-create (silo)
"Select SILO and run `denote-open-or-create' in it.
SILO is a file path from `denote-silo-extras-directories'.
When called from Lisp, SILO is a file system path to a directory."
(interactive (list (denote-silo-extras--directory-prompt)))
(let ((denote-user-enforced-denote-directory silo))
(call-interactively #'denote-open-or-create)))
;;;###autoload
(defun denote-silo-extras-select-silo-then-command (silo command)
"Select SILO and run Denote COMMAND in it.
SILO is a file path from `denote-silo-extras-directories', while
COMMAND is one among `denote-silo-extras-commands'.
When called from Lisp, SILO is a file system path to a directory."
(interactive
(list
(denote-silo-extras--directory-prompt)
(denote-command-prompt)))
(let ((denote-user-enforced-denote-directory silo))
(call-interactively command)))
(provide 'denote-silo-extras)
;;; denote-silo-extras.el ends here