From 49ea3bec58671145222e5181145665995b55519a Mon Sep 17 00:00:00 2001 From: djcb Date: Sat, 13 Aug 2016 10:57:49 +0300 Subject: [PATCH] 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. --- mu4e/mu4e-message.el | 17 +++++++++++------ mu4e/mu4e-view.el | 10 +++++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/mu4e/mu4e-message.el b/mu4e/mu4e-message.el index 74e5b6b8..e0c8da16 100644 --- a/mu4e/mu4e-message.el +++ b/mu4e/mu4e-message.el @@ -158,12 +158,16 @@ This is equivalent to: (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. -This is either :body-txt, or if not available, :body-html converted -to text, using `mu4e-html2text-command' is non-nil, it will use -that. Normally, thiss function prefers the text part, but this can -be changed by setting `mu4e-view-prefer-html'." +This is either :body-txt, or if not available, :body-html +converted to text, using `mu4e-html2text-command' is non-nil, it +will use that. Normally, this function prefers the text part, +unless PREFER-HTML is non-nil." + (setq mu4e~message-body-html nil) ;; default (let* ((txt (mu4e-message-field msg :body-txt)) (html (mu4e-message-field msg :body-html)) (body @@ -176,7 +180,7 @@ be changed by setting `mu4e-view-prefer-html'." ((and (> (* mu4e-view-html-plaintext-ratio-heuristic (length txt)) (length 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) ;; otherwise, it there some html? (html @@ -192,6 +196,7 @@ be changed by setting `mu4e-view-prefer-html'." ((functionp mu4e-html2text-command) (funcall mu4e-html2text-command)) (t (mu4e-error "Invalid `mu4e-html2text-command'"))) + (setq mu4e~message-body-html t) (buffer-string)) ) (t ;; otherwise, an empty body diff --git a/mu4e/mu4e-view.el b/mu4e/mu4e-view.el index 564835d4..359e3c23 100644 --- a/mu4e/mu4e-view.el +++ b/mu4e/mu4e-view.el @@ -247,7 +247,7 @@ found." (mu4e~view-custom-field msg field)))))) mu4e-view-fields "") "\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) (add-face-text-property 0 (length body) 'mu4e-view-body-face t 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-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 (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 () "Toggle html-display of the message body (if any)." (interactive) - (setq mu4e-view-prefer-html (not mu4e-view-prefer-html)) - (mu4e-view-refresh)) + (let ((mu4e-view-prefer-html (not mu4e~message-body-html))) + (mu4e-view-refresh))) (defun mu4e-view-refresh () "Redisplay the current message."