Skip to content

Commit

Permalink
fix(mu4e): mu 1.10 UI and evil fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
abougouffa committed Mar 26, 2023
1 parent 6eff30b commit 2398bd0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 32 deletions.
17 changes: 16 additions & 1 deletion core/me-evil.el
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,29 @@
(seq-filter
(lambda (mode)
(not (memq mode '(evil-mc ; Default bindings for `evil-mc' are messy
mu4e ; TEMP: until `evil-collection-mu4e' gets fixed, see github.com/emacs-evil/evil-collection/issues/695
elisp-mode)))) ; I don't like "gz" for `ielm', I like "gr" though
evil-collection-mode-list))

;; Use "gr" to find references for elisp mode
(with-eval-after-load 'elisp-mode
(when evil-collection-want-find-usages-bindings
(evil-collection-define-key 'normal 'emacs-lisp-mode-map
"gr" 'xref-find-references))))
"gr" 'xref-find-references)))

;; TEMP: Fix `mu4e' evil integraion
(with-eval-after-load 'mu4e
(require 'evil-collection-mu4e
(concat (file-name-directory (feature-file 'evil-collection))
"modes/mu4e/evil-collection-mu4e.el"))
(evil-collection-mu4e-set-state)
(evil-collection-mu4e-set-bindings)

;; Fix some missed up bindings
(defalias 'mu4e~view-quit-buffer #'mu4e-view-quit)

(add-hook 'org-mode-hook #'evil-collection-mu4e-org-set-header-to-normal-mode)
(add-hook 'mu4e-compose-pre-hook #'evil-collection-mu4e-org-set-header-to-insert-mode)))

(use-package evil-snipe
:straight t
Expand Down
69 changes: 38 additions & 31 deletions modules/extras/me-mu4e-ui.el
Original file line number Diff line number Diff line change
Expand Up @@ -62,32 +62,39 @@ STR and any integer OFFSET."
+mu4e-header-colorized-faces)))
color))

(defun +mu4e--main-action-str-prettier-a (str &optional func-or-shortcut)
"Highlight the first occurrence of [.] in STR.
If FUNC-OR-SHORTCUT is non-nil and if it is a function, call it
when STR is clicked (using RET or mouse-2); if FUNC-OR-SHORTCUT is
a string, execute the corresponding keyboard action when it is
clicked."
(let ((newstr
(replace-regexp-in-string
"\\[\\(..?\\)\\]"
(lambda(m)
(format "%s"
(propertize (match-string 1 m) 'face '(mode-line-emphasis bold))))
(replace-regexp-in-string "\t\\*" (format "\t%s" +mu4e-main-bullet) str)))
(map (make-sparse-keymap))
(func (if (functionp func-or-shortcut)
func-or-shortcut
(if (stringp func-or-shortcut)
(lambda()
(interactive)
(execute-kbd-macro func-or-shortcut))))))
(define-key map [mouse-2] func)
(define-key map (kbd "RET") func)
(put-text-property 0 (length newstr) 'keymap map newstr)
(put-text-property (string-match "[A-Za-z].+$" newstr)
(- (length newstr) 1) 'mouse-face 'highlight newstr)
newstr))
(defun +mu4e--main-action-prettier-a (title cmd &optional bindstr alt)
(let* ((bindstr (or bindstr (mu4e-key-description cmd) (and alt (string alt))
(mu4e-error "No binding for %s" cmd)))
(bindstr
(if (and alt (> (length bindstr) 1)) alt bindstr))
(title ;; remove first letter afrer [] if it equal last of binding
(mu4e-string-replace
(concat "[@]" (substring bindstr -1)) "[@]" title))
(title ;; Special case: replace "jump" with "Jump"
(if (string= "j" bindstr)
(progn
(setq bindstr "J")
(replace-regexp-in-string "jump" "Jump" title))
title))
(title ;; insert binding in [@]
(mu4e-string-replace
"[@]" (format "[%s]" (propertize bindstr 'face 'mu4e-highlight-face))
title))
(title ;; Prettify the title
(replace-regexp-in-string
"\\[\\(..?\\)\\]"
(lambda(m)
(format "%s"
(propertize (match-string 1 m) 'face '(mode-line-emphasis bold))))
(replace-regexp-in-string "\t\\*" (format "\t%s" +mu4e-main-bullet) title)))
(map (make-sparse-keymap)))
(define-key map [mouse-2] cmd)
(define-key map (kbd "RET") cmd)
;; Add highlighting on mouse hover
(put-text-property 0 (length title) 'keymap map title)
(put-text-property (string-match "[A-Za-z].+$" title)
(- (length title) 1) 'mouse-face 'highlight title)
(propertize title 'keymap map)))

(defun +mu4e--main-keyval-str-prettier-a (str)
"Replace '*' with `+mu4e-main-bullet' in STR."
Expand Down Expand Up @@ -214,16 +221,16 @@ will also be the width of all other printable characters."
;; Evil collection overwrite the jump, search, compose and quit commands
(with-eval-after-load 'evil-collection
(setq evil-collection-mu4e-new-region-basic
(concat (+mu4e--main-action-str-prettier-a
"\t* [J]ump to some maildir\n" 'mu4e-jump-to-maildir)
(+mu4e--main-action-str-prettier-a
(concat (+mu4e--main-action-prettier-a
"\t* [J]ump to some maildir\n" 'mu4e-search-maildir)
(+mu4e--main-action-prettier-a
"\t* Enter a [s]earch query\n" 'mu4e-search)
(+mu4e--main-action-str-prettier-a
(+mu4e--main-action-prettier-a
"\t* [C]ompose a new message\n" 'mu4e-compose-new))
evil-collection-mu4e-end-region-misc "quit"))

(advice-add #'mu4e--key-val :filter-return #'+mu4e--main-keyval-str-prettier-a)
(advice-add #'mu4e--main-action-str :override #'+mu4e--main-action-str-prettier-a))
(advice-add #'mu4e--main-action :override #'+mu4e--main-action-prettier-a))

(defun +mu4e-ui-setup ()
(if (display-graphic-p)
Expand Down

0 comments on commit 2398bd0

Please sign in to comment.