;;; +org-capture.el -*- lexical-binding: t; -*- ;;; Code: (require 'cl-lib) ;; Don't /require/ `org-capture', since that'll pull in all of `org' and that'll ;; take a minute. Just let the compiler know that this variable exists. (defvar org-capture-templates nil) ;; https://github.com/cadadr/configuration/blob/39813a771286e542af3aa333172858532c3bb257/emacs.d/gk/gk-org.el#L1573 (defun +org-capture-template-define (description &rest args) "Define a capture template. Creates a list and adds it to `org-capture-templates', if it's not already there. ARGS is a plist, which in addition to the additional options `org-capture-templates' accepts (which see), takes the following and puts them in the right spot: `:keys', `:description', `:type', `:target', and `:template'." (declare (indent 1)) (let* ((keys (plist-get args :keys)) (type (plist-get args :type)) (target (plist-get args :target)) (template (plist-get args :template)) (template-value (append (list description) (when (or type target template) (list (or type 'entry) target template)) (cl-loop for i from 0 below (length args) by 2 unless (member (nth i args) '(:keys :description :type :target :template)) append (list (nth i args) (plist-get args (nth i args))))))) ;; The only way I know how to do this properly (add a value to the end of ;; the list, if it exists; otherwise update it) is to do this weird if-setf ;; dance. (if (seq-find (lambda (el) (equal (car el) keys)) org-capture-templates) (setf (alist-get keys org-capture-templates nil nil #'equal) template-value) (setf org-capture-templates (append org-capture-templates (list (cons keys template-value))))) ;; Regardless of what we do, return the new value of ;; `org-capture-templates'. org-capture-templates)) (provide '+org-capture) ;;; +org-capture.el