emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 0dc9c9a68f 3/6: New command image-transform-set-percent


From: Stefan Kangas
Subject: master 0dc9c9a68f 3/6: New command image-transform-set-percent
Date: Thu, 18 Aug 2022 14:33:42 -0400 (EDT)

branch: master
commit 0dc9c9a68f5a137fd71d7aca356d08fd52b16d52
Author: Stefan Kangas <stefan@marxist.se>
Commit: Stefan Kangas <stefankangas@gmail.com>

    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.
---
 doc/emacs/files.texi | 14 ++++++++------
 etc/NEWS             |  5 +++++
 lisp/image-mode.el   | 11 +++++++++++
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi
index 404978b315..5b3b15cd38 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 4b3a48a820..511687a174 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 726f2af2ad..7892f0d5b9 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: ")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]