image-mode: Advertize viewing as text less eagerly
* lisp/image-mode.el (image-text-based-formats): New defcustom. (image-mode--setup-mode): Don't show message to show image as text unless it is a text based image format. Don't mention key binding for editing as hex. (Bug#51961) (image-mode-as-text): Don't mention key binding for editing as hex. (image-mode-as-hex): Minor cleanup.
This commit is contained in:
parent
9db76af76c
commit
8fda6770af
2 changed files with 32 additions and 17 deletions
6
etc/NEWS
6
etc/NEWS
|
@ -522,6 +522,12 @@ This works like 'image-transform-fit-to-window'.
|
|||
The new 'fit-window' option will never scale an image more than this
|
||||
much (in percent). It is nil by default, which means no limit.
|
||||
|
||||
---
|
||||
*** New user option 'image-text-based-formats'.
|
||||
This controls whether or not to show a message when opening certain
|
||||
image formats saying how to edit it as text. The default is to show
|
||||
this message for SVG and XPM.
|
||||
|
||||
** Image-Dired
|
||||
|
||||
+++
|
||||
|
|
|
@ -457,6 +457,15 @@ call."
|
|||
|
||||
;;; Image Mode setup
|
||||
|
||||
(defcustom image-text-based-formats '(svg xpm)
|
||||
"List of image formats that use a plain text format.
|
||||
For such formats, display a message that explains how to edit the
|
||||
image as text, when opening such images in `image-mode'."
|
||||
:type '(choice (const :tag "Disable completely" nil)
|
||||
(repeat :tag "List of formats" sexp))
|
||||
:version "29.1"
|
||||
:group 'image)
|
||||
|
||||
(defvar-local image-type nil
|
||||
"The image type for the current Image mode buffer.")
|
||||
|
||||
|
@ -695,12 +704,10 @@ Key bindings:
|
|||
|
||||
(run-mode-hooks 'image-mode-hook)
|
||||
(let ((image (image-get-display-property))
|
||||
(msg1 (substitute-command-keys
|
||||
"Type \\[image-toggle-display] or \\[image-toggle-hex-display] to view the image as "))
|
||||
animated)
|
||||
msg animated)
|
||||
(cond
|
||||
((null image)
|
||||
(message "%s" (concat msg1 "an image.")))
|
||||
(setq msg "an image"))
|
||||
((setq animated (image-multi-frame-p image))
|
||||
(setq image-multi-frame t
|
||||
mode-line-process
|
||||
|
@ -718,10 +725,13 @@ Key bindings:
|
|||
keymap
|
||||
(down-mouse-1 . image-next-frame)
|
||||
(down-mouse-3 . image-previous-frame)))))))
|
||||
(message "%s"
|
||||
(concat msg1 "text. This image has multiple frames.")))
|
||||
(setq msg "text. This image has multiple frames"))
|
||||
(t
|
||||
(message "%s" (concat msg1 "text or hex."))))))
|
||||
(setq msg "text")))
|
||||
(when (memq (plist-get (cdr image) :type) image-text-based-formats)
|
||||
(message (substitute-command-keys
|
||||
"Type \\[image-toggle-display] to view the image as %s")
|
||||
msg))))
|
||||
|
||||
;;;###autoload
|
||||
(define-minor-mode image-minor-mode
|
||||
|
@ -768,11 +778,11 @@ on these modes."
|
|||
(image-mode-to-text)
|
||||
;; Turn on hexl-mode
|
||||
(hexl-mode)
|
||||
(message "%s" (concat
|
||||
(substitute-command-keys
|
||||
"Type \\[image-toggle-hex-display] or \\[image-toggle-display] to view the image as ")
|
||||
(if (image-get-display-property)
|
||||
"hex" "an image or text") ".")))
|
||||
(message (substitute-command-keys
|
||||
"Type \\[image-toggle-hex-display] or \
|
||||
\\[image-toggle-display] to view the image as %s")
|
||||
(if (image-get-display-property)
|
||||
"hex" "an image or text")))
|
||||
|
||||
(defun image-mode-as-text ()
|
||||
"Set a non-image mode as major mode in combination with image minor mode.
|
||||
|
@ -788,11 +798,10 @@ See commands `image-mode' and `image-minor-mode' for more information
|
|||
on these modes."
|
||||
(interactive)
|
||||
(image-mode-to-text)
|
||||
(message "%s" (concat
|
||||
(substitute-command-keys
|
||||
"Type \\[image-toggle-display] or \\[image-toggle-hex-display] to view the image as ")
|
||||
(if (image-get-display-property)
|
||||
"text" "an image or hex") ".")))
|
||||
(message (substitute-command-keys
|
||||
"Type \\[image-toggle-display] to view the image as %s")
|
||||
(if (image-get-display-property)
|
||||
"text" "an image")))
|
||||
|
||||
(defun image-toggle-display-text ()
|
||||
"Show the image file as text.
|
||||
|
|
Loading…
Add table
Reference in a new issue