comparison lisp/mh-e/mh-xface.el @ 92780:23eda9299411

(mh-uncompface, mh-picon-file-contents): Use set-buffer-multibyte... (mh-face-display-function, mh-x-image-display): ...rather than bind default-enable-multibyte-characters.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 12 Mar 2008 20:51:26 +0000
parents f991f10f15ec
children 90c9ebd43589
comparison
equal deleted inserted replaced
92779:e9bef8bf2940 92780:23eda9299411
58 (or mh-decode-mime-flag mh-mhl-format-file 58 (or mh-decode-mime-flag mh-mhl-format-file
59 mh-clean-message-header-flag)) 59 mh-clean-message-header-flag))
60 (funcall mh-show-xface-function))) 60 (funcall mh-show-xface-function)))
61 61
62 ;; Shush compiler. 62 ;; Shush compiler.
63 (defvar default-enable-multibyte-characters) ; XEmacs
64 63
65 (defun mh-face-display-function () 64 (defun mh-face-display-function ()
66 "Display a Face, X-Face, or X-Image-URL header field. 65 "Display a Face, X-Face, or X-Image-URL header field.
67 If more than one of these are present, then the first one found 66 If more than one of these are present, then the first one found
68 in this order is used." 67 in this order is used."
69 (save-restriction 68 (save-restriction
70 (goto-char (point-min)) 69 (goto-char (point-min))
71 (re-search-forward "\n\n" (point-max) t) 70 (re-search-forward "\n\n" (point-max) t)
72 (narrow-to-region (point-min) (point)) 71 (narrow-to-region (point-min) (point))
73 (let* ((case-fold-search t) 72 (let* ((case-fold-search t)
74 (default-enable-multibyte-characters nil)
75 (face (message-fetch-field "face" t)) 73 (face (message-fetch-field "face" t))
76 (x-face (message-fetch-field "x-face" t)) 74 (x-face (message-fetch-field "x-face" t))
77 (url (message-fetch-field "x-image-url" t)) 75 (url (message-fetch-field "x-image-url" t))
78 raw type) 76 raw type)
79 (cond (face (setq raw (mh-face-to-png face) 77 (cond (face (setq raw (mh-face-to-png face)
128 (when raw (insert " ")))))))) 126 (when raw (insert " "))))))))
129 127
130 (defun mh-face-to-png (data) 128 (defun mh-face-to-png (data)
131 "Convert base64 encoded DATA to png image." 129 "Convert base64 encoded DATA to png image."
132 (with-temp-buffer 130 (with-temp-buffer
131 (set-buffer-multibyte nil)
133 (insert data) 132 (insert data)
134 (ignore-errors (base64-decode-region (point-min) (point-max))) 133 (ignore-errors (base64-decode-region (point-min) (point-max)))
135 (buffer-string))) 134 (buffer-string)))
136 135
137 (defun mh-uncompface (data) 136 (defun mh-uncompface (data)
138 "Run DATA through `uncompface' to generate bitmap." 137 "Run DATA through `uncompface' to generate bitmap."
139 (with-temp-buffer 138 (with-temp-buffer
139 (set-buffer-multibyte nil)
140 (insert data) 140 (insert data)
141 (when (and mh-uncompface-executable 141 (when (and mh-uncompface-executable
142 (equal (call-process-region (point-min) (point-max) 142 (equal (call-process-region (point-min) (point-max)
143 mh-uncompface-executable t '(t nil)) 143 mh-uncompface-executable t '(t nil))
144 0)) 144 0))
272 A list of consisting of a symbol for the type of the file and the 272 A list of consisting of a symbol for the type of the file and the
273 file contents as a string is returned. If FILE is nil, then both 273 file contents as a string is returned. If FILE is nil, then both
274 elements of the list are nil." 274 elements of the list are nil."
275 (if (stringp file) 275 (if (stringp file)
276 (with-temp-buffer 276 (with-temp-buffer
277 (set-buffer-multibyte nil)
277 (let ((type (and (string-match ".*\\.\\(...\\)$" file) 278 (let ((type (and (string-match ".*\\.\\(...\\)$" file)
278 (intern (match-string 1 file))))) 279 (intern (match-string 1 file)))))
279 (insert-file-contents-literally file) 280 (insert-file-contents-literally file)
280 (values type (buffer-string)))) 281 (values type (buffer-string))))
281 (values nil nil))) 282 (values nil nil)))
395 ((> len 100) nil) 396 ((> len 100) nil)
396 (t t)))) 397 (t t))))
397 398
398 (defun mh-x-image-display (image marker) 399 (defun mh-x-image-display (image marker)
399 "Display IMAGE at MARKER." 400 "Display IMAGE at MARKER."
400 (save-excursion 401 (with-current-buffer (marker-buffer marker)
401 (set-buffer (marker-buffer marker)) 402 (let ((inhibit-read-only t)
402 (let ((buffer-read-only nil)
403 (default-enable-multibyte-characters nil)
404 (buffer-modified-flag (buffer-modified-p))) 403 (buffer-modified-flag (buffer-modified-p)))
405 (unwind-protect 404 (unwind-protect
406 (when (and (file-readable-p image) (not (file-symlink-p image)) 405 (when (and (file-readable-p image) (not (file-symlink-p image))
407 (eq marker mh-x-image-marker)) 406 (eq marker mh-x-image-marker))
408 (goto-char marker) 407 (goto-char marker)
426 (if mh-wget-executable 425 (if mh-wget-executable
427 (let ((buffer (get-buffer-create (generate-new-buffer-name 426 (let ((buffer (get-buffer-create (generate-new-buffer-name
428 mh-temp-fetch-buffer))) 427 mh-temp-fetch-buffer)))
429 (filename (or (mh-funcall-if-exists make-temp-file "mhe-fetch") 428 (filename (or (mh-funcall-if-exists make-temp-file "mhe-fetch")
430 (expand-file-name (make-temp-name "~/mhe-fetch"))))) 429 (expand-file-name (make-temp-name "~/mhe-fetch")))))
431 (save-excursion 430 (with-current-buffer buffer
432 (set-buffer buffer)
433 (set (make-local-variable 'mh-x-image-url-cache-file) cache-file) 431 (set (make-local-variable 'mh-x-image-url-cache-file) cache-file)
434 (set (make-local-variable 'mh-x-image-marker) marker) 432 (set (make-local-variable 'mh-x-image-marker) marker)
435 (set (make-local-variable 'mh-x-image-temp-file) filename)) 433 (set (make-local-variable 'mh-x-image-temp-file) filename))
436 (set-process-sentinel 434 (set-process-sentinel
437 (start-process "*mh-x-image-url-fetch*" buffer 435 (start-process "*mh-x-image-url-fetch*" buffer
443 (defun mh-x-image-scale-and-display (process change) 441 (defun mh-x-image-scale-and-display (process change)
444 "When the wget PROCESS terminates scale and display image. 442 "When the wget PROCESS terminates scale and display image.
445 The argument CHANGE is ignored." 443 The argument CHANGE is ignored."
446 (when (eq (process-status process) 'exit) 444 (when (eq (process-status process) 'exit)
447 (let (marker temp-file cache-filename wget-buffer) 445 (let (marker temp-file cache-filename wget-buffer)
448 (save-excursion 446 (with-current-buffer (setq wget-buffer (process-buffer process))
449 (set-buffer (setq wget-buffer (process-buffer process)))
450 (setq marker mh-x-image-marker 447 (setq marker mh-x-image-marker
451 cache-filename mh-x-image-url-cache-file 448 cache-filename mh-x-image-url-cache-file
452 temp-file mh-x-image-temp-file)) 449 temp-file mh-x-image-temp-file))
453 (cond 450 (cond
454 ;; Check if we have `convert' 451 ;; Check if we have `convert'