2017-12-08 22:59:42 -05:00
|
|
|
;;; lang/org/autoload/org-capture.el -*- lexical-binding: t; -*-
|
|
|
|
;;;###if (featurep! +capture)
|
|
|
|
|
2018-03-20 21:20:45 -04:00
|
|
|
(defvar org-capture-initial)
|
|
|
|
|
2017-10-01 18:03:48 +02:00
|
|
|
;; --- External frame ---------------------
|
|
|
|
|
2018-08-08 20:44:03 +02:00
|
|
|
;;;###autoload
|
2018-08-08 21:38:58 +02:00
|
|
|
(defvar +org-capture-frame-parameters
|
2017-10-01 18:03:48 +02:00
|
|
|
`((name . "org-capture")
|
|
|
|
(width . 70)
|
|
|
|
(height . 25)
|
2018-02-07 01:04:29 -05:00
|
|
|
(transient . t)
|
2017-10-02 20:00:01 +02:00
|
|
|
,(if IS-LINUX '(display . ":0")))
|
2017-10-01 18:03:48 +02:00
|
|
|
"TODO")
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +org-capture|cleanup-frame ()
|
|
|
|
"Closes the org-capture frame once done adding an entry."
|
|
|
|
(when (+org-capture-frame-p)
|
|
|
|
(delete-frame nil t)))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +org-capture-frame-p (&rest _)
|
|
|
|
"Return t if the current frame is an org-capture frame opened by
|
|
|
|
`+org-capture/open-frame'."
|
2018-02-07 01:04:29 -05:00
|
|
|
(and (equal "org-capture" (frame-parameter nil 'name))
|
|
|
|
(frame-parameter nil 'transient)))
|
2017-10-01 18:03:48 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +org-capture/open-frame (&optional string key)
|
|
|
|
"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."
|
|
|
|
(interactive)
|
2018-02-07 01:04:29 -05:00
|
|
|
(when (and string (string-empty-p string))
|
|
|
|
(setq string nil))
|
|
|
|
(when (and key (string-empty-p key))
|
|
|
|
(setq key nil))
|
2018-04-23 17:50:24 -04:00
|
|
|
(let* ((frame-title-format "")
|
|
|
|
(frame (if (+org-capture-frame-p)
|
|
|
|
(selected-frame)
|
|
|
|
(let (before-make-frame-hook after-make-frame-functions)
|
2018-08-08 21:38:58 +02:00
|
|
|
(make-frame +org-capture-frame-parameters)))))
|
2018-02-07 01:04:29 -05:00
|
|
|
(with-selected-frame frame
|
2018-02-14 20:54:53 -05:00
|
|
|
(require 'org-capture)
|
2018-02-07 01:04:29 -05:00
|
|
|
(condition-case ex
|
|
|
|
(cl-letf (((symbol-function #'pop-to-buffer)
|
|
|
|
(symbol-function #'switch-to-buffer)))
|
|
|
|
(switch-to-buffer (doom-fallback-buffer))
|
|
|
|
(let ((org-capture-initial string)
|
|
|
|
org-capture-entry)
|
|
|
|
(when (and key (not (string-empty-p key)))
|
|
|
|
(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))))))
|
2017-10-01 18:03:48 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +org-capture-available-keys ()
|
|
|
|
"TODO"
|
|
|
|
(string-join (mapcar #'car org-capture-templates) ""))
|