2012-04-01 11:29:24 +02:00
|
|
|
;;; mu4e-main.el -- part of mu4e, the mu mail user agent
|
2011-12-04 22:49:15 +01:00
|
|
|
;;
|
2016-01-09 20:27:13 +01:00
|
|
|
;; Copyright (C) 2011-2016 Dirk-Jan C. Binnema
|
2011-12-04 22:49:15 +01:00
|
|
|
|
|
|
|
;; Author: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
|
|
|
;; Maintainer: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
2012-04-01 11:29:24 +02:00
|
|
|
|
2011-12-04 22:49:15 +01:00
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;; GNU Emacs 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.
|
|
|
|
|
|
|
|
;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;;; Code:
|
2012-04-09 10:52:33 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2012-08-14 09:20:27 +02:00
|
|
|
(require 'smtpmail) ;; the queing stuff (silence elint)
|
2012-04-09 10:52:33 +02:00
|
|
|
(require 'mu4e-utils) ;; utility functions
|
2015-12-13 16:42:27 +01:00
|
|
|
(require 'mu4e-context) ;; the context
|
2011-12-04 22:49:15 +01:00
|
|
|
|
2012-08-14 09:20:27 +02:00
|
|
|
|
2012-09-06 09:33:53 +02:00
|
|
|
(defconst mu4e~main-buffer-name " *mu4e-main*"
|
2012-04-01 11:29:24 +02:00
|
|
|
"*internal* Name of the mu4e main view buffer.")
|
2012-02-28 21:34:22 +01:00
|
|
|
|
2011-12-13 08:07:38 +01:00
|
|
|
(defvar mu4e-main-mode-map
|
2011-12-04 22:49:15 +01:00
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
|
2012-05-01 21:45:54 +02:00
|
|
|
(define-key map "b" 'mu4e-headers-search-bookmark)
|
2012-05-05 10:07:58 +02:00
|
|
|
(define-key map "B" 'mu4e-headers-search-bookmark-edit)
|
2012-03-27 20:15:47 +02:00
|
|
|
|
2012-05-01 21:45:54 +02:00
|
|
|
(define-key map "s" 'mu4e-headers-search)
|
2011-12-15 20:47:01 +01:00
|
|
|
(define-key map "q" 'mu4e-quit)
|
2012-05-01 21:45:54 +02:00
|
|
|
(define-key map "j" 'mu4e~headers-jump-to-maildir)
|
2011-12-15 07:51:39 +01:00
|
|
|
(define-key map "C" 'mu4e-compose-new)
|
2011-12-04 22:49:15 +01:00
|
|
|
|
2012-04-26 16:59:34 +02:00
|
|
|
(define-key map "m" 'mu4e~main-toggle-mail-sending-mode)
|
2011-12-04 22:49:15 +01:00
|
|
|
(define-key map "f" 'smtpmail-send-queued-mail)
|
|
|
|
|
2012-10-25 10:59:50 +02:00
|
|
|
;;
|
|
|
|
(define-key map "U" 'mu4e-update-mail-and-index)
|
2015-02-13 10:47:25 +01:00
|
|
|
(define-key map (kbd "C-S-u") 'mu4e-update-mail-and-index)
|
|
|
|
;; for terminal users
|
|
|
|
(define-key map (kbd "C-c C-u") 'mu4e-update-mail-and-index)
|
|
|
|
|
2013-10-08 14:42:30 +02:00
|
|
|
(define-key map "S" 'mu4e-interrupt-update-mail)
|
2012-10-25 10:59:50 +02:00
|
|
|
(define-key map (kbd "C-S-u") 'mu4e-update-mail-and-index)
|
2015-12-13 16:42:27 +01:00
|
|
|
(define-key map ";" 'mu4e-context-switch)
|
2013-06-16 22:01:06 +02:00
|
|
|
|
2012-04-16 17:31:48 +02:00
|
|
|
(define-key map "$" 'mu4e-show-log)
|
2012-06-15 10:00:21 +02:00
|
|
|
(define-key map "A" 'mu4e-about)
|
2015-06-07 20:07:59 +02:00
|
|
|
(define-key map "N" 'mu4e-news)
|
2011-12-15 07:51:39 +01:00
|
|
|
(define-key map "H" 'mu4e-display-manual)
|
2011-12-04 22:49:15 +01:00
|
|
|
map)
|
2011-12-28 18:47:39 +01:00
|
|
|
|
2011-12-14 08:13:10 +01:00
|
|
|
"Keymap for the *mu4e-main* buffer.")
|
2011-12-13 08:07:38 +01:00
|
|
|
(fset 'mu4e-main-mode-map mu4e-main-mode-map)
|
2011-12-04 22:49:15 +01:00
|
|
|
|
2012-08-14 09:20:27 +02:00
|
|
|
(defvar mu4e-main-mode-abbrev-table nil)
|
2012-03-27 20:15:47 +02:00
|
|
|
(define-derived-mode mu4e-main-mode special-mode "mu4e:main"
|
2012-01-14 10:05:23 +01:00
|
|
|
"Major mode for the mu4e main screen.
|
|
|
|
\\{mu4e-main-mode-map}."
|
2011-12-13 08:07:38 +01:00
|
|
|
(use-local-map mu4e-main-mode-map)
|
2015-12-19 09:14:49 +01:00
|
|
|
(setq
|
|
|
|
truncate-lines t
|
|
|
|
overwrite-mode 'overwrite-mode-binary)
|
|
|
|
|
|
|
|
;; show context in mode-string
|
|
|
|
(set (make-local-variable 'global-mode-string) '(:eval (mu4e-context-label)))
|
2014-10-30 20:02:18 +01:00
|
|
|
(set (make-local-variable 'revert-buffer-function) #'mu4e~main-view-real))
|
2011-12-04 22:49:15 +01:00
|
|
|
|
2011-12-25 12:38:44 +01:00
|
|
|
|
2012-04-26 16:59:34 +02:00
|
|
|
(defun mu4e~main-action-str (str &optional func-or-shortcut)
|
2014-01-12 12:07:36 +01:00
|
|
|
"Highlight the first occurence of [.] in STR.
|
2012-11-10 14:01:17 +01:00
|
|
|
If FUNC-OR-SHORTCUT is non-nil and if it is a function, call it
|
2014-01-12 12:07:36 +01:00
|
|
|
when STR is clicked (using RET or mouse-2); if FUNC-OR-SHORTCUT is
|
|
|
|
a string, execute the corresponding keyboard action when it is
|
2011-12-28 18:47:39 +01:00
|
|
|
clicked."
|
2011-12-25 12:38:44 +01:00
|
|
|
(let ((newstr
|
2015-01-19 10:53:11 +01:00
|
|
|
(replace-regexp-in-string
|
|
|
|
"\\[\\(..?\\)\\]"
|
|
|
|
(lambda(m)
|
|
|
|
(format "[%s]"
|
|
|
|
(propertize (match-string 1 m) 'face 'mu4e-highlight-face)))
|
|
|
|
str))
|
|
|
|
(map (make-sparse-keymap))
|
|
|
|
(func (if (functionp func-or-shortcut)
|
|
|
|
func-or-shortcut
|
|
|
|
(if (stringp func-or-shortcut)
|
|
|
|
(lexical-let ((macro func-or-shortcut))
|
|
|
|
(lambda()(interactive)
|
|
|
|
(execute-kbd-macro macro)))))))
|
2011-12-25 12:38:44 +01:00
|
|
|
(define-key map [mouse-2] func)
|
|
|
|
(define-key map (kbd "RET") func)
|
2011-12-26 11:17:28 +01:00
|
|
|
(put-text-property 0 (length newstr) 'keymap map newstr)
|
2014-01-26 05:08:16 +01:00
|
|
|
(put-text-property (string-match "\\[.+$" newstr)
|
2015-01-19 10:53:11 +01:00
|
|
|
(- (length newstr) 1) 'mouse-face 'highlight newstr) newstr))
|
2011-12-25 12:38:44 +01:00
|
|
|
|
2014-05-21 20:38:19 +02:00
|
|
|
;; NEW
|
|
|
|
;; This is the old `mu4e~main-view' function but without
|
|
|
|
;; buffer switching at the end.
|
2014-10-30 20:02:18 +01:00
|
|
|
(defun mu4e~main-view-real (ignore-auto noconfirm)
|
2012-04-26 16:59:34 +02:00
|
|
|
(let ((buf (get-buffer-create mu4e~main-buffer-name))
|
2015-01-19 10:53:11 +01:00
|
|
|
(inhibit-read-only t))
|
2011-12-04 22:49:15 +01:00
|
|
|
(with-current-buffer buf
|
2011-12-13 06:43:49 +01:00
|
|
|
(erase-buffer)
|
|
|
|
(insert
|
2015-01-19 10:53:11 +01:00
|
|
|
"* "
|
2015-12-13 16:42:27 +01:00
|
|
|
(propertize "mu4e - mu for emacs version " 'face 'mu4e-title-face)
|
|
|
|
(propertize mu4e-mu-version 'face 'mu4e-header-key-face)
|
2015-01-19 10:53:11 +01:00
|
|
|
|
|
|
|
;; show some server properties; in this case; a big C when there's
|
|
|
|
;; crypto support, a big G when there's Guile support
|
|
|
|
" "
|
|
|
|
(propertize
|
|
|
|
(concat
|
|
|
|
(when (plist-get mu4e~server-props :crypto) "C")
|
|
|
|
(when (plist-get mu4e~server-props :guile) "G"))
|
2015-12-13 16:42:27 +01:00
|
|
|
'face 'mu4e-title-face)
|
|
|
|
|
2015-01-19 10:53:11 +01:00
|
|
|
"\n\n"
|
|
|
|
(propertize " Basics\n\n" 'face 'mu4e-title-face)
|
|
|
|
(mu4e~main-action-str "\t* [j]ump to some maildir\n" 'mu4e-jump-to-maildir)
|
|
|
|
(mu4e~main-action-str "\t* enter a [s]earch query\n" 'mu4e-search)
|
|
|
|
(mu4e~main-action-str "\t* [C]ompose a new message\n" 'mu4e-compose-new)
|
|
|
|
"\n"
|
|
|
|
(propertize " Bookmarks\n\n" 'face 'mu4e-title-face)
|
|
|
|
;; TODO: it's a bit uncool to hard-code the "b" shortcut...
|
|
|
|
(mapconcat
|
|
|
|
(lambda (bm)
|
2016-07-31 10:20:59 +02:00
|
|
|
(mu4e~main-action-str
|
|
|
|
(concat "\t* [b" (make-string 1 (mu4e-bookmark-key bm)) "] "
|
|
|
|
(mu4e-bookmark-name bm))
|
|
|
|
(concat "b" (make-string 1 (mu4e-bookmark-key bm)))))
|
|
|
|
(mu4e-bookmarks) "\n")
|
2015-01-19 10:53:11 +01:00
|
|
|
"\n\n"
|
|
|
|
(propertize " Misc\n\n" 'face 'mu4e-title-face)
|
|
|
|
|
2015-12-13 16:42:27 +01:00
|
|
|
(mu4e~main-action-str "\t* [;]Switch focus\n" 'mu4e-context-switch)
|
|
|
|
|
|
|
|
(mu4e~main-action-str "\t* [U]pdate email & database\n"
|
|
|
|
'mu4e-update-mail-and-index)
|
2013-10-13 23:07:27 +02:00
|
|
|
|
2011-12-22 23:39:12 +01:00
|
|
|
;; show the queue functions if `smtpmail-queue-dir' is defined
|
2015-12-13 16:42:27 +01:00
|
|
|
(if (file-directory-p smtpmail-queue-dir)
|
|
|
|
(mu4e~main-view-queue)
|
2015-01-19 10:36:55 +01:00
|
|
|
"")
|
2011-12-13 06:43:49 +01:00
|
|
|
"\n"
|
2015-06-07 20:07:59 +02:00
|
|
|
(mu4e~main-action-str "\t* [N]ews\n" 'mu4e-news)
|
2012-06-15 10:00:21 +02:00
|
|
|
(mu4e~main-action-str "\t* [A]bout mu4e\n" 'mu4e-about)
|
2012-04-26 16:59:34 +02:00
|
|
|
(mu4e~main-action-str "\t* [H]elp\n" 'mu4e-display-manual)
|
|
|
|
(mu4e~main-action-str "\t* [q]uit\n" 'mu4e-quit))
|
2014-05-24 12:22:47 +02:00
|
|
|
(mu4e-main-mode)
|
2014-05-21 20:38:19 +02:00
|
|
|
)))
|
|
|
|
|
2015-01-19 10:36:55 +01:00
|
|
|
(defun mu4e~main-view-queue ()
|
|
|
|
"Display queue-related actions in the main view."
|
|
|
|
(concat
|
|
|
|
(mu4e~main-action-str "\t* toggle [m]ail sending mode "
|
|
|
|
'mu4e~main-toggle-mail-sending-mode)
|
|
|
|
"(currently "
|
|
|
|
(propertize (if smtpmail-queue-mail "queued" "direct")
|
|
|
|
'face 'mu4e-header-key-face)
|
|
|
|
")\n"
|
|
|
|
(let ((queue-size (mu4e~main-queue-size)))
|
|
|
|
(if (zerop queue-size)
|
|
|
|
""
|
|
|
|
(mu4e~main-action-str
|
|
|
|
(format "\t* [f]lush %s queued %s\n"
|
|
|
|
(propertize (int-to-string queue-size)
|
|
|
|
'face 'mu4e-header-key-face)
|
|
|
|
(if (> queue-size 1) "mails" "mail"))
|
|
|
|
'smtpmail-send-queued-mail)))))
|
|
|
|
|
|
|
|
(defun mu4e~main-queue-size ()
|
|
|
|
"Return, as an int, the number of emails in the queue."
|
|
|
|
(condition-case nil
|
|
|
|
(with-temp-buffer
|
|
|
|
(insert-file-contents (expand-file-name smtpmail-queue-index-file
|
|
|
|
smtpmail-queue-dir))
|
|
|
|
(count-lines (point-min) (point-max)))
|
|
|
|
(error 0)))
|
|
|
|
|
2014-05-21 20:38:19 +02:00
|
|
|
(defun mu4e~main-view ()
|
2014-10-30 20:02:18 +01:00
|
|
|
"Create the mu4e main-view, and switch to it."
|
|
|
|
(mu4e~main-view-real nil nil)
|
|
|
|
(switch-to-buffer mu4e~main-buffer-name)
|
2015-12-13 16:42:27 +01:00
|
|
|
(goto-char (point-min))
|
|
|
|
(setq global-mode-string '(:eval (mu4e-context-label))))
|
|
|
|
|
2011-12-04 22:49:15 +01:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Interactive functions
|
2014-05-21 20:38:19 +02:00
|
|
|
;; NEW
|
|
|
|
;; Toggle mail sending mode without switching
|
2012-04-26 16:59:34 +02:00
|
|
|
(defun mu4e~main-toggle-mail-sending-mode ()
|
2014-05-21 21:33:02 +02:00
|
|
|
"Toggle sending mail mode, either queued or direct."
|
2011-12-04 22:49:15 +01:00
|
|
|
(interactive)
|
2014-03-13 16:12:54 +01:00
|
|
|
(let ((curpos (point)))
|
|
|
|
(unless (file-directory-p smtpmail-queue-dir)
|
|
|
|
(mu4e-error "`smtpmail-queue-dir' does not exist"))
|
|
|
|
(setq smtpmail-queue-mail (not smtpmail-queue-mail))
|
|
|
|
(message
|
|
|
|
(concat "Outgoing mail will now be "
|
|
|
|
(if smtpmail-queue-mail "queued" "sent directly")))
|
2014-10-30 20:02:18 +01:00
|
|
|
(mu4e~main-view-real nil nil)
|
2014-03-13 16:12:54 +01:00
|
|
|
(goto-char curpos)))
|
2012-09-01 19:05:17 +02:00
|
|
|
|
2014-05-24 14:44:39 +02:00
|
|
|
|
|
|
|
;; (progn
|
|
|
|
;; (define-key mu4e-compose-mode-map (kbd "C-c m") 'mu4e~main-toggle-mail-sending-mode)
|
|
|
|
;; (define-key mu4e-view-mode-map (kbd "C-c m") 'mu4e~main-toggle-mail-sending-mode)
|
|
|
|
;; (define-key mu4e-compose-mode-map (kbd "C-c m") 'mu4e~main-toggle-mail-sending-mode)
|
|
|
|
;; (define-key mu4e-headers-mode-map (kbd "C-c m") 'mu4e~main-toggle-mail-sending-mode)
|
|
|
|
;; )
|
2014-05-21 20:38:19 +02:00
|
|
|
|
2011-12-13 08:07:38 +01:00
|
|
|
(provide 'mu4e-main)
|