aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaúl Benencia <id@rbenencia.name>2024-10-27 17:02:26 -0700
committerRaúl Benencia <id@rbenencia.name>2024-10-27 17:02:26 -0700
commit172492bd2cc09b8af2554f6e0fc0ca995e1aa52b (patch)
treeff992e0e114d43dfccb28b96d0a8b0ebf6ca20df
parent5b6428917a8e46df69a58a10c4aeea119f27a6da (diff)
emacs: mv {mail-mode,notmuch}.el to package rul-mail
-rw-r--r--.emacs.d/init.el11
-rw-r--r--.emacs.d/rul-emacs.org9
-rw-r--r--.emacs.d/rul-init.d/mail-mode.el15
-rw-r--r--.emacs.d/rul-lisp/packages/rul-mail.el151
4 files changed, 152 insertions, 34 deletions
diff --git a/.emacs.d/init.el b/.emacs.d/init.el
index 6ca8098..476591b 100644
--- a/.emacs.d/init.el
+++ b/.emacs.d/init.el
@@ -20,7 +20,6 @@
;; Global keybindings
(global-set-key (kbd "C-c R") 'revert-buffer)
-(global-set-key (kbd "C-c q") 'auto-fill-mode)
(global-set-key (kbd "C-c w") 'whitespace-cleanup)
(defun help/insert-em-dash ()
@@ -71,7 +70,6 @@
(dolist (path '("~/.emacs.d/rul-lisp/config" "~/.emacs.d/rul-lisp/packages"))
(add-to-list 'load-path path))
-(require 'rul-themes)
(require 'rul-completion)
(require 'rul-fm)
(require 'rul-prog)
@@ -83,20 +81,11 @@
(require 'rul-write)
;; Init parts (will be deprecated in favor of packages)
-(load-file "~/.emacs.d/rul-init.d/auto-fill.el")
-(load-file "~/.emacs.d/rul-init.d/flycheck.el")
-(load-file "~/.emacs.d/rul-init.d/flyspell.el")
(load-file "~/.emacs.d/rul-init.d/fonts.el")
-(load-file "~/.emacs.d/rul-init.d/go-lang.el")
(load-file "~/.emacs.d/rul-init.d/hydra.el")
(load-file "~/.emacs.d/rul-init.d/ibuffer.el")
(load-file "~/.emacs.d/rul-init.d/imenu.el")
-(load-file "~/.emacs.d/rul-init.d/latex.el")
-(load-file "~/.emacs.d/rul-init.d/logos.el")
(load-file "~/.emacs.d/rul-init.d/magit.el")
-(load-file "~/.emacs.d/rul-init.d/mail-mode.el")
-(load-file "~/.emacs.d/rul-init.d/markdown.el")
-(load-file "~/.emacs.d/rul-init.d/notmuch.el")
(load-file "~/.emacs.d/rul-init.d/vterm.el")
(load-file "~/.emacs.d/rul-init.d/which-key.el")
diff --git a/.emacs.d/rul-emacs.org b/.emacs.d/rul-emacs.org
index 57394ee..e517f12 100644
--- a/.emacs.d/rul-emacs.org
+++ b/.emacs.d/rul-emacs.org
@@ -193,6 +193,7 @@ Now, I simply start it from Emacs itself. This approach works well for me.
(require 'rul-fm)
(require 'rul-prog)
(require 'rul-elfeed)
+(require 'rul-mail)
(require 'rul-modeline)
(require 'rul-media)
(require 'rul-org)
@@ -200,19 +201,11 @@ Now, I simply start it from Emacs itself. This approach works well for me.
(require 'rul-write)
;; Init parts (will be deprecated in favor of packages)
-(load-file "~/.emacs.d/rul-init.d/flycheck.el")
-(load-file "~/.emacs.d/rul-init.d/flyspell.el")
(load-file "~/.emacs.d/rul-init.d/fonts.el")
-(load-file "~/.emacs.d/rul-init.d/go-lang.el")
(load-file "~/.emacs.d/rul-init.d/hydra.el")
(load-file "~/.emacs.d/rul-init.d/ibuffer.el")
(load-file "~/.emacs.d/rul-init.d/imenu.el")
-(load-file "~/.emacs.d/rul-init.d/latex.el")
-(load-file "~/.emacs.d/rul-init.d/logos.el")
(load-file "~/.emacs.d/rul-init.d/magit.el")
-(load-file "~/.emacs.d/rul-init.d/mail-mode.el")
-(load-file "~/.emacs.d/rul-init.d/markdown.el")
-(load-file "~/.emacs.d/rul-init.d/notmuch.el")
(load-file "~/.emacs.d/rul-init.d/vterm.el")
(load-file "~/.emacs.d/rul-init.d/which-key.el")
diff --git a/.emacs.d/rul-init.d/mail-mode.el b/.emacs.d/rul-init.d/mail-mode.el
deleted file mode 100644
index 09b04f9..0000000
--- a/.emacs.d/rul-init.d/mail-mode.el
+++ /dev/null
@@ -1,15 +0,0 @@
-(setq auto-mode-alist (append '((".*tmp/mutt.*" . message-mode)) auto-mode-alist))
-(setq auto-mode-alist (append '((".*tmp/neomutt.*" . message-mode)) auto-mode-alist))
-(add-to-list 'auto-mode-alist '("/mutt" . mail-mode))
-
-(setq mml-secure-openpgp-sign-with-sender t)
-
-(add-hook 'mail-mode-hook
- (lambda ()
- (font-lock-add-keywords nil
- '(("^[ \t]*>[ \t]*>[ \t]*>.*$"
- (0 'compilation-error))
- ("^[ \t]*>[ \t]*>.*$"
- (0 'compilation-column-number))
- ("^[ \t]*>.*$"
- (0 'comint-highlight-prompt))))))
diff --git a/.emacs.d/rul-lisp/packages/rul-mail.el b/.emacs.d/rul-lisp/packages/rul-mail.el
new file mode 100644
index 0000000..b69557e
--- /dev/null
+++ b/.emacs.d/rul-lisp/packages/rul-mail.el
@@ -0,0 +1,151 @@
+;; mail-mode
+(setq mml-secure-openpgp-sign-with-sender t)
+
+(add-hook 'mail-mode-hook
+ (lambda ()
+ (font-lock-add-keywords nil
+ '(("^[ \t]*>[ \t]*>[ \t]*>.*$"
+ (0 'compilation-error))
+ ("^[ \t]*>[ \t]*>.*$"
+ (0 'compilation-column-number))
+ ("^[ \t]*>.*$"
+ (0 'comint-highlight-prompt))))))
+
+;; notmuch
+(require 'rul-config-mail)
+
+(use-package notmuch
+ :ensure t
+ :config
+ ;; UI
+ (setq notmuch-show-logo nil
+ notmuch-column-control 1.0
+ notmuch-hello-auto-refresh t
+ notmuch-hello-recent-searches-max 20
+ notmuch-hello-thousands-separator ""
+ notmuch-show-all-tags-list t)
+
+ ;; Keymaps
+ (defun rul/capture-mail()
+ "Capture mail to org mode."
+ (interactive)
+ (org-store-link nil)
+ (org-capture nil "m")
+ )
+
+ (bind-key "c" 'rul/capture-mail notmuch-show-mode-map)
+
+ (define-key notmuch-show-mode-map "R" 'notmuch-show-reply)
+ (define-key notmuch-search-mode-map "R" 'notmuch-search-reply-to-thread)
+
+ ;; Spam
+ (define-key notmuch-show-mode-map "S"
+ (lambda ()
+ "mark message as spam"
+ (interactive)
+ (notmuch-show-tag (list "+spam" "-inbox" "-unread"))))
+
+ (define-key notmuch-search-mode-map "S"
+ (lambda (&optional beg end)
+ "mark thread as spam"
+ (interactive (notmuch-search-interactive-region))
+ (notmuch-search-tag (list "+spam" "-inbox" "-unread") beg end)))
+
+ ;; Archive
+ (setq notmuch-archive-tags (list "-inbox" "+archive"))
+ (define-key notmuch-show-mode-map "A"
+ (lambda ()
+ "archive"
+ (interactive)
+ (notmuch-show-tag (list "+archive" "-inbox" "-unread"))
+ (notmuch-refresh-this-buffer)))
+
+ (define-key notmuch-search-mode-map "A"
+ (lambda (&optional beg end)
+ "archive thread"
+ (interactive (notmuch-search-interactive-region))
+ (notmuch-search-tag (list "+archive" "-inbox" "-unread") beg end)
+ (notmuch-refresh-this-buffer)))
+
+ ;; Mark as read
+ (define-key notmuch-search-mode-map "r"
+ (lambda (&optional beg end)
+ "mark thread as read"
+ (interactive (notmuch-search-interactive-region))
+ (notmuch-search-tag (list "-unread") beg end)
+ (notmuch-search-next-thread)))
+
+ (define-key notmuch-search-mode-map (kbd "RET")
+ (lambda ()
+ "Show the selected thread with notmuch-tree if it has more
+than one email. Use notmuch-show otherwise."
+ (interactive)
+ (if (= (plist-get (notmuch-search-get-result) :total) 1)
+ (notmuch-search-show-thread)
+ (notmuch-tree (notmuch-search-find-thread-id)
+ notmuch-search-query-string
+ nil
+ (notmuch-prettify-subject (notmuch-search-find-subject))))))
+
+ (defun color-inbox-if-unread () (interactive)
+ (save-excursion
+ (goto-char (point-min))
+ (let ((cnt (car (process-lines "notmuch" "count" "tag:inbox and tag:unread"))))
+ (when (> (string-to-number cnt) 0)
+ (save-excursion
+ (when (search-forward "inbox" (point-max) t)
+ (let* ((overlays (overlays-in (match-beginning 0) (match-end 0)))
+ (overlay (car overlays)))
+ (when overlay
+ (overlay-put overlay 'face '((:inherit bold) (:foreground "green")))))))))))
+
+ (defvar notmuch-hello-refresh-count 0)
+ (defun notmuch-hello-refresh-status-message ()
+ (let* ((new-count
+ (string-to-number
+ (car (process-lines notmuch-command "count"))))
+ (diff-count (- new-count notmuch-hello-refresh-count)))
+ (cond
+ ((= notmuch-hello-refresh-count 0)
+ (message "You have %s messages."
+ (notmuch-hello-nice-number new-count)))
+ ((> diff-count 0)
+ (message "You have %s more messages since last refresh."
+ (notmuch-hello-nice-number diff-count)))
+ ((< diff-count 0)
+ (message "You have %s fewer messages since last refresh."
+ (notmuch-hello-nice-number (- diff-count)))))
+ (setq notmuch-hello-refresh-count new-count)))
+
+ (add-hook 'notmuch-hello-refresh-hook 'color-inbox-if-unread)
+ (add-hook 'notmuch-hello-refresh-hook 'notmuch-hello-refresh-status-message)
+
+ (setq notmuch-hello-sections '(notmuch-hello-insert-saved-searches
+ notmuch-hello-insert-search
+ notmuch-hello-insert-recent-searches
+ notmuch-hello-insert-alltags
+ ))
+
+ ;; https://git.sr.ht/~tslil/dotfiles/tree/4e51afbb/emacs/notmuch-config.el#L76-82
+ (defmacro make-binds (mode-map binds argfunc &rest body)
+ "Create keybindings in `mode-map' using a list of (keystr . arg)
+pairs in `binds' of the form ( ... (argfunc arg) body)."
+ `(progn ,@(mapcar (lambda (pair)
+ `(define-key ,mode-map (kbd ,(car pair))
+ (lambda () (interactive) (,argfunc ,(cdr pair)) ,@body)))
+ (eval binds))))
+
+ (defvar notmuch-hello-tree-searches '(("u" . "tag:unread")
+ ("i" . "tag:inbox")
+ ("*" . "*"))
+ "List of (key . query) pairs to bind in notmuch-hello.")
+
+ (make-binds notmuch-hello-mode-map
+ notmuch-hello-tree-searches
+ notmuch-search)
+) ;; ends use-package notmuch
+
+(use-package notmuch-indicator :ensure t)
+
+(provide 'rul-mail)
+
nihil fit ex nihilo