annotate lisp/apel/tinyrich.el @ 177:6075d714658b r20-3b15

Import from CVS: tag r20-3b15
author cvs
date Mon, 13 Aug 2007 09:51:16 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
177
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
1 ;;;
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
2 ;;; $Id: tinyrich.el,v 1.2 1997/07/26 22:09:38 steve Exp $
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
3 ;;;
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
4 ;;; by MORIOKA Tomohiko <morioka@jaist.ac.jp>
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
5 ;;; modified by YAMATE Keiichirou <ics9118@sem1.info.osaka-cu.ac.jp>
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
6 ;;;
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
7
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
8 (defvar mime-viewer/face-list-for-text/enriched
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
9 (cond ((and (>= emacs-major-version 19) window-system)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
10 '(bold italic fixed underline)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
11 )
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
12 ((and (boundp 'NEMACS) NEMACS)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
13 '("bold" "italic" "underline")
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
14 )))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
15
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
16 (defun enriched-decode (beg end)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
17 (interactive "*r")
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
18 (save-excursion
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
19 (save-restriction
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
20 (narrow-to-region beg end)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
21 (goto-char beg)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
22 (while (re-search-forward "[ \t]*\\(\n+\\)[ \t]*" nil t)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
23 (let ((str (buffer-substring (match-beginning 1)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
24 (match-end 1))))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
25 (if (string= str "\n")
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
26 (replace-match " ")
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
27 (replace-match (substring str 1))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
28 )))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
29 (goto-char beg)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
30 (let (cmd sym str (fb (point)) fe b e)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
31 (while (re-search-forward "<\\(<\\|[^<>\n\r \t]+>\\)" nil t)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
32 (setq b (match-beginning 0))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
33 (setq cmd (buffer-substring b (match-end 0)))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
34 (if (string= cmd "<<")
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
35 (replace-match "<")
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
36 (replace-match "")
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
37 (setq cmd (downcase (substring cmd 1 (- (length cmd) 1))))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
38 )
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
39 (setq sym (intern cmd))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
40 (cond ((eq sym 'param)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
41 (setq b (point))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
42 (save-excursion
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
43 (save-restriction
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
44 (if (search-forward "</param>" nil t)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
45 (progn
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
46 (replace-match "")
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
47 (setq e (point))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
48 )
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
49 (setq e end)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
50 )))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
51 (delete-region b e)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
52 )
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
53 ((memq sym mime-viewer/face-list-for-text/enriched)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
54 (setq b (point))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
55 (save-excursion
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
56 (save-restriction
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
57 (if (re-search-forward (concat "</" cmd ">") nil t)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
58 (progn
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
59 (replace-match "")
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
60 (setq e (point))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
61 )
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
62 (setq e end)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
63 )))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
64 (tm:set-face-region b e sym)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
65 )))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
66 (goto-char (point-max))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
67 (if (not (eq (preceding-char) ?\n))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
68 (insert "\n")
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
69 )
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
70 ))))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
71
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
72
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
73 ;;; @ text/richtext <-> text/enriched converter
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
74 ;;;
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
75
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
76 (defun richtext-to-enriched-region (beg end)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
77 "Convert the region of text/richtext style to text/enriched style."
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
78 (save-excursion
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
79 (save-restriction
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
80 (narrow-to-region beg end)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
81 (goto-char (point-min))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
82 (let (b e i)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
83 (while (re-search-forward "[ \t]*<comment>" nil t)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
84 (setq b (match-beginning 0))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
85 (delete-region b
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
86 (if (re-search-forward "</comment>[ \t]*" nil t)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
87 (match-end 0)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
88 (point-max)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
89 ))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
90 )
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
91 (goto-char (point-min))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
92 (while (re-search-forward "\n\n+" nil t)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
93 (replace-match "\n")
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
94 )
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
95 (goto-char (point-min))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
96 (while (re-search-forward "[ \t\n]*<nl>[ \t\n]*" nil t)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
97 (setq b (match-beginning 0))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
98 (setq e (match-end 0))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
99 (setq i 1)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
100 (while (looking-at "[ \t\n]*<nl>[ \t\n]*")
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
101 (setq e (match-end 0))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
102 (setq i (1+ i))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
103 (goto-char e)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
104 )
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
105 (delete-region b e)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
106 (while (>= i 0)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
107 (insert "\n")
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
108 (setq i (1- i))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
109 ))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
110 (goto-char (point-min))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
111 (while (search-forward "<lt>" nil t)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
112 (replace-match "<<")
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
113 )
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
114 ))))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
115
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
116 (defun enriched-to-richtext-region (beg end)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
117 "Convert the region of text/enriched style to text/richtext style."
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
118 (save-excursion
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
119 (save-restriction
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
120 (goto-char beg)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
121 (and (search-forward "text/enriched")
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
122 (replace-match "text/richtext"))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
123 (search-forward "\n\n")
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
124 (narrow-to-region (match-end 0) end)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
125 (let (str n)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
126 (goto-char (point-min))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
127 (while (re-search-forward "\n\n+" nil t)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
128 (setq str (buffer-substring (match-beginning 0)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
129 (match-end 0)))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
130 (setq n (1- (length str)))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
131 (setq str "")
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
132 (while (> n 0)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
133 (setq str (concat str "<nl>\n"))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
134 (setq n (1- n))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
135 )
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
136 (replace-match str)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
137 )
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
138 (goto-char (point-min))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
139 (while (search-forward "<<" nil t)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
140 (replace-match "<lt>")
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
141 )
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
142 ))))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
143
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
144
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
145 ;;; @ encoder and decoder
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
146 ;;;
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
147
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
148 (defun richtext-decode (beg end)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
149 (save-restriction
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
150 (narrow-to-region beg end)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
151 (richtext-to-enriched-region beg (point-max))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
152 (enriched-decode beg (point-max))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
153 ))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
154
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
155 ;; (defun richtext-encode (beg end)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
156 ;; (save-restriction
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
157 ;; (narrow-to-region beg end)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
158 ;; (enriched-encode beg (point-max))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
159 ;; (enriched-to-richtext-region beg (point-max))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
160 ;; ))
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
161
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
162
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
163 ;;; @ end
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
164 ;;;
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
165
6075d714658b Import from CVS: tag r20-3b15
cvs
parents:
diff changeset
166 (provide 'tinyrich)