Mercurial > emacs
comparison lisp/image-mode.el @ 95224:889084703e3f
(image-mode-winprops): Add argument CLEANUP to prune
image-mode-winprops-alist, preventing it from growing indefinitely.
(image-mode-reapply-winprops): Use it.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Thu, 22 May 2008 21:27:42 +0000 |
parents | ee5932bf781d |
children | 88781ac6a1be |
comparison
equal
deleted
inserted
replaced
95223:b1c20ce02fa2 | 95224:889084703e3f |
---|---|
54 | 54 |
55 (defvar image-mode-new-window-functions nil | 55 (defvar image-mode-new-window-functions nil |
56 "Special hook run when image data is requested in a new window. | 56 "Special hook run when image data is requested in a new window. |
57 It is called with one argument, the initial WINPROPS.") | 57 It is called with one argument, the initial WINPROPS.") |
58 | 58 |
59 (defun image-mode-winprops (&optional window) | 59 (defun image-mode-winprops (&optional window cleanup) |
60 "Return winprops of WINDOW. | 60 "Return winprops of WINDOW. |
61 A winprops object has the shape (WINDOW . ALIST)." | 61 A winprops object has the shape (WINDOW . ALIST)." |
62 (unless window (setq window (selected-window))) | 62 (cond ((null window) |
63 (setq window (selected-window))) | |
64 ((not (windowp window)) | |
65 (error "Not a window: %s" window))) | |
66 (when cleanup | |
67 (setq image-mode-winprops-alist | |
68 (delq nil (mapcar (lambda (winprop) | |
69 (if (window-live-p (car-safe winprop)) | |
70 winprop)) | |
71 image-mode-winprops-alist)))) | |
63 (let ((winprops (assq window image-mode-winprops-alist))) | 72 (let ((winprops (assq window image-mode-winprops-alist))) |
64 ;; For new windows, set defaults from the latest. | 73 ;; For new windows, set defaults from the latest. |
65 (unless winprops | 74 (unless winprops |
66 (setq winprops (cons window | 75 (setq winprops (cons window |
67 (copy-alist (cdar image-mode-winprops-alist)))) | 76 (copy-alist (cdar image-mode-winprops-alist)))) |
92 (set-window-hscroll (selected-window) ncol)) | 101 (set-window-hscroll (selected-window) ncol)) |
93 | 102 |
94 (defun image-mode-reapply-winprops () | 103 (defun image-mode-reapply-winprops () |
95 ;; When set-window-buffer, set hscroll and vscroll to what they were | 104 ;; When set-window-buffer, set hscroll and vscroll to what they were |
96 ;; last time the image was displayed in this window. | 105 ;; last time the image was displayed in this window. |
97 (when (listp image-mode-winprops-alist) | 106 (when (and (image-get-display-property) |
98 (let* ((winprops (image-mode-winprops)) | 107 (listp image-mode-winprops-alist)) |
108 (let* ((winprops (image-mode-winprops nil t)) | |
99 (hscroll (image-mode-window-get 'hscroll winprops)) | 109 (hscroll (image-mode-window-get 'hscroll winprops)) |
100 (vscroll (image-mode-window-get 'vscroll winprops))) | 110 (vscroll (image-mode-window-get 'vscroll winprops))) |
101 (if hscroll (set-window-hscroll (selected-window) hscroll)) | 111 (if hscroll (set-window-hscroll (selected-window) hscroll)) |
102 (if vscroll (set-window-vscroll (selected-window) vscroll))))) | 112 (if vscroll (set-window-vscroll (selected-window) vscroll))))) |
103 | 113 |