Add mu4e layer

This commit is contained in:
Allen Li 2015-08-01 22:30:30 -07:00 committed by Eivind Fonn
parent 7b3436bece
commit f8368f9c94
3 changed files with 167 additions and 0 deletions

View File

@ -0,0 +1,89 @@
* mu4e layer for Spacemacs
This layer provides mu4e support for Spacemacs.
** Installation
You need to install mu and mu4e separately in order to use this layer. On Arch
Linux, simply installing the mu package will do. I assume the same will work
for most other Linux distros.
** Commands
| Keybinding | Command |
|------------+------------|
| SPC a M | Start mu4e |
** Configuration
Configuration varies too much to give precise instructions. What follows is one
example configuration. Refer to mu4e's manual for more detailed configuration
instructions.
*** Important note
This layer includes support for multiple sending accounts. Configure the
`mu4e-account-alist` variable:
#+BEGIN_SRC emacs-lisp
(setq mu4e-account-alist
'(("gmail"
;; Under each account, set the account-specific variables you want.
(mu4e-sent-messages-behavior delete)
(mu4e-sent-folder "/gmail/[Gmail]/.Sent Mail")
(mu4e-drafts-folder "/gmail/[Gmail]/.Drafts")
(user-mail-address "billy@gmail.com")
(user-full-name "Billy"))
("college"
(mu4e-sent-messages-behavior sent)
(mu4e-sent-folder "/college/Sent Items")
(mu4e-drafts-folder "/college/Drafts")
(user-mail-address "bb15@college.edu")
(user-full-name "Billy Bob 15"))))
(mu4e/mail-account-reset)
#+END_SRC
The first account listed will be the default account, so variables like
`user-full-name`, which is used by other parts of Emacs, will have their value
reset for the default account after sending each email.
Make sure you call `mu4e/mail-account-reset` afterward, which will initialize
the given account variables.
*** Example configuration
#+BEGIN_SRC emacs-lisp
;;; Set up some common mu4e variables
(setq mu4e-maildir "~/.mail"
mu4e-trash-folder "/Trash"
mu4e-refile-folder "/Archive"
mu4e-get-mail-command "mbsync -a"
mu4e-update-interval nil
mu4e-compose-signature-auto-include nil
mu4e-view-show-images t
mu4e-view-show-addresses t)
;;; Mail directory shortcuts
(setq mu4e-maildir-shortcuts
'(("/gmail/INBOX" . ?g)
("/college/INBOX" . ?c)))
;;; Bookmarks
(setq mu4e-bookmarks
`(("flag:unread AND NOT flag:trashed" "Unread messages" ?u)
("date:today..now" "Today's messages" ?t)
("date:7d..now" "Last 7 days" ?w)
("mime:image/*" "Messages with images" ?p)
(,(mapconcat 'identity
(mapcar
(lambda (maildir)
(concat "maildir:" (car maildir)))
mu4e-maildir-shortcuts) " OR ")
"All inboxes" ?i)))
#+END_SRC
** See also
Refer to the official mu and mu4e documentation for additional info.
- [[http://www.djcbsoftware.nl/code/mu/mu4e/index.html][mu4e Manual]]

View File

@ -0,0 +1,42 @@
;;; extensions.el --- mu4e Layer extensions File for Spacemacs
;;
;; Copyright (c) 2012-2014 Sylvain Benner
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(setq mu4e-pre-extensions
'(mu4e))
(setq mu4e-post-extensions
'())
(defvar mu4e-account-alist nil
"Account alist for custom multi-account compose.")
(defun mu4e/init-mu4e ()
(use-package mu4e
:init
(progn
(evil-leader/set-key "a M" 'mu4e)
(global-set-key (kbd "C-x m") 'mu4e-compose-new))
:config
(progn
(spacemacs|evilify-map mu4e-main-mode-map
:mode mu4e-main-mode
:bindings
(kbd "j") 'mu4e~headers-jump-to-maildir)
(spacemacs|evilify-map mu4e-headers-mode-map :mode mu4e-headers-mode)
(spacemacs|evilify-map mu4e-view-mode-map :mode mu4e-view-mode)
(setq mu4e-completing-read-function 'helm--completing-read-default)
(add-to-list 'mu4e-view-actions
'("View in browser" . mu4e-action-view-in-browser) t)
(add-hook 'mu4e-compose-pre-hook 'mu4e/set-account)
(add-hook 'message-sent-hook 'mu4e/mail-account-reset))))

View File

@ -0,0 +1,36 @@
;;; funcs.el --- mu4e Layer extensions File for Spacemacs
;;
;; Copyright (c) 2012-2014 Sylvain Benner
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(defun mu4e/set-account ()
"Set the account for composing a message."
(let* ((account
(if mu4e-compose-parent-message
(let ((maildir
(mu4e-message-field mu4e-compose-parent-message :maildir)))
(string-match "/\\(.*?\\)/" maildir)
(match-string 1 maildir))
(helm-comp-read
"Compose with account:"
(mapcar (lambda (var) (car var)) mu4e-account-alist))))
(account-vars (cdr (assoc account mu4e-account-alist))))
(if account-vars
(mu4e//map-set account-vars)
(error "No email account found"))))
(defun mu4e//map-set (vars)
"Setq an alist VARS of variables and values."
(mapc (lambda (var) (set (car var) (cadr var)))
vars))
(defun mu4e/mail-account-reset ()
"Reset mail account info to first."
(mu4e//map-set (cdar mu4e-account-alist)))