* mu4e: run mu4e-view-mode only when the marked-as-read message is received

This commit is contained in:
djcb 2013-10-20 16:55:36 +03:00
parent 9c8101d949
commit c171a61827
1 changed files with 34 additions and 42 deletions

View File

@ -216,52 +216,41 @@ found."
(win (or (get-buffer-window buf) (split-window-vertically)))) (win (or (get-buffer-window buf) (split-window-vertically))))
(select-window win) (select-window win)
(switch-to-buffer buf))) (switch-to-buffer buf)))
(defun mu4e-view (msg headersbuf)
(defun mu4e-view (msg headersbuf &optional refresh)
"Display the message MSG in a new buffer, and keep in sync with HDRSBUF. "Display the message MSG in a new buffer, and keep in sync with HDRSBUF.
'In sync' here means that moving to the next/previous message in 'In sync' here means that moving to the next/previous message in
the the message view affects HDRSBUF, as does marking etc. the the message view affects HDRSBUF, as does marking etc.
REFRESH is for re-showing an already existing message.
As a side-effect, a message that is being viewed loses its 'unread' As a side-effect, a message that is being viewed loses its 'unread'
marking if it still had that." marking if it still had that."
(let* ((embedded ;; is it registered as an embedded msg (ie. message/rfc822 (let* ((embedded ;; is it as an embedded msg (ie. message/rfc822 att)?
;; att)?
(when (gethash (mu4e-message-field msg :path) (when (gethash (mu4e-message-field msg :path)
mu4e~path-parent-docid-map) t)) mu4e~path-parent-docid-map) t))
(buf (buf
(if embedded (if embedded
(mu4e~view-embedded-winbuf) (mu4e~view-embedded-winbuf)
(get-buffer-create mu4e~view-buffer-name)))) (get-buffer-create mu4e~view-buffer-name))))
;; note: mu4e~view-mark-as-read will pseudo-recursively call mu4e-view again
;; by triggering mu4e~view again as it marks the message as read
(with-current-buffer buf (with-current-buffer buf
(switch-to-buffer buf) (switch-to-buffer buf)
(let ((inhibit-read-only t)) (setq mu4e~view-msg msg)
(erase-buffer) (when (or embedded (not (mu4e~view-mark-as-read msg)))
(insert (mu4e-view-message-text msg)) (let ((inhibit-read-only t))
(goto-char (point-min)) (erase-buffer)
(mu4e~fontify-cited) (insert (mu4e-view-message-text msg))
(mu4e~fontify-signature) (goto-char (point-min))
(mu4e~view-make-urls-clickable) (mu4e~fontify-cited)
(mu4e~view-show-images-maybe msg) (mu4e~fontify-signature)
(mu4e~view-make-urls-clickable)
(if embedded (mu4e~view-show-images-maybe msg)
(local-set-key "q" 'kill-buffer-and-window) (setq
(setq mu4e~view-buffer buf))) mu4e~view-buffer buf
mu4e~view-headers-buffer headersbuf)
(unless (eq major-mode 'mu4e-view-mode) (when embedded (local-set-key "q" 'kill-buffer-and-window))
(mu4e-view-mode)) (mu4e-view-mode))))))
(setq ;; buffer local
mu4e~view-msg msg
mu4e~view-headers-buffer headersbuf)
(unless (or refresh embedded)
;; no use in trying to set flags again, or when it's an embedded
;; message
(mu4e~view-mark-as-read-maybe)))))
(defun mu4e~view-construct-header (field val &optional dont-propertize-val) (defun mu4e~view-construct-header (field val &optional dont-propertize-val)
"Return header field FIELD (as in `mu4e-header-info') with value "Return header field FIELD (as in `mu4e-header-info') with value
VAL if VAL is non-nil. If DONT-PROPERTIZE-VAL is non-nil, do not VAL if VAL is non-nil. If DONT-PROPERTIZE-VAL is non-nil, do not
@ -694,19 +683,22 @@ FUNC should be a function taking two arguments:
(when (boundp 'autopair-dont-activate) (when (boundp 'autopair-dont-activate)
(setq autopair-dont-activate t))) (setq autopair-dont-activate t)))
(defun mu4e~view-mark-as-read-maybe () (defun mu4e~view-mark-as-read (msg)
"Clear the current message's New/Unread status and set it to Seen. "Clear the message MSG New/Unread status and set it to Seen.
If the message is not New/Unread, do nothing." If the message is not New/Unread, do nothing. Evaluates to t if it
(when mu4e~view-msg triggers any changes, nil otherwise. If this function does any
(let ((flags (mu4e-message-field mu4e~view-msg :flags)) changes, it triggers a refresh."
(msgid (mu4e-message-field mu4e~view-msg :message-id)) (when msg
(docid (mu4e-message-field mu4e~view-msg :docid))) (let ((flags (mu4e-message-field msg :flags))
(msgid (mu4e-message-field msg :message-id))
(docid (mu4e-message-field msg :docid)))
;; attached (embedded) messages don't have docids; leave them alone ;; attached (embedded) messages don't have docids; leave them alone
;; is it a new message ;; is it a new message
(when (and docid (or (member 'unread flags) (member 'new flags))) (when (and docid (or (member 'unread flags) (member 'new flags)))
;; mark /all/ messages with this message-id as read, so all copies of ;; mark /all/ messages with this message-id as read, so all copies of
;; this message will be marked as read. ;; this message will be marked as read.
(mu4e~proc-move msgid nil "+S-u-N"))))) (mu4e~proc-move msgid nil "+S-u-N")
t))))
(defun mu4e~view-browse-url-func (url) (defun mu4e~view-browse-url-func (url)
"Return a function that executes `browse-url' with URL. "Return a function that executes `browse-url' with URL.
@ -820,7 +812,7 @@ N (prefix argument), to the Nth previous header."
(defun mu4e-view-refresh () (defun mu4e-view-refresh ()
"Redisplay the current message." "Redisplay the current message."
(interactive) (interactive)
(mu4e-view mu4e~view-msg mu4e~view-headers-buffer t) (mu4e-view mu4e~view-msg mu4e~view-headers-buffer)
(setq mu4e~view-cited-hidden nil)) (setq mu4e~view-cited-hidden nil))
(defun mu4e-view-action (&optional msg) (defun mu4e-view-action (&optional msg)