Mu4e: add function for filing email to agenda
This commit is contained in:
parent
74411c87b8
commit
66557c9fe4
1 changed files with 67 additions and 0 deletions
|
@ -203,6 +203,73 @@ will also be the width of all other printable characters."
|
||||||
(when (fboundp 'imagemagick-register-types)
|
(when (fboundp 'imagemagick-register-types)
|
||||||
(imagemagick-register-types))
|
(imagemagick-register-types))
|
||||||
|
|
||||||
|
;; Adding emails to the agenda
|
||||||
|
;; Perfect for when you see an email you want to reply to
|
||||||
|
;; later, but don't want to forget about
|
||||||
|
|
||||||
|
(defun mu4e-msg-to-agenda (arg)
|
||||||
|
"Refile a message and add a entry in the agenda file with a
|
||||||
|
deadline. Default deadline is today. With one prefix, deadline
|
||||||
|
is tomorrow. With two prefixes, select the deadline."
|
||||||
|
(interactive "p")
|
||||||
|
(let ((file (car org-agenda-files))
|
||||||
|
(sec "^* Email")
|
||||||
|
(msg (mu4e-message-at-point)))
|
||||||
|
(when msg
|
||||||
|
;; put the message in the agenda
|
||||||
|
(with-current-buffer (find-file-noselect file)
|
||||||
|
(save-excursion
|
||||||
|
;; find header section
|
||||||
|
(goto-char (point-min))
|
||||||
|
(when (re-search-forward sec nil t)
|
||||||
|
(let (org-M-RET-may-split-line
|
||||||
|
(lev (org-outline-level))
|
||||||
|
(folded-p (invisible-p (point-at-eol))))
|
||||||
|
;; place the subheader
|
||||||
|
(when folded-p (show-branches)) ; unfold if necessary
|
||||||
|
(org-end-of-meta-data) ; skip property drawer
|
||||||
|
(org-insert-todo-heading 1) ; insert a todo heading
|
||||||
|
(when (= (org-outline-level) lev) ; demote if necessary
|
||||||
|
(org-do-demote))
|
||||||
|
;; insert message and add deadline
|
||||||
|
(insert (concat " Respond to "
|
||||||
|
"[[mu4e:msgid:"
|
||||||
|
(plist-get msg :message-id) "]["
|
||||||
|
(truncate-string-to-width
|
||||||
|
(caar (plist-get msg :from)) 25 nil nil t)
|
||||||
|
" - "
|
||||||
|
(truncate-string-to-width
|
||||||
|
(plist-get msg :subject) 40 nil nil t)
|
||||||
|
"]] "))
|
||||||
|
(org-deadline nil
|
||||||
|
(cond ((= arg 1) (format-time-string "%Y-%m-%d"))
|
||||||
|
((= arg 4) "+1d")))
|
||||||
|
|
||||||
|
(org-update-parent-todo-statistics)
|
||||||
|
|
||||||
|
;; refold as necessary
|
||||||
|
(if folded-p
|
||||||
|
(progn
|
||||||
|
(org-up-heading-safe)
|
||||||
|
(hide-subtree))
|
||||||
|
(hide-entry))))))
|
||||||
|
;; refile the message and update
|
||||||
|
;; (cond ((eq major-mode 'mu4e-view-mode)
|
||||||
|
;; (mu4e-view-mark-for-refile))
|
||||||
|
;; ((eq major-mode 'mu4e-headers-mode)
|
||||||
|
;; (mu4e-headers-mark-for-refile)))
|
||||||
|
(message "Refiled \"%s\" and added to the agenda for %s"
|
||||||
|
(truncate-string-to-width
|
||||||
|
(plist-get msg :subject) 40 nil nil t)
|
||||||
|
(cond ((= arg 1) "today")
|
||||||
|
((= arg 4) "tomorrow")
|
||||||
|
(t "later"))))))
|
||||||
|
|
||||||
|
(map! :map mu4e-headers-mode-map
|
||||||
|
:e "l" #'mu4e-msg-to-agenda)
|
||||||
|
|
||||||
|
;; General keybindings
|
||||||
|
|
||||||
(map! :localleader
|
(map! :localleader
|
||||||
:map mu4e-compose-mode-map
|
:map mu4e-compose-mode-map
|
||||||
:desc "send and exit" "s" #'message-send-and-exit
|
:desc "send and exit" "s" #'message-send-and-exit
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue