emacs-diffs
[Top][All Lists]
Advanced

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

master 8fda677 2/3: image-mode: Advertize viewing as text less eagerly


From: Stefan Kangas
Subject: master 8fda677 2/3: image-mode: Advertize viewing as text less eagerly
Date: Fri, 3 Dec 2021 09:42:32 -0500 (EST)

branch: master
commit 8fda6770afcd0d340cd5dc3d34697e454a7a3809
Author: Stefan Kangas <stefan@marxist.se>
Commit: Stefan Kangas <stefan@marxist.se>

    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.
---
 etc/NEWS           |  6 ++++++
 lisp/image-mode.el | 43 ++++++++++++++++++++++++++-----------------
 2 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 227409d..c55b74f 100644
--- a/etc/NEWS
+++ b/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
 
 +++
diff --git a/lisp/image-mode.el b/lisp/image-mode.el
index 4ee02c0..c2b145d 100644
--- a/lisp/image-mode.el
+++ b/lisp/image-mode.el
@@ -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.



reply via email to

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