[Org] Quick capture setup

This commit is contained in:
Marcel Kapfer 2022-10-13 20:31:51 +02:00
parent 558a5a9f5e
commit 777c358e8a
Signed by: mmk2410
GPG key ID: CADE6F0C09F21B09
2 changed files with 55 additions and 0 deletions

View file

@ -1206,6 +1206,21 @@ Finally define the org-agenda display using [[https://github.com/alphapapa/org-s
(:name "Someday" :todo "SOMEDAY" :scheduled future :order 101)))))))))) (:name "Someday" :todo "SOMEDAY" :scheduled future :order 101))))))))))
#+end_src #+end_src
** Quick Capture from everywhere
Given the fact that I run Emacs using Emacsclient all the time I though it would be quite helpful to have the ability to capture a to-do from everywhere, e.g. a sudden thought crossing my mind while developing photos or browsing the web. Thanks to the help of an [[https://www.reddit.com/r/emacs/comments/74gkeq/system_wide_org_capture][Reddit post]] by [[https://www.reddit.com/user/lebitso][u/lebitso]] I was able to achieve this goal and I put the code in an extra package that is loaded here.
#+begin_src emacs-lisp
(use-package org-quick-capture
:load-path "packages/")
#+end_src
To use this, I wrote a small shell script that I'm assigning a keyboard shortcut in my window manager / desktop environment. The shell script essentially runs the following command:
#+begin_src sh
emacsclient -c -F '(quote (name . "capture"))' -e '(activate-capture-frame)'
#+end_src
** Automatic UUID creation ** Automatic UUID creation
I am currently exploring the option in Org mode to export a file (or some entries) to an ics-file which I can then in turn import into my calendar. For reliably creating (and most importantly: updating) entries it is necessary that each one has an unique ID. To create a ID for the current entry I could just run =M-x org-id-get-create= and for an entire file execute the following Emacs Lisp ~(org-map-entries 'org-id-get-create)~. Of course this is not an ideal solution. But adding this s-expression to ~org-mode-hook~ would create IDs in all Org file I edit which I also don't like. Since the amount of files I do want the automatic creation is (currently) not that large it is OK for me to do some work on my own, at least if it is only a one time setup. I am currently exploring the option in Org mode to export a file (or some entries) to an ics-file which I can then in turn import into my calendar. For reliably creating (and most importantly: updating) entries it is necessary that each one has an unique ID. To create a ID for the current entry I could just run =M-x org-id-get-create= and for an entire file execute the following Emacs Lisp ~(org-map-entries 'org-id-get-create)~. Of course this is not an ideal solution. But adding this s-expression to ~org-mode-hook~ would create IDs in all Org file I edit which I also don't like. Since the amount of files I do want the automatic creation is (currently) not that large it is OK for me to do some work on my own, at least if it is only a one time setup.

View file

@ -0,0 +1,40 @@
;;; org-quick-capture.el --- Open a org capture frame and close it directly afterwards. -*- lexical-binding: t; -*-
;;; Commentary:
;;; The code is grabbed from Reddit
;;; (https://www.reddit.com/r/emacs/comments/74gkeq/system_wide_org_capture/)
;;; and was written by u/lebitso (https://www.reddit.com/user/lebitso)
;;; with the help of an anoymous other user.
;;; Code:
(require 'org)
(require 'org-capture)
(defadvice org-switch-to-buffer-other-window
(after supress-window-splitting activate)
"Delete the extra window if we're in a capture frame."
(if (equal "Org Capture" (frame-parameter nil 'name))
(delete-other-windows)))
(defadvice org-capture-finalize
(after delete-capture-frame activate)
"Advise capture-finalize to close the frame when finished."
(when (and (equal "Org Capture" (frame-parameter nil 'name))
(not (eq this-command 'org-capture-refile)))
(delete-frame)))
(defadvice org-capture-refile
(after delete-capture-frame activate)
"Advise org-refile to close the frame when finished."
(delete-frame))
(defun org-quick-capture ()
"Run 'org-capture' in an own capture frame."
(select-frame-by-name "Org Capture")
(switch-to-buffer (get-buffer-create "*scratch*"))
(org-capture))
(provide 'org-quick-capture)
;;; org-quick-capture.el ends here