- ;; save-current-buffer/get-buffer-create rather than
- ;; with-temp-buffer.
- (save-current-buffer
- (set-buffer (generate-new-buffer "*fontification*"))
- (unwind-protect
- (progn
- (buffer-disable-undo)
- (mm-insert-part handle)
- (funcall mode)
- (require 'font-lock)
- (let ((font-lock-verbose nil))
- ;; I find font-lock a bit too verbose.
- (font-lock-fontify-buffer))
- ;; By default, XEmacs font-lock uses non-duplicable text
- ;; properties. This code forces all the text properties
- ;; to be copied along with the text.
- (when (fboundp 'extent-list)
- (map-extents (lambda (ext ignored)
- (set-extent-property ext 'duplicable t)
- nil)
- nil nil nil nil nil 'text-prop))
- (setq text (buffer-string)))
- (kill-buffer (current-buffer))))
+ ;; `with-current-buffer'/`generate-new-buffer' rather than
+ ;; `with-temp-buffer'.
+ (with-current-buffer (generate-new-buffer "*fontification*")
+ (buffer-disable-undo)
+ (mm-enable-multibyte)
+ (insert (cond ((eq charset 'gnus-decoded)
+ (mm-insert-part handle))
+ (coding-system
+ (mm-decode-coding-string text coding-system))
+ (charset
+ (mm-decode-string text charset))
+ (t
+ text)))
+ (require 'font-lock)
+ (let ((font-lock-maximum-size nil)
+ ;; Disable support modes, e.g., jit-lock, lazy-lock, etc.
+ (font-lock-mode-hook nil)
+ (font-lock-support-mode nil)
+ ;; I find font-lock a bit too verbose.
+ (font-lock-verbose nil))
+ (funcall mode)
+ ;; The mode function might have already turned on font-lock.
+ (unless (symbol-value 'font-lock-mode)
+ (font-lock-fontify-buffer)))
+ ;; By default, XEmacs font-lock uses non-duplicable text
+ ;; properties. This code forces all the text properties
+ ;; to be copied along with the text.
+ (when (fboundp 'extent-list)
+ (map-extents (lambda (ext ignored)
+ (set-extent-property ext 'duplicable t)
+ nil)
+ nil nil nil nil nil 'text-prop))
+ (setq text (buffer-string))
+ (kill-buffer (current-buffer)))