--- image+.el.orig 2015-07-08 01:16:40.000000000 +0900 +++ image+.el 2015-10-13 01:01:06.169900100 +0900 @@ -226,7 +226,7 @@ (plist-get (cdr image) :relief))) new)) -(defun imagex--fit-to-size (image width height &optional max) +(defun imagex--fit-to-size (image width height flag &optional max) "Resize IMAGE with preserving magnification." (let* ((pixels (image-size image t)) (margin (or (plist-get (cdr image) :margin) 0)) @@ -236,15 +236,19 @@ (h (+ (cdr pixels) mr)) (wr (/ width (ftruncate w))) (hr (/ height (ftruncate h))) - (magnification (apply 'min (delq nil (list wr hr max))))) + (magnification (apply 'min (delq nil (if (eq flag 1) + (list wr max) + (if (eq flag 2) + (list hr max) + (list wr hr max))))))) (imagex--zoom image magnification))) -(defun imagex--maximize (image &optional maximum) +(defun imagex--maximize (image flag &optional maximum) "Adjust IMAGE to current frame." (let* ((edges (window-inside-pixel-edges)) (width (- (nth 2 edges) (nth 0 edges))) (height (- (nth 3 edges) (nth 1 edges)))) - (imagex--fit-to-size image width height maximum))) + (imagex--fit-to-size image width height flag maximum))) (defun imagex--rotate-degrees (arg) (cond @@ -338,8 +342,9 @@ (when display (cl-destructuring-bind (image ov) display (let ((new (funcall converter image))) - (plist-put (cdr new) 'imagex-manual-manipulation t) - (overlay-put ov 'display new)) + (if new (progn + (plist-put (cdr new) 'imagex-manual-manipulation t) + (overlay-put ov 'display new)))) (throw 'done t)))) (error (setq err (append err err1)))) @@ -348,8 +353,9 @@ (when display (cl-destructuring-bind (image begin end) display (let ((new (funcall converter image))) - (plist-put (cdr new) 'imagex-manual-manipulation t) - (imagex--replace-textprop-image begin end new)) + (if new (progn + (plist-put (cdr new) 'imagex-manual-manipulation t) + (imagex--replace-textprop-image begin end new)))) (throw 'done t)))) (error (setq err (append err err2)))) @@ -411,7 +417,21 @@ (interactive) (imagex-sticky--convert-image (lambda (image) - (imagex--maximize image)))) + (imagex--maximize image 0)))) + +(defun imagex-sticky-maximize-width () + "Maximize the point image to fit the current frame-width." + (interactive) + (imagex-sticky--convert-image + (lambda (image) + (imagex--maximize image 1)))) + +(defun imagex-sticky-maximize-height () + "Maximize the point image to fit the current frame-height." + (interactive) + (imagex-sticky--convert-image + (lambda (image) + (imagex--maximize image 2)))) (defun imagex-sticky-restore-original () "Restore the original image if current image has been converted." @@ -419,8 +439,6 @@ (imagex-sticky--convert-image (lambda (image) (let ((orig (plist-get (cdr image) 'imagex-original-image))) - (unless orig - (error "No original image here")) orig)))) (defun imagex-sticky-rotate-left (&optional degrees) @@ -477,7 +495,7 @@ (let* ((orig (plist-get (cdr image) 'imagex-original-image)) (target (or orig image)) (new-image - (imagex--maximize target imagex-auto-adjust-threshold))) + (imagex--maximize target 0 imagex-auto-adjust-threshold))) ;; new-image may be nil if original image file was removed (when new-image (imagex--replace-current-image new-image) @@ -552,7 +570,7 @@ (condition-case err ;; suppress eternal recurse (let ((imagex-adjusting t)) - (imagex--maximize img imagex-auto-adjust-threshold)) + (imagex--maximize img 0 imagex-auto-adjust-threshold)) (error ;; handling error that is caused by ImageMagick unsupported image. (imagex--message "%s" err)