From 9565f45876f4911a0f27fced215f7e86d59655e8 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Tue, 4 Oct 2022 15:09:33 +0200 Subject: [PATCH] Move image commands to the 'i' sub map * doc/lispref/display.texi (Showing Images): Adjust. * lisp/image.el (image-map): Move all keys under the "i" prefix. (image--repeat-map): New map. (image-increase-size, image-rotate, image-decrease-size): Make repeatable. (image--delayed-change-size): New function. --- doc/lispref/display.texi | 21 ++++++++++---- etc/NEWS | 17 ++++++++++-- lisp/image.el | 59 ++++++++++++++++++++++------------------ 3 files changed, 61 insertions(+), 36 deletions(-) diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index 0c217e329e7..64400ef9314 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -6850,28 +6850,37 @@ keymap installed in the text properties (or overlays) that span the displayed image. This keymap defines the following commands: @table @kbd -@item + +@item i + Increase the image size (@code{image-increase-size}). A prefix value of @samp{4} means to increase the size by 40%. The default is 20%. -@item - +@item i - Decrease the image size (@code{image-increase-size}). A prefix value of @samp{4} means to decrease the size by 40%. The default is 20%. -@item r +@item i r Rotate the image by 90 degrees clockwise (@code{image-rotate}). A prefix means to rotate by 90 degrees counter-clockwise instead. -@item o +@item i h +Flip the image horizontally (@code{image-flip-horizontally}). + +@item i v +Flip the image vertically (@code{image-flip-vertically}). + +@item i o Save the image to a file (@code{image-save}). -@item c +@item i c Crop the image interactively (@code{image-crop}). -@item x +@item i x Cut a rectangle from the image interactively (@code{image-cut}). @end table +The size and rotation commands are ``repeating'', which means that you +can continue adjusting the image without using the @kbd{i} prefix. + @node Multi-Frame Images @subsection Multi-Frame Images @cindex multi-frame images diff --git a/etc/NEWS b/etc/NEWS index d4934fb98db..23425eb5567 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -193,6 +193,16 @@ of 'user-emacs-directory'. * Incompatible changes in Emacs 29.1 ++++ +*** The image commands have changed key bindings. +In previous Emacs versions, images have had the '+', '-' and 'r' keys +bound when point is over an image. In Emacs 29.1, additional commands +were added, and this made it more likely that users would trigger the +image commands by mistake. To avoid this, all image commands have +moved to the 'i' keymap, so '+' is now 'i +', '-' is now 'i -', and +'r' is now 'i r'. In addition, these commands are now repeating, so +you can rotate an image twice by saying 'i r r', for instance. + +++ *** Emacs now picks the correct coding system for X input methods. Previously, Emacs would use the locale coding system for input @@ -2134,7 +2144,8 @@ 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. +These commands horizontally and vertically flip the image under point, +and are bound to 'i h' and 'i v', respectively. +++ *** New command 'image-transform-set-percent'. @@ -2685,8 +2696,8 @@ name. +++ ** New commands 'image-crop' and 'image-cut. These commands allow interactively cropping/cutting the image at -point. The commands are bound to keys 'c' and 'x' (respectively) in -the local keymap over images. They rely on external programs, by +point. The commands are bound to keys 'i c' and 'i x' (respectively) +in the local keymap over images. They rely on external programs, by default "convert" from ImageMagick, to do the actual cropping/eliding of the image file. diff --git a/lisp/image.el b/lisp/image.el index 18b840a6510..b6817d3fda3 100644 --- a/lisp/image.el +++ b/lisp/image.el @@ -174,14 +174,15 @@ or \"ffmpeg\") is installed." (defvar-keymap image-map :doc "Map put into text properties on images." - "-" #'image-decrease-size - "+" #'image-increase-size - "r" #'image-rotate - "o" #'image-save - "c" #'image-crop - "x" #'image-cut - "h" #'image-flip-horizontally - "v" #'image-flip-vertically + "i" (define-keymap + "-" #'image-decrease-size + "+" #'image-increase-size + "r" #'image-rotate + "o" #'image-save + "c" #'image-crop + "x" #'image-cut + "h" #'image-flip-horizontally + "v" #'image-flip-vertically) "C-" #'image-mouse-decrease-size "C-" #'image-mouse-decrease-size "C-" #'image-mouse-increase-size @@ -1151,41 +1152,43 @@ has no effect." (imagemagick-register-types) +(defvar-keymap image--repeat-map + "+" #'image-increase-size + "-" #'image-decrease-size + "r" #'image-rotate) + (defun image-increase-size (&optional n position) "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--delayed-change-size (if n + (1+ (/ (prefix-numeric-value n) 10.0)) + 1.2) + position) + (set-transient-map image--repeat-map nil nil + "Use %k for further adjustments")) + +(defun image--delayed-change-size (size position) ;; Wait for a bit of idle-time before actually performing the change, ;; so as to batch together sequences of closely consecutive size changes. ;; `image--change-size' just changes one value in a plist. The actual ;; image resizing happens later during redisplay. So if those ;; consecutive calls happen without any redisplay between them, ;; the costly operation of image resizing should happen only once. - (run-with-idle-timer 0.3 nil - #'image--change-size - (if n - (1+ (/ (prefix-numeric-value n) 10.0)) - 1.2) - position)) + (run-with-idle-timer 0.3 nil #'image--change-size size position)) (defun image-decrease-size (&optional n position) "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") - ;; Wait for a bit of idle-time before actually performing the change, - ;; so as to batch together sequences of closely consecutive size changes. - ;; `image--change-size' just changes one value in a plist. The actual - ;; image resizing happens later during redisplay. So if those - ;; consecutive calls happen without any redisplay between them, - ;; the costly operation of image resizing should happen only once. - (run-with-idle-timer 0.3 nil - #'image--change-size - (if n - (- 1 (/ (prefix-numeric-value n) 10.0)) - 0.8) - position)) + (image--delayed-change-size (if n + (- 1 (/ (prefix-numeric-value n) 10.0)) + 0.8) + position) + (set-transient-map image--repeat-map nil nil + "Use %k for further adjustments")) (defun image-mouse-increase-size (&optional event) "Increase the image size using the mouse." @@ -1270,7 +1273,9 @@ rotations by only multiples of 90 degrees." (or angle 90)) ;; We don't want to exceed 360 degrees rotation, ;; because it's not seen as valid in Exif data. - 360))))) + 360)))) + (set-transient-map image--repeat-map nil nil + "Use %k for further adjustments")) (defun image-save () "Save the image under point. -- 2.39.2