summaryrefslogtreecommitdiff
path: root/emacs/.config/emacs-v2/lisp/kj-email.el
diff options
context:
space:
mode:
Diffstat (limited to 'emacs/.config/emacs-v2/lisp/kj-email.el')
-rw-r--r--emacs/.config/emacs-v2/lisp/kj-email.el84
1 files changed, 84 insertions, 0 deletions
diff --git a/emacs/.config/emacs-v2/lisp/kj-email.el b/emacs/.config/emacs-v2/lisp/kj-email.el
new file mode 100644
index 0000000..4aa6439
--- /dev/null
+++ b/emacs/.config/emacs-v2/lisp/kj-email.el
@@ -0,0 +1,84 @@
+;;; -*- lexical-binding: t; -*-
+
+(setq kj/fastmail-maildir (expand-file-name "~/Maildir/fastmail"))
+
+(when (file-exists-p (expand-file-name "~/Maildir"))
+ (with-eval-after-load 'message
+ (setq message-mail-user-agent 'notmuch-user-agent
+ message-cite-style 'message-cite-style-gmail
+ message-citation-line-function 'message-insert-formatted-citation-line
+ message-kill-buffer-on-exit t)
+ (add-hook 'message-mode-hook 'turn-off-auto-fill)
+ (add-hook 'message-mode-hook 'visual-line-mode))
+ (use-package notmuch
+ :bind
+ (:map notmuch-hello-mode-map
+ ("T" . kj/notmuch-tree-by-tag))
+ :config
+
+ (setq notmuch-show-all-tags-list t
+ notmuch-show-relative-dates t
+ notmuch-hello-tag-list-make-query "tag:unread"
+ notmuch-archive-tags '("-inbox" "-unread")
+ notmuch-fcc-dirs nil
+ notmuch-show-logo nil
+ notmuch-mua-cite-function 'message-cite-original-without-signature
+ notmuch-wash-citation-lines-prefix most-positive-fixnum
+ notmuch-wash-citation-lines-suffix most-positive-fixnum
+ notmuch-show-indent-messages-width 0)
+ (add-hook 'notmuch-show-hook 'kj/disable-trailing-whitespace)
+
+ (defun kj/confirm-empty-subject ()
+ "Allow user to quit when current message subject is empty."
+ (or (message-field-value "Subject")
+ (yes-or-no-p "Really send without Subject? ")
+ (keyboard-quit)))
+ (add-hook 'message-send-hook #'kj/confirm-empty-subject)
+ (advice-add
+ 'message-send :before (defun kj/notmuch-switch-to-local (&args)
+ (when (file-remote-p default-directory)
+ (cd (expand-file-name "~")))))
+ (setq notmuch-saved-searches
+ '((:name "inbox" :query "tag:inbox -tag:_gz" :key "i" :search-type tree)
+ (:name "unread" :query "tag:unread" :key "u" :search-type tree)
+ (:name "flagged" :query "tag:flagged" :key "f" :search-type tree)
+ (:name "sent" :query "tag:sent" :key "t" :search-type tree)
+ (:name "drafts" :query "tag:draft" :key "d" :search-type tree)
+ (:name "all mail" :query "*" :key "a" :search-type tree)
+ )))
+
+ (setq kj/notmuch-wash-citation-regexp "^\\(\\(>\\|[[:space:]]\\)+\\).*\n")
+
+ ;;; XXX consider upstreaming this.
+ (defun kj/notmuch-wash-citations-by-depth (_msg _depth)
+ (goto-char (point-min))
+ (beginning-of-line)
+ (let ((maxlevel 1))
+ (while (intern-soft (format "message-cited-text-%d" maxlevel))
+ (setq maxlevel (1+ maxlevel)))
+ (setq maxlevel (1- maxlevel))
+
+ (while (and (< (point) (point-max))
+ (re-search-forward kj/notmuch-wash-citation-regexp nil t))
+ (let* ((cite-start (match-beginning 0))
+ (cite-end (match-end 0))
+ (cite-level (seq-count (lambda (c) (eql c ?>)) (match-string 1)))
+ (face-level (1+ (% (1- cite-level) maxlevel)))
+ (cited-text-face (intern (format "message-cited-text-%d" face-level))))
+ (overlay-put (make-overlay cite-start cite-end)
+ 'face cited-text-face)))))
+ ;; This doesn't seem to work that well... :(
+ ;;(add-hook 'notmuch-show-insert-text/plain-hook #'kj/notmuch-wash-citations-by-depth 90)
+
+ (defun kj/notmuch-tree-by-tag (tag)
+ (interactive
+ (list (notmuch-select-tag-with-completion "Notmuch search tag: ")))
+ (notmuch-tree (concat "tag:" tag))))
+
+(when (file-exists-p kj/fastmail-maildir)
+ (setq sendmail-program "mujmap"
+ message-send-mail-function 'message-send-mail-with-sendmail
+ message-signature "Kjetil"
+ message-sendmail-extra-arguments (list "-C" kj/fastmail-maildir "send")))
+
+(provide 'kj-email)