1 ;; iso-sgml.el --- display SGML entity references as ISO 8859-1 characters
3 ;; Copyright (C) 1994 Frederic Lepied
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
10 ;; Last Modified By: Frederic Lepied [STERIA SIT] 69577103
11 ;; Last Modified On: Wed Dec 7 10:14:41 1994
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|
19 ;; $Id: iso-sgml.el,v 1.1.1.1 1998/01/14 06:37:10 steve Exp $
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)
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.
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.
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>
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
51 ;; add the following line to your .emacs :
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))
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")
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.")
67 (defun isosgml-translate-conventions (trans-tab)
68 "Use the translation table argument to translate the current buffer."
70 (let ((beg (point-min-marker)) ; see the `(elisp)Narrowing' Info node
71 (end (point-max-marker)))
75 (goto-char (point-min))
76 (let ((buffer-read-only nil) ; (inhibit-read-only t)?
77 (case-fold-search nil))
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)))))
86 (defvar sgml2iso-trans-tab
193 "Translation table from SGML entity references to ISO 8859-1 characters.")
195 (defun fix-sgml2iso ()
196 "Replace SGML entity references with ISO 8859-1 (aka Latin-1) characters."
198 (if (member major-mode isosgml-modes-list)
199 (let ((buffer-modified-p (buffer-modified-p)))
201 (isosgml-translate-conventions sgml2iso-trans-tab)
202 (set-buffer-modified-p buffer-modified-p)))))
204 (defvar iso2sgml-trans-tab
205 (mapcar (function (lambda (entity-char) ; (ENTITY CHAR)
206 ;; Return (CHAR ENTITY)
207 (list (car (cdr entity-char))
210 "Translation table from ISO 8859-1 characters to SGML entity references.")
212 (defun fix-iso2sgml ()
213 "Replace ISO 8859-1 (aka Latin-1) characters with SGML entity references."
215 (if (member major-mode isosgml-modes-list)
216 (let ((buffer-modified-p (buffer-modified-p)))
218 (isosgml-translate-conventions iso2sgml-trans-tab)
219 (set-buffer-modified-p buffer-modified-p)))))
222 (add-hook 'find-file-hooks 'fix-sgml2iso)
223 (add-hook 'write-file-hooks 'fix-iso2sgml)
224 (add-hook 'after-save-hook 'fix-sgml2iso)
228 ;; iso-sgml.el ends here
230 ; $Log: iso-sgml.el,v $
231 ; Revision 1.1.1.1 1998/01/14 06:37:10 steve
234 ; Revision 1.4 1995/05/10 06:19:41 lepied
235 ; * protect code with unwind-protect to prevent errors
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
242 ; Revision 1.2 1994/11/24 06:49:08 lepied
243 ; Integrated patch from kevinr@ihs.com (Kevin Rodgers) :
245 ; * iso-sgml.el (sgml2iso-trans-tab): Delete backslash (`\') from
246 ; "±" entity reference.
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);
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.
258 ; * iso-sgml.el (iso2sgml-trans-tab): Initialize by
259 ; programmatically reversing elements of sgml2iso-trans-tab,
260 ; instead of hand-coding each element.
262 ; Revision 1.1 1994/06/22 15:15:13 lepied