dotemacs

My Emacs configuration
git clone git://git.entf.net/dotemacs
Log | Files | Refs | LICENSE

denote-silo-extras.el (3927B)


      1 ;;; denote-silo-extras.el --- Convenience functions for using Denote in multiple silos  -*- lexical-binding: t; -*-
      2 
      3 ;; Copyright (C) 2023-2024  Free Software Foundation, Inc.
      4 
      5 ;; Author: Protesilaos Stavrou <info@protesilaos.com>
      6 ;; Maintainer: Protesilaos Stavrou <info@protesilaos.com>
      7 ;; URL: https://github.com/protesilaos/denote
      8 
      9 ;; This file is NOT part of GNU Emacs.
     10 
     11 ;; This program is free software; you can redistribute it and/or modify
     12 ;; it under the terms of the GNU General Public License as published by
     13 ;; the Free Software Foundation, either version 3 of the License, or
     14 ;; (at your option) any later version.
     15 
     16 ;; This program is distributed in the hope that it will be useful,
     17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
     18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19 ;; GNU General Public License for more details.
     20 
     21 ;; You should have received a copy of the GNU General Public License
     22 ;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
     23 
     24 ;;; Commentary:
     25 
     26 ;; This is a set of convenience functions that used to be provided in
     27 ;; the Denote manual.  A "silo" is a `denote-directory' that is
     28 ;; self-contained.  Users can maintain multiple silos.  Consult the
     29 ;; manual for the details.  With the Denote package installed,
     30 ;; evaluate the following to read the relevant node:
     31 ;;
     32 ;;     (info "(denote) Maintain separate directory silos for notes")
     33 
     34 ;;; Code:
     35 
     36 (require 'denote)
     37 
     38 (defgroup denote-silo-extras nil
     39   "Make it easier to use Denote across Silos."
     40   :group 'denote
     41   :link '(info-link "(denote) Top")
     42   :link '(url-link :tag "Homepage" "https://protesilaos.com/emacs/denote"))
     43 
     44 (defcustom denote-silo-extras-directories
     45   `(,denote-directory)
     46   "List of file paths pointing to Denote silos.
     47 Each file path points to a directory, which takes the same value
     48 as the variable `denote-directory'."
     49   :group 'denote-silo-extras
     50   :link '(info-link "(denote) Maintain separate directories for notes")
     51   :type '(repeat directory))
     52 
     53 (defvar denote-silo-extras-directory-history nil
     54   "Minibuffer history for `denote-silo-extras--directory-prompt'.")
     55 
     56 (defalias 'denote-silo-extras--directory-history 'denote-silo-extras-directory-history
     57   "Compatibility alias for `denote-silo-extras-directory-history'.")
     58 
     59 (defun denote-silo-extras--directory-prompt ()
     60   "Prompt for directory among `denote-silo-extras-directories'."
     61   (let ((default (car denote-silo-extras-directory-history)))
     62     (completing-read
     63      (format-prompt "Select a silo" default)
     64      denote-silo-extras-directories nil :require-match
     65      nil 'denote-silo-extras-directory-history)))
     66 
     67 ;;;###autoload
     68 (defun denote-silo-extras-create-note (silo)
     69   "Select SILO and run `denote' in it.
     70 SILO is a file path from `denote-silo-extras-directories'.
     71 
     72 When called from Lisp, SILO is a file system path to a directory."
     73   (interactive (list (denote-silo-extras--directory-prompt)))
     74   (let ((denote-directory silo))
     75     (call-interactively #'denote)))
     76 
     77 ;;;###autoload
     78 (defun denote-silo-extras-open-or-create (silo)
     79   "Select SILO and run `denote-open-or-create' in it.
     80 SILO is a file path from `denote-silo-extras-directories'.
     81 
     82 When called from Lisp, SILO is a file system path to a directory."
     83   (interactive (list (denote-silo-extras--directory-prompt)))
     84   (let ((denote-directory silo))
     85     (call-interactively #'denote-open-or-create)))
     86 
     87 ;;;###autoload
     88 (defun denote-silo-extras-select-silo-then-command (silo command)
     89   "Select SILO and run Denote COMMAND in it.
     90 SILO is a file path from `denote-silo-extras-directories', while
     91 COMMAND is one among `denote-silo-extras-commands'.
     92 
     93 When called from Lisp, SILO is a file system path to a directory."
     94   (interactive
     95    (list
     96     (denote-silo-extras--directory-prompt)
     97     (denote-command-prompt)))
     98   (let ((denote-directory silo))
     99     (call-interactively command)))
    100 
    101 (provide 'denote-silo-extras)
    102 ;;; denote-silo-extras.el ends here