comparison lisp/psgml/iso-sgml.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
comparison
equal deleted inserted replaced
-1:000000000000 0:376386a54a3c
1 ;; iso-sgml.el --- display SGML entity references as ISO 8859-1 characters
2
3 ;; Copyright (C) 1994 Frederic Lepied
4
5 ;; Author: Frederic Lepied <lepied@cenaath.cena.dgac.fr>
6 ;; Maintainer: lepied@cenaath.cena.dgac.fr
7 ;; Keywords: SGML, HTML, ISO, Latin, i18n
8 ;; Status: Works with emacs 19.24
9 ;; Created: 1994-06-21
10 ;; Last Modified By: Frederic Lepied [STERIA SIT] 69577103
11 ;; Last Modified On: Wed Dec 7 10:14:41 1994
12 ;; Update Count: 5
13
14 ;; LCD Archive Entry:
15 ;; iso-sgml|Frederic Lepied|lepied@cenaath.cena.dgac.fr|
16 ;; Edit SGML or HTML buffers with ISO 8859-1 (Latin-1) display|
17 ;; 10-May-1995|1.4|~/misc/iso-sgml.el.Z|
18
19 ;; $Id: iso-sgml.el,v 1.1.1.1 1996/12/18 03:35:17 steve Exp $
20
21 ;; This program is free software; you can redistribute it and/or modify
22 ;; it under the terms of the GNU General Public License as published by
23 ;; the Free Software Foundation; either version 2, or (at your option)
24 ;; any later version.
25 ;;
26 ;; This program is distributed in the hope that it will be useful,
27 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
28 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 ;; GNU General Public License for more details.
30 ;;
31 ;; You should have received a copy of the GNU General Public License
32 ;; along with this program; if not, you can either send email to this
33 ;; program's maintainer or write to: The Free Software Foundation,
34 ;; Inc.; 675 Massachusetts Avenue; Cambridge, MA 02139, USA.
35
36 ;; Commentary:
37 ;; Based on iso-cvt.el from Michael Gschwind <mike@vlsivie.tuwien.ac.at>,
38 ;; iso-sgml.el transparently displays entity references in SGML or HTML
39 ;; buffers as ISO 8859-1 (aka Latin-1) characters.
40
41 ;; SEE ALSO:
42 ;; iso-cvt.el
43 ;; If you are interested in questions related to using the ISO 8859-1
44 ;; characters set (configuring emacs, Unix, etc. to use ISO), then you
45 ;; can get the ISO 8859-1 FAQ via anonymous ftp from
46 ;; ftp.vlsivie.tuwien.ac.at in /pub/bit/FAQ-ISO-8859-1
47
48 ;; INSTALLATION:
49 ;; add the following line to your .emacs :
50 ;; (load "iso-sgml")
51 ;; If you want it to work with other modes change the value of the
52 ;; the variable isosgml-modes-list like this :
53 ;; (setq isosgml-modes-list '(my-mode))
54
55 ;; Code:
56
57 (defconst isosgml-version "$Id: iso-sgml.el,v 1.1.1.1 1996/12/18 03:35:17 steve Exp $"
58 "iso-sgml RCS version number")
59
60 (defvar isosgml-modes-list '(html-mode html-helper-mode sgml-mode)
61 "*List of modes to translate between SGML or HTML entity references
62 and the ISO 8859-1 character set.")
63
64
65 (defun isosgml-translate-conventions (trans-tab)
66 "Use the translation table argument to translate the current buffer."
67 (save-excursion
68 (let ((beg (point-min-marker)) ; see the `(elisp)Narrowing' Info node
69 (end (point-max-marker)))
70 (unwind-protect
71 (progn
72 (widen)
73 (goto-char (point-min))
74 (let ((buffer-read-only nil) ; (inhibit-read-only t)?
75 (case-fold-search nil))
76 (while trans-tab
77 (save-excursion
78 (let ((trans-this (car trans-tab)))
79 (while (search-forward (car trans-this) nil t)
80 (replace-match (car (cdr trans-this)) t t)))
81 (setq trans-tab (cdr trans-tab))))))
82 (narrow-to-region beg end)))))
83
84 (defvar sgml2iso-trans-tab
85 '(
86 ("&AElig\;" "Æ")
87 ("&Aacute\;" "Á")
88 ("&Acirc\;" "Â")
89 ("&Agrave\;" "À")
90 ("&Atilde\;" "Ã")
91 ("&Ccedil\;" "Ç")
92 ("&Eacute\;" "É")
93 ("&Egrave\;" "È")
94 ("&Euml\;" "Ë")
95 ("&Iacute\;" "Í")
96 ("&Icirc\;" "Î")
97 ("&Igrave\;" "Ì")
98 ("&Iuml\;" "Ï")
99 ("&Ntilde\;" "Ñ")
100 ("&Oacute\;" "Ó")
101 ("&Ocirc\;" "Ô")
102 ("&Ograve\;" "Ò")
103 ("&Oslash\;" "Ø")
104 ("&Uacute\;" "Ú")
105 ("&Ugrave\;" "Ù")
106 ("&Yacute\;" "Ý")
107 ("&aacute\;" "á")
108 ("&acirc\;" "â")
109 ("&aelig\;" "æ")
110 ("&agrave\;" "à")
111 ("&aring\;" "å")
112 ("&atilde\;" "ã")
113 ("&ccedil\;" "ç")
114 ("&eacute\;" "é")
115 ("&ecirc\;" "ê")
116 ("&egrave\;" "è")
117 ("&euml\;" "ë")
118 ("&iacute\;" "í")
119 ("&icirc\;" "î")
120 ("&igrave\;" "ì")
121 ("&iuml\;" "ï")
122 ("&ntilde\;" "ñ")
123 ("&oacute\;" "ó")
124 ("&ocirc\;" "ô")
125 ("&ograve\;" "ò")
126 ("&oslash\;" "ø")
127 ("&otilde\;" "õ")
128 ("&uacute\;" "ú")
129 ("&ucirc\;" "û")
130 ("&ugrave\;" "ù")
131 ("&yacute\;" "ý")
132 ("&Auml\;" "Ä")
133 ("&auml\;" "ä")
134 ("&Ouml\;" "Ö")
135 ("&ouml\;" "ö")
136 ("&Uuml\;" "Ü")
137 ("&uuml\;" "ü")
138 ("&szlig\;" "ß")
139 ("&sect\;" "§")
140 ("&para\;" "¶")
141 ("&copy\;" "©")
142 ("&iexcl\;" "¡")
143 ("&iquest\;" "¿")
144 ("&cent\;" "¢")
145 ("&pound\;" "£")
146 ("&times\;" "×")
147 ("&plusmn\;" "±")
148 ("&divide\;" "÷")
149 ("&not\;" "¬")
150 ("&mu\;" "µ")
151 ("&Ae\;" "Ä")
152 ("&ae\;" "ä")
153 ("&Oe\;" "Ö")
154 ("&oe\;" "ö")
155 ("&Ue\;" "Ü")
156 ("&ue\;" "ü")
157 ("&sz\;" "ß")
158 )
159 "Translation table from SGML entity references to ISO 8859-1 characters.")
160
161 (defun fix-sgml2iso ()
162 "Replace SGML entity references with ISO 8859-1 (aka Latin-1) characters."
163 (interactive)
164 (if (member major-mode isosgml-modes-list)
165 (let ((buffer-modified-p (buffer-modified-p)))
166 (unwind-protect
167 (isosgml-translate-conventions sgml2iso-trans-tab)
168 (set-buffer-modified-p buffer-modified-p)))))
169
170 (defvar iso2sgml-trans-tab
171 (mapcar (function (lambda (entity-char) ; (ENTITY CHAR)
172 ;; Return (CHAR ENTITY)
173 (list (car (cdr entity-char))
174 (car entity-char))))
175 sgml2iso-trans-tab)
176 "Translation table from ISO 8859-1 characters to SGML entity references.")
177
178 (defun fix-iso2sgml ()
179 "Replace ISO 8859-1 (aka Latin-1) characters with SGML entity references."
180 (interactive)
181 (if (member major-mode isosgml-modes-list)
182 (let ((buffer-modified-p (buffer-modified-p)))
183 (unwind-protect
184 (isosgml-translate-conventions iso2sgml-trans-tab)
185 (set-buffer-modified-p buffer-modified-p)))))
186
187
188 (add-hook 'find-file-hooks 'fix-sgml2iso)
189 (add-hook 'write-file-hooks 'fix-iso2sgml)
190 (add-hook 'after-save-hook 'fix-sgml2iso)
191
192 (provide 'iso-sgml)
193
194 ;; iso-sgml.el ends here
195
196 ; $Log: iso-sgml.el,v $
197 ; Revision 1.1.1.1 1996/12/18 03:35:17 steve
198 ; XEmacs 19.14 -- Release
199 ;
200 ; Revision 1.4 1995/05/10 06:19:41 lepied
201 ; * protect code with unwind-protect to prevent errors
202 ;
203 ; Revision 1.3 1994/12/07 09:08:07 lepied
204 ; Thanks to kevinr@ihs.com (Kevin Rodgers)
205 ; * replace regular expression search with normal one
206 ; * cleanup interactive use
207 ;
208 ; Revision 1.2 1994/11/24 06:49:08 lepied
209 ; Integrated patch from kevinr@ihs.com (Kevin Rodgers) :
210 ;
211 ; * iso-sgml.el (sgml2iso-trans-tab): Delete backslash (`\') from
212 ; "&plusmn;" entity reference.
213 ;
214 ; * iso-sgml.el (file header, library header (Keywords), LCD
215 ; Archive Entry (description) [comment blocks]): Properly refer to
216 ; SGML entity references; uppercase acronyms (ISO, SGML, HTML);
217 ; capitalize Latin.
218 ; (Commentary [comment block]): Rewrite as a complete sentence.
219 ; (sgml2iso-trans-tab, fix-sgml2iso [doc strings]): Properly refer
220 ; to SGML entity references.
221 ; (iso2sgml-trans-tab, fix-iso2sgml [doc strings]): Properly refer
222 ; to SGML entity references.
223 ;
224 ; * iso-sgml.el (iso2sgml-trans-tab): Initialize by
225 ; programmatically reversing elements of sgml2iso-trans-tab,
226 ; instead of hand-coding each element.
227 ;
228 ; Revision 1.1 1994/06/22 15:15:13 lepied
229 ; Initial revision
230 ;