From 22b0a6b56ffe8c423047ee25440dce79a990610c Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 12 Jan 2023 16:39:38 -0600 Subject: Make it work for ... $work --- lisp/+org-capture.el | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 lisp/+org-capture.el (limited to 'lisp/+org-capture.el') diff --git a/lisp/+org-capture.el b/lisp/+org-capture.el new file mode 100644 index 0000000..2f7bf6a --- /dev/null +++ b/lisp/+org-capture.el @@ -0,0 +1,49 @@ +;;; +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 -- cgit 1.4.1-21-gabe81