bin/org-capture: reformat & improve daemon cleanup

Ensures the temporary daemon is killed after org-capture is finished.
This commit is contained in:
Henrik Lissner 2018-06-24 15:16:17 +02:00
parent 3284356fc2
commit 6c8df7c6bb
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -10,12 +10,11 @@
set -e
cleanup() {
emacsclient --eval '(kill-emacs)'
emacsclient --eval '(let (kill-emacs-hook) (kill-emacs))'
}
# If emacs isn't running, we start a temporary daemon, solely for this window.
daemon=
if ! pgrep emacs >/dev/null; then
if ! emacsclient -e nil; then
emacs --daemon
trap cleanup EXIT INT TERM
daemon=1
@ -34,10 +33,10 @@ shift $((OPTIND-1))
if [[ $daemon ]]; then
emacsclient -a "" \
-c -F '((name . "org-capture") (width . 70) (height . 25) (transient . t))' \
-e "(+org-capture/open-frame \"$str\" ${key:-nil})"
-e "(+org-capture/open-frame \"$str\" ${key:-nil} t)"
else
# Non-daemon servers flicker a lot if frames are created from terminal, so
# we do it internally instead.
# Non-daemon servers flicker a lot if frames are created from terminal, so we
# do it internally instead.
emacsclient -a "" \
-e "(+org-capture/open-frame \"$str\" ${key:-nil})"
fi