2 ;;; $Id: tinyrich.el,v 5.0 1995/09/20 14:45:56 morioka Exp $
4 ;;; by MORIOKA Tomohiko <morioka@jaist.ac.jp>
5 ;;; modified by YAMATE Keiichirou <ics9118@sem1.info.osaka-cu.ac.jp>
8 (defvar mime-viewer/face-list-for-text/enriched
9 (cond ((and (>= emacs-major-version 19) window-system)
10 '(bold italic fixed underline)
12 ((and (boundp 'NEMACS) NEMACS)
13 '("bold" "italic" "underline")
16 (defun enriched-decode (beg end)
20 (narrow-to-region beg end)
22 (while (re-search-forward "[ \t]*\\(\n+\\)[ \t]*" nil t)
23 (let ((str (buffer-substring (match-beginning 1)
25 (if (string= str "\n")
27 (replace-match (substring str 1))
30 (let (cmd sym str (fb (point)) fe b e)
31 (while (re-search-forward "<\\(<\\|[^<>\n\r \t]+>\\)" nil t)
32 (setq b (match-beginning 0))
33 (setq cmd (buffer-substring b (match-end 0)))
34 (if (string= cmd "<<")
37 (setq cmd (downcase (substring cmd 1 (- (length cmd) 1))))
39 (setq sym (intern cmd))
40 (cond ((eq sym 'param)
44 (if (search-forward "</param>" nil t)
53 ((memq sym mime-viewer/face-list-for-text/enriched)
57 (if (re-search-forward (concat "</" cmd ">") nil t)
64 (tm:set-face-region b e sym)
66 (goto-char (point-max))
67 (if (not (eq (preceding-char) ?\n))
73 ;;; @ text/richtext <-> text/enriched converter
76 (defun richtext-to-enriched-region (beg end)
77 "Convert the region of text/richtext style to text/enriched style."
80 (narrow-to-region beg end)
81 (goto-char (point-min))
83 (while (re-search-forward "[ \t]*<comment>" nil t)
84 (setq b (match-beginning 0))
86 (if (re-search-forward "</comment>[ \t]*" nil t)
91 (goto-char (point-min))
92 (while (re-search-forward "\n\n+" nil t)
95 (goto-char (point-min))
96 (while (re-search-forward "[ \t\n]*<nl>[ \t\n]*" nil t)
97 (setq b (match-beginning 0))
98 (setq e (match-end 0))
100 (while (looking-at "[ \t\n]*<nl>[ \t\n]*")
101 (setq e (match-end 0))
110 (goto-char (point-min))
111 (while (search-forward "<lt>" nil t)
116 (defun enriched-to-richtext-region (beg end)
117 "Convert the region of text/enriched style to text/richtext style."
121 (and (search-forward "text/enriched")
122 (replace-match "text/richtext"))
123 (search-forward "\n\n")
124 (narrow-to-region (match-end 0) end)
126 (goto-char (point-min))
127 (while (re-search-forward "\n\n+" nil t)
128 (setq str (buffer-substring (match-beginning 0)
130 (setq n (1- (length str)))
133 (setq str (concat str "<nl>\n"))
138 (goto-char (point-min))
139 (while (search-forward "<<" nil t)
140 (replace-match "<lt>")
145 ;;; @ encoder and decoder
148 (defun richtext-decode (beg end)
150 (narrow-to-region beg end)
151 (richtext-to-enriched-region beg (point-max))
152 (enriched-decode beg (point-max))
155 ;; (defun richtext-encode (beg end)
157 ;; (narrow-to-region beg end)
158 ;; (enriched-encode beg (point-max))
159 ;; (enriched-to-richtext-region beg (point-max))