lang/org: fix external org-capture workflow
+ Fix frame-spawning when calling bin/org-capture + Integrate counsel-org-capture into bin/org-capture workflow + Ensure frame is closed if counsel-org-capture is cancelled + Ensure org-capture buffer closes the associated frame + Add transient frame property for org-capture frames If you are using a tiling window manager, you'll need to add a rule for a window named "org-capture" in order to make a floating window.
This commit is contained in:
parent
68a4c85088
commit
69dc25ae4c
2 changed files with 36 additions and 20 deletions
|
@ -33,7 +33,7 @@ shift $((OPTIND-1))
|
||||||
|
|
||||||
if [[ $daemon ]]; then
|
if [[ $daemon ]]; then
|
||||||
emacsclient -a "" \
|
emacsclient -a "" \
|
||||||
-c -F '((name . "org-capture") (width . 70) (height . 25))' \
|
-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})"
|
||||||
else
|
else
|
||||||
# Non-daemon servers flicker a lot if frames are created from terminal, so
|
# Non-daemon servers flicker a lot if frames are created from terminal, so
|
||||||
|
|
|
@ -34,6 +34,7 @@ Uses the capture template specified by KEY. Otherwise, prompts you for one."
|
||||||
`((name . "org-capture")
|
`((name . "org-capture")
|
||||||
(width . 70)
|
(width . 70)
|
||||||
(height . 25)
|
(height . 25)
|
||||||
|
(transient . t)
|
||||||
(window-system . ,(cond (IS-MAC 'ns)
|
(window-system . ,(cond (IS-MAC 'ns)
|
||||||
(IS-LINUX 'x)
|
(IS-LINUX 'x)
|
||||||
(t 'w32)))
|
(t 'w32)))
|
||||||
|
@ -50,31 +51,46 @@ Uses the capture template specified by KEY. Otherwise, prompts you for one."
|
||||||
(defun +org-capture-frame-p (&rest _)
|
(defun +org-capture-frame-p (&rest _)
|
||||||
"Return t if the current frame is an org-capture frame opened by
|
"Return t if the current frame is an org-capture frame opened by
|
||||||
`+org-capture/open-frame'."
|
`+org-capture/open-frame'."
|
||||||
(equal "org-capture" (frame-parameter nil 'name)))
|
(and (equal "org-capture" (frame-parameter nil 'name))
|
||||||
|
(frame-parameter nil 'transient)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +org-capture/open-frame (&optional string key)
|
(defun +org-capture/open-frame (&optional string key)
|
||||||
"Opens the org-capture window in a floating frame that cleans itself up once
|
"Opens the org-capture window in a floating frame that cleans itself up once
|
||||||
you're done. This can be called from an external shell script."
|
you're done. This can be called from an external shell script."
|
||||||
(interactive)
|
(interactive)
|
||||||
(require 'org)
|
(when (and string (string-empty-p string))
|
||||||
(let (after-make-frame-functions before-make-frame-hook)
|
(setq string nil))
|
||||||
(let ((frame (if (+org-capture-frame-p)
|
(when (and key (string-empty-p key))
|
||||||
(selected-frame)
|
(setq key nil))
|
||||||
(make-frame +org-capture-window-params))))
|
(require 'org-capture)
|
||||||
(with-selected-frame frame
|
(let ((frame (if (+org-capture-frame-p)
|
||||||
(condition-case ex
|
(selected-frame)
|
||||||
(cl-letf (((symbol-function #'pop-to-buffer)
|
(make-frame +org-capture-window-params))))
|
||||||
(symbol-function #'switch-to-buffer)))
|
(with-selected-frame frame
|
||||||
(if (and (stringp string)
|
(condition-case ex
|
||||||
(not (string-empty-p string)))
|
(cl-letf (((symbol-function #'pop-to-buffer)
|
||||||
(org-capture-string string key)
|
(symbol-function #'switch-to-buffer)))
|
||||||
(org-capture nil key))
|
(switch-to-buffer (doom-fallback-buffer))
|
||||||
(when (featurep 'solaire-mode)
|
(let ((org-capture-initial string)
|
||||||
(solaire-mode +1)))
|
(org-capture-mode-hook org-capture-mode-hook)
|
||||||
('error
|
org-capture-entry)
|
||||||
(message "org-capture: %s" (error-message-string ex))
|
(when (and key (not (string-empty-p key)))
|
||||||
(delete-frame frame)))))))
|
(setq org-capture-entry (org-capture-select-template key)))
|
||||||
|
(if (or org-capture-entry
|
||||||
|
(not (fboundp 'counsel-org-capture)))
|
||||||
|
(org-capture)
|
||||||
|
(unwind-protect
|
||||||
|
(counsel-org-capture)
|
||||||
|
(if-let* ((buf (cl-loop for buf in (buffer-list)
|
||||||
|
if (buffer-local-value 'org-capture-mode buf)
|
||||||
|
return buf)))
|
||||||
|
(with-current-buffer buf
|
||||||
|
(add-hook 'kill-buffer-hook #'+org-capture|cleanup-frame nil t))
|
||||||
|
(delete-frame frame))))))
|
||||||
|
('error
|
||||||
|
(message "org-capture: %s" (error-message-string ex))
|
||||||
|
(delete-frame frame))))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +org-capture-available-keys ()
|
(defun +org-capture-available-keys ()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue