diff options
| author | Ravi R Kiran <aine.marina@gmail.com> | 2015-03-17 04:17:17 (GMT) |
|---|---|---|
| committer | Ravi R Kiran <aine.marina@gmail.com> | 2015-03-17 04:17:17 (GMT) |
| commit | a6e94a30a835ea389fe8fc40df162ff327035ccb (patch) | |
| tree | cf695ab8c77b2c78434b2c6913295641a9287110 /lisp/ravi-init-mu.el | |
| parent | b94602dccfa28b997b1fc1f2e0373d997f4b95ce (diff) | |
| download | dotemacs-a6e94a30a835ea389fe8fc40df162ff327035ccb.zip dotemacs-a6e94a30a835ea389fe8fc40df162ff327035ccb.tar.gz dotemacs-a6e94a30a835ea389fe8fc40df162ff327035ccb.tar.bz2 | |
Move main emacs directory out of load path
This follows the official emacs recommendation for lisp code inside
emacs.d.
Diffstat (limited to 'lisp/ravi-init-mu.el')
| -rw-r--r-- | lisp/ravi-init-mu.el | 196 |
1 files changed, 196 insertions, 0 deletions
diff --git a/lisp/ravi-init-mu.el b/lisp/ravi-init-mu.el new file mode 100644 index 0000000..b123da2 --- /dev/null +++ b/lisp/ravi-init-mu.el @@ -0,0 +1,196 @@ +;;; ravi-init-mu.el --- mail + +;; Copyright (C) 2014 + +;; Author: <ravi@nero.lan> +;; Keywords: + +;; 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 <http://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Set up mu4e conditionally +;; - actual account information should be in local.el +;; - requires definitions of ravi/mu4e-account-alist + +;;; Code: + +(defvar ravi/use-mu-for-email nil + "Use mu for email") +(defvar ravi/mu4e-account-alist nil + "An alist containing account information for all accounts") +(defvar ravi/mu4e-update-interval 1800 ; 30 minutes + "Basic update interval; all other update intervals are multiples") + +(setq message-citation-line-format "On %a %Y-%m-%d %l:%M:%S%p %Z, %f wrote:" + message-citation-line-function 'message-insert-formatted-citation-line) + +(when ravi/use-mu-for-email + (use-package mu4e + :load-path (lambda () (ravi/emacs-file "site-lisp/mu/mu4e")) + :commands mu4e + :init + (progn + (add-to-list 'Info-additional-directory-list (ravi/emacs-file "site-lisp/mu/mu4e")) + (unless ravi/mu4e-account-alist (error "Email account list not found")) + (defun ravi/switch-to-mu4e () + (interactive) + (let ((buf (or (and (boundp 'mu4e~headers-buffer-name) + (get-buffer mu4e~headers-buffer-name)) + (get-buffer "*mu4e-main*")))) + (if buf + (if (get-buffer-window buf t) + (select-window (get-buffer-window buf t)) + (switch-to-buffer buf)) + (mu4e)))) + (bind-key "C-'" 'ravi/switch-to-mu4e) + ) + :config + (progn + + ;; Basic identity for sending mail + (require 'smtpmail) + (setq send-mail-function 'smtpmail-send-it) + (setq message-send-mail-function 'smtpmail-send-it) + + ;; Set up defaults from first account on the list + ;; user-full-name + ;; smtp-local-domain + ;; user-mail-address + ;; smtpmail-smtp-user + ;; smtpmail-smtp-server + ;; mu4e-sent-folder + ;; mu4e-trash-folder + ;; mu4e-refile-folder + (let* ((account (caar ravi/mu4e-account-alist)) + (account-vars (cdr (assoc account ravi/mu4e-account-alist)))) + (if account-vars + (mapc #'(lambda (var) + (set (car var) (cadr var))) + account-vars) + (error "No email account found"))) + + ;; Choose correct SMTP identity wisely + (defun ravi/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)) + (if (= (length ravi/mu4e-account-alist) 1) + (caar ravi/mu4e-account-alist) + (completing-read (format "Compose with account: (%s) " + (mapconcat #'(lambda (var) (car var)) + ravi/mu4e-account-alist "/")) + (mapcar #'(lambda (var) (car var)) ravi/mu4e-account-alist) + nil t nil nil (caar ravi/mu4e-account-alist))))) + (account-vars (cdr (assoc account ravi/mu4e-account-alist)))) + (if account-vars + (mapc #'(lambda (var) + (set (car var) (cadr var))) + account-vars) + (error "No email account found")))) + (add-hook 'mu4e-compose-pre-hook 'ravi/mu4e-set-account) + + (setq mu4e-compose-dont-reply-to-self t) + (defun ravi/set-self-addresses () + (setq mu4e-user-mail-address-list (list user-mail-address))) + (add-hook 'mu4e-compose-pre-hook 'ravi/set-self-addresses) + + ;; Use async method of sending email, if possible + (use-package async + :config + (progn + (require 'smtpmail-async) + (setq send-mail-function 'async-smtpmail-send-it) + (setq message-send-mail-function 'async-smtpmail-send-it) + ) + :ensure t + ) + + ;; Basic mu4e configuration parameters + (setq mu4e-mu-binary (ravi/emacs-file "site-lisp/mu/mu/mu")) + (setq mu4e-maildir "~/.mail") + + ;; Poll accounts only as often as necessary + (defvar ravi/mu4e-get-mail-attempts 0 + "Number of attempts so far to get mail") + (defun ravi/check-whether-to-get-mail-for-account (account-info) + (let* ((account-interval (assq 'ravi/account-update-interval account-info)) + (account-update-interval (if account-interval (cadr account-interval) 1))) + (if (= (% ravi/mu4e-get-mail-attempts account-update-interval) 0) + (concat " " (car account-info)) + ""))) + (defun ravi/get-mu4e-get-mail-command () + "Figure out arguments to mbsync" + (let ((ravi/all-channels (mapconcat 'ravi/check-whether-to-get-mail-for-account + ravi/mu4e-account-alist ""))) + (setq ravi/mu4e-get-mail-attempts (1+ ravi/mu4e-get-mail-attempts)) + (if (= (length ravi/all-channels) 0) + "true" ;; do nothing command + (concat (ravi/emacs-file "site-lisp/isync/src/mbsync") " -q -q" ravi/all-channels) + ))) + (add-hook 'mu4e-update-pre-hook + (lambda () + (setq mu4e-get-mail-command (ravi/get-mu4e-get-mail-command)))) + ;(message "%d: '%s'" ravi/mu4e-get-mail-attempts (ravi/get-mu4e-get-mail-command)) + ;; Default update command if something goes wrong + (setq mu4e-get-mail-command (concat (ravi/emacs-file "site-lisp/isync/src/mbsync") " -a -q -q")) + (setq mu4e-update-interval ravi/mu4e-update-interval) + (setq mu4e-change-filenames-when-moving t) + + ;; User interface + (setq mu4e-html-renderer 'w3m) + (setq mu4e-html2text-command "w3m -T text/html") + (setq mu4e-view-show-images t) + (when (boundp 'ravi/mu4e-maildir-shortcuts) + (setq mu4e-maildir-shortcuts ravi/mu4e-maildir-shortcuts)) + + (add-to-list 'mu4e-view-actions + '("ViewInBrowser" . mu4e-action-view-in-browser) t) + + ;; Show summary of all folders + (use-package mu4e-maildirs-extension + ;;:config (mu4e-maildirs-extension) ; does not work with mu now + :ensure t + ) + + (setq message-citation-line-function 'message-insert-formatted-citation-line) + (setq message-kill-buffer-on-exit t) + (setq mu4e-compose-signature-auto-include nil) + ;; Allow attaching files from dired + (require 'gnus-dired) + ;; make the `gnus-dired-mail-buffers' function also work on + ;; message-mode derived modes, such as mu4e-compose-mode + (defun gnus-dired-mail-buffers () + "Return a list of active message buffers." + (let (buffers) + (save-current-buffer + (dolist (buffer (buffer-list t)) + (set-buffer buffer) + (when (and (derived-mode-p 'message-mode) + (null message-sent-message-via)) + (push (buffer-name buffer) buffers)))) + (nreverse buffers))) + (setq gnus-dired-mail-mode 'mu4e-user-agent) + (add-hook 'dired-mode-hook 'turn-on-gnus-dired-mode) + + (imagemagick-register-types) + ) + ) + ) + +(provide 'ravi-init-mu) +;;; ravi-init-mu.el ends here |
