mm-view: font-lock based on filename
authorJulien Danjou <julien@danjou.info>
Mon, 21 Mar 2011 17:28:09 +0000 (18:28 +0100)
committerJulien Danjou <julien@danjou.info>
Mon, 21 Mar 2011 17:28:09 +0000 (18:28 +0100)
Signed-off-by: Julien Danjou <julien@danjou.info>
lisp/ChangeLog
lisp/mm-view.el

index 8f52c49..ec1bc75 100644 (file)
@@ -1,6 +1,11 @@
 2011-03-21  Julien Danjou  <julien@danjou.info>
 
 2011-03-21  Julien Danjou  <julien@danjou.info>
 
-       * mm-view.el (mm-display-inline-fontify):
+       * mm-view.el (mm-display-inline-fontify): Make mode optional, and call
+       normal-mode if not set. Set temp buffer unmodified to avoid kill-buffer
+       query.
+       (mm-inline-text): Render normal text with fontification whenever
+       possible.
+
        * gnus-sum.el (gnus-summary-save-parts-1):
        * gnus-art.el (gnus-article-browse-html-save-cid-content)
        (gnus-article-browse-html-parts, gnus-mime-delete-part)
        * gnus-sum.el (gnus-summary-save-parts-1):
        * gnus-art.el (gnus-article-browse-html-save-cid-content)
        (gnus-article-browse-html-parts, gnus-mime-delete-part)
index e8282ed..39d49af 100644 (file)
          (narrow-to-region (point) (point))
          (mm-insert-part handle)
          (goto-char (point-max)))
          (narrow-to-region (point) (point))
          (mm-insert-part handle)
          (goto-char (point-max)))
-      (insert (mm-decode-string (mm-get-part handle) charset)))
+      (mm-display-inline-fontify handle))
     (when (and mm-fill-flowed
               (equal type "plain")
               (equal (cdr (assoc 'format (mm-handle-type handle)))
     (when (and mm-fill-flowed
               (equal type "plain")
               (equal (cdr (assoc 'format (mm-handle-type handle)))
                     (face-property 'default prop) (current-buffer))))
              (delete-region ,(point-min-marker) ,(point-max-marker)))))))))
 
                     (face-property 'default prop) (current-buffer))))
              (delete-region ,(point-min-marker) ,(point-max-marker)))))))))
 
-(defun mm-display-inline-fontify (handle mode)
+(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)
     (unless (eq charset 'gnus-decoded)
   (let ((charset (mail-content-type-get (mm-handle-type handle) 'charset))
        text coding-system)
     (unless (eq charset 'gnus-decoded)
            (font-lock-support-mode nil)
            ;; I find font-lock a bit too verbose.
            (font-lock-verbose nil))
            (font-lock-support-mode nil)
            ;; I find font-lock a bit too verbose.
            (font-lock-verbose nil))
-       (funcall mode)
+        (setq buffer-file-name (mm-handle-filename handle))
+        (if mode
+            (funcall mode)
+          (normal-mode))
        ;; The mode function might have already turned on font-lock.
        (unless (symbol-value 'font-lock-mode)
          (font-lock-fontify-buffer)))
        ;; The mode function might have already turned on font-lock.
        (unless (symbol-value 'font-lock-mode)
          (font-lock-fontify-buffer)))
                       nil)
                     nil nil nil nil nil 'text-prop))
       (setq text (buffer-string))
                       nil)
                     nil nil nil nil nil 'text-prop))
       (setq text (buffer-string))
+      ;; Set buffer unmodified to avoid confirmation when killing the
+      ;; buffer.
+      (set-buffer-modified-p nil)
       (kill-buffer (current-buffer)))
     (mm-insert-inline handle text)))
 
       (kill-buffer (current-buffer)))
     (mm-insert-inline handle text)))