From c0313263675974dc952092dfb72f5464e07efb0a Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 16 Feb 2022 23:19:27 -0600 Subject: Notmuch and stuff --- lisp/+notmuch.el | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 lisp/+notmuch.el (limited to 'lisp') diff --git a/lisp/+notmuch.el b/lisp/+notmuch.el new file mode 100644 index 0000000..890edbe --- /dev/null +++ b/lisp/+notmuch.el @@ -0,0 +1,62 @@ +;;; +notmuch.el --- Notmuch extras -*- lexical-binding: t; -*- + +;;; Commentary: + +;; This is stuff that I suppose /could/ go in notmuch/init.el, but ... doesn't. + +;;; Code: + +(require 'cl-lib) +(require 'notmuch) + +(defvar +notmuch-send-dispatch-rules nil + "Alist of from addresses and variables to set when sending.") + +(defun +notmuch-query-concat (&rest queries) + "Concatenate notmuch queries." + (mapconcat #'identity queries " AND ")) + +(defun +send-mail-dispatch () + "Dispatch mail sender, depending on account." + (let ((from (message-fetch-field "from"))) + (dolist (vars (cl-loop for (addr . vars) in +notmuch-send-dispatch-rules + if (string-match-p addr from) return vars)) + (set (car vars) (cdr vars))))) + +(defun +notmuch-correct-tags (args) + (list (car args) (mapcar #'string-trim (cadr args)))) + +(defun +notmuch-goto (&optional prefix) + "Go straight to a `notmuch' search. +Without PREFIX argument, go to the first one in +`notmuch-saved-searches'; with a PREFIX argument, prompt the user +for which saved search to go to; with a double PREFIX +argument (\\[universal-argument] \\[universal-argument]), prompt +for search." + (interactive "P") + (pcase prefix + ('nil (notmuch-search (plist-get (car notmuch-saved-searches) :query))) + ('(4) (notmuch-search (plist-get (cl-find (completing-read "Saved Search: " + (mapcar (lambda (el) + (plist-get el :name)) + notmuch-saved-searches)) + notmuch-saved-searches + :key (lambda (el) (plist-get el :name)) + :test #'equal) + :query))) + (_ (notmuch-search)))) + +;; Don't add an initial input when completing addresses +(el-patch-feature notmuch) +(with-eval-after-load 'notmuch + (el-patch-defun notmuch-address-selection-function (prompt collection initial-input) + "Call (`completing-read' + PROMPT COLLECTION nil nil INITIAL-INPUT 'notmuch-address-history)" + (completing-read + prompt collection nil nil + (el-patch-swap initial-input + nil) + 'notmuch-address-history))) + +(provide '+notmuch) +;;; +notmuch.el ends here -- cgit 1.4.1-21-gabe81