From 05b01a431d62f9e843586a48080bc1a419aa4cc8 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 22 Apr 2017 01:49:44 -0400 Subject: [PATCH] Add bin/org-capture script --- bin/org-capture | 28 ++++++++++++++++++++++++++++ modules/lang/org/autoload/capture.el | 10 +++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100755 bin/org-capture diff --git a/bin/org-capture b/bin/org-capture new file mode 100755 index 000000000..66d0b31b0 --- /dev/null +++ b/bin/org-capture @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +# Open an org-capture popup frame from the shell. This opens a temporary emacs +# daemon if emacs isn't already running. +# +# Usage: org-capture [key] [message...] +# Examples: +# org-capture n "To the mind that is still, the whole universe surrenders." + +set -e + +key="${1:-n}" + +cleanup() { + emacsclient --eval '(kill-emacs)' +} + +if ! pgrep emacs >/dev/null; then + emacs --daemon + trap cleanup EXIT INT TERM +fi + +# TODO Allow piping from stdin + +emacsclient -c \ + -F '((name . "org-capture") (width . 70) (height . 25))' \ + --eval "(+org-capture \"$key\" \"$2\")" + diff --git a/modules/lang/org/autoload/capture.el b/modules/lang/org/autoload/capture.el index 07ac217e2..5cfcece3a 100644 --- a/modules/lang/org/autoload/capture.el +++ b/modules/lang/org/autoload/capture.el @@ -1,3 +1,11 @@ ;;; lang/org/autoload/capture.el - +;;;###autoload +(defun +org-capture (&optional key string) + "Initializes the current frame as a pop-up `org-capture' frame." + (interactive) + (let ((key (or key "n")) + (string (unless (string-empty-p string) string))) + (if string + (org-capture-string string key) + (org-capture nil key))))