summaryrefslogtreecommitdiff
path: root/lisp/image-mode.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/image-mode.el')
-rw-r--r--lisp/image-mode.el65
1 files changed, 26 insertions, 39 deletions
diff --git a/lisp/image-mode.el b/lisp/image-mode.el
index 3666009c7e0..fa1362c471b 100644
--- a/lisp/image-mode.el
+++ b/lisp/image-mode.el
@@ -53,7 +53,7 @@ See `image-mode-winprops'.")
It is called with one argument, the initial WINPROPS.")
;; FIXME this doesn't seem mature yet. Document in manual when it is.
-(defvar image-transform-resize nil
+(defvar-local image-transform-resize nil
"The image resize operation.
Its value should be one of the following:
- nil, meaning no resizing.
@@ -61,10 +61,10 @@ Its value should be one of the following:
- `fit-width', meaning to fit the image to the window width.
- A number, which is a scale factor (the default size is 1).")
-(defvar image-transform-scale 1.0
+(defvar-local image-transform-scale 1.0
"The scale factor of the image being displayed.")
-(defvar image-transform-rotation 0.0
+(defvar-local image-transform-rotation 0.0
"Rotation angle for the image in the current Image mode buffer.")
(defvar image-transform-right-angle-fudge 0.0001
@@ -145,7 +145,7 @@ otherwise it defaults to t, used for times when the buffer is not displayed."
(unless (listp image-mode-winprops-alist)
(setq image-mode-winprops-alist nil))
(add-hook 'window-configuration-change-hook
- 'image-mode-reapply-winprops nil t))
+ #'image-mode-reapply-winprops nil t))
;;; Image scrolling functions
@@ -412,9 +412,6 @@ call."
(defvar-local image-multi-frame nil
"Non-nil if image for the current Image mode buffer has multiple frames.")
-(defvar image-mode-previous-major-mode nil
- "Internal variable to keep the previous non-image major mode.")
-
(defvar image-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "\C-c\C-c" 'image-toggle-display)
@@ -551,7 +548,7 @@ Key bindings:
(unless (display-images-p)
(error "Display does not support images"))
- (kill-all-local-variables)
+ (major-mode-suspend)
(setq major-mode 'image-mode)
(if (not (image-get-display-property))
@@ -575,8 +572,8 @@ Key bindings:
;; 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)
+ (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
@@ -620,9 +617,6 @@ mouse-3: Previous frame"
;;;###autoload
(define-minor-mode image-minor-mode
"Toggle Image minor mode in this buffer.
-With a prefix argument ARG, enable Image minor mode if ARG is
-positive, and disable it otherwise. If called from Lisp, enable
-the mode if ARG is omitted or nil.
Image minor mode provides the key \\<image-mode-map>\\[image-toggle-display],
to switch back to `image-mode' and display an image file as the
@@ -641,26 +635,7 @@ A non-mage major mode found from `auto-mode-alist' or fundamental mode
displays an image file as text."
;; image-mode-as-text = normal-mode + image-minor-mode
(let ((previous-image-type image-type)) ; preserve `image-type'
- (if image-mode-previous-major-mode
- ;; Restore previous major mode that was already found by this
- ;; function and cached in `image-mode-previous-major-mode'
- (funcall image-mode-previous-major-mode)
- (let ((auto-mode-alist
- (delq nil (mapcar
- (lambda (elt)
- (unless (memq (or (car-safe (cdr elt)) (cdr elt))
- '(image-mode image-mode-maybe image-mode-as-text))
- elt))
- auto-mode-alist)))
- (magic-fallback-mode-alist
- (delq nil (mapcar
- (lambda (elt)
- (unless (memq (or (car-safe (cdr elt)) (cdr elt))
- '(image-mode image-mode-maybe image-mode-as-text))
- elt))
- magic-fallback-mode-alist))))
- (normal-mode)
- (setq-local image-mode-previous-major-mode major-mode)))
+ (major-mode-restore '(image-mode image-mode-maybe image-mode-as-text))
;; Restore `image-type' after `kill-all-local-variables' in `normal-mode'.
(setq image-type previous-image-type)
;; Enable image minor mode with `C-c C-c'.
@@ -717,6 +692,7 @@ on these modes."
Remove text properties that display the image."
(let ((inhibit-read-only t)
(buffer-undo-list t)
+ (create-lockfiles nil) ; avoid changing dir mtime by lock_file
(modified (buffer-modified-p)))
(remove-list-of-text-properties (point-min) (point-max)
'(display read-nonsticky ;; intangible
@@ -749,16 +725,20 @@ was inserted."
(not (and (boundp 'epa-file-encrypt-to)
(local-variable-p
'epa-file-encrypt-to))))))
- (file-or-data (if data-p
- (string-make-unibyte
- (buffer-substring-no-properties (point-min) (point-max)))
- filename))
+ (file-or-data
+ (if data-p
+ (let ((str
+ (buffer-substring-no-properties (point-min) (point-max))))
+ (if enable-multibyte-characters
+ (encode-coding-string str buffer-file-coding-system)
+ str))
+ filename))
;; If we have a `fit-width' or a `fit-height', don't limit
;; the size of the image to the window size.
(edges (and (null image-transform-resize)
(window-inside-pixel-edges
(get-buffer-window (current-buffer)))))
- (type (if (fboundp 'imagemagick-types)
+ (type (if (image--imagemagick-wanted-p filename)
'imagemagick
(image-type file-or-data nil data-p)))
;; :scale 1: If we do not set this, create-image will apply
@@ -782,7 +762,7 @@ was inserted."
rear-nonsticky (display) ;; intangible
read-only t front-sticky (read-only)))
- (let ((buffer-file-truename nil)) ; avoid changing dir mtime by lock_file
+ (let ((create-lockfiles nil)) ; avoid changing dir mtime by lock_file
(add-text-properties (point-min) (point-max) props)
(restore-buffer-modified-p modified))
;; Inhibit the cursor when the buffer contains only an image,
@@ -805,6 +785,13 @@ was inserted."
(if (called-interactively-p 'any)
(message "Repeat this command to go back to displaying the file as text"))))
+(defun image--imagemagick-wanted-p (filename)
+ (and (fboundp 'imagemagick-types)
+ (not (eq imagemagick-types-inhibit t))
+ (not (and filename (file-name-extension filename)
+ (memq (intern (upcase (file-name-extension filename)) obarray)
+ imagemagick-types-inhibit)))))
+
(defun image-toggle-hex-display ()
"Toggle between image and hex display."
(interactive)