diff options
Diffstat (limited to 'lisp/image-mode.el')
-rw-r--r-- | lisp/image-mode.el | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/lisp/image-mode.el b/lisp/image-mode.el index 9ed295e2aa1..69ef7015cce 100644 --- a/lisp/image-mode.el +++ b/lisp/image-mode.el @@ -95,6 +95,9 @@ Its value should be one of the following: (defvar-local image-transform-rotation 0.0 "Rotation angle for the image in the current Image mode buffer.") +(defvar-local image--transform-smoothing nil + "Whether to use transform smoothing.") + (defvar image-transform-right-angle-fudge 0.0001 "Snap distance to a multiple of a right angle. There's no deep theory behind the default value, it should just @@ -457,6 +460,7 @@ call." (define-key map "sb" 'image-transform-fit-both) (define-key map "ss" 'image-transform-set-scale) (define-key map "sr" 'image-transform-set-rotation) + (define-key map "sm" 'image-transform-set-smoothing) (define-key map "so" 'image-transform-original) (define-key map "s0" 'image-transform-reset) @@ -523,6 +527,8 @@ call." :help "Rotate the image"] ["Set Rotation..." image-transform-set-rotation :help "Set rotation angle of the image"] + ["Set Smoothing..." image-transform-set-smoothing + :help "Toggle smoothing"] ["Original Size" image-transform-original :help "Reset image to actual size"] ["Reset to Default Size" image-transform-reset @@ -707,8 +713,7 @@ Key bindings: Image minor mode provides the key \\<image-mode-map>\\[image-toggle-display], to switch back to `image-mode' and display an image file as the actual image." - nil (:eval (if image-type (format " Image[%s]" image-type) " Image")) - image-minor-mode-map + :lighter (:eval (if image-type (format " Image[%s]" image-type) " Image")) :group 'image :version "22.1" (if image-minor-mode @@ -726,8 +731,9 @@ displays an image file as text." (setq image-type previous-image-type) ;; Enable image minor mode with `C-c C-c'. (image-minor-mode 1) - ;; Show the image file as text. - (image-toggle-display-text))) + (unless (image-get-display-property) + ;; Show the image file as text. + (image-toggle-display-text)))) (defun image-mode-as-hex () "Set a non-image mode as major mode in combination with image minor mode. @@ -858,7 +864,9 @@ was inserted." (setq image-transform-rotation (or (exif-orientation (ignore-error exif-error - (exif-parse-buffer))) + ;; exif-parse-buffer can move point, so preserve it. + (save-excursion + (exif-parse-buffer)))) 0.0))) ;; Swap width and height when changing orientation ;; between portrait and landscape. @@ -985,7 +993,13 @@ Otherwise, display the image by calling `image-mode'." (edges (window-inside-pixel-edges window)) (window-width (- (nth 2 edges) (nth 0 edges))) (window-height (- (nth 3 edges) (nth 1 edges)))) + ;; If the size has been changed manually (with `+'/`-'), + ;; then :max-width/:max-height is nil. In that case, do + ;; no automatic resizing. (when (and image-width image-height + ;; Don't do resizing if we have a manual + ;; rotation (from the `r' command), either. + (not (plist-get (cdr spec) :rotation)) (or (not (= image-width window-width)) (not (= image-height window-height)))) (unless image-fit-to-window-lock @@ -1130,8 +1144,8 @@ replacing the current Image mode buffer." (funcall next)))) (defun image-mode--directory-buffers (file) - "Return a alist of type/buffer for all \"parent\" buffers to image FILE. -This is normally a list of dired buffers, but can also be archive and + "Return an alist of type/buffer for all \"parent\" buffers to image FILE. +This is normally a list of Dired buffers, but can also be archive and tar mode buffers." (let ((buffers nil) (dir (file-name-directory file))) @@ -1466,7 +1480,10 @@ return value is suitable for appending to an image spec." ,@(when (cdr resized) (list :height (cdr resized))) ,@(unless (= 0.0 image-transform-rotation) - (list :rotation image-transform-rotation)))))) + (list :rotation image-transform-rotation)) + ,@(when image--transform-smoothing + (list :transform-smoothing + (string= image--transform-smoothing "smooth"))))))) (defun image-transform-set-scale (scale) "Prompt for a number, and resize the current image by that amount." @@ -1499,6 +1516,12 @@ ROTATION should be in degrees." (setq image-transform-rotation (float (mod rotation 360))) (image-toggle-display-image)) +(defun image-transform-set-smoothing (smoothing) + (interactive (list (completing-read "Smoothing: " + '("none" "smooth") nil t))) + (setq image--transform-smoothing smoothing) + (image-toggle-display-image)) + (defun image-transform-original () "Display the current image with the original (actual) size and rotation." (interactive) @@ -1511,7 +1534,8 @@ ROTATION should be in degrees." (interactive) (setq image-transform-resize image-auto-resize image-transform-rotation 0.0 - image-transform-scale 1) + image-transform-scale 1 + image--transform-smoothing nil) (image-toggle-display-image)) (provide 'image-mode) |