Remove non-free old and crusty clearcase pkg
[packages] / xemacs-packages / psgml / iso-sgml.el
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 1998/01/14 06:37:10 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 ;; Modified for XEmacs 19.15 to include the proposed extensions to Latin-1
41 ;;  by Steve Baur <steve@xemacs.org>
42
43 ;; SEE ALSO:
44 ;; iso-cvt.el
45 ;; If you are interested in questions related to using the ISO 8859-1 
46 ;; characters set (configuring emacs, Unix, etc. to use ISO), then you
47 ;; can get the ISO 8859-1 FAQ via anonymous ftp from 
48 ;; ftp.vlsivie.tuwien.ac.at in /pub/bit/FAQ-ISO-8859-1
49
50 ;; INSTALLATION:
51 ;; add the following line to your .emacs :
52 ;; (load "iso-sgml")
53 ;; If you want it to work with other modes change the value of the
54 ;; the variable isosgml-modes-list like this :
55 ;; (setq isosgml-modes-list '(my-mode))
56
57 ;; Code:
58
59 (defconst isosgml-version "$Id: iso-sgml.el,v 1.1.1.1 1998/01/14 06:37:10 steve Exp $"
60   "iso-sgml RCS version number")
61
62 (defvar isosgml-modes-list '(html-mode html-helper-mode sgml-mode)
63   "*List of modes to translate between SGML or HTML entity references
64  and the ISO 8859-1 character set.")
65
66
67 (defun isosgml-translate-conventions (trans-tab)
68   "Use the translation table argument to translate the current buffer."
69   (save-excursion
70     (let ((beg (point-min-marker))    ; see the `(elisp)Narrowing' Info node
71           (end (point-max-marker)))
72       (unwind-protect
73           (progn
74             (widen)
75             (goto-char (point-min))
76             (let ((buffer-read-only nil) ; (inhibit-read-only t)?
77                   (case-fold-search nil))
78               (while trans-tab
79                 (save-excursion
80                   (let ((trans-this (car trans-tab)))
81                     (while (search-forward (car trans-this) nil t)
82                       (replace-match (car (cdr trans-this)) t t)))
83                   (setq trans-tab (cdr trans-tab))))))
84         (narrow-to-region beg end)))))
85
86 (defvar sgml2iso-trans-tab
87   '(
88     ("&AElig\;"  "Æ")
89     ("&Aacute\;"  "Á")
90     ("&Acirc\;"  "Â")
91     ("&Agrave\;"  "À")
92     ("&Atilde\;"  "Ã")
93     ("&Ccedil\;"  "Ç")
94     ("&Eacute\;"  "É")
95     ("&Egrave\;"  "È")
96     ("&Euml\;"  "Ë")
97     ("&Iacute\;"  "Í")
98     ("&Icirc\;"  "Î")
99     ("&Igrave\;"  "Ì")
100     ("&Iuml\;"  "Ï")
101     ("&Ntilde\;"  "Ñ")
102     ("&Oacute\;"  "Ó")
103     ("&Ocirc\;"  "Ô")
104     ("&Ograve\;"  "Ò")
105     ("&Oslash\;"  "Ø")
106     ("&Uacute\;"  "Ú")
107     ("&Ugrave\;"  "Ù")
108     ("&Yacute\;"  "Ý")
109     ("&aacute\;"  "á")
110     ("&acirc\;"  "â")
111     ("&acute\;" "´")
112     ("&aelig\;"  "æ")
113     ("&agrave\;"  "à")
114     ("&aring\;"  "å")
115     ("&atilde\;"  "ã")
116     ("&brvbar\;" "¦")
117     ("&ccedil\;"  "ç")
118     ("&cedil\;" "¸")
119     ("&cent\;" "¢")
120     ("&copy\;" "©")
121     ("&curren\;" "¤")
122     ("&deg\;" "°")
123     ("&eacute\;"  "é")
124     ("&ecirc\;"  "ê")
125     ("&egrave\;"  "è")
126     ("&euml\;"  "ë")
127     ("&frac12\;" "½")
128     ("&frac14\;" "¼")
129     ("&frac34\;" "¾")
130     ("&iacute\;"  "í")
131     ("&icirc\;"  "î")
132     ("&igrave\;"  "ì")
133     ("&iexcl\;" "¡")
134     ("&iquest\;" "¿")
135     ("&iuml\;"  "ï")
136     ("&laquo\;" "«")
137     ("&macr\;" "¯")
138     ("&micro\;" "µ")
139     ("&middot\;" "·")
140     ("&nbsp\;" " ")
141     ("&not\;" "¬")
142     ("&ntilde\;"  "ñ")
143     ("&oacute\;"  "ó")
144     ("&ocirc\;"  "ô")
145     ("&ograve\;"  "ò")
146     ("&ordf\;" "ª")
147     ("&ordm\;" "º")
148     ("&oslash\;"  "ø")
149     ("&otilde\;"  "õ")
150     ("&para\;" "¶")
151     ("&pound\;" "£")
152     ("&plusmn\;" "±")
153     ("&laquo\;" "»")
154     ("&reg\;" "®")
155     ("&sect\;" "§")
156     ("&shy\;" "­")
157     ("&sup1\;" "¹")
158     ("&sup2\;" "²")
159     ("&sup2\;" "³")
160     ("&uacute\;"  "ú")
161     ("&ucirc\;"  "û")
162     ("&ugrave\;"  "ù")
163     ("&uml\;" "¨")
164     ("&yacute\;"  "ý")
165     ("&yen\;" "¥")
166     ("&Auml\;"  "Ä")
167     ("&auml\;"  "ä")
168     ("&Ouml\;"  "Ö")
169     ("&ouml\;"  "ö")
170     ("&Uuml\;"  "Ü")
171     ("&uuml\;"  "ü")
172     ("&szlig\;"  "ß")
173     ("&sect\;"  "§")
174     ("&para\;"  "¶")
175     ("&copy\;"  "©")
176     ("&iexcl\;"  "¡")
177     ("&iquest\;"  "¿")
178     ("&cent\;"  "¢")
179     ("&pound\;"  "£")
180     ("&times\;"  "×")
181     ("&plusmn\;"  "±")
182     ("&divide\;"  "÷")
183     ("&not\;"  "¬")
184     ("&mu\;"  "µ")
185     ("&Ae\;"  "Ä")
186     ("&ae\;"  "ä")
187     ("&Oe\;"  "Ö")
188     ("&oe\;"  "ö")
189     ("&Ue\;"  "Ü")
190     ("&ue\;"  "ü")
191     ("&sz\;"  "ß")
192    )
193   "Translation table from SGML entity references to ISO 8859-1 characters.")
194
195 (defun fix-sgml2iso ()
196   "Replace SGML entity references with ISO 8859-1 (aka Latin-1) characters."
197   (interactive)
198   (if (member major-mode isosgml-modes-list)
199       (let ((buffer-modified-p (buffer-modified-p)))
200           (unwind-protect
201               (isosgml-translate-conventions sgml2iso-trans-tab)
202             (set-buffer-modified-p buffer-modified-p)))))
203
204 (defvar iso2sgml-trans-tab
205   (mapcar (function (lambda (entity-char) ; (ENTITY CHAR)
206                       ;; Return (CHAR ENTITY)
207                       (list (car (cdr entity-char))
208                             (car entity-char))))
209           sgml2iso-trans-tab)
210    "Translation table from ISO 8859-1 characters to SGML entity references.")
211
212 (defun fix-iso2sgml ()
213   "Replace ISO 8859-1 (aka Latin-1) characters with SGML entity references."
214   (interactive)
215   (if (member major-mode isosgml-modes-list)
216       (let ((buffer-modified-p (buffer-modified-p)))
217           (unwind-protect
218               (isosgml-translate-conventions iso2sgml-trans-tab)
219             (set-buffer-modified-p buffer-modified-p)))))
220
221
222 (add-hook 'find-file-hooks 'fix-sgml2iso)
223 (add-hook 'write-file-hooks 'fix-iso2sgml)
224 (add-hook 'after-save-hook 'fix-sgml2iso)
225
226 (provide 'iso-sgml)
227
228 ;; iso-sgml.el ends here
229
230 ; $Log: iso-sgml.el,v $
231 ; Revision 1.1.1.1  1998/01/14 06:37:10  steve
232 ; Created
233 ;
234 ; Revision 1.4  1995/05/10  06:19:41  lepied
235 ;       * protect code with unwind-protect to prevent errors
236 ;
237 ; Revision 1.3  1994/12/07  09:08:07  lepied
238 ; Thanks to kevinr@ihs.com (Kevin Rodgers)
239 ;       * replace regular expression search with normal one
240 ;       * cleanup interactive use
241 ;
242 ; Revision 1.2  1994/11/24  06:49:08  lepied
243 ; Integrated patch from kevinr@ihs.com (Kevin Rodgers) :
244 ;
245 ;       * iso-sgml.el (sgml2iso-trans-tab): Delete backslash (`\') from
246 ;       "&plusmn;" entity reference.
247 ;
248 ;       * iso-sgml.el (file header, library header (Keywords), LCD
249 ;       Archive Entry (description) [comment blocks]): Properly refer to
250 ;       SGML entity references; uppercase acronyms (ISO, SGML, HTML);
251 ;       capitalize Latin.
252 ;       (Commentary [comment block]): Rewrite as a complete sentence.
253 ;       (sgml2iso-trans-tab, fix-sgml2iso [doc strings]): Properly refer
254 ;       to SGML entity references.
255 ;       (iso2sgml-trans-tab, fix-iso2sgml [doc strings]): Properly refer
256 ;       to SGML entity references.
257 ;
258 ;       * iso-sgml.el (iso2sgml-trans-tab): Initialize by
259 ;       programmatically reversing elements of sgml2iso-trans-tab,
260 ;       instead of hand-coding each element.
261 ;
262 ; Revision 1.1  1994/06/22  15:15:13  lepied
263 ; Initial revision
264 ;