comparison lisp/image-mode.el @ 85800:0810efbbb396

(image-forward-hscroll, image-next-line, image-eol) (image-eob, image-mode, image-minor-mode, image-toggle-display-text) (image-toggle-display): Take overlays into account and don't assume point-min==1.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 30 Oct 2007 17:09:41 +0000
parents 827101d5eacc
children f6ce12419345
comparison
equal deleted inserted replaced
85799:10f70d5f0ff3 85800:0810efbbb396
57 (cond ((= n 0) nil) 57 (cond ((= n 0) nil)
58 ((< n 0) 58 ((< n 0)
59 (set-window-hscroll (selected-window) 59 (set-window-hscroll (selected-window)
60 (max 0 (+ (window-hscroll) n)))) 60 (max 0 (+ (window-hscroll) n))))
61 (t 61 (t
62 (let* ((image (get-text-property 1 'display)) 62 (let* ((image (get-char-property (point-min) 'display))
63 (edges (window-inside-edges)) 63 (edges (window-inside-edges))
64 (win-width (- (nth 2 edges) (nth 0 edges))) 64 (win-width (- (nth 2 edges) (nth 0 edges)))
65 (img-width (ceiling (car (image-size image))))) 65 (img-width (ceiling (car (image-size image)))))
66 (set-window-hscroll (selected-window) 66 (set-window-hscroll (selected-window)
67 (min (max 0 (- img-width win-width)) 67 (min (max 0 (- img-width win-width))
80 (cond ((= n 0) nil) 80 (cond ((= n 0) nil)
81 ((< n 0) 81 ((< n 0)
82 (set-window-vscroll (selected-window) 82 (set-window-vscroll (selected-window)
83 (max 0 (+ (window-vscroll) n)))) 83 (max 0 (+ (window-vscroll) n))))
84 (t 84 (t
85 (let* ((image (get-text-property 1 'display)) 85 (let* ((image (get-char-property (point-min) 'display))
86 (edges (window-inside-edges)) 86 (edges (window-inside-edges))
87 (win-height (- (nth 3 edges) (nth 1 edges))) 87 (win-height (- (nth 3 edges) (nth 1 edges)))
88 (img-height (ceiling (cdr (image-size image))))) 88 (img-height (ceiling (cdr (image-size image)))))
89 (set-window-vscroll (selected-window) 89 (set-window-vscroll (selected-window)
90 (min (max 0 (- img-height win-height)) 90 (min (max 0 (- img-height win-height))
154 stopping if the top or bottom edge of the image is reached." 154 stopping if the top or bottom edge of the image is reached."
155 (interactive "p") 155 (interactive "p")
156 (and arg 156 (and arg
157 (/= (setq arg (prefix-numeric-value arg)) 1) 157 (/= (setq arg (prefix-numeric-value arg)) 1)
158 (image-next-line (- arg 1))) 158 (image-next-line (- arg 1)))
159 (let* ((image (get-text-property 1 'display)) 159 (let* ((image (get-char-property (point-min) 'display))
160 (edges (window-inside-edges)) 160 (edges (window-inside-edges))
161 (win-width (- (nth 2 edges) (nth 0 edges))) 161 (win-width (- (nth 2 edges) (nth 0 edges)))
162 (img-width (ceiling (car (image-size image))))) 162 (img-width (ceiling (car (image-size image)))))
163 (set-window-hscroll (selected-window) 163 (set-window-hscroll (selected-window)
164 (max 0 (- img-width win-width))))) 164 (max 0 (- img-width win-width)))))
170 (set-window-vscroll (selected-window) 0)) 170 (set-window-vscroll (selected-window) 0))
171 171
172 (defun image-eob () 172 (defun image-eob ()
173 "Scroll to the bottom-right corner of the image in the current window." 173 "Scroll to the bottom-right corner of the image in the current window."
174 (interactive) 174 (interactive)
175 (let* ((image (get-text-property 1 'display)) 175 (let* ((image (get-char-property (point-min) 'display))
176 (edges (window-inside-edges)) 176 (edges (window-inside-edges))
177 (win-width (- (nth 2 edges) (nth 0 edges))) 177 (win-width (- (nth 2 edges) (nth 0 edges)))
178 (img-width (ceiling (car (image-size image)))) 178 (img-width (ceiling (car (image-size image))))
179 (win-height (- (nth 3 edges) (nth 1 edges))) 179 (win-height (- (nth 3 edges) (nth 1 edges)))
180 (img-height (ceiling (cdr (image-size image))))) 180 (img-height (ceiling (cdr (image-size image)))))
219 (kill-all-local-variables) 219 (kill-all-local-variables)
220 (setq mode-name "Image[text]") 220 (setq mode-name "Image[text]")
221 (setq major-mode 'image-mode) 221 (setq major-mode 'image-mode)
222 (add-hook 'change-major-mode-hook 'image-toggle-display-text nil t) 222 (add-hook 'change-major-mode-hook 'image-toggle-display-text nil t)
223 (if (and (display-images-p) 223 (if (and (display-images-p)
224 (not (get-text-property (point-min) 'display))) 224 (not (get-char-property (point-min) 'display)))
225 (image-toggle-display) 225 (image-toggle-display)
226 ;; Set next vars when image is already displayed but local 226 ;; Set next vars when image is already displayed but local
227 ;; variables were cleared by kill-all-local-variables 227 ;; variables were cleared by kill-all-local-variables
228 (use-local-map image-mode-map) 228 (use-local-map image-mode-map)
229 (setq cursor-type nil truncate-lines t)) 229 (setq cursor-type nil truncate-lines t))
230 (run-mode-hooks 'image-mode-hook) 230 (run-mode-hooks 'image-mode-hook)
231 (if (display-images-p) 231 (if (display-images-p)
232 (message "%s" (concat 232 (message "%s" (concat
233 (substitute-command-keys 233 (substitute-command-keys
234 "Type \\[image-toggle-display] to view as ") 234 "Type \\[image-toggle-display] to view as ")
235 (if (get-text-property (point-min) 'display) 235 (if (get-char-property (point-min) 'display)
236 "text" "an image") ".")))) 236 "text" "an image") "."))))
237 237
238 ;;;###autoload 238 ;;;###autoload
239 (define-minor-mode image-minor-mode 239 (define-minor-mode image-minor-mode
240 "Toggle Image minor mode. 240 "Toggle Image minor mode.
243 nil (:eval (format " Image[%s]" image-type)) image-mode-text-map 243 nil (:eval (format " Image[%s]" image-type)) image-mode-text-map
244 :group 'image 244 :group 'image
245 :version "22.1" 245 :version "22.1"
246 (if (not image-minor-mode) 246 (if (not image-minor-mode)
247 (image-toggle-display-text) 247 (image-toggle-display-text)
248 (if (get-text-property (point-min) 'display) 248 (if (get-char-property (point-min) 'display)
249 (setq cursor-type nil truncate-lines t) 249 (setq cursor-type nil truncate-lines t)
250 (setq image-type "text")) 250 (setq image-type "text"))
251 (add-hook 'change-major-mode-hook (lambda () (image-minor-mode -1)) nil t) 251 (add-hook 'change-major-mode-hook (lambda () (image-minor-mode -1)) nil t)
252 (message "%s" (concat (substitute-command-keys 252 (message "%s" (concat (substitute-command-keys
253 "Type \\[image-toggle-display] to view the image as ") 253 "Type \\[image-toggle-display] to view the image as ")
254 (if (get-text-property (point-min) 'display) 254 (if (get-char-property (point-min) 'display)
255 "text" "an image") ".")))) 255 "text" "an image") "."))))
256 256
257 ;;;###autoload 257 ;;;###autoload
258 (defun image-mode-maybe () 258 (defun image-mode-maybe ()
259 "Set major or minor mode for image files. 259 "Set major or minor mode for image files.
279 (image-minor-mode t)) 279 (image-minor-mode t))
280 (image-mode)))) 280 (image-mode))))
281 281
282 (defun image-toggle-display-text () 282 (defun image-toggle-display-text ()
283 "Showing the text of the image file." 283 "Showing the text of the image file."
284 (if (get-text-property (point-min) 'display) 284 (if (get-char-property (point-min) 'display)
285 (image-toggle-display))) 285 (image-toggle-display)))
286 286
287 (defvar archive-superior-buffer) 287 (defvar archive-superior-buffer)
288 (defvar tar-superior-buffer) 288 (defvar tar-superior-buffer)
289 289
290 (defun image-toggle-display () 290 (defun image-toggle-display ()
291 "Start or stop displaying an image file as the actual image. 291 "Start or stop displaying an image file as the actual image.
292 This command toggles between showing the text of the image file 292 This command toggles between showing the text of the image file
293 and showing the image as an image." 293 and showing the image as an image."
294 (interactive) 294 (interactive)
295 (if (get-text-property (point-min) 'display) 295 (if (get-char-property (point-min) 'display)
296 (let ((inhibit-read-only t) 296 (let ((inhibit-read-only t)
297 (buffer-undo-list t) 297 (buffer-undo-list t)
298 (modified (buffer-modified-p))) 298 (modified (buffer-modified-p)))
299 (remove-list-of-text-properties (point-min) (point-max) 299 (remove-list-of-text-properties (point-min) (point-max)
300 '(display intangible read-nonsticky 300 '(display intangible read-nonsticky