From b26bd3a4e739522510fe6752a393cdb2f5b94bda Mon Sep 17 00:00:00 2001 From: djcb Date: Sat, 6 Jul 2013 11:51:33 +0300 Subject: [PATCH] * mu4e: do a better job of trying to show images (without delay) --- mu4e/mu4e-utils.el | 17 +++++++++++------ mu4e/mu4e-view.el | 11 ++++++++++- mu4e/mu4e.texi | 4 +--- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/mu4e/mu4e-utils.el b/mu4e/mu4e-utils.el index cf433c9e..ea6774b5 100644 --- a/mu4e/mu4e-utils.el +++ b/mu4e/mu4e-utils.el @@ -600,6 +600,7 @@ and fill the list `mu4e~contacts-for-completion' with it, with each element looking like name This is used by the completion function in mu4e-compose." + (setq mu4e~contact-list contacts) (let ((lst) ;; sort by the frequency (descending), then timestamp (descending) ;; FIXME: sadly, the emacs completion subsystem re-sorts the list @@ -929,11 +930,11 @@ This includes expanding e.g. 3-5 into 3,4,5. If the letter (defvar mu4e-imagemagick-identify "identify" "Name/path of the Imagemagick 'identify' program.") -(defun mu4e-display-image (imgpath &optional maxwidth) - "Display image IMG at point; optionally specify -MAXWIDTH. Function tries to use imagemagick if available (ie., +(defun mu4e-display-image (imgpath &optional maxwidth maxheight) + "Display image IMG at point; optionally specify MAXWIDTH and +MAXHEIGHT. Function tries to use imagemagick if available (ie., emacs was compiled with inmagemagick support); otherwise MAXWIDTH -is ignored." +and MAXHEIGHT are ignored." (let* ((have-im (and (fboundp 'imagemagick-types) (imagemagick-types))) ;; hmm, should check for specific type (identify (and have-im maxwidth @@ -949,8 +950,12 @@ is ignored." (create-image imgpath)))) ;;(message "DISPLAY: %S %S" imgpath img) (when img - (newline) - (insert-image img)))) + (insert "\n") + (let ((size (image-size img))) ;; inspired by gnus.. + (insert-char ?\n (max 0 (round (- (window-height) (or maxheight (cdr size)) 1) 2))) + (insert-char ?\ (max 0 (round (- (window-width) (or maxwidth (car size))) 2))) + (insert-image img))))) + (defun mu4e-hide-other-mu4e-buffers () "Bury mu4e-buffers (main, headers, view) (and delete all windows diff --git a/mu4e/mu4e-view.el b/mu4e/mu4e-view.el index 604e5d0d..5d391ff0 100644 --- a/mu4e/mu4e-view.el +++ b/mu4e/mu4e-view.el @@ -80,6 +80,13 @@ This is only effective if you're using an emacs with Imagemagick support, and `mu4e-view-show-images' is non-nil." :group 'mu4e-view) +(defcustom mu4e-view-image-max-height 600 + "The maximum height for images to display. +This is only effective if you're using an emacs with Imagemagick +support, and `mu4e-view-show-images' is non-nil." + :group 'mu4e-view) + + (defcustom mu4e-view-scroll-to-next t "If non-nil, move to the next message when calling `mu4e-view-scroll-up-or-next' (typically bound to SPC) when at the @@ -743,7 +750,9 @@ What browser is called is depending on (when (and imgfile (file-exists-p imgfile)) (save-excursion (goto-char (point-max)) - (mu4e-display-image imgfile mu4e-view-image-max-width))))))))) + (mu4e-display-image imgfile + mu4e-view-image-max-width + mu4e-view-image-max-height))))))))) ;; this is fairly simplistic... (defun mu4e~view-make-urls-clickable () diff --git a/mu4e/mu4e.texi b/mu4e/mu4e.texi index 9e957a8b..935f5d40 100644 --- a/mu4e/mu4e.texi +++ b/mu4e/mu4e.texi @@ -2831,9 +2831,7 @@ default for various reasons. (setq mu4e-attachment-dir "~/Desktop") ;; attempt to show images when viewing messages -(setq - mu4e-view-show-images t - mu4e-view-image-max-width 800) +(setq mu4e-view-show-images t) @end lisp @node FAQ