diff options
| author | Juri Linkov | 2020-04-20 02:07:43 +0300 |
|---|---|---|
| committer | Juri Linkov | 2020-04-20 02:07:43 +0300 |
| commit | 751510f8659e49c94ab7981c3abc8fb421bf9ba9 (patch) | |
| tree | 014dc2ceff4ba5931618aa29d9bf8d9bec33afa2 | |
| parent | 9261a219ec20340b3323015b756ef023901aed43 (diff) | |
| download | emacs-751510f8659e49c94ab7981c3abc8fb421bf9ba9.tar.gz emacs-751510f8659e49c94ab7981c3abc8fb421bf9ba9.zip | |
* 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.
| -rw-r--r-- | etc/NEWS | 2 | ||||
| -rw-r--r-- | lisp/image-mode.el | 76 |
2 files changed, 40 insertions, 38 deletions
| @@ -3556,6 +3556,8 @@ name to the kill ring. | |||
| 3556 | With a prefix argument, 'image-rotate' now rotates the image at point | 3556 | With a prefix argument, 'image-rotate' now rotates the image at point |
| 3557 | 90 degrees counter-clockwise, instead of the default clockwise. | 3557 | 90 degrees counter-clockwise, instead of the default clockwise. |
| 3558 | 3558 | ||
| 3559 | *** 'image-mode' has a new key prefix 's' for transformation commands. | ||
| 3560 | |||
| 3559 | ** Modules | 3561 | ** Modules |
| 3560 | 3562 | ||
| 3561 | --- | 3563 | --- |
diff --git a/lisp/image-mode.el b/lisp/image-mode.el index 22d7d913141..fbce1193cd0 100644 --- a/lisp/image-mode.el +++ b/lisp/image-mode.el | |||
| @@ -418,24 +418,40 @@ call." | |||
| 418 | 418 | ||
| 419 | (defvar image-mode-map | 419 | (defvar image-mode-map |
| 420 | (let ((map (make-sparse-keymap))) | 420 | (let ((map (make-sparse-keymap))) |
| 421 | |||
| 422 | ;; Toggling keys | ||
| 421 | (define-key map "\C-c\C-c" 'image-toggle-display) | 423 | (define-key map "\C-c\C-c" 'image-toggle-display) |
| 422 | (define-key map "\C-c\C-x" 'image-toggle-hex-display) | 424 | (define-key map "\C-c\C-x" 'image-toggle-hex-display) |
| 423 | (define-key map (kbd "SPC") 'image-scroll-up) | 425 | |
| 424 | (define-key map (kbd "S-SPC") 'image-scroll-down) | 426 | ;; Transformation keys |
| 425 | (define-key map (kbd "DEL") 'image-scroll-down) | 427 | (define-key map "sf" 'image-mode-fit-frame) |
| 426 | (define-key map (kbd "RET") 'image-toggle-animation) | 428 | (define-key map "sh" 'image-transform-fit-to-height) |
| 429 | (define-key map "sw" 'image-transform-fit-to-width) | ||
| 430 | (define-key map "sr" 'image-transform-set-rotation) | ||
| 431 | (define-key map "s0" 'image-transform-reset) | ||
| 432 | (define-key map "ss" 'image-transform-set-scale) | ||
| 433 | |||
| 434 | ;; Multi-frame keys | ||
| 435 | (define-key map (kbd "RET") 'image-toggle-animation) | ||
| 427 | (define-key map "F" 'image-goto-frame) | 436 | (define-key map "F" 'image-goto-frame) |
| 428 | (define-key map "f" 'image-next-frame) | 437 | (define-key map "f" 'image-next-frame) |
| 429 | (define-key map "b" 'image-previous-frame) | 438 | (define-key map "b" 'image-previous-frame) |
| 430 | (define-key map "n" 'image-next-file) | ||
| 431 | (define-key map "p" 'image-previous-file) | ||
| 432 | (define-key map "a+" 'image-increase-speed) | 439 | (define-key map "a+" 'image-increase-speed) |
| 433 | (define-key map "a-" 'image-decrease-speed) | 440 | (define-key map "a-" 'image-decrease-speed) |
| 434 | (define-key map "a0" 'image-reset-speed) | 441 | (define-key map "a0" 'image-reset-speed) |
| 435 | (define-key map "ar" 'image-reverse-speed) | 442 | (define-key map "ar" 'image-reverse-speed) |
| 443 | |||
| 444 | ;; File keys | ||
| 445 | (define-key map "n" 'image-next-file) | ||
| 446 | (define-key map "p" 'image-previous-file) | ||
| 436 | (define-key map "w" 'image-mode-copy-file-name-as-kill) | 447 | (define-key map "w" 'image-mode-copy-file-name-as-kill) |
| 437 | (define-key map "m" 'image-mode-mark-file) | 448 | (define-key map "m" 'image-mode-mark-file) |
| 438 | (define-key map "u" 'image-mode-unmark-file) | 449 | (define-key map "u" 'image-mode-unmark-file) |
| 450 | |||
| 451 | ;; Scrolling keys | ||
| 452 | (define-key map (kbd "SPC") 'image-scroll-up) | ||
| 453 | (define-key map (kbd "S-SPC") 'image-scroll-down) | ||
| 454 | (define-key map (kbd "DEL") 'image-scroll-down) | ||
| 439 | (define-key map [remap forward-char] 'image-forward-hscroll) | 455 | (define-key map [remap forward-char] 'image-forward-hscroll) |
| 440 | (define-key map [remap backward-char] 'image-backward-hscroll) | 456 | (define-key map [remap backward-char] 'image-backward-hscroll) |
| 441 | (define-key map [remap right-char] 'image-forward-hscroll) | 457 | (define-key map [remap right-char] 'image-forward-hscroll) |
| @@ -452,6 +468,7 @@ call." | |||
| 452 | (define-key map [remap move-end-of-line] 'image-eol) | 468 | (define-key map [remap move-end-of-line] 'image-eol) |
| 453 | (define-key map [remap beginning-of-buffer] 'image-bob) | 469 | (define-key map [remap beginning-of-buffer] 'image-bob) |
| 454 | (define-key map [remap end-of-buffer] 'image-eob) | 470 | (define-key map [remap end-of-buffer] 'image-eob) |
| 471 | |||
| 455 | (easy-menu-define image-mode-menu map "Menu for Image mode." | 472 | (easy-menu-define image-mode-menu map "Menu for Image mode." |
| 456 | '("Image" | 473 | '("Image" |
| 457 | ["Show as Text" image-toggle-display :active t | 474 | ["Show as Text" image-toggle-display :active t |
| @@ -459,17 +476,15 @@ call." | |||
| 459 | ["Show as Hex" image-toggle-hex-display :active t | 476 | ["Show as Hex" image-toggle-hex-display :active t |
| 460 | :help "Show image as hex"] | 477 | :help "Show image as hex"] |
| 461 | "--" | 478 | "--" |
| 479 | ["Fit Frame to Image" image-mode-fit-frame :active t | ||
| 480 | :help "Resize frame to match image"] | ||
| 462 | ["Fit to Window Height" image-transform-fit-to-height | 481 | ["Fit to Window Height" image-transform-fit-to-height |
| 463 | :visible (eq image-type 'imagemagick) | ||
| 464 | :help "Resize image to match the window height"] | 482 | :help "Resize image to match the window height"] |
| 465 | ["Fit to Window Width" image-transform-fit-to-width | 483 | ["Fit to Window Width" image-transform-fit-to-width |
| 466 | :visible (eq image-type 'imagemagick) | ||
| 467 | :help "Resize image to match the window width"] | 484 | :help "Resize image to match the window width"] |
| 468 | ["Rotate Image..." image-transform-set-rotation | 485 | ["Rotate Image..." image-transform-set-rotation |
| 469 | :visible (eq image-type 'imagemagick) | ||
| 470 | :help "Rotate the image"] | 486 | :help "Rotate the image"] |
| 471 | ["Reset Transformations" image-transform-reset | 487 | ["Reset Transformations" image-transform-reset |
| 472 | :visible (eq image-type 'imagemagick) | ||
| 473 | :help "Reset all image transformations"] | 488 | :help "Reset all image transformations"] |
| 474 | "--" | 489 | "--" |
| 475 | ["Show Thumbnails" | 490 | ["Show Thumbnails" |
| @@ -486,9 +501,6 @@ call." | |||
| 486 | :active buffer-file-name | 501 | :active buffer-file-name |
| 487 | :help "Copy the current file name to the kill ring"] | 502 | :help "Copy the current file name to the kill ring"] |
| 488 | "--" | 503 | "--" |
| 489 | ["Fit Frame to Image" image-mode-fit-frame :active t | ||
| 490 | :help "Resize frame to match image"] | ||
| 491 | "--" | ||
| 492 | ["Animate Image" image-toggle-animation :style toggle | 504 | ["Animate Image" image-toggle-animation :style toggle |
| 493 | :selected (let ((image (image-get-display-property))) | 505 | :selected (let ((image (image-get-display-property))) |
| 494 | (and image (image-animate-timer image))) | 506 | (and image (image-animate-timer image))) |
| @@ -767,11 +779,12 @@ was inserted." | |||
| 767 | props image) | 779 | props image) |
| 768 | 780 | ||
| 769 | ;; Get the rotation data from the file, if any. | 781 | ;; Get the rotation data from the file, if any. |
| 770 | (setq image-transform-rotation | 782 | (when (zerop image-transform-rotation) ; don't reset modified value |
| 771 | (or (exif-orientation | 783 | (setq image-transform-rotation |
| 772 | (ignore-error exif-error | 784 | (or (exif-orientation |
| 773 | (exif-parse-buffer))) | 785 | (ignore-error exif-error |
| 774 | 0.0)) | 786 | (exif-parse-buffer))) |
| 787 | 0.0))) | ||
| 775 | 788 | ||
| 776 | ;; :scale 1: If we do not set this, create-image will apply | 789 | ;; :scale 1: If we do not set this, create-image will apply |
| 777 | ;; default scaling based on font size. | 790 | ;; default scaling based on font size. |
| @@ -1250,8 +1263,7 @@ Do this for an image of type `imagemagick' to make sure that the | |||
| 1250 | elisp code matches the way ImageMagick computes the bounding box | 1263 | elisp code matches the way ImageMagick computes the bounding box |
| 1251 | of a rotated image." | 1264 | of a rotated image." |
| 1252 | (when (and (not (numberp image-transform-resize)) | 1265 | (when (and (not (numberp image-transform-resize)) |
| 1253 | (boundp 'image-type) | 1266 | (boundp 'image-type)) |
| 1254 | (eq image-type 'imagemagick)) | ||
| 1255 | (let ((size (image-display-size (image-get-display-property) t))) | 1267 | (let ((size (image-display-size (image-get-display-property) t))) |
| 1256 | (cond ((eq image-transform-resize 'fit-width) | 1268 | (cond ((eq image-transform-resize 'fit-width) |
| 1257 | (cl-assert (= (car size) | 1269 | (cl-assert (= (car size) |
| @@ -1268,10 +1280,7 @@ of a rotated image." | |||
| 1268 | "Return rescaling/rotation properties for image SPEC. | 1280 | "Return rescaling/rotation properties for image SPEC. |
| 1269 | These properties are determined by the Image mode variables | 1281 | These properties are determined by the Image mode variables |
| 1270 | `image-transform-resize' and `image-transform-rotation'. The | 1282 | `image-transform-resize' and `image-transform-rotation'. The |
| 1271 | return value is suitable for appending to an image spec. | 1283 | return value is suitable for appending to an image spec." |
| 1272 | |||
| 1273 | Rescaling and rotation properties only take effect if Emacs is | ||
| 1274 | compiled with ImageMagick support." | ||
| 1275 | (setq image-transform-scale 1.0) | 1284 | (setq image-transform-scale 1.0) |
| 1276 | (when (or image-transform-resize | 1285 | (when (or image-transform-resize |
| 1277 | (/= image-transform-rotation 0.0)) | 1286 | (/= image-transform-rotation 0.0)) |
| @@ -1302,41 +1311,32 @@ compiled with ImageMagick support." | |||
| 1302 | (list :rotation image-transform-rotation)))))) | 1311 | (list :rotation image-transform-rotation)))))) |
| 1303 | 1312 | ||
| 1304 | (defun image-transform-set-scale (scale) | 1313 | (defun image-transform-set-scale (scale) |
| 1305 | "Prompt for a number, and resize the current image by that amount. | 1314 | "Prompt for a number, and resize the current image by that amount." |
| 1306 | This command has no effect unless Emacs is compiled with | ||
| 1307 | ImageMagick support." | ||
| 1308 | (interactive "nScale: ") | 1315 | (interactive "nScale: ") |
| 1309 | (setq image-transform-resize scale) | 1316 | (setq image-transform-resize scale) |
| 1310 | (image-toggle-display-image)) | 1317 | (image-toggle-display-image)) |
| 1311 | 1318 | ||
| 1312 | (defun image-transform-fit-to-height () | 1319 | (defun image-transform-fit-to-height () |
| 1313 | "Fit the current image to the height of the current window. | 1320 | "Fit the current image to the height of the current window." |
| 1314 | This command has no effect unless Emacs is compiled with | ||
| 1315 | ImageMagick support." | ||
| 1316 | (interactive) | 1321 | (interactive) |
| 1317 | (setq image-transform-resize 'fit-height) | 1322 | (setq image-transform-resize 'fit-height) |
| 1318 | (image-toggle-display-image)) | 1323 | (image-toggle-display-image)) |
| 1319 | 1324 | ||
| 1320 | (defun image-transform-fit-to-width () | 1325 | (defun image-transform-fit-to-width () |
| 1321 | "Fit the current image to the width of the current window. | 1326 | "Fit the current image to the width of the current window." |
| 1322 | This command has no effect unless Emacs is compiled with | ||
| 1323 | ImageMagick support." | ||
| 1324 | (interactive) | 1327 | (interactive) |
| 1325 | (setq image-transform-resize 'fit-width) | 1328 | (setq image-transform-resize 'fit-width) |
| 1326 | (image-toggle-display-image)) | 1329 | (image-toggle-display-image)) |
| 1327 | 1330 | ||
| 1328 | (defun image-transform-set-rotation (rotation) | 1331 | (defun image-transform-set-rotation (rotation) |
| 1329 | "Prompt for an angle ROTATION, and rotate the image by that amount. | 1332 | "Prompt for an angle ROTATION, and rotate the image by that amount. |
| 1330 | ROTATION should be in degrees. This command has no effect unless | 1333 | ROTATION should be in degrees." |
| 1331 | Emacs is compiled with ImageMagick support." | ||
| 1332 | (interactive "nRotation angle (in degrees): ") | 1334 | (interactive "nRotation angle (in degrees): ") |
| 1333 | (setq image-transform-rotation (float (mod rotation 360))) | 1335 | (setq image-transform-rotation (float (mod rotation 360))) |
| 1334 | (image-toggle-display-image)) | 1336 | (image-toggle-display-image)) |
| 1335 | 1337 | ||
| 1336 | (defun image-transform-reset () | 1338 | (defun image-transform-reset () |
| 1337 | "Display the current image with the default size and rotation. | 1339 | "Display the current image with the default size and rotation." |
| 1338 | This command has no effect unless Emacs is compiled with | ||
| 1339 | ImageMagick support." | ||
| 1340 | (interactive) | 1340 | (interactive) |
| 1341 | (setq image-transform-resize nil | 1341 | (setq image-transform-resize nil |
| 1342 | image-transform-rotation 0.0 | 1342 | image-transform-rotation 0.0 |