Rewrite org/org-capture
This commit is contained in:
parent
3c05966347
commit
f32c556257
3 changed files with 72 additions and 56 deletions
|
@ -1,10 +1,10 @@
|
||||||
;;; org/org-capture/autoload/evil.el -*- lexical-binding: t; -*-
|
;;; org/org-capture/autoload/evil.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
;;;###autoload (autoload '+org-capture:dwim "org/org-capture/autoload/evil" nil t)
|
;;;###autoload (autoload '+org-capture:open "org/org-capture/autoload/evil" nil t)
|
||||||
(evil-define-operator +org-capture:dwim (&optional beg end)
|
(evil-define-operator +org-capture:open (&optional beg end)
|
||||||
"Evil ex interface to `+org-capture/dwim'."
|
"Evil ex interface to `+org-capture/dwim'."
|
||||||
:move-point nil :type inclusive
|
:move-point nil :type inclusive
|
||||||
(interactive "<r>")
|
(interactive "<r>")
|
||||||
(+org-capture/dwim
|
(+org-capture/open
|
||||||
(unless (or (evil-normal-state-p) (evil-insert-state-p))
|
(unless (or (evil-normal-state-p) (evil-insert-state-p))
|
||||||
(buffer-substring beg end))))
|
(buffer-substring beg end))))
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
;;; org/org-capture/autoload/org-capture.el -*- lexical-binding: t; -*-
|
;;; org/org-capture/autoload/org-capture.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +org-capture/dwim (&optional string key)
|
(defun +org-capture/open (&optional string key)
|
||||||
"Sends STRING, the current selection or prompted input to `org-capture'.
|
"Sends STRING, the current selection or prompted input to `org-capture'.
|
||||||
|
|
||||||
Uses the capture template specified by KEY. Otherwise, prompts you for one."
|
Uses the capture template specified by KEY. Otherwise, prompts you for one."
|
||||||
|
@ -15,3 +15,58 @@ Uses the capture template specified by KEY. Otherwise, prompts you for one."
|
||||||
(region-end)))))
|
(region-end)))))
|
||||||
(org-capture-string string key)
|
(org-capture-string string key)
|
||||||
(org-capture nil key))))
|
(org-capture nil key))))
|
||||||
|
|
||||||
|
|
||||||
|
;; --- External frame ---------------------
|
||||||
|
|
||||||
|
(defvar +org-capture-window-params
|
||||||
|
`((name . "org-capture")
|
||||||
|
(width . 70)
|
||||||
|
(height . 25)
|
||||||
|
(window-system . ,(cond (IS-MAC 'ns)
|
||||||
|
(IS-LINUX 'x)
|
||||||
|
(t 'w32)))
|
||||||
|
,(when IS-LINUX
|
||||||
|
'(display . ":0")))
|
||||||
|
"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'."
|
||||||
|
(equal "org-capture" (frame-parameter nil 'name)))
|
||||||
|
|
||||||
|
;;;###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)
|
||||||
|
(require 'org)
|
||||||
|
(let (after-make-frame-functions before-make-frame-hook)
|
||||||
|
(let ((frame (if (+org-capture-frame-p)
|
||||||
|
(selected-frame)
|
||||||
|
(make-frame +org-capture-window-params))))
|
||||||
|
(with-selected-frame frame
|
||||||
|
(condition-case ex
|
||||||
|
(cl-letf (((symbol-function #'pop-to-buffer)
|
||||||
|
(symbol-function #'switch-to-buffer)))
|
||||||
|
(if (and (stringp string)
|
||||||
|
(not (string-empty-p string)))
|
||||||
|
(org-capture-string string key)
|
||||||
|
(org-capture nil key))
|
||||||
|
(when (featurep 'solaire-mode)
|
||||||
|
(solaire-mode +1)))
|
||||||
|
('error
|
||||||
|
(message "org-capture: %s" (error-message-string ex))
|
||||||
|
(delete-frame frame)))))))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun +org-capture-available-keys ()
|
||||||
|
"TODO"
|
||||||
|
(string-join (mapcar #'car org-capture-templates) ""))
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
;;; org/org-capture/config.el -*- lexical-binding: t; -*-
|
;;; org/org-capture/config.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
(add-hook 'org-load-hook #'+org-capture|init t)
|
|
||||||
|
|
||||||
;; Sets up two `org-capture' workflows that I like:
|
;; Sets up two `org-capture' workflows that I like:
|
||||||
;;
|
;;
|
||||||
;; 1. The traditional way: invoking `org-capture' directly (or through a
|
;; 1. The traditional way: invoking `org-capture' directly (or through a
|
||||||
|
@ -12,56 +10,19 @@
|
||||||
;; anywhere I can call org-capture (whether or not Emacs is open/running),
|
;; anywhere I can call org-capture (whether or not Emacs is open/running),
|
||||||
;; like, say, from qutebrowser, vimperator, dmenu or a global keybinding.
|
;; like, say, from qutebrowser, vimperator, dmenu or a global keybinding.
|
||||||
|
|
||||||
(defun +org-capture|init ()
|
(setq org-default-notes-file (concat +org-dir "notes.org")
|
||||||
"Set up a sane `org-capture' workflow."
|
org-capture-templates
|
||||||
(setq org-default-notes-file (concat +org-dir "notes.org")
|
'(("t" "Todo" entry
|
||||||
;; FIXME This is incomplete!
|
(file+headline (expand-file-name "todo.org" +org-dir) "Inbox")
|
||||||
org-capture-templates
|
"* [ ] %?\n%i" :prepend t :kill-buffer t)
|
||||||
'(;; TODO: New vocabulary word
|
|
||||||
|
|
||||||
("t" "Todo" entry
|
("n" "Notes" entry
|
||||||
(file+headline (expand-file-name "todo.org" +org-dir) "Inbox")
|
(file+headline org-default-notes-file "Inbox")
|
||||||
"* [ ] %?")
|
"* %u %?\n%i" :prepend t :kill-buffer t)))
|
||||||
|
|
||||||
("c" "Changelog" entry
|
(add-hook 'org-capture-after-finalize-hook #'+org-capture|cleanup-frame)
|
||||||
(file+headline (expand-file-name "CHANGELOG.org" (doom-project-root)) "Unreleased")
|
(when (featurep! :feature evil)
|
||||||
"* %?")
|
(add-hook 'org-capture-mode-hook #'evil-insert-state))
|
||||||
|
|
||||||
;; ("p" "Project Notes" entry
|
(when (featurep! :ui doom-dashboard)
|
||||||
;; (file+headline org-default-notes-file "Inbox")
|
(add-hook '+doom-dashboard-inhibit-functions #'+org-capture-frame-p))
|
||||||
;; "* %u %?\n%i" :prepend t)
|
|
||||||
|
|
||||||
;; ("m" "Major-mode Notes" entry
|
|
||||||
;; (file+headline org-default-notes-file "Inbox")
|
|
||||||
;; "* %u %?\n%i" :prepend t)
|
|
||||||
|
|
||||||
("n" "Notes" entry
|
|
||||||
(file+headline (concat +org-dir "notes.org") "Inbox")
|
|
||||||
"* %u %?\n%i" :prepend t)
|
|
||||||
|
|
||||||
;; ("v" "Vocab" entry
|
|
||||||
;; (file+headline (concat org-directory "topics/vocab.org") "Unsorted")
|
|
||||||
;; "** %i%?\n")
|
|
||||||
))
|
|
||||||
|
|
||||||
(when (featurep! :feature evil)
|
|
||||||
(add-hook 'org-capture-mode-hook #'evil-insert-state))
|
|
||||||
|
|
||||||
;; Allows the Emacs mini-frame (opened from an external shell script to run
|
|
||||||
;; and clean up properly) if the frame is named "org-capture".
|
|
||||||
(require 'org-capture)
|
|
||||||
(require 'org-protocol)
|
|
||||||
(defun +org-capture*init (&rest _)
|
|
||||||
"Makes sure the org-capture window is the only window in the frame."
|
|
||||||
(when (equal "org-capture" (frame-parameter nil 'name))
|
|
||||||
(setq mode-line-format nil)
|
|
||||||
(delete-other-windows)))
|
|
||||||
(advice-add #'org-capture :after #'+org-capture*init)
|
|
||||||
|
|
||||||
(defun +org-capture|finalize ()
|
|
||||||
"Closes the frame once org-capture is done."
|
|
||||||
(when (equal "org-capture" (frame-parameter nil 'name))
|
|
||||||
(when (and (featurep 'persp-mode) persp-mode)
|
|
||||||
(+workspace/delete (+workspace-current-name)))
|
|
||||||
(delete-frame)))
|
|
||||||
(add-hook 'org-capture-after-finalize-hook #'+org-capture|finalize))
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue