diff options
author | Case Duckworth | 2023-05-05 09:58:21 -0500 |
---|---|---|
committer | Case Duckworth | 2023-05-05 09:58:21 -0500 |
commit | 989171268461a0069ecd53a49e6098ce08638102 (patch) | |
tree | b88889d371152458f674c0a608222bf1192f3980 /lisp/acdw-mail.el | |
parent | remove bad fiels (diff) | |
download | emacs-989171268461a0069ecd53a49e6098ce08638102.tar.gz emacs-989171268461a0069ecd53a49e6098ce08638102.zip |
changes use-package
Diffstat (limited to 'lisp/acdw-mail.el')
-rw-r--r-- | lisp/acdw-mail.el | 87 |
1 files changed, 76 insertions, 11 deletions
diff --git a/lisp/acdw-mail.el b/lisp/acdw-mail.el index f8111e7..bf20c9b 100644 --- a/lisp/acdw-mail.el +++ b/lisp/acdw-mail.el | |||
@@ -146,7 +146,7 @@ the saved search as well." | |||
146 | (notmuch-poll))) | 146 | (notmuch-poll))) |
147 | (lambda (_) | 147 | (lambda (_) |
148 | (message "Polling mail (async)...done")))) | 148 | (message "Polling mail (async)...done")))) |
149 | ;;(user-error "Feature `async' not found!") | 149 | (user-error "Feature `async' not found!") |
150 | (notmuch-poll))) | 150 | (notmuch-poll))) |
151 | 151 | ||
152 | ;;; https://kitchingroup.cheme.cmu.edu/blog/2015/09/04/Checking-for-email-attachments-before-you-send-email/ | 152 | ;;; https://kitchingroup.cheme.cmu.edu/blog/2015/09/04/Checking-for-email-attachments-before-you-send-email/ |
@@ -172,28 +172,93 @@ the saved search as well." | |||
172 | (error "No attachment. Aborting send.")))) | 172 | (error "No attachment. Aborting send.")))) |
173 | 173 | ||
174 | ;;; Process ical attachments | 174 | ;;; Process ical attachments |
175 | ;; https://www.reddit.com/r/emacs/comments/8s1ion/comment/e0x5kgd/ | ||
176 | |||
177 | (defun ical2org (&optional replace output-buffer) | ||
178 | "Run ical2org on contents of this buffer. | ||
179 | If REPLACE (interactive prefix argument), replace contents of the | ||
180 | buffer. If no REPLACE nor OUTPUT-BUFFER, output goes to | ||
181 | minibuffer." | ||
182 | (interactive "P") | ||
183 | (shell-command-on-region (point-min) (point-max) | ||
184 | "ical2org.awk" | ||
185 | output-buffer | ||
186 | replace | ||
187 | "*ical2org errors*" | ||
188 | 'display-errors)) | ||
189 | |||
190 | (defun ical2org-capture () | ||
191 | "Run `ical2org' on this buffer, then `org-capture' the result. | ||
192 | Leaves current buffer as-was afterwards." | ||
193 | (interactive) | ||
194 | (let ((buf (current-buffer)) | ||
195 | (ics (buffer-string))) | ||
196 | (ical2org 'replace buf) | ||
197 | (mark-whole-buffer) | ||
198 | (org-capture nil "a") | ||
199 | (mark-whole-buffer) | ||
200 | (delete-region (point-min) (point-max)) | ||
201 | (insert ics))) | ||
202 | |||
203 | (defun notmuch-ics-refile (filename header) | ||
204 | "Refile the current ICS buffer to FILENAME, under HEADER." | ||
205 | (org-refile nil nil | ||
206 | (list header | ||
207 | filename | ||
208 | nil | ||
209 | (with-current-buffer (find-file-noselect filename) | ||
210 | (org-find-exact-headline-in-buffer header)))) | ||
211 | (notmuch-ics-kill)) | ||
212 | |||
213 | (defun notmuch-ics-kill () | ||
214 | "Kill the current ICS buffer and delete its file." | ||
215 | (let ((kill-buffer-hook nil) | ||
216 | (kill-buffer-query-functions nil) | ||
217 | (file (buffer-file-name))) | ||
218 | (set-buffer-modified-p nil) | ||
219 | (kill-buffer-and-window) | ||
220 | (delete-file file))) | ||
221 | |||
222 | (defun notmuch-ics-cancel () | ||
223 | "Cancel saving ICS buffer." | ||
224 | (interactive) | ||
225 | (notmuch-ics-kill)) | ||
226 | |||
227 | (define-derived-mode notmuch-save-ics-mode org-mode | ||
228 | "Org-mode but with a different keymap.") | ||
175 | 229 | ||
176 | (defun notmuch-save-ics () | 230 | (defun notmuch-save-ics () |
231 | ;; XXX: this is hacky as hell | ||
177 | "Save a .ics file in a message." | 232 | "Save a .ics file in a message." |
178 | (interactive) | 233 | (interactive) |
179 | (with-current-notmuch-show-message | 234 | (with-current-notmuch-show-message |
180 | (notmuch-foreach-mime-part | 235 | (notmuch-foreach-mime-part |
181 | (lambda (part) | 236 | (lambda (part) |
182 | (message "%S" part) | ||
183 | (when (and (listp part) | 237 | (when (and (listp part) |
184 | (or (equal "application/ics" (caadr part)) | 238 | (or (equal "application/ics" (caadr part)) |
185 | ;; (equal "text/calendar" (caadr part)) | 239 | ;; (equal "text/calendar" (caadr part)) |
186 | )) | 240 | )) |
187 | (save-window-excursion | 241 | (let* ((filename (format "/dev/shm/notmuch-%s.ics" |
188 | (let* ((filename "/tmp/notmuch.ics") | 242 | (time-convert (current-time) 'integer)))) |
189 | (buf (find-file-noselect filename))) | 243 | (mm-save-part-to-file part filename) |
190 | (delete-file filename) | 244 | (message "Converting ICS to org ...") |
191 | (kill-buffer (get-file-buffer filename)) | 245 | (with-current-buffer (find-file-other-window filename) |
192 | (mm-save-part-to-file part filename) | 246 | (ical2org 'replace (current-buffer)) |
193 | (icalendar-import-file filename diary-file) | 247 | (deactivate-mark) |
194 | (kill-buffer buf))))) | 248 | (let ((org-mode-hook nil)) |
249 | (notmuch-save-ics-mode)) | ||
250 | (local-set-key (kbd "C-c C-c") | ||
251 | (lambda () (interactive) | ||
252 | (notmuch-ics-refile (sync/ "org/diary.org") "Appointments"))) | ||
253 | (local-set-key (kbd "C-c C-k") #'notmuch-ics-cancel) | ||
254 | (setq-local header-line-format | ||
255 | (concat "ICAL buffer. " | ||
256 | "Finish: `C-c C-c'. " | ||
257 | "Abort: `C-c C-k'.")))))) | ||
195 | (mm-dissect-buffer t t)))) | 258 | (mm-dissect-buffer t t)))) |
196 | 259 | ||
260 | (add-hook 'notmuch-show-hook #'notmuch-save-ics) | ||
261 | |||
197 | 262 | ||
198 | ;;; Fixes | 263 | ;;; Fixes |
199 | 264 | ||
@@ -338,7 +403,7 @@ the saved search as well." | |||
338 | (add-hook 'notmuch-show-mode-hook #'visual-fill-column-mode) | 403 | (add-hook 'notmuch-show-mode-hook #'visual-fill-column-mode) |
339 | 404 | ||
340 | (define-advice notmuch-bury-or-kill-this-buffer (:after (&rest _) poll-async) | 405 | (define-advice notmuch-bury-or-kill-this-buffer (:after (&rest _) poll-async) |
341 | (notmuch-async-poll)) | 406 | (call-process "swaymail")) |
342 | 407 | ||
343 | (define-advice notmuch-address-selection-function | 408 | (define-advice notmuch-address-selection-function |
344 | (:override (prompt collection _) no-initial-input) | 409 | (:override (prompt collection _) no-initial-input) |