diff options
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/files.el | 46 | ||||
-rw-r--r-- | lisp/image-mode.el | 144 | ||||
-rw-r--r-- | lisp/image.el | 4 |
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 ;; The following should come after the ChangeLog pattern ;; for the sake of ChangeLog.1, etc. ;; and after the .scm.[0-9] and CVS' <file>.<rev> patterns too. - ("\\.[1-9]\\'" . nroff-mode))) + ("\\.[1-9]\\'" . nroff-mode) + ;; Image file types probably supported by `image-convert'. + ("\\.art\\'" . image-mode) + ("\\.avs\\'" . image-mode) + ("\\.bmp\\'" . image-mode) + ("\\.cmyk\\'" . image-mode) + ("\\.cmyka\\'" . image-mode) + ("\\.crw\\'" . image-mode) + ("\\.dcr\\'" . image-mode) + ("\\.dcx\\'" . image-mode) + ("\\.dng\\'" . image-mode) + ("\\.dpx\\'" . image-mode) + ("\\.fax\\'" . image-mode) + ("\\.hrz\\'" . image-mode) + ("\\.icb\\'" . image-mode) + ("\\.icc\\'" . image-mode) + ("\\.icm\\'" . image-mode) + ("\\.ico\\'" . image-mode) + ("\\.icon\\'" . image-mode) + ("\\.jbg\\'" . image-mode) + ("\\.jbig\\'" . image-mode) + ("\\.jng\\'" . image-mode) + ("\\.jnx\\'" . image-mode) + ("\\.miff\\'" . image-mode) + ("\\.mng\\'" . image-mode) + ("\\.mvg\\'" . image-mode) + ("\\.otb\\'" . image-mode) + ("\\.p7\\'" . image-mode) + ("\\.pcx\\'" . image-mode) + ("\\.pdb\\'" . image-mode) + ("\\.pfa\\'" . image-mode) + ("\\.pfb\\'" . image-mode) + ("\\.picon\\'" . image-mode) + ("\\.pict\\'" . image-mode) + ("\\.rgb\\'" . image-mode) + ("\\.rgba\\'" . image-mode) + ("\\.tga\\'" . image-mode) + ("\\.wbmp\\'" . image-mode) + ("\\.webp\\'" . image-mode) + ("\\.wmf\\'" . image-mode) + ("\\.wpg\\'" . image-mode) + ("\\.xcf\\'" . image-mode) + ("\\.xmp\\'" . image-mode) + ("\\.xwd\\'" . image-mode) + ("\\.yuv\\'" . image-mode))) "Alist of filename patterns vs corresponding major mode functions. Each element looks like (REGEXP . FUNCTION) or (REGEXP FUNCTION NON-NIL). \(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. Key bindings: \\{image-mode-map}" (interactive) - (condition-case err + (unless (display-images-p) + (error "Display does not support images")) + + (major-mode-suspend) + (setq major-mode 'image-mode) + + (if (not (image-get-display-property)) (progn - (unless (display-images-p) - (error "Display does not support images")) - - (major-mode-suspend) - (setq major-mode 'image-mode) - - (if (not (image-get-display-property)) - (progn - (image-toggle-display-image) - ;; If attempt to display the image fails. - (if (not (image-get-display-property)) - (error "Invalid image"))) - ;; Set next vars when image is already displayed but local - ;; variables were cleared by kill-all-local-variables - (setq cursor-type nil truncate-lines t - image-type (plist-get (cdr (image-get-display-property)) :type))) - - (setq mode-name (if image-type (format "Image[%s]" image-type) "Image")) - (use-local-map image-mode-map) - - ;; Use our own bookmarking function for images. - (setq-local bookmark-make-record-function - #'image-bookmark-make-record) - - ;; Keep track of [vh]scroll when switching buffers - (image-mode-setup-winprops) - - (add-hook 'change-major-mode-hook #'image-toggle-display-text nil t) - (add-hook 'after-revert-hook #'image-after-revert-hook nil t) - (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) - (cond - ((null image) - (message "%s" (concat msg1 "an image."))) - ((setq animated (image-multi-frame-p image)) - (setq image-multi-frame t - mode-line-process - `(:eval - (concat " " - (propertize - (format "[%s/%s]" - (1+ (image-current-frame ',image)) - ,(car animated)) - 'help-echo "Frames -mouse-1: Next frame -mouse-3: Previous frame" - 'mouse-face 'mode-line-highlight - 'local-map - '(keymap - (mode-line - keymap - (down-mouse-1 . image-next-frame) - (down-mouse-3 . image-previous-frame))))))) - (message "%s" - (concat msg1 "text. This image has multiple frames."))) -;;; (substitute-command-keys -;;; "\\[image-toggle-animation] to animate.")))) - (t - (message "%s" (concat msg1 "text or hex.")))))) - - (error - (image-mode-as-text) - (funcall - (if (called-interactively-p 'any) 'error 'message) - "Cannot display image: %s" (cdr err))))) + (when (condition-case err + (progn + (image-toggle-display-image) + t) + (unknown-image-type + (image-mode-as-text) + (funcall + (if (called-interactively-p 'any) 'error 'message) + "Unknown image type; consider switching `image-use-external-converter' on") + nil) + (error + (image-mode-as-text) + (funcall + (if (called-interactively-p 'any) 'error 'message) + "Cannot display image: %s" (cdr err)) + nil)) + ;; If attempt to display the image fails. + (if (not (image-get-display-property)) + (error "Invalid image")) + (image-mode--setup-mode))) + ;; Set next vars when image is already displayed but local + ;; variables were cleared by kill-all-local-variables + (setq cursor-type nil truncate-lines t + image-type (plist-get (cdr (image-get-display-property)) :type)) + (image-mode--setup-mode))) + +(defun image-mode--setup-mode () + (setq mode-name (if image-type (format "Image[%s]" image-type) "Image")) + (use-local-map image-mode-map) + + ;; Use our own bookmarking function for images. + (setq-local bookmark-make-record-function + #'image-bookmark-make-record) + + ;; Keep track of [vh]scroll when switching buffers + (image-mode-setup-winprops) + + (add-hook 'change-major-mode-hook #'image-toggle-display-text nil t) + (add-hook 'after-revert-hook #'image-after-revert-hook nil t) + (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) + (cond + ((null image) + (message "%s" (concat msg1 "an image."))) + ((setq animated (image-multi-frame-p image)) + (setq image-multi-frame t + mode-line-process + `(:eval + (concat " " + (propertize + (format "[%s/%s]" + (1+ (image-current-frame ',image)) + ,(car animated)) + 'help-echo "Frames\nmouse-1: Next frame\nmouse-3: Previous frame" + 'mouse-face 'mode-line-highlight + 'local-map + '(keymap + (mode-line + keymap + (down-mouse-1 . image-next-frame) + (down-mouse-3 . image-previous-frame))))))) + (message "%s" + (concat msg1 "text. This image has multiple frames."))) + (t + (message "%s" (concat msg1 "text or hex.")))))) ;;;###autoload (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." :type 'boolean :version "27.1") +(define-error 'unknown-image-type "Unknown image type") + ;; Map put into text properties on images. (defvar image-map (let ((map (make-sparse-keymap))) @@ -391,7 +393,7 @@ Optional DATA-P non-nil means SOURCE is a string containing image data." (require 'image-converter) (image-convert-p source)))))) (unless type - (error "Cannot determine image type"))) + (signal 'unknown-image-type "Cannot determine image type"))) (when (and (not (eq type 'image-convert)) (not (memq type (and (boundp 'image-types) image-types)))) (error "Invalid image type `%s'" type)) |