From: Stefan Kangas Date: Thu, 28 Oct 2021 01:36:28 +0000 (+0200) Subject: New command image-transform-set-percent X-Git-Tag: emacs-29.0.90~1447^2~66 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0dc9c9a68f5a137fd71d7aca356d08fd52b16d52;p=emacs.git New command image-transform-set-percent * lisp/image-mode.el (image-transform-set-percent): New command. (image-mode-map): Bind above new command to "s p". * doc/emacs/files.texi (Image Mode): Document it. --- diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi index 404978b315d..5b3b15cd38f 100644 --- a/doc/emacs/files.texi +++ b/doc/emacs/files.texi @@ -2273,12 +2273,14 @@ behavior by using the options @code{image-auto-resize} and @findex image-transform-set-scale @findex image-transform-reset To resize the image manually you can use the command -@code{image-transform-fit-to-window} bound to @kbd{s w} -that fits the image to both the window height and width. -To scale the image specifying a scale factor, use the command -@code{image-transform-set-scale} bound to @kbd{s s}. -To reset all transformations to the initial state, use -@code{image-transform-reset} bound to @kbd{s 0}. +@code{image-transform-fit-to-window} bound to @kbd{s w} that fits the +image to both the window height and width. To scale the image to a +percentage of its original size, use the command +@code{image-transform-set-percent} bound to @kbd{s p}. To scale +the image specifying a scale factor, use the command +@code{image-transform-set-scale} bound to @kbd{s s}. To reset all +transformations to the initial state, use @code{image-transform-reset} +bound to @kbd{s 0}. @findex image-next-file @findex image-previous-file diff --git a/etc/NEWS b/etc/NEWS index 4b3a48a8206..511687a1746 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1863,6 +1863,11 @@ this message for SVG and XPM. *** New commands: 'image-flip-horizontally' and 'image-flip-vertically'. These commands horizontally and vertically flip the image under point. ++++ +*** New command 'image-transform-set-percent'. +It allows setting the image size to a percentage of its original size, +and is bound to "s p" in Image mode. + ** Images +++ diff --git a/lisp/image-mode.el b/lisp/image-mode.el index 726f2af2ad1..7892f0d5b9e 100644 --- a/lisp/image-mode.el +++ b/lisp/image-mode.el @@ -494,6 +494,7 @@ image as text, when opening such images in `image-mode'." "s h" #'image-transform-fit-to-height "s i" #'image-transform-fit-to-width "s b" #'image-transform-fit-both + "s p" #'image-transform-set-percent "s s" #'image-transform-set-scale "s r" #'image-transform-set-rotation "s m" #'image-transform-set-smoothing @@ -1530,6 +1531,16 @@ return value is suitable for appending to an image spec." (list :transform-smoothing (string= image--transform-smoothing "smooth"))))))) +(defun image-transform-set-percent (scale) + "Prompt for a percentage, and resize the current image to that size. +The percentage is in relation to the original size of the image." + (interactive (list (read-number "Scale (% of original): " 100 + 'read-number-history))) + (unless (cl-plusp scale) + (error "Not a positive number: %s" scale)) + (setq image-transform-resize (/ scale 100.0)) + (image-toggle-display-image)) + (defun image-transform-set-scale (scale) "Prompt for a number, and resize the current image by that amount." (interactive "nScale: ")