emacs-diffs
[Top][All Lists]
Advanced

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

emacs-27 751510f: * lisp/image-mode.el: Add prefix key 's' and reduce de


From: Juri Linkov
Subject: emacs-27 751510f: * lisp/image-mode.el: Add prefix key 's' and reduce dependency on ImageMagick.
Date: Sun, 19 Apr 2020 19:07:52 -0400 (EDT)

branch: emacs-27
commit 751510f8659e49c94ab7981c3abc8fb421bf9ba9
Author: Juri Linkov <address@hidden>
Commit: Juri Linkov <address@hidden>

    * lisp/image-mode.el: Add prefix key 's' and reduce dependency on 
ImageMagick.
    
    * lisp/image-mode.el (image-mode-map): Regroup existing keybindings and
    add new ones with the prefix key 's'.
    Remove condition ":visible (eq image-type 'imagemagick)" from menu.
    (image-toggle-display-image): Don't rotate again after user rotated 
manually.
    (image-transform-check-size): Remove check for imagemagick.
    (image-transform-properties, image-transform-set-scale)
    (image-transform-fit-to-height, image-transform-fit-to-width)
    (image-transform-set-rotation, image-transform-reset):
    Remove mentions of ImageMagick from docstrings since these commands
    now work without ImageMagick.
---
 etc/NEWS           |  2 ++
 lisp/image-mode.el | 76 +++++++++++++++++++++++++++---------------------------
 2 files changed, 40 insertions(+), 38 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index bca2037..091c831 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -3556,6 +3556,8 @@ name to the kill ring.
 With a prefix argument, 'image-rotate' now rotates the image at point
 90 degrees counter-clockwise, instead of the default clockwise.
 
+*** 'image-mode' has a new key prefix 's' for transformation commands.
+
 ** Modules
 
 ---
diff --git a/lisp/image-mode.el b/lisp/image-mode.el
index 22d7d91..fbce119 100644
--- a/lisp/image-mode.el
+++ b/lisp/image-mode.el
@@ -418,24 +418,40 @@ call."
 
 (defvar image-mode-map
   (let ((map (make-sparse-keymap)))
+
+    ;; Toggling keys
     (define-key map "\C-c\C-c" 'image-toggle-display)
     (define-key map "\C-c\C-x" 'image-toggle-hex-display)
-    (define-key map (kbd "SPC")       'image-scroll-up)
-    (define-key map (kbd "S-SPC")     'image-scroll-down)
-    (define-key map (kbd "DEL")       'image-scroll-down)
-    (define-key map (kbd "RET")       'image-toggle-animation)
+
+    ;; Transformation keys
+    (define-key map "sf" 'image-mode-fit-frame)
+    (define-key map "sh" 'image-transform-fit-to-height)
+    (define-key map "sw" 'image-transform-fit-to-width)
+    (define-key map "sr" 'image-transform-set-rotation)
+    (define-key map "s0" 'image-transform-reset)
+    (define-key map "ss" 'image-transform-set-scale)
+
+    ;; Multi-frame keys
+    (define-key map (kbd "RET") 'image-toggle-animation)
     (define-key map "F" 'image-goto-frame)
     (define-key map "f" 'image-next-frame)
     (define-key map "b" 'image-previous-frame)
-    (define-key map "n" 'image-next-file)
-    (define-key map "p" 'image-previous-file)
     (define-key map "a+" 'image-increase-speed)
     (define-key map "a-" 'image-decrease-speed)
     (define-key map "a0" 'image-reset-speed)
     (define-key map "ar" 'image-reverse-speed)
+
+    ;; File keys
+    (define-key map "n" 'image-next-file)
+    (define-key map "p" 'image-previous-file)
     (define-key map "w" 'image-mode-copy-file-name-as-kill)
     (define-key map "m" 'image-mode-mark-file)
     (define-key map "u" 'image-mode-unmark-file)
+
+    ;; Scrolling keys
+    (define-key map (kbd "SPC")   'image-scroll-up)
+    (define-key map (kbd "S-SPC") 'image-scroll-down)
+    (define-key map (kbd "DEL")   'image-scroll-down)
     (define-key map [remap forward-char] 'image-forward-hscroll)
     (define-key map [remap backward-char] 'image-backward-hscroll)
     (define-key map [remap right-char] 'image-forward-hscroll)
@@ -452,6 +468,7 @@ call."
     (define-key map [remap move-end-of-line] 'image-eol)
     (define-key map [remap beginning-of-buffer] 'image-bob)
     (define-key map [remap end-of-buffer] 'image-eob)
+
     (easy-menu-define image-mode-menu map "Menu for Image mode."
       '("Image"
        ["Show as Text" image-toggle-display :active t
@@ -459,17 +476,15 @@ call."
     ["Show as Hex" image-toggle-hex-display :active t
      :help "Show image as hex"]
        "--"
+       ["Fit Frame to Image" image-mode-fit-frame :active t
+        :help "Resize frame to match image"]
        ["Fit to Window Height" image-transform-fit-to-height
-        :visible (eq image-type 'imagemagick)
         :help "Resize image to match the window height"]
        ["Fit to Window Width" image-transform-fit-to-width
-        :visible (eq image-type 'imagemagick)
         :help "Resize image to match the window width"]
        ["Rotate Image..." image-transform-set-rotation
-        :visible (eq image-type 'imagemagick)
         :help "Rotate the image"]
        ["Reset Transformations" image-transform-reset
-        :visible (eq image-type 'imagemagick)
         :help "Reset all image transformations"]
        "--"
        ["Show Thumbnails"
@@ -486,9 +501,6 @@ call."
          :active buffer-file-name
          :help "Copy the current file name to the kill ring"]
        "--"
-       ["Fit Frame to Image" image-mode-fit-frame :active t
-        :help "Resize frame to match image"]
-       "--"
        ["Animate Image" image-toggle-animation :style toggle
         :selected (let ((image (image-get-display-property)))
                     (and image (image-animate-timer image)))
@@ -767,11 +779,12 @@ was inserted."
         props image)
 
     ;; Get the rotation data from the file, if any.
-    (setq image-transform-rotation
-          (or (exif-orientation
-               (ignore-error exif-error
-                 (exif-parse-buffer)))
-              0.0))
+    (when (zerop image-transform-rotation) ; don't reset modified value
+      (setq image-transform-rotation
+            (or (exif-orientation
+                 (ignore-error exif-error
+                   (exif-parse-buffer)))
+                0.0)))
 
     ;; :scale 1: If we do not set this, create-image will apply
     ;; default scaling based on font size.
@@ -1250,8 +1263,7 @@ Do this for an image of type `imagemagick' to make sure 
that the
 elisp code matches the way ImageMagick computes the bounding box
 of a rotated image."
   (when (and (not (numberp image-transform-resize))
-            (boundp 'image-type)
-            (eq image-type 'imagemagick))
+            (boundp 'image-type))
     (let ((size (image-display-size (image-get-display-property) t)))
       (cond ((eq image-transform-resize 'fit-width)
             (cl-assert (= (car size)
@@ -1268,10 +1280,7 @@ of a rotated image."
   "Return rescaling/rotation properties for image SPEC.
 These properties are determined by the Image mode variables
 `image-transform-resize' and `image-transform-rotation'.  The
-return value is suitable for appending to an image spec.
-
-Rescaling and rotation properties only take effect if Emacs is
-compiled with ImageMagick support."
+return value is suitable for appending to an image spec."
   (setq image-transform-scale 1.0)
   (when (or image-transform-resize
            (/= image-transform-rotation 0.0))
@@ -1302,41 +1311,32 @@ compiled with ImageMagick support."
            (list :rotation image-transform-rotation))))))
 
 (defun image-transform-set-scale (scale)
-  "Prompt for a number, and resize the current image by that amount.
-This command has no effect unless Emacs is compiled with
-ImageMagick support."
+  "Prompt for a number, and resize the current image by that amount."
   (interactive "nScale: ")
   (setq image-transform-resize scale)
   (image-toggle-display-image))
 
 (defun image-transform-fit-to-height ()
-  "Fit the current image to the height of the current window.
-This command has no effect unless Emacs is compiled with
-ImageMagick support."
+  "Fit the current image to the height of the current window."
   (interactive)
   (setq image-transform-resize 'fit-height)
   (image-toggle-display-image))
 
 (defun image-transform-fit-to-width ()
-  "Fit the current image to the width of the current window.
-This command has no effect unless Emacs is compiled with
-ImageMagick support."
+  "Fit the current image to the width of the current window."
   (interactive)
   (setq image-transform-resize 'fit-width)
   (image-toggle-display-image))
 
 (defun image-transform-set-rotation (rotation)
   "Prompt for an angle ROTATION, and rotate the image by that amount.
-ROTATION should be in degrees.  This command has no effect unless
-Emacs is compiled with ImageMagick support."
+ROTATION should be in degrees."
   (interactive "nRotation angle (in degrees): ")
   (setq image-transform-rotation (float (mod rotation 360)))
   (image-toggle-display-image))
 
 (defun image-transform-reset ()
-  "Display the current image with the default size and rotation.
-This command has no effect unless Emacs is compiled with
-ImageMagick support."
+  "Display the current image with the default size and rotation."
   (interactive)
   (setq image-transform-resize nil
        image-transform-rotation 0.0



reply via email to

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