Last active
October 24, 2021 16:15
-
-
Save amygrinn/958846157bfbd26035f58308530fa357 to your computer and use it in GitHub Desktop.
[Move and] capture from gnus to org
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; With point on an email in summary or article view, use '\' | |
;; (backslash) to move that email to a new group and capture it to org. | |
;; Uses `gnus-capture-template' instead of `org-capture-templates'. | |
;; To capture without moving, use 'C-c c'. | |
(require 'ol) | |
(require 'ol-gnus) | |
(require 'org-capture) | |
;; Set a ist of capture templates to use for gnus | |
;; These are mine. I capture most things to IN.org which is in | |
;; `my-org-directory'. 'f' for if I need to follow up or reply to a | |
;; message, 'l' for reading later, and 'r' for refiling to my ref.org | |
;; file (use 'C-c C-w' instead of 'C-c C-c' in the capture popup) | |
(setq org-intray "~/org/IN.org") | |
(setq gnus-capture-templates | |
`(("f" "Follow up" entry | |
(file ,org-intray) | |
"* TODO Follow up with %:fromname on %:subject :email:%:group: | |
%a | |
%i" | |
:prepend t) | |
("l" "Later to read" entry | |
(file ,org-intray) | |
"* TODO Read %:subject :email:%:group: | |
%a | |
%i" | |
:prepend t) | |
("r" "Refile" entry | |
(file ,org-intray) | |
"* %^{Headline} :email:%:group: | |
%a | |
%i" | |
:prepend t))) | |
(defun gnus-capture (&optional goto keys) | |
"Capture the current email. | |
Prefix arguments are passed to `org-capture'." | |
(interactive "P") | |
(let ((org-capture-templates gnus-capture-templates)) | |
(org-store-link nil t) | |
(org-capture goto keys))) | |
(define-key gnus-summary-mode-map (kbd "C-c c") #'gnus-capture) | |
(define-key gnus-article-mode-map (kbd "C-c c") #'gnus-capture) | |
(defun org-gnus-store-link-replace-group (link) | |
"If `new-group' is defined, replace it in stored LINK." | |
(if (boundp 'new-group) | |
(let ((new-link (replace-regexp-in-string "\\(^gnus:\\)[^#]*\\(#.*\\)" | |
(format "\\1%s\\2" new-group) | |
link))) | |
(org-link-add-props :link new-link | |
:group new-group) | |
new-link) | |
link)) | |
(advice-add 'org-gnus-store-link :filter-return | |
#'org-gnus-store-link-replace-group) | |
(defun gnus-move-and-capture (&optional goto keys) | |
"Move email to a new group then capture it. | |
Prefix arguments are passed to `org-capture'." | |
(interactive "P") | |
(let ((new-group (gnus-read-move-group-name | |
"move" gnus-current-move-group | |
(gnus-summary-work-articles 1) nil)) | |
(org-capture-templates gnus-capture-templates)) | |
(gnus-summary-move-article nil new-group) | |
(org-store-link nil t) | |
(org-capture goto keys))) | |
(define-key gnus-summary-mode-map (kbd "\\") #'gnus-move-and-capture) | |
(define-key gnus-article-mode-map (kbd "\\") #'gnus-move-and-capture) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment