mu4e: update html/URL handling
Make mu4e-view-toggle-html _not_ toggle the global value of of mu4e-view-prefer-html, but only the current one. Make the link map 'permanent', so it survives the buffer changes when refreshing. This fixes issue #904.
This commit is contained in:
@ -158,12 +158,16 @@ This is equivalent to:
|
|||||||
(mu4e-message-field (mu4e-message-at-point) FIELD)."
|
(mu4e-message-field (mu4e-message-at-point) FIELD)."
|
||||||
(mu4e-message-field (mu4e-message-at-point) field))
|
(mu4e-message-field (mu4e-message-at-point) field))
|
||||||
|
|
||||||
(defun mu4e-message-body-text (msg)
|
(defvar mu4e~message-body-html nil
|
||||||
|
"Whether the body text uses HTML.")
|
||||||
|
|
||||||
|
(defun mu4e-message-body-text (msg &optional prefer-html)
|
||||||
"Get the body in text form for this message.
|
"Get the body in text form for this message.
|
||||||
This is either :body-txt, or if not available, :body-html converted
|
This is either :body-txt, or if not available, :body-html
|
||||||
to text, using `mu4e-html2text-command' is non-nil, it will use
|
converted to text, using `mu4e-html2text-command' is non-nil, it
|
||||||
that. Normally, thiss function prefers the text part, but this can
|
will use that. Normally, this function prefers the text part,
|
||||||
be changed by setting `mu4e-view-prefer-html'."
|
unless PREFER-HTML is non-nil."
|
||||||
|
(setq mu4e~message-body-html nil) ;; default
|
||||||
(let* ((txt (mu4e-message-field msg :body-txt))
|
(let* ((txt (mu4e-message-field msg :body-txt))
|
||||||
(html (mu4e-message-field msg :body-html))
|
(html (mu4e-message-field msg :body-html))
|
||||||
(body
|
(body
|
||||||
@ -176,7 +180,7 @@ be changed by setting `mu4e-view-prefer-html'."
|
|||||||
((and (> (* mu4e-view-html-plaintext-ratio-heuristic
|
((and (> (* mu4e-view-html-plaintext-ratio-heuristic
|
||||||
(length txt)) (length html))
|
(length txt)) (length html))
|
||||||
;; use html if it's prefered, unless there is no html
|
;; use html if it's prefered, unless there is no html
|
||||||
(or (not mu4e-view-prefer-html) (not html)))
|
(or (not prefer-html) (not html)))
|
||||||
txt)
|
txt)
|
||||||
;; otherwise, it there some html?
|
;; otherwise, it there some html?
|
||||||
(html
|
(html
|
||||||
@ -192,6 +196,7 @@ be changed by setting `mu4e-view-prefer-html'."
|
|||||||
((functionp mu4e-html2text-command)
|
((functionp mu4e-html2text-command)
|
||||||
(funcall mu4e-html2text-command))
|
(funcall mu4e-html2text-command))
|
||||||
(t (mu4e-error "Invalid `mu4e-html2text-command'")))
|
(t (mu4e-error "Invalid `mu4e-html2text-command'")))
|
||||||
|
(setq mu4e~message-body-html t)
|
||||||
(buffer-string))
|
(buffer-string))
|
||||||
)
|
)
|
||||||
(t ;; otherwise, an empty body
|
(t ;; otherwise, an empty body
|
||||||
|
|||||||
@ -247,7 +247,7 @@ found."
|
|||||||
(mu4e~view-custom-field msg field))))))
|
(mu4e~view-custom-field msg field))))))
|
||||||
mu4e-view-fields "")
|
mu4e-view-fields "")
|
||||||
"\n"
|
"\n"
|
||||||
(let ((body (mu4e-message-body-text msg)))
|
(let ((body (mu4e-message-body-text msg mu4e-view-prefer-html)))
|
||||||
(when (fboundp 'add-face-text-property)
|
(when (fboundp 'add-face-text-property)
|
||||||
(add-face-text-property 0 (length body) 'mu4e-view-body-face t body))
|
(add-face-text-property 0 (length body) 'mu4e-view-body-face t body))
|
||||||
body)))
|
body)))
|
||||||
@ -747,6 +747,10 @@ FUNC should be a function taking two arguments:
|
|||||||
(make-local-variable 'mu4e~view-attach-map)
|
(make-local-variable 'mu4e~view-attach-map)
|
||||||
(make-local-variable 'mu4e~view-cited-hidden)
|
(make-local-variable 'mu4e~view-cited-hidden)
|
||||||
|
|
||||||
|
;; make permanent too, so they'll survive changing the mode
|
||||||
|
(put 'mu4e~view-link-map 'permanent-local t)
|
||||||
|
(put 'mu4e~view-attach-map 'permanent-local t)
|
||||||
|
|
||||||
;; show context in mode-string
|
;; show context in mode-string
|
||||||
(set (make-local-variable 'global-mode-string) '(:eval (mu4e-context-label)))
|
(set (make-local-variable 'global-mode-string) '(:eval (mu4e-context-label)))
|
||||||
|
|
||||||
@ -932,8 +936,8 @@ the new docid. Otherwise, return nil."
|
|||||||
(defun mu4e-view-toggle-html ()
|
(defun mu4e-view-toggle-html ()
|
||||||
"Toggle html-display of the message body (if any)."
|
"Toggle html-display of the message body (if any)."
|
||||||
(interactive)
|
(interactive)
|
||||||
(setq mu4e-view-prefer-html (not mu4e-view-prefer-html))
|
(let ((mu4e-view-prefer-html (not mu4e~message-body-html)))
|
||||||
(mu4e-view-refresh))
|
(mu4e-view-refresh)))
|
||||||
|
|
||||||
(defun mu4e-view-refresh ()
|
(defun mu4e-view-refresh ()
|
||||||
"Redisplay the current message."
|
"Redisplay the current message."
|
||||||
|
|||||||
Reference in New Issue
Block a user