aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorLars Ingebrigtsen2019-10-29 21:42:33 +0100
committerLars Ingebrigtsen2019-10-29 21:42:39 +0100
commit19c98f762092adab01bf35d4b0c958af7d4ea59e (patch)
tree7740857748d7b0d916593181762f26db1719e62d /lisp
parent1997e3b80f1046d789c4120d50e0f1dde05e7a74 (diff)
downloademacs-19c98f762092adab01bf35d4b0c958af7d4ea59e.tar.gz
emacs-19c98f762092adab01bf35d4b0c958af7d4ea59e.zip
Default exotic image formats (like .webp) to image-mode
* doc/lispref/errors.texi (Standard Errors): Mention the new error. * lisp/files.el (auto-mode-alist): Add a bunch of image suffixes to the list (bug#37972) based on the output from "gm convert -list format" (i.e., graphicsmagick). * lisp/image-mode.el (image-mode): Rewrite to possibly notify the user about image-use-external-converter. (image-mode--setup-mode): Factor out into own function and don't run under `condition-case' as there's nothing here that should error. * lisp/image.el (unknown-image-type): New error. (image-type): Signal that error so that image-mode can offer sensible feedback to the user.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/files.el46
-rw-r--r--lisp/image-mode.el144
-rw-r--r--lisp/image.el4
3 files changed, 123 insertions, 71 deletions
diff --git a/lisp/files.el b/lisp/files.el
index 4b364b49d84..f6dc4baa7fb 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -2847,7 +2847,51 @@ ARC\\|ZIP\\|LZH\\|LHA\\|ZOO\\|[JEW]AR\\|XPI\\|RAR\\|CBR\\|7Z\\)\\'" . archive-mo
2847 ;; The following should come after the ChangeLog pattern 2847 ;; The following should come after the ChangeLog pattern
2848 ;; for the sake of ChangeLog.1, etc. 2848 ;; for the sake of ChangeLog.1, etc.
2849 ;; and after the .scm.[0-9] and CVS' <file>.<rev> patterns too. 2849 ;; and after the .scm.[0-9] and CVS' <file>.<rev> patterns too.
2850 ("\\.[1-9]\\'" . nroff-mode))) 2850 ("\\.[1-9]\\'" . nroff-mode)
2851 ;; Image file types probably supported by `image-convert'.
2852 ("\\.art\\'" . image-mode)
2853 ("\\.avs\\'" . image-mode)
2854 ("\\.bmp\\'" . image-mode)
2855 ("\\.cmyk\\'" . image-mode)
2856 ("\\.cmyka\\'" . image-mode)
2857 ("\\.crw\\'" . image-mode)
2858 ("\\.dcr\\'" . image-mode)
2859 ("\\.dcx\\'" . image-mode)
2860 ("\\.dng\\'" . image-mode)
2861 ("\\.dpx\\'" . image-mode)
2862 ("\\.fax\\'" . image-mode)
2863 ("\\.hrz\\'" . image-mode)
2864 ("\\.icb\\'" . image-mode)
2865 ("\\.icc\\'" . image-mode)
2866 ("\\.icm\\'" . image-mode)
2867 ("\\.ico\\'" . image-mode)
2868 ("\\.icon\\'" . image-mode)
2869 ("\\.jbg\\'" . image-mode)
2870 ("\\.jbig\\'" . image-mode)
2871 ("\\.jng\\'" . image-mode)
2872 ("\\.jnx\\'" . image-mode)
2873 ("\\.miff\\'" . image-mode)
2874 ("\\.mng\\'" . image-mode)
2875 ("\\.mvg\\'" . image-mode)
2876 ("\\.otb\\'" . image-mode)
2877 ("\\.p7\\'" . image-mode)
2878 ("\\.pcx\\'" . image-mode)
2879 ("\\.pdb\\'" . image-mode)
2880 ("\\.pfa\\'" . image-mode)
2881 ("\\.pfb\\'" . image-mode)
2882 ("\\.picon\\'" . image-mode)
2883 ("\\.pict\\'" . image-mode)
2884 ("\\.rgb\\'" . image-mode)
2885 ("\\.rgba\\'" . image-mode)
2886 ("\\.tga\\'" . image-mode)
2887 ("\\.wbmp\\'" . image-mode)
2888 ("\\.webp\\'" . image-mode)
2889 ("\\.wmf\\'" . image-mode)
2890 ("\\.wpg\\'" . image-mode)
2891 ("\\.xcf\\'" . image-mode)
2892 ("\\.xmp\\'" . image-mode)
2893 ("\\.xwd\\'" . image-mode)
2894 ("\\.yuv\\'" . image-mode)))
2851 "Alist of filename patterns vs corresponding major mode functions. 2895 "Alist of filename patterns vs corresponding major mode functions.
2852Each element looks like (REGEXP . FUNCTION) or (REGEXP FUNCTION NON-NIL). 2896Each element looks like (REGEXP . FUNCTION) or (REGEXP FUNCTION NON-NIL).
2853\(NON-NIL stands for anything that is not nil; the value does not matter.) 2897\(NON-NIL stands for anything that is not nil; the value does not matter.)
diff --git a/lisp/image-mode.el b/lisp/image-mode.el
index 342102568ca..db6864649d0 100644
--- a/lisp/image-mode.el
+++ b/lisp/image-mode.el
@@ -552,76 +552,82 @@ to toggle between display as an image and display as text or hex.
552Key bindings: 552Key bindings:
553\\{image-mode-map}" 553\\{image-mode-map}"
554 (interactive) 554 (interactive)
555 (condition-case err 555 (unless (display-images-p)
556 (error "Display does not support images"))
557
558 (major-mode-suspend)
559 (setq major-mode 'image-mode)
560
561 (if (not (image-get-display-property))
556 (progn 562 (progn
557 (unless (display-images-p) 563 (when (condition-case err
558 (error "Display does not support images")) 564 (progn
559 565 (image-toggle-display-image)
560 (major-mode-suspend) 566 t)
561 (setq major-mode 'image-mode) 567 (unknown-image-type
562 568 (image-mode-as-text)
563 (if (not (image-get-display-property)) 569 (funcall
564 (progn 570 (if (called-interactively-p 'any) 'error 'message)
565 (image-toggle-display-image) 571 "Unknown image type; consider switching `image-use-external-converter' on")
566 ;; If attempt to display the image fails. 572 nil)
567 (if (not (image-get-display-property)) 573 (error
568 (error "Invalid image"))) 574 (image-mode-as-text)
569 ;; Set next vars when image is already displayed but local 575 (funcall
570 ;; variables were cleared by kill-all-local-variables 576 (if (called-interactively-p 'any) 'error 'message)
571 (setq cursor-type nil truncate-lines t 577 "Cannot display image: %s" (cdr err))
572 image-type (plist-get (cdr (image-get-display-property)) :type))) 578 nil))
573 579 ;; If attempt to display the image fails.
574 (setq mode-name (if image-type (format "Image[%s]" image-type) "Image")) 580 (if (not (image-get-display-property))
575 (use-local-map image-mode-map) 581 (error "Invalid image"))
576 582 (image-mode--setup-mode)))
577 ;; Use our own bookmarking function for images. 583 ;; Set next vars when image is already displayed but local
578 (setq-local bookmark-make-record-function 584 ;; variables were cleared by kill-all-local-variables
579 #'image-bookmark-make-record) 585 (setq cursor-type nil truncate-lines t
580 586 image-type (plist-get (cdr (image-get-display-property)) :type))
581 ;; Keep track of [vh]scroll when switching buffers 587 (image-mode--setup-mode)))
582 (image-mode-setup-winprops) 588
583 589(defun image-mode--setup-mode ()
584 (add-hook 'change-major-mode-hook #'image-toggle-display-text nil t) 590 (setq mode-name (if image-type (format "Image[%s]" image-type) "Image"))
585 (add-hook 'after-revert-hook #'image-after-revert-hook nil t) 591 (use-local-map image-mode-map)
586 (run-mode-hooks 'image-mode-hook) 592
587 (let ((image (image-get-display-property)) 593 ;; Use our own bookmarking function for images.
588 (msg1 (substitute-command-keys 594 (setq-local bookmark-make-record-function
589 "Type \\[image-toggle-display] or \\[image-toggle-hex-display] to view the image as ")) 595 #'image-bookmark-make-record)
590 animated) 596
591 (cond 597 ;; Keep track of [vh]scroll when switching buffers
592 ((null image) 598 (image-mode-setup-winprops)
593 (message "%s" (concat msg1 "an image."))) 599
594 ((setq animated (image-multi-frame-p image)) 600 (add-hook 'change-major-mode-hook #'image-toggle-display-text nil t)
595 (setq image-multi-frame t 601 (add-hook 'after-revert-hook #'image-after-revert-hook nil t)
596 mode-line-process 602 (run-mode-hooks 'image-mode-hook)
597 `(:eval 603 (let ((image (image-get-display-property))
598 (concat " " 604 (msg1 (substitute-command-keys
599 (propertize 605 "Type \\[image-toggle-display] or \\[image-toggle-hex-display] to view the image as "))
600 (format "[%s/%s]" 606 animated)
601 (1+ (image-current-frame ',image)) 607 (cond
602 ,(car animated)) 608 ((null image)
603 'help-echo "Frames 609 (message "%s" (concat msg1 "an image.")))
604mouse-1: Next frame 610 ((setq animated (image-multi-frame-p image))
605mouse-3: Previous frame" 611 (setq image-multi-frame t
606 'mouse-face 'mode-line-highlight 612 mode-line-process
607 'local-map 613 `(:eval
608 '(keymap 614 (concat " "
609 (mode-line 615 (propertize
610 keymap 616 (format "[%s/%s]"
611 (down-mouse-1 . image-next-frame) 617 (1+ (image-current-frame ',image))
612 (down-mouse-3 . image-previous-frame))))))) 618 ,(car animated))
613 (message "%s" 619 'help-echo "Frames\nmouse-1: Next frame\nmouse-3: Previous frame"
614 (concat msg1 "text. This image has multiple frames."))) 620 'mouse-face 'mode-line-highlight
615;;; (substitute-command-keys 621 'local-map
616;;; "\\[image-toggle-animation] to animate.")))) 622 '(keymap
617 (t 623 (mode-line
618 (message "%s" (concat msg1 "text or hex.")))))) 624 keymap
619 625 (down-mouse-1 . image-next-frame)
620 (error 626 (down-mouse-3 . image-previous-frame)))))))
621 (image-mode-as-text) 627 (message "%s"
622 (funcall 628 (concat msg1 "text. This image has multiple frames.")))
623 (if (called-interactively-p 'any) 'error 'message) 629 (t
624 "Cannot display image: %s" (cdr err))))) 630 (message "%s" (concat msg1 "text or hex."))))))
625 631
626;;;###autoload 632;;;###autoload
627(define-minor-mode image-minor-mode 633(define-minor-mode image-minor-mode
diff --git a/lisp/image.el b/lisp/image.el
index 66fb5fa5fc9..ad2ee6c6071 100644
--- a/lisp/image.el
+++ b/lisp/image.el
@@ -151,6 +151,8 @@ or \"ffmpeg\") is installed."
151 :type 'boolean 151 :type 'boolean
152 :version "27.1") 152 :version "27.1")
153 153
154(define-error 'unknown-image-type "Unknown image type")
155
154;; Map put into text properties on images. 156;; Map put into text properties on images.
155(defvar image-map 157(defvar image-map
156 (let ((map (make-sparse-keymap))) 158 (let ((map (make-sparse-keymap)))
@@ -391,7 +393,7 @@ Optional DATA-P non-nil means SOURCE is a string containing image data."
391 (require 'image-converter) 393 (require 'image-converter)
392 (image-convert-p source)))))) 394 (image-convert-p source))))))
393 (unless type 395 (unless type
394 (error "Cannot determine image type"))) 396 (signal 'unknown-image-type "Cannot determine image type")))
395 (when (and (not (eq type 'image-convert)) 397 (when (and (not (eq type 'image-convert))
396 (not (memq type (and (boundp 'image-types) image-types)))) 398 (not (memq type (and (boundp 'image-types) image-types))))
397 (error "Invalid image type `%s'" type)) 399 (error "Invalid image type `%s'" type))