diff options
| author | Stefan Kangas | 2022-08-18 18:46:10 +0200 |
|---|---|---|
| committer | Stefan Kangas | 2022-08-18 19:48:35 +0200 |
| commit | 104cb5cbf5da4c07d5e4b3d26431eaa42e8ce33d (patch) | |
| tree | 0e33eb72f2d50799c85266e892f36d36e1a1ad6c | |
| parent | 054d1e80dc7cf3ba612ff704f312d0b8953416cf (diff) | |
| download | emacs-104cb5cbf5da4c07d5e4b3d26431eaa42e8ce33d.tar.gz emacs-104cb5cbf5da4c07d5e4b3d26431eaa42e8ce33d.zip | |
Make toggling between image, hex and text more consistent
* lisp/image-mode.el (image-toggle-hex-display, image-toggle-display):
Ensure commands work correctly also in `hexl-mode'.
(image-mode-to-text):
(image-mode-as-hex, image-mode-as-text): Enable image-minor-mode also
in hexl-mode, which adds the "C-c C-x" keybinding for easier toggling.
| -rw-r--r-- | lisp/image-mode.el | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/lisp/image-mode.el b/lisp/image-mode.el index 0888e565a3e..20aa9588b38 100644 --- a/lisp/image-mode.el +++ b/lisp/image-mode.el | |||
| @@ -773,8 +773,6 @@ displays an image file as text." | |||
| 773 | (major-mode-restore '(image-mode image-mode-as-text)) | 773 | (major-mode-restore '(image-mode image-mode-as-text)) |
| 774 | ;; Restore `image-type' after `kill-all-local-variables' in `normal-mode'. | 774 | ;; Restore `image-type' after `kill-all-local-variables' in `normal-mode'. |
| 775 | (setq image-type previous-image-type) | 775 | (setq image-type previous-image-type) |
| 776 | ;; Enable image minor mode with `C-c C-c'. | ||
| 777 | (image-minor-mode 1) | ||
| 778 | (unless (image-get-display-property) | 776 | (unless (image-get-display-property) |
| 779 | ;; Show the image file as text. | 777 | ;; Show the image file as text. |
| 780 | (image-toggle-display-text)))) | 778 | (image-toggle-display-text)))) |
| @@ -794,8 +792,10 @@ on these modes." | |||
| 794 | (interactive) | 792 | (interactive) |
| 795 | (image-mode-to-text) | 793 | (image-mode-to-text) |
| 796 | (hexl-mode) | 794 | (hexl-mode) |
| 797 | (message "%s" (substitute-command-keys | 795 | (image-minor-mode 1) |
| 798 | "Type \\[hexl-mode-exit] to view the image as an image"))) | 796 | (message (substitute-command-keys |
| 797 | "Type \\[image-toggle-display] or \ | ||
| 798 | \\[image-toggle-hex-display] to view the image as an image"))) | ||
| 799 | 799 | ||
| 800 | (defun image-mode-as-text () | 800 | (defun image-mode-as-text () |
| 801 | "Set a non-image mode as major mode in combination with image minor mode. | 801 | "Set a non-image mode as major mode in combination with image minor mode. |
| @@ -811,6 +811,7 @@ See commands `image-mode' and `image-minor-mode' for more information | |||
| 811 | on these modes." | 811 | on these modes." |
| 812 | (interactive) | 812 | (interactive) |
| 813 | (image-mode-to-text) | 813 | (image-mode-to-text) |
| 814 | (image-minor-mode 1) | ||
| 814 | (message (substitute-command-keys | 815 | (message (substitute-command-keys |
| 815 | "Type \\[image-toggle-display] to view the image as %s") | 816 | "Type \\[image-toggle-display] to view the image as %s") |
| 816 | (if (image-get-display-property) | 817 | (if (image-get-display-property) |
| @@ -986,14 +987,17 @@ was inserted." | |||
| 986 | (memq (intern (upcase (file-name-extension filename)) obarray) | 987 | (memq (intern (upcase (file-name-extension filename)) obarray) |
| 987 | imagemagick-types-inhibit))))) | 988 | imagemagick-types-inhibit))))) |
| 988 | 989 | ||
| 990 | (declare-function hexl-mode-exit "hexl" (&optional arg)) | ||
| 991 | |||
| 989 | (defun image-toggle-hex-display () | 992 | (defun image-toggle-hex-display () |
| 990 | "Toggle between image and hex display." | 993 | "Toggle between image and hex display." |
| 991 | (interactive) | 994 | (interactive) |
| 992 | (if (image-get-display-property) | 995 | (cond ((or (image-get-display-property) ; in `image-mode' |
| 993 | (image-mode-as-hex) | 996 | (eq major-mode 'fundamental-mode)) |
| 994 | (if (eq major-mode 'fundamental-mode) | 997 | (image-mode-as-hex)) |
| 995 | (image-mode-as-hex) | 998 | ((eq major-mode 'hexl-mode) |
| 996 | (image-mode)))) | 999 | (hexl-mode-exit)) |
| 1000 | (t (error "That command is invalid here")))) | ||
| 997 | 1001 | ||
| 998 | (defun image-toggle-display () | 1002 | (defun image-toggle-display () |
| 999 | "Toggle between image and text display. | 1003 | "Toggle between image and text display. |
| @@ -1002,11 +1006,11 @@ If the current buffer is displaying an image file as an image, | |||
| 1002 | call `image-mode-as-text' to switch to text or hex display. | 1006 | call `image-mode-as-text' to switch to text or hex display. |
| 1003 | Otherwise, display the image by calling `image-mode'." | 1007 | Otherwise, display the image by calling `image-mode'." |
| 1004 | (interactive) | 1008 | (interactive) |
| 1005 | (if (image-get-display-property) | 1009 | (cond ((image-get-display-property) ; in `image-mode' |
| 1006 | (image-mode-as-text) | 1010 | (image-mode-as-text)) |
| 1007 | (if (eq major-mode 'hexl-mode) | 1011 | ((eq major-mode 'hexl-mode) |
| 1008 | (image-mode-as-text) | 1012 | (hexl-mode-exit)) |
| 1009 | (image-mode)))) | 1013 | ((image-mode)))) |
| 1010 | 1014 | ||
| 1011 | (defun image-kill-buffer () | 1015 | (defun image-kill-buffer () |
| 1012 | "Kill the current buffer." | 1016 | "Kill the current buffer." |