Synch with the semi-1_14 branch.
[elisp/semi.git] / mime-w3.el
1 ;;; mime-w3.el --- mime-view content filter for text
2
3 ;; Copyright (C) 1994,1995,1996,1997,1998,1999 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: HTML, MIME, multimedia, mail, news
7
8 ;; This file is part of SEMI (Suite of Emacs MIME Interfaces).
9
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
14
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 ;; General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Code:
26
27 (require 'w3)
28 (require 'mime)
29
30 (eval-when-compile
31   (require 'poe))
32
33 (defun-maybe mime-find-root-entity (entity)
34   "Return root entity of entity"
35   (while (not (mime-root-entity-p entity))
36     (setq entity (mime-entity-parent entity)))
37   entity)
38
39 (defmacro mime-put-keymap-region (start end keymap)
40   `(put-text-property ,start ,end
41                       ',(if (featurep 'xemacs)
42                             'keymap
43                           'local-map)
44                       ,keymap))
45
46 (defmacro mime-save-background-color (&rest body)
47   (if (featurep 'xemacs)
48       `(let ((color (color-name (face-background 'default))))
49          (prog1
50              (progn ,@body)
51            (font-set-face-background 'default color (current-buffer))))
52     (cons 'progn body)))
53
54 (defun mime-preview-text/html (entity situation)
55   (goto-char (point-max))
56   (let ((p (point)))
57     (insert "\n")
58     (goto-char p)
59     (mime-save-background-color
60      (save-restriction
61        (narrow-to-region p p)
62        (mime-insert-text-content entity)
63        (run-hooks 'mime-text-decode-hook)
64        (condition-case err
65            (w3-region p (point-max))
66          (error (message (format "%s" err))))
67        (mime-put-keymap-region p (point-max) w3-mode-map)))))
68
69 (defun url-cid (url &optional proxy-info)
70   (let ((entity
71          (mime-find-entity-from-content-id (mime-uri-parse-cid url)
72                                            (mime-find-root-entity
73                                             (get-text-property
74                                              (point)
75                                              'mime-view-entity)))))
76     (when entity
77       (mime-insert-entity-content entity)
78       (setq url-current-mime-type (mime-entity-type/subtype entity)))))
79
80 (url-register-protocol "cid"
81                        'url-cid
82                        'url-identity-expander)
83
84
85 ;;; @ end
86 ;;;
87
88 (provide 'mime-w3)
89
90 ;;; mime-w3.el ends here