]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/image.el: Mouse-wheel scaling on images (bug#38187)
authorJuri Linkov <juri@linkov.net>
Wed, 20 Nov 2019 22:59:49 +0000 (00:59 +0200)
committerJuri Linkov <juri@linkov.net>
Wed, 20 Nov 2019 22:59:49 +0000 (00:59 +0200)
* lisp/image.el (image-mouse-increase-size)
(image-mouse-decrease-size): New commands.
(image-map): Bind C-wheel-down and C-mouse-5 to
image-mouse-decrease-size, C-wheel-up and C-mouse-4 to
image-mouse-increase-size.

lisp/image.el

index 5f24475ce5bac6fe17b63d67282358b22c288da1..e0965c10914800e7d7cf53bd5d5b0eeb332c5cab 100644 (file)
@@ -158,6 +158,10 @@ or \"ffmpeg\") is installed."
   (let ((map (make-sparse-keymap)))
     (define-key map "-" 'image-decrease-size)
     (define-key map "+" 'image-increase-size)
+    (define-key map [C-wheel-down] 'image-mouse-decrease-size)
+    (define-key map [C-mouse-5]    'image-mouse-decrease-size)
+    (define-key map [C-wheel-up]   'image-mouse-increase-size)
+    (define-key map [C-mouse-4]    'image-mouse-increase-size)
     (define-key map "r" 'image-rotate)
     (define-key map "o" 'image-save)
     map))
@@ -1007,24 +1011,40 @@ has no effect."
 
 (imagemagick-register-types)
 
-(defun image-increase-size (n)
+(defun image-increase-size (&optional n)
   "Increase the image size by a factor of N.
 If N is 3, then the image size will be increased by 30%.  The
 default is 20%."
   (interactive "P")
   (image--change-size (if n
-                          (1+ (/ n 10.0))
+                          (1+ (/ (prefix-numeric-value n) 10.0))
                         1.2)))
 
-(defun image-decrease-size (n)
+(defun image-decrease-size (&optional n)
   "Decrease the image size by a factor of N.
 If N is 3, then the image size will be decreased by 30%.  The
 default is 20%."
   (interactive "P")
   (image--change-size (if n
-                          (- 1 (/ n 10.0))
+                          (- 1 (/ (prefix-numeric-value n) 10.0))
                         0.8)))
 
+(defun image-mouse-increase-size (&optional event)
+  "Increase the image size using the mouse."
+  (interactive "e")
+  (when (listp event)
+    (save-window-excursion
+      (posn-set-point (event-start event))
+      (image-increase-size))))
+
+(defun image-mouse-decrease-size (&optional event)
+  "Decrease the image size using the mouse."
+  (interactive "e")
+  (when (listp event)
+    (save-window-excursion
+      (posn-set-point (event-start event))
+      (image-decrease-size))))
+
 (defun image--get-image ()
   "Return the image at point."
   (let ((image (get-char-property (point) 'display)))