Compare commits

...

7 commits

Author SHA1 Message Date
Benson Chu
cab634d3fc Turns out there was a real function for this 2026-04-20 06:54:19 -05:00
Benson Chu
546a6ef9ce Primary filter 2026-04-20 06:54:19 -05:00
42e67e873a Wow, I like this way more than deadgrep
Wish wgrep worked though...
2026-04-20 06:30:35 -05:00
7de2adae19 Brighter please 2026-04-20 06:30:25 -05:00
c5eee2990d Will I actually start using mu4e at home now? 2026-04-20 05:22:30 -05:00
cca5ed04c8 Consolidate similarities 2026-04-19 20:15:17 -05:00
e5d54febb5 use-package 2026-04-16 06:42:06 -05:00
7 changed files with 475 additions and 261 deletions

View file

@ -66,6 +66,15 @@
(dedicated . t))) (dedicated . t)))
(window-width . 100))) (window-width . 100)))
(add-to-list 'display-buffer-alist
`((major-mode . grep-mode)
display-buffer-in-side-window
(side . right)
(slot . 3)
(window-parameters . ((no-delete-other-windows . t)
(dedicated . t)))
(window-width . 100)))
(add-to-list 'display-buffer-alist (add-to-list 'display-buffer-alist
`(my/is-compilation-buffer `(my/is-compilation-buffer
display-buffer-in-side-window display-buffer-in-side-window
@ -153,10 +162,7 @@
* colorful compilation buffer * colorful compilation buffer
#+begin_src emacs-lisp #+begin_src emacs-lisp
(require 'ansi-color) (require 'ansi-color)
(defun colorize-compilation-buffer () (add-hook 'compilation-filter-hook 'ansi-color-compilation-filter)
(let ((buffer-read-only nil))
(ansi-color-apply-on-region (point-min) (point-max))))
(add-hook 'compilation-filter-hook 'colorize-compilation-buffer)
#+end_src #+end_src
* World time * World time
#+begin_src emacs-lisp #+begin_src emacs-lisp

View file

@ -23,160 +23,140 @@
;;; Commentary: ;;; Commentary:
;;; Code: ;;; Code:
(require 'mbsync) (require 'mu4e)
(require 'mu4e-generic)
(unless (eq system-type 'windows-nt) (add-to-list 'mu4e-view-actions
(add-to-list 'load-path '("ViewInBrowser" . mu4e-action-view-in-browser) t)
"/usr/share/emacs/site-lisp/mu4e/")
(require 'mu4e)
(add-hook 'mbsync-postsync-hooks
'(lambda (&rest _ignore)
(mu4e-update-mail-and-index t)))
;; For mbsync, this must be set
(setq mu4e-change-filenames-when-moving t)
(add-to-list 'mu4e-view-actions
'("ViewInBrowser" . mu4e-action-view-in-browser) t)
;; (global-set-key (kbd "<f8>") 'mu4e) ;; (global-set-key (kbd "<f8>") 'mu4e)
(setq mu4e-maildir "~/.mail"
mu4e-sent-folder "/fastmail/Sent"
mu4e-drafts-folder "/fastmail/Drafts"
mu4e-refile-folder "/fastmail/Archive"
mu4e-trash-folder "/fastmail/Trash")
(setq mu4e-maildir-shortcuts (setq mu4e-maildir "~/.mail"
'(("/fastmail/INBOX" . ?i) mu4e-sent-folder "/fastmail/Sent"
("/fastmail/INBOX/tracking" . ?t) mu4e-drafts-folder "/fastmail/Drafts"
("/fastmail/INBOX/unsorted" . ?u) mu4e-refile-folder "/fastmail/Archive"
("/fastmail/Archive" . ?a))) mu4e-trash-folder "/fastmail/Trash")
(setq mu4e-bookmarks (setq mu4e-maildir-shortcuts
'(( :name "Unread messages" '(("/fastmail/INBOX" . ?i)
:query "flag:unread AND NOT flag:trashed" ("/fastmail/important.Development" . ?d)
:key ?u) ("/fastmail/important.Puppet" . ?p)
( :name "Today's messages" ("/fastmail/important.VIPs" . ?v)
:query "date:today..now" ("/fastmail/Archive" . ?a)))
:key ?t)
( :name "Last 7 days"
:query "date:7d..now"
:hide-unread t
:key ?w)
( :name "Messages with images"
:query "mime:image/*"
:key ?p)))
(setq mu4e-bookmarks (setq mu4e-bookmarks
(mapcar (lambda (x) '(( :name "Inbox"
(let ((str (plist-get x :query))) :query "maildir:/fastmail/INBOX AND NOT flag:trashed"
(when (not (string-match-p "Unnecessary/mailing_lists" str)) :key ?i)
(setf (plist-get x :query) ( :name "Today's messages"
(concat str " AND NOT maildir:/Unnecessary/mailing_lists*")))) :query "date:today..now"
x) :key ?t)
mu4e-bookmarks)) ( :name "Last 7 days"
:query "date:7d..now"
:hide-unread t
:key ?w)))
(defvar my/email-accounts (setq mu4e-bookmarks
'("bensonchu457@fastmail.com" (mapcar (lambda (x)
"bensonchu@fastmail.com" (let ((str (plist-get x :query)))
"bensonchu457@gmail.com" (when (not (string-match-p "Unnecessary/mailing_lists" str))
"me@mail.pestctrl.io" (setf (plist-get x :query)
"dev@mail.pestctrl.io" (concat str " AND NOT maildir:/Unnecessary/mailing_lists*"))))
"accounts@mail.pestctrl.io")) x)
mu4e-bookmarks))
(defun my/mu-init () (defvar my/email-accounts
(interactive) '("bensonchu457@fastmail.com"
(async-shell-command "bensonchu@fastmail.com"
(format "mu init --maildir=~/.mail/ %s" "bensonchu457@gmail.com"
(--> my/email-accounts "me@mail.pestctrl.io"
(mapcar #'(lambda (x) (concat "--my-address=" x)) it) "dev@mail.pestctrl.io"
(string-join it " "))))) "accounts@mail.pestctrl.io"
"chuan.chu01@fastmail.com"
"julie.chu01@fastmail.com"))
(defun my-mu4e-set-account () (defun my/mu-init ()
(setq user-mail-address (interactive)
(or (and mu4e-compose-parent-message (async-shell-command
(mu4e-contact-email (format "mu init --maildir=~/.mail/ %s"
(-any (--> my/email-accounts
#'(lambda (x) (mapcar #'(lambda (x) (concat "--my-address=" x)) it)
(mu4e-message-contact-field-matches-me mu4e-compose-parent-message (string-join it " ")))))
x))
'(:to :cc :bcc :from))))
(completing-read "Compose with account: "
my/email-accounts
nil t))))
(add-hook 'mu4e-compose-pre-hook 'my-mu4e-set-account) (defun my-mu4e-set-account ()
(setq user-mail-address
(or (and mu4e-compose-parent-message
(mu4e-contact-email
(-any
#'(lambda (x)
(mu4e-message-contact-field-matches-me mu4e-compose-parent-message
x))
'(:to :cc :bcc :from))))
(completing-read "Compose with account: "
my/email-accounts
nil t))))
(add-hook 'mu4e-compose-pre-hook 'my-mu4e-set-account)
;; (setcar mu4e-headers-thread-last-child-prefix "╰┬►") ;; (setcar mu4e-headers-thread-last-child-prefix "╰┬►")
;; (setcar mu4e-headers-thread-first-child-prefix "├┬►") ;; (setcar mu4e-headers-thread-first-child-prefix "├┬►")
;; (setcar mu4e-headers-thread-connection-prefix "│") ;; (setcar mu4e-headers-thread-connection-prefix "│")
(defun my/mu4e~headers-thread-prefix (thread)
"Calculate the thread prefix based on thread info THREAD." (defun my/mu4e~headers-thread-prefix (thread)
(when thread "Calculate the thread prefix based on thread info THREAD."
(let* ((prefix "") (when thread
(level (plist-get thread :level)) (let* ((prefix "")
(has-child (plist-get thread :has-child)) (level (plist-get thread :level))
(last-child (plist-get thread :last-child)) (has-child (plist-get thread :has-child))
(duplicate (plist-get thread :duplicate))) (last-child (plist-get thread :last-child))
;; Do not prefix root messages. (duplicate (plist-get thread :duplicate)))
(when (= level 0) ;; Do not prefix root messages.
(setq mu4e~headers-thread-state '()) (when (= level 0)
(when has-child (setq mu4e~headers-thread-state '())
(setq prefix "┬►"))) (when has-child
(if (> level 0) (setq prefix "┬►")))
(let* ((length (length mu4e~headers-thread-state)) (if (> level 0)
(padding (make-list (max 0 (- level length)) nil))) (let* ((length (length mu4e~headers-thread-state))
;; Trim and pad the state to ensure a message will (padding (make-list (max 0 (- level length)) nil)))
;; always be shown with the correct indentation, even if ;; Trim and pad the state to ensure a message will
;; a broken thread is returned. It's trimmed to level-1 ;; always be shown with the correct indentation, even if
;; because the current level has always an connection ;; a broken thread is returned. It's trimmed to level-1
;; and it used a special formatting. ;; because the current level has always an connection
(setq mu4e~headers-thread-state ;; and it used a special formatting.
(cl-subseq (append mu4e~headers-thread-state padding)
0 (- level 1)))
;; Prepare the thread prefix.
(setq prefix
(concat
;; Current mu4e~headers-thread-state, composed by
;; connections or blanks.
(mapconcat
(lambda (s)
(if s "" " "))
mu4e~headers-thread-state "")
(if last-child "" "")
(if has-child "" "")
""))))
;; If a new sub-thread will follow (has-child) and the current
;; one is still not done (not last-child), then a new
;; connection needs to be added to the tree-state. It's not
;; necessary to a blank (nil), because padding will handle
;; that.
(if (and has-child (not last-child))
(setq mu4e~headers-thread-state (setq mu4e~headers-thread-state
(append mu4e~headers-thread-state '(t)))) (cl-subseq (append mu4e~headers-thread-state padding)
;; Return the thread prefix. 0 (- level 1)))
(format "%s%s" ;; Prepare the thread prefix.
(propertize prefix 'face 'mu4e-related-face) (setq prefix
(if duplicate (concat
(mu4e~headers-thread-prefix-map 'duplicate) ""))))) ;; Current mu4e~headers-thread-state, composed by
;; connections or blanks.
(mapconcat
(lambda (s)
(if s "" " "))
mu4e~headers-thread-state "")
(if last-child "" "")
(if has-child "" "")
""))))
;; If a new sub-thread will follow (has-child) and the current
;; one is still not done (not last-child), then a new
;; connection needs to be added to the tree-state. It's not
;; necessary to a blank (nil), because padding will handle
;; that.
(if (and has-child (not last-child))
(setq mu4e~headers-thread-state
(append mu4e~headers-thread-state '(t))))
;; Return the thread prefix.
(format "%s%s"
(propertize prefix 'face 'mu4e-related-face)
(if duplicate
(mu4e~headers-thread-prefix-map 'duplicate) "")))))
(advice-add #'mu4e~headers-thread-prefix (advice-add #'mu4e~headers-thread-prefix
:override :override
#'my/mu4e~headers-thread-prefix) #'my/mu4e~headers-thread-prefix)
(defun mu4e-print-path ()
(interactive)
(-->
(mu4e-message-at-point)
(mu4e-message-field it :path)
(progn
(kill-new it)
(message "Path Copied: %s" it))))
(define-key mu4e-search-minor-mode-map (kbd "l") #'mu4e-print-path))
(provide 'mu4e-configuration) (provide 'mu4e-configuration)
;;; mu4e-config.el ends here ;;; mu4e-config.el ends here

152
lisp/mail/mu4e-generic.el Normal file
View file

@ -0,0 +1,152 @@
;;; mu4e-generic.el --- -*- lexical-binding: t -*-
;; Copyright (C) 2026 Benson Chu
;; Author: Benson Chu <bensonchu457@gmail.com>
;; Created: [2026-04-19 20:10]
;; This file is not part of GNU Emacs
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(require 'mu4e)
(require 'mu4e-contrib)
(define-key mu4e-headers-mode-map (kbd "M") #'mu4e-headers-mark-all)
(defun mu4e-print-path ()
(interactive)
(-->
(mu4e-message-at-point)
(mu4e-message-field it :path)
(progn
(kill-new it)
(message "Path Copied: %s" it))))
(define-key mu4e-search-minor-mode-map (kbd "l") #'mu4e-print-path)
(add-hook 'mu4e-headers-found-hook #'mu4e-thread-fold-all)
(define-key mu4e-headers-mode-map (kbd "C-M-a") #'mu4e-view-thread-goto-root)
(define-key mu4e-thread-mode-map (kbd "<tab>") #'mu4e-thread-fold-toggle)
;; Prevent automatic baseline resets to keep (+x) indicators persistent
(defvar my/mu4e-allow-baseline-reset nil
"When non-nil, allow baseline resets. Otherwise, preserve the baseline.")
(defun my/mu4e--query-items-refresh-no-auto-reset (orig-fun &optional reset-baseline)
"Advice for `mu4e--query-items-refresh' to prevent automatic baseline resets.
Only reset the baseline if `my/mu4e-allow-baseline-reset' is non-nil."
(funcall orig-fun (and reset-baseline my/mu4e-allow-baseline-reset)))
(advice-add 'mu4e--query-items-refresh :around
#'my/mu4e--query-items-refresh-no-auto-reset)
(defun my/mu4e-reset-baseline ()
"Manually reset the mu4e baseline to clear all (+x) indicators."
(interactive)
(let ((my/mu4e-allow-baseline-reset t))
(mu4e--query-items-refresh 'reset-baseline))
(message "mu4e baseline reset - (+x) indicators cleared"))
(defun my/goto-mail ()
(interactive)
(switch-or-create-tab "mail")
(delete-other-windows)
(mu4e))
(global-set-key (kbd "C-x m") #'my/goto-mail)
(with-eval-after-load 'mu4e-view
(add-hook 'mu4e-view-mode-hook
#'olivetti-mode))
(add-to-list 'mu4e-view-actions
'("ViewInBrowser" . mu4e-action-view-in-browser) t)
(defun my/mu4e~headers-thread-prefix (thread)
"Calculate the thread prefix based on thread info THREAD."
(when thread
(let* ((prefix "")
(level (plist-get thread :level))
(has-child (plist-get thread :has-child))
(last-child (plist-get thread :last-child))
(duplicate (plist-get thread :duplicate)))
;; Do not prefix root messages.
(when (= level 0)
(setq mu4e~headers-thread-state '())
(when has-child
(setq prefix "┬►")))
(if (> level 0)
(let* ((length (length mu4e~headers-thread-state))
(padding (make-list (max 0 (- level length)) nil)))
;; Trim and pad the state to ensure a message will
;; always be shown with the correct indentation, even if
;; a broken thread is returned. It's trimmed to level-1
;; because the current level has always an connection
;; and it used a special formatting.
(setq mu4e~headers-thread-state
(cl-subseq (append mu4e~headers-thread-state padding)
0 (- level 1)))
;; Prepare the thread prefix.
(setq prefix
(concat
;; Current mu4e~headers-thread-state, composed by
;; connections or blanks.
(mapconcat
(lambda (s)
(if s "" " "))
mu4e~headers-thread-state "")
(if last-child "" "")
(if has-child "" "")
""))))
;; If a new sub-thread will follow (has-child) and the current
;; one is still not done (not last-child), then a new
;; connection needs to be added to the tree-state. It's not
;; necessary to a blank (nil), because padding will handle
;; that.
(if (and has-child (not last-child))
(setq mu4e~headers-thread-state
(append mu4e~headers-thread-state '(t))))
;; Return the thread prefix.
(format "%s%s"
prefix
(if duplicate
(mu4e~headers-thread-prefix-map 'duplicate) "")))))
(advice-add #'mu4e~headers-thread-prefix
:override
#'my/mu4e~headers-thread-prefix)
(defun my/mu4e-compose-edit-ignore-draft()
"Edit an existing draft message."
(interactive)
(let* ((msg (mu4e-message-at-point)))
(mu4e--draft
'edit
(lambda ()
(with-current-buffer
(find-file-noselect (mu4e-message-readable-path msg))
(mu4e--delimit-headers)
(current-buffer))))))
(advice-add #'mu4e-compose-edit
:override
#'my/mu4e-compose-edit-ignore-draft)
(provide 'mu4e-generic)
;;; mu4e-generic.el ends here

View file

@ -25,7 +25,8 @@
;;; Code: ;;; Code:
(require 'cl-lib) (require 'cl-lib)
(require 'dash) (require 'dash)
(require 'vterm) (require 'use-package)
(use-package vterm)
(require 'tab-bar) (require 'tab-bar)
(defclass multi-vterm-tab-info () (defclass multi-vterm-tab-info ()

188
lisp/ripgrep.el Normal file
View file

@ -0,0 +1,188 @@
;;; ripgrep.el --- -*- lexical-binding: t -*-
;; https://www.dyerdwelling.family/emacs/20260109094340-emacs--a-single-function-ripgrep-alternative-to-rgrep/
;;; Commentary:
;;; Code:
(defconst ripgrep-error-regexp
`((,(concat "^\\(?:"
;; Parse using NUL characters when `--null' is used.
;; Note that we must still assume no newlines in
;; filenames due to "foo: Is a directory." type
;; messages.
"\\(?1:[^\0\n]+\\)\\(?3:\0\\)\\(?2:[0-9]+\\):"
"\\|"
;; Fallback if `--null' is not used, use a tight regexp
;; to handle weird file names (with colons in them) as
;; well as possible. E.g., use [1-9][0-9]* rather than
;; [0-9]+ so as to accept ":034:" in file names.
"\\(?1:"
"\\(?:[a-zA-Z]:\\)?" ; Allow "C:..." for w32.
"[^\n:]+?[^\n/:]\\):[\t ]*\\(?2:[1-9][0-9]*\\)[\t ]*:\\(?:[1-9][0-9]*\\)[\t ]*:"
"\\)")
1 2
;; Calculate column positions (col . end-col) of first grep match on a line
(,(lambda ()
(when grep-highlight-matches
(let* ((beg (match-end 0))
(end (save-excursion (goto-char beg) (line-end-position)))
(mbeg
(text-property-any beg end 'font-lock-face grep-match-face)))
(when mbeg
(- mbeg beg)))))
.
,(lambda ()
(when grep-highlight-matches
(let* ((beg (match-end 0))
(end (save-excursion (goto-char beg) (line-end-position)))
(mbeg
(text-property-any beg end 'font-lock-face grep-match-face))
(mend
(and mbeg (next-single-property-change
mbeg 'font-lock-face nil end))))
(when mend
(- mend beg 1))))))
nil nil
(3 '(face nil display ":")))
("^Binary file \\(.+\\) matches" 1 nil nil 0 1)))
(defun ripgrep (search-term &optional directory glob)
"Run ripgrep (rg) with SEARCH-TERM and optionally DIRECTORY and GLOB.
If ripgrep is unavailable, fall back to Emacs's rgrep command. Highlights SEARCH-TERM in results.
By default, only the SEARCH-TERM needs to be provided. If called with a
universal argument, DIRECTORY and GLOB are prompted for as well."
(interactive
(let* ((univ-arg current-prefix-arg)
(default-search-term
(cond
((use-region-p)
(buffer-substring-no-properties (region-beginning) (region-end)))
((thing-at-point 'symbol t))
((thing-at-point 'word t))
(t ""))))
(list
(read-string (if (string-empty-p default-search-term)
"Search for: "
(format "Search for (default `%s`): " default-search-term))
nil nil default-search-term)
(when univ-arg (read-directory-name "Directory: "))
(when univ-arg (read-string "File pattern (glob, default: ): " nil nil "")))))
(let* ((directory (expand-file-name (or directory default-directory)))
(glob (or glob ""))
(buffer-name "*grep*"))
(if (executable-find "rg")
(let ((buffer (get-buffer-create buffer-name)))
(with-current-buffer buffer
(setq default-directory directory)
(let ((inhibit-read-only t))
(erase-buffer)
(insert (format "-*- mode: grep; default-directory: \"%s\" -*-\n\n" directory))
(if (not (string= "" glob))
(insert (format "[o] Glob: %s\n\n" glob)))
(insert "Searching...\n\n"))
(grep-mode)
(setq-local compilation-error-regexp-alist ripgrep-error-regexp)
(setq-local my/grep-search-term search-term)
(setq-local my/grep-directory directory)
(setq-local my/grep-glob glob))
(pop-to-buffer buffer)
(goto-char (point-min))
(make-process
:name "ripgrep"
:buffer buffer
:command `("rg" "--color=never" "--max-columns=500"
"--column" "--line-number" "--no-heading"
"--smart-case" "-e" ,search-term
"--glob" ,glob ,directory)
:filter `(lambda (proc string)
(when (buffer-live-p (process-buffer proc))
(with-current-buffer (process-buffer proc)
(let ((inhibit-read-only t)
(moving (= (point) (process-mark proc))))
(setq string (replace-regexp-in-string "[\r\0\x01-\x08\x0B-\x0C\x0E-\x1F]" "" string))
;; Replace full directory path with ./ in the incoming output
(setq string (replace-regexp-in-string
(concat "^" (regexp-quote ,directory))
"./"
string))
(save-excursion
(goto-char (process-mark proc))
(insert string)
(set-marker (process-mark proc) (point)))
(if moving (goto-char (process-mark proc)))))))
:sentinel
`(lambda (proc _event)
(when (memq (process-status proc) '(exit signal))
(with-current-buffer (process-buffer proc)
(let ((inhibit-read-only t))
;; Remove "Searching..." line
(goto-char (point-min))
(while (re-search-forward "Searching\\.\\.\\.\n\n" nil t)
(replace-match "" nil t))
;; Clean up the output - replace full paths with ./
(goto-char (point-min))
(forward-line 3)
(let ((start-pos (point)))
(while (re-search-forward (concat "^" (regexp-quote ,directory)) nil t)
(replace-match "./" t t))
;; Check if any results were found
(goto-char start-pos)
(when (= (point) (point-max))
(insert "No results found.\n")))
(goto-char (point-max))
(insert "\nRipgrep finished\n")
;; Highlight search terms using grep's match face
(goto-char (point-min))
(forward-line 3)
(save-excursion
(while (re-search-forward (regexp-quote ,search-term) nil t)
(put-text-property (match-beginning 0) (match-end 0)
'face 'match)
(put-text-property (match-beginning 0) (match-end 0)
'font-lock-face 'match))))
;; Set up keybindings
(local-set-key (kbd "D")
(lambda ()
(interactive)
(ripgrep my/grep-search-term
(read-directory-name "New search directory: ")
my/grep-glob)))
(local-set-key (kbd "S")
(lambda ()
(interactive)
(ripgrep (read-string "New search term: "
nil nil my/grep-search-term)
my/grep-directory
my/grep-glob)))
(local-set-key (kbd "o")
(lambda ()
(interactive)
(ripgrep my/grep-search-term
my/grep-directory
(read-string "New glob: "))))
(local-set-key (kbd "g")
(lambda ()
(interactive)
(ripgrep my/grep-search-term my/grep-directory my/grep-glob)))
(goto-char (point-min))
(message "ripgrep finished."))))
)
(message "ripgrep started..."))
;; Fallback to rgrep
(progn
(setq default-directory directory)
(message (format "%s : %s : %s" search-term glob directory))
(rgrep search-term (if (string= "" glob) "*" glob) directory)))))
(provide 'ripgrep)
;;; ripgrep.el ends here

View file

@ -45,6 +45,8 @@
'(mode-line ((t :foreground "gray60" :background "black" :inverse-video nil))) '(mode-line ((t :foreground "gray60" :background "black" :inverse-video nil)))
'(eldoc-highlight-function-argument ((t :foreground "dodger blue"))) '(eldoc-highlight-function-argument ((t :foreground "dodger blue")))
'(highlight ((t :background "gray20")))
'(sml/charging ((t (:inherit sml/global :foreground "forest green")))) '(sml/charging ((t (:inherit sml/global :foreground "forest green"))))
;; TODO: Rework according to prot: ;; TODO: Rework according to prot:

View file

@ -25,6 +25,7 @@
;;; Code: ;;; Code:
(require 'mu4e) (require 'mu4e)
(require 'mu4e-generic)
(require 'ti-mail-identity) (require 'ti-mail-identity)
(require 'gnus-article-hack) (require 'gnus-article-hack)
@ -33,28 +34,9 @@
(setq mu4e-update-interval (* 60 5)) (setq mu4e-update-interval (* 60 5))
(defun my/goto-mail ()
(interactive)
(switch-or-create-tab "mail")
(delete-other-windows)
(mu4e))
(global-set-key (kbd "C-x m") #'my/goto-mail)
(with-eval-after-load 'mu4e-view
(add-hook 'mu4e-view-mode-hook
#'olivetti-mode))
(add-hook 'mbsync-postsync-hooks
'(lambda (&rest _ignore)
(mu4e-update-mail-and-index t)))
;; For mbsync, this must be set ;; For mbsync, this must be set
(setq mu4e-change-filenames-when-moving t) (setq mu4e-change-filenames-when-moving t)
(add-to-list 'mu4e-view-actions
'("ViewInBrowser" . mu4e-action-view-in-browser) t)
;; (global-set-key (kbd "<f8>") 'mu4e) ;; (global-set-key (kbd "<f8>") 'mu4e)
(setq mu4e-maildir "~/.mail" (setq mu4e-maildir "~/.mail"
@ -68,12 +50,12 @@
(:key ?a :maildir "/work/Done"))) (:key ?a :maildir "/work/Done")))
(setq mu4e-bookmarks (setq mu4e-bookmarks
'(( :name "Unread messages" '(( :name "Inbox"
:query "flag:unread AND NOT maildir:/work/Other* AND NOT flag:trashed"
:key ?u)
( :name "Inbox"
:query "maildir:/work/INBOX AND NOT flag:trashed" :query "maildir:/work/INBOX AND NOT flag:trashed"
:key ?i) :key ?i)
( :name "Unread messages"
:query "flag:unread AND NOT maildir:/work/Other* AND NOT flag:trashed"
:key ?u)
( :name "mailing_lists" ( :name "mailing_lists"
:query "maildir:/work/INBOX/mailing_lists* AND NOT flag:trashed" :query "maildir:/work/INBOX/mailing_lists* AND NOT flag:trashed"
:key ?m) :key ?m)
@ -118,104 +100,7 @@
;; (setcar mu4e-headers-thread-first-child-prefix "├┬►") ;; (setcar mu4e-headers-thread-first-child-prefix "├┬►")
;; (setcar mu4e-headers-thread-connection-prefix "│") ;; (setcar mu4e-headers-thread-connection-prefix "│")
(defun my/mu4e~headers-thread-prefix (thread)
"Calculate the thread prefix based on thread info THREAD."
(when thread
(let* ((prefix "")
(level (plist-get thread :level))
(has-child (plist-get thread :has-child))
(last-child (plist-get thread :last-child))
(duplicate (plist-get thread :duplicate)))
;; Do not prefix root messages.
(when (= level 0)
(setq mu4e~headers-thread-state '())
(when has-child
(setq prefix "┬►")))
(if (> level 0)
(let* ((length (length mu4e~headers-thread-state))
(padding (make-list (max 0 (- level length)) nil)))
;; Trim and pad the state to ensure a message will
;; always be shown with the correct indentation, even if
;; a broken thread is returned. It's trimmed to level-1
;; because the current level has always an connection
;; and it used a special formatting.
(setq mu4e~headers-thread-state
(cl-subseq (append mu4e~headers-thread-state padding)
0 (- level 1)))
;; Prepare the thread prefix.
(setq prefix
(concat
;; Current mu4e~headers-thread-state, composed by
;; connections or blanks.
(mapconcat
(lambda (s)
(if s "" " "))
mu4e~headers-thread-state "")
(if last-child "" "")
(if has-child "" "")
""))))
;; If a new sub-thread will follow (has-child) and the current
;; one is still not done (not last-child), then a new
;; connection needs to be added to the tree-state. It's not
;; necessary to a blank (nil), because padding will handle
;; that.
(if (and has-child (not last-child))
(setq mu4e~headers-thread-state
(append mu4e~headers-thread-state '(t))))
;; Return the thread prefix.
(format "%s%s"
prefix
(if duplicate
(mu4e~headers-thread-prefix-map 'duplicate) "")))))
(advice-add #'mu4e~headers-thread-prefix
:override
#'my/mu4e~headers-thread-prefix)
(defun my/mu4e-compose-edit-ignore-draft()
"Edit an existing draft message."
(interactive)
(let* ((msg (mu4e-message-at-point)))
(mu4e--draft
'edit
(lambda ()
(with-current-buffer
(find-file-noselect (mu4e-message-readable-path msg))
(mu4e--delimit-headers)
(current-buffer))))))
(advice-add #'mu4e-compose-edit
:override
#'my/mu4e-compose-edit-ignore-draft)
(add-hook 'mu4e-headers-found-hook #'mu4e-thread-fold-all)
(define-key mu4e-headers-mode-map (kbd "C-M-a") #'mu4e-view-thread-goto-root)
(define-key mu4e-thread-mode-map (kbd "<tab>") #'mu4e-thread-fold-toggle)
(setq mu4e-attachment-dir "/scratch/benson/mail_attachments") (setq mu4e-attachment-dir "/scratch/benson/mail_attachments")
(require 'mu4e-contrib)
(define-key mu4e-headers-mode-map (kbd "M") #'mu4e-headers-mark-all)
;; Prevent automatic baseline resets to keep (+x) indicators persistent
(defvar my/mu4e-allow-baseline-reset nil
"When non-nil, allow baseline resets. Otherwise, preserve the baseline.")
(defun my/mu4e--query-items-refresh-no-auto-reset (orig-fun &optional reset-baseline)
"Advice for `mu4e--query-items-refresh' to prevent automatic baseline resets.
Only reset the baseline if `my/mu4e-allow-baseline-reset' is non-nil."
(funcall orig-fun (and reset-baseline my/mu4e-allow-baseline-reset)))
(advice-add 'mu4e--query-items-refresh :around
#'my/mu4e--query-items-refresh-no-auto-reset)
(defun my/mu4e-reset-baseline ()
"Manually reset the mu4e baseline to clear all (+x) indicators."
(interactive)
(let ((my/mu4e-allow-baseline-reset t))
(mu4e--query-items-refresh 'reset-baseline))
(message "mu4e baseline reset - (+x) indicators cleared"))
(provide 'work-mail) (provide 'work-mail)
;;; work-mail.el ends here ;;; work-mail.el ends here