Skip to content

Instantly share code, notes, and snippets.

@amno1
Last active October 9, 2023 15:05
Show Gist options
  • Save amno1/4bfdb3087417fe7e49fc2b0b40a3eb03 to your computer and use it in GitHub Desktop.
Save amno1/4bfdb3087417fe7e49fc2b0b40a3eb03 to your computer and use it in GitHub Desktop.
Two different ideas for org-capture via completing read
;;; org-capture-complete.el --- Two different ideas for org-capture via completing read -*- lexical-binding: t; -*-
;; Copyright (C) 2023 Arthur Miller
;; Author: Arthur Miller <[email protected]>
;; Keywords: tools, lisp
;; 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:
;; Two small somewhat different versions of a command to run org-capture
;; via completing read instead of the standard org-capture dialog.
;;; Code:
(defun org-capture-complete (&optional goto)
"Call org-capture via completing read. GOTO as in `org-capture'"
(interactive)
(let* ((label (completing-read "Capture: "
(mapcar (lambda (s)
(cons (cadr s) (car s)))
org-capture-templates)))
(template
(catch 'found (dolist (tmpl org-capture-templates)
(when (equal (cadr tmpl) label)
(throw 'found (car tmpl)))))))
(condition-case error
(org-capture goto template)
((error quit) (message "Capture aborted")))))
(defun org-capture-complete2 (&optional goto)
"Call org-capture via completing read. GOTO as in `org-capture'"
(interactive)
(let ((label (completing-read "Capture: "
(mapcar (lambda (s)
(concat (car s) " " (cadr s)))
org-capture-templates))))
(condition-case error
(org-capture goto (substring label 0 1))
((error quit) (message "Capture aborted")))))
(provide 'org-capture-complete)
;;; org-capture-complete.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment