tvl-depot/users/tazjin/emacs/config/mail-setup.el
Vincent Ambo e78b79c6cd refactor(tazjin/emacs): ivy,swiper,counsel -> vertico,consult
vertico and consult are more modern versions of interactive narrowing
helpers, as those implemented by ivy and its related packages.

The primary differences (and what I care about here) is that they are
more focused on integration with the core Emacs primitives, rather
than building an ecosystem around them.

For example:

* vertico enhances `completing-read' and friends, but does not attempt
  to provide its own ecosystem of functions to *trigger* completions.

* vertico integrates with the default `completion-style' system,
  meaning that I can continue to use things like prescient without
  extra packages that integrate it with vertico

* consult does not rely on vertico or any other specific completion
  framework (such as counsel/swiper do with ivy), and simply
  implements its functions using completing-read

This reduces the overall amount of code in the dependency closure and
leads to a less special setup.

Functionality is basically equivalent, except for two things which
counsel came with that I will need to substitute:

* counsel-notmuch (actually this was a separate package, but I didn't
  use it much anyways, so just ignoring it for now)
* counsel-linux-app (opening desktop shortcuts, this I will need to make)

As a side note, consult notes "This package is a part of GNU Emacs",
but it doesn't seem to be the case.

Change-Id: Ia046b763bf3d401b505e0f6393cfe1ccd6f41293
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9155
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
2023-08-26 23:30:21 +00:00

83 lines
3.2 KiB
EmacsLisp

(require 'notmuch)
;; (global-set-key (kbd "C-c m") 'notmuch-hello)
;; (global-set-key (kbd "C-c C-e n") 'notmuch-mua-new-mail)
(setq notmuch-cache-dir (format "%s/.cache/notmuch" (getenv "HOME")))
(make-directory notmuch-cache-dir t)
;; Cache addresses for completion:
(setq notmuch-address-save-filename (concat notmuch-cache-dir "/addresses"))
;; Don't spam my home folder with drafts:
(setq notmuch-draft-folder "drafts") ;; relative to notmuch database
;; Mark things as read when archiving them:
(setq notmuch-archive-tags '("-inbox" "-unread" "+archive"))
;; Show me saved searches that I care about:
(setq notmuch-saved-searches
'((:name "inbox" :query "tag:inbox" :count-query "tag:inbox AND tag:unread" :key "i")
(:name "sent" :query "tag:sent" :key "t")
(:name "drafts" :query "tag:draft")))
(setq notmuch-show-empty-saved-searches t)
;; Mail sending configuration
(setq sendmail-program "gmi") ;; lieer binary supports sendmail emulation
(setq message-sendmail-extra-arguments
'("send" "--quiet" "-t" "-C" "~/mail/account.tazjin"))
(setq send-mail-function 'sendmail-send-it)
(setq notmuch-mua-user-agent-function
(lambda () (format "Emacs %s; notmuch.el %s" emacs-version notmuch-emacs-version)))
(setq mail-host-address (system-name))
(setq notmuch-mua-cite-function #'message-cite-original-without-signature)
(setq notmuch-fcc-dirs nil) ;; Gmail does this server-side
(setq message-signature nil) ;; Insert message signature manually with C-c C-w
;; Close mail buffers after sending mail
(setq message-kill-buffer-on-exit t)
;; Ensure sender is correctly passed to msmtp
(setq mail-specify-envelope-from t
message-sendmail-envelope-from 'header
mail-envelope-from 'header)
;; Store sent mail in the correct folder per account
(setq notmuch-maildir-use-notmuch-insert nil)
;; I don't use drafts but I instinctively hit C-x C-s constantly, lets
;; handle that gracefully.
(define-key notmuch-message-mode-map (kbd "C-x C-s") #'ignore)
;; Define a telephone-line segment for displaying the count of unread,
;; important mails in the last window's mode-line:
(defvar *last-notmuch-count-redraw* 0)
(defvar *current-notmuch-count* nil)
(defun update-display-notmuch-counts ()
"Update and render the current state of the notmuch unread
count for display in the mode-line.
The offlineimap-timer runs every 2 minutes, so it does not make
sense to refresh this much more often than that."
(when (> (- (float-time) *last-notmuch-count-redraw*) 30)
(setq *last-notmuch-count-redraw* (float-time))
(let* ((inbox-unread (notmuch-saved-search-count "tag:inbox and tag:unread"))
(notmuch-count (format "I: %s; D: %s" inbox-unread)))
(setq *current-notmuch-count* notmuch-count)))
(when (and (bottom-right-window-p)
;; Only render if the initial update is done and there
;; are unread mails:
*current-notmuch-count*
(not (equal *current-notmuch-count* "I: 0; D: 0")))
*current-notmuch-count*))
(telephone-line-defsegment telephone-line-notmuch-counts ()
"This segment displays the count of unread notmuch messages in
the last window's mode-line (if unread messages are present)."
(update-display-notmuch-counts))
(provide 'mail-setup)