+(defvar image-mode-current-vscroll nil
+ "An alist with elements (WINDOW . VSCROLL).")
+(make-variable-buffer-local 'image-mode-current-vscroll)
+
+(defvar image-mode-current-hscroll nil
+ "An alist with elements (WINDOW . HSCROLL).")
+(make-variable-buffer-local 'image-mode-current-hscroll)
+
+(defun image-set-window-vscroll (window vscroll &optional pixels-p)
+ (setq image-mode-current-vscroll
+ (cons (cons window vscroll)
+ (delq (assq window image-mode-current-vscroll)
+ image-mode-current-vscroll)))
+ (set-window-vscroll window vscroll pixels-p))
+
+(defun image-set-window-hscroll (window ncol)
+ (setq image-mode-current-hscroll
+ (cons (cons window ncol)
+ (delq (assq window image-mode-current-hscroll)
+ image-mode-current-hscroll)))
+ (set-window-hscroll window ncol))
+
+(defun image-reset-current-vhscroll ()
+ (walk-windows
+ (lambda (win)
+ (with-current-buffer (window-buffer win)
+ ;; When set-window-buffer, set hscroll and vscroll to what they were
+ ;; last time the image was displayed in this window. If it's the first
+ ;; time it's displayed in this window, use the most recent setting.
+ (when image-mode-current-hscroll
+ (set-window-hscroll win (cdr (or (assoc win image-mode-current-hscroll)
+ (car image-mode-current-hscroll)))))
+ (when image-mode-current-vscroll
+ (set-window-vscroll win (cdr (or (assoc win image-mode-current-vscroll)
+ (car image-mode-current-vscroll)))))))
+ 'nomini
+ (selected-frame)))
+
+(defun image-get-display-property ()
+ (get-char-property (point-min) 'display
+ ;; There might be different images for different displays.
+ (if (eq (window-buffer) (current-buffer))
+ (selected-window))))
+