about summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/+cus-edit.el12
-rw-r--r--lisp/+org-capture.el82
2 files changed, 90 insertions, 4 deletions
diff --git a/lisp/+cus-edit.el b/lisp/+cus-edit.el index 6ab8527..7fa46d4 100644 --- a/lisp/+cus-edit.el +++ b/lisp/+cus-edit.el
@@ -34,15 +34,19 @@
34 "Variables to allow changing while loading the Custom file.") 34 "Variables to allow changing while loading the Custom file.")
35 35
36(defun +custom-load-ignoring-most-customizations (&optional 36(defun +custom-load-ignoring-most-customizations (&optional
37 noerror 37 error
38 nomessage 38 nomessage
39 nosuffix 39 nosuffix
40 must-suffix) 40 must-suffix)
41 "Load `custom-file', ignoring most customizations. 41 "Load `custom-file', ignoring most customizations.
42Ignore all faces, and only load variables in 42Ignore all faces, and only load variables in
43`+customize-variable-allowlist'. All the optional 43`+customize-variable-allowlist'. All the optional
44variables---NOERROR, NOMESSAGE, NOSUFFIX, MUST-SUFFIX---are 44variables---ERROR, NOMESSAGE, NOSUFFIX, MUST-SUFFIX---are
45passed on to `load'." 45passed on to `load'.
46
47NOTE: ERROR is the opposite of its value in `load' -- meaning
48that this function by default does /not/ error, but will if you
49pass t to it."
46 (cl-letf (((symbol-function 'custom-set-faces) 'ignore) 50 (cl-letf (((symbol-function 'custom-set-faces) 'ignore)
47 ((symbol-function 'custom-set-variables) 51 ((symbol-function 'custom-set-variables)
48 (lambda (&rest args) 52 (lambda (&rest args)
@@ -51,7 +55,7 @@ passed on to `load'."
51 (memq (car el) 55 (memq (car el)
52 +custom-variable-allowlist)) 56 +custom-variable-allowlist))
53 args))))) 57 args)))))
54 (load custom-file noerror nomessage nosuffix must-suffix))) 58 (load custom-file (not error) nomessage nosuffix must-suffix)))
55 59
56(defun +cus-edit-expand-widgets (&rest _) 60(defun +cus-edit-expand-widgets (&rest _)
57 "Expand descriptions in `Custom-mode' buffers." 61 "Expand descriptions in `Custom-mode' buffers."
diff --git a/lisp/+org-capture.el b/lisp/+org-capture.el new file mode 100644 index 0000000..1631bdd --- /dev/null +++ b/lisp/+org-capture.el
@@ -0,0 +1,82 @@
1;;; +org-capture.el -*- lexical-binding: t; -*-
2
3;;; Code:
4
5(require 'cl-lib)
6;; We don't require `org-capture' here because I'll have to require this library
7;; to init.el /before/ org-capture is fully needed.
8
9(defun +org-capture--get (key &optional list)
10 "Find KEY in LIST, or return nil.
11LIST defaults to `org-capture-templates'."
12 (alist-get key (or list org-capture-templates) nil nil #'equal))
13
14;; Set it up as a generic value. Based on the one for `alist-get'.
15(gv-define-expander +org-capture--get
16 (lambda (do key &optional alist)
17 (setq alist (or alist org-capture-templates))
18 (macroexp-let2 macroexp-copyable-p k key
19 (gv-letplace (getter setter) alist
20 (macroexp-let2 nil p `(assoc ,k ,getter 'equal)
21 (funcall do `(cdr ,p)
22 (lambda (v)
23 (macroexp-let2 nil v v
24 (let ((set-exp
25 `(if ,p (setcdr ,p ,v)
26 ,(funcall setter
27 `(cons (setq ,p (cons ,k ,v))
28 ,getter)))))
29 `(progn
30 ,set-exp
31 ,v))))))))))
32
33(defun +org-capture-sort (&optional list)
34 "Sort LIST by string keys.
35LIST is a symbol and defaults to `org-capture-templates'."
36 (setq list (or list 'org-capture-templates))
37 (set list (sort (symbol-value list) (lambda (a b)
38 (string< (car a) (car b))))))
39
40;;;###autoload
41(defun +org-capture-templates-setf (key value &optional list sort-after)
42 "Add KEY to LIST, using `setf'.
43LIST is a symbol and defaults to `org-capture-templates' -- so
44this function sets values on a list that's structured as such.
45
46Thus, KEY is a string key. If it's longer than one character,
47this function will search LIST for each successive run of
48characters before the final, ensuring sub-lists exist of the
49form (CHARS DESCRIPTION).
50
51For example, if KEY is \"abc\", first a LIST item of the form (a
52DESCRIPTION), if non-existant, will be added to the list (with a
53default description), then an item of the
54form (\"ab\" DESCRIPTION), before adding (KEY VALUE) to the LIST.
55
56VALUE is the template or group header required for
57`org-capture-templates', which see.
58
59SORT-AFTER, when set to t, will call
60`+org-capture-templates-sort' after setting, to ensure org can
61properly process the variable."
62 ;; LIST defaults to `org-capture-templates'
63 (declare (indent 2))
64 (unless list (setq list 'org-capture-templates))
65 ;; Ensure VALUE is a list to cons properly
66 (unless (listp value) (setq value (list value)))
67 (when (> (length key) 1)
68 ;; Check for existence of groups.
69 (let ((expected (cl-loop for i from 1 to (1- (length key))
70 collect (substring key 0 i) into keys
71 finally return keys)))
72 (cl-loop for ek in expected
73 if (not (+org-capture--get ek (symbol-value list))) do
74 (setf (+org-capture--get ek (symbol-value list))
75 (list (format "(Group %s)" ek))))))
76 (prog1 ;; Set KEY to VALUE
77 (setf (+org-capture--get key (symbol-value list)) value)
78 ;; Sort after, maybe
79 (when sort-after (+org-capture-sort list))))
80
81(provide '+org-capture)
82;;; +org-capture.el ends here