diff --git a/emacs/.emacs.d/config/init-email.el b/emacs/.emacs.d/config/init-email.el index 31f7196..009cc21 100644 --- a/emacs/.emacs.d/config/init-email.el +++ b/emacs/.emacs.d/config/init-email.el @@ -4,9 +4,6 @@ :if (locate-library "mu4e") :commands (mu4e mu4e-update-mail-and-index) :hook (after-init . (lambda () (mu4e t))) - :general - (normal mu4e-headers-mode-map "t" #'mu4e-headers-mark-thread) - (normal mu4e-view-mode-map "t" #'mu4e-view-mark-thread) :config (setq ;; General @@ -17,6 +14,7 @@ user-mail-address "jeremy.dormitzer@gmail.com" mu4e-view-show-images t mu4e-headers-skip-duplicates t + mu4e-search-results-limit 3000 mu4e-split-view 'horizontal mail-user-agent 'mu4e-user-agent ;; Custom actions @@ -124,11 +122,51 @@ ("Matching current message from: field" mu4e-mark-matching-from-pred mu4e-mark-matching-from-input))) + + (defun mu4e-matching-search-query (msg field) + "Generates a mu query to find message with the same `field' value as `msg'." + (if-let ((field-str (substring (symbol-name field) 1)) + (field-val (mu4e-message-field msg field))) + (pcase field + ((or :to :from :cc :bcc) (format "%s:%s" field-str (plist-get (car field-val) :email))) + (:date (let ((time-string (format-time-string "%Y%m%d" field-val))) + (format "%s:%s..%s" field-str time-string time-string))) + (_ (format "%s:%s" field-str field-val))) + (error "No such message field %s" field))) + + (defun mu4e-search-matching (msg field) + (interactive (list (mu4e-message-at-point) + (let ((field-str (completing-read "Field to match: " + '("from" + "date" + "list") + nil + t))) + (intern (format ":%s" field-str))))) + (let ((query (mu4e-matching-search-query msg field))) + (mu4e-search query))) + + (defvar mu4e-search-map (make-sparse-keymap)) + (general-def mu4e-search-map + "s" #'mu4e-search + "S" #'mu4e-search-edit + "/" #'mu4e-search-narrow + "" #'mu4e-search-prev + "\\" #'mu4e-search-prev + "" #'mu4e-search-next + "O" #'mu4e-search-change-sorting + "P" #'mu4e-search-toggle-property + "b" #'mu4e-search-bookmark + "B" #'mu4e-search-bookmark-edit + "j" #'mu4e-search-maildir + "m" #'mu4e-search-matching) + (add-hook 'mu4e-compose-pre-hook (lambda () (set (make-local-variable '*should-delete-trailing-whitespace*) nil))) + ;; For some reason mu4e--server-filter expects these to be defined, but doesn't define them (when (null mu4e-info-func) (setq mu4e-info-func (lambda (&rest args)))) @@ -451,6 +489,13 @@ If given prefix arg ARG, skips markdown conversion." (add-face-text-property (point) (min (line-end-position) end) type) (if (< (line-end-position) end) (forward-line 1) - (goto-char end))))))) + (goto-char end)))))) + :general + (normal mu4e-headers-mode-map + "t" #'mu4e-headers-mark-thread + "s" mu4e-search-map) + (normal mu4e-view-mode-map + "t" #'mu4e-view-mark-thread + "s" mu4e-search-map)) (provide 'init-email)