Function: mm-display-inline-fontify

mm-display-inline-fontify is a byte-compiled function defined in mm-view.el.gz.

Signature

(mm-display-inline-fontify HANDLE &optional MODE)

Documentation

Insert HANDLE inline fontifying with MODE.

If MODE is not set, try to find mode automatically.

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/mm-view.el.gz
(defun mm-display-inline-fontify (handle &optional mode)
  "Insert HANDLE inline fontifying with MODE.
If MODE is not set, try to find mode automatically."
  (let ((charset (mail-content-type-get (mm-handle-type handle) 'charset))
	text coding-system ovs)
    (unless (eq charset 'gnus-decoded)
      (mm-with-unibyte-buffer
	(mm-insert-part handle)
	(mm-decompress-buffer
         (mm-handle-filename handle)
	 t t)
	(unless charset
	  (setq coding-system (mm-find-buffer-file-coding-system)))
	(setq text (buffer-string))))
    (with-temp-buffer
      (setq untrusted-content t)
      (insert (cond ((eq charset 'gnus-decoded)
		     (with-current-buffer (mm-handle-buffer handle)
		       (buffer-string)))
		    (coding-system
		     (decode-coding-string text coding-system))
                    (t
                     (mm-decode-string text (or charset 'undecided)))))
      (let ((font-lock-verbose nil)     ; font-lock is a bit too verbose.
	    (enable-local-variables nil))
        ;; We used to set font-lock-mode-hook to nil to avoid enabling
        ;; support modes, but now that we use font-lock-ensure, support modes
        ;; aren't a problem any more.  So we could probably get rid of this
        ;; setting now, but it seems harmless and potentially still useful.
	(setq-local font-lock-mode-hook nil)
        (setq buffer-file-name (mm-handle-filename handle))
	(with-demoted-errors "Error setting mode: %S"
	  (if mode
              (save-window-excursion
                ;; According to Katsumi Yamaoka <yamaoka@jpl.org>, org-mode
                ;; requires the buffer to be temporarily displayed here, but
                ;; I could not reproduce this problem.  Furthermore, if
                ;; there's such a problem, we should fix org-mode rather than
                ;; use switch-to-buffer which can have undesirable
                ;; side-effects!
                ;;(switch-to-buffer (current-buffer))
                (funcall mode))
	    (let ((auto-mode-alist
		   (delq (rassq 'doc-view-mode-maybe auto-mode-alist)
			 (copy-sequence auto-mode-alist))))
	      ;; Don't run hooks that might assume buffer-file-name
	      ;; really associates buffer with a file (bug#39190).
	      (delay-mode-hooks (set-auto-mode))
	      (setq mode major-mode)))
	  ;; Do not fontify if the guess mode is fundamental.
	  (when (and (not (eq major-mode 'fundamental-mode))
		     mm-inline-font-lock)
	    (font-lock-ensure))))
      (setq text (buffer-string))
      (when (eq mode 'diff-mode)
	(setq ovs (mapcar (lambda (ov) (list ov (overlay-start ov)
                                                (overlay-end ov)))
                          (overlays-in (point-min) (point-max)))))
      ;; Set buffer unmodified to avoid confirmation when killing the
      ;; buffer.
      (set-buffer-modified-p nil))
    (let ((b (- (point) (save-restriction (widen) (point-min)))))
      (mm-insert-inline handle text)
      (dolist (ov ovs)
	(move-overlay (nth 0 ov) (+ (nth 1 ov) b)
                                 (+ (nth 2 ov) b) (current-buffer))))))