1 ;;; iso-cvt.-el -- translate ISO 8859-1 from/to various encodings -*- coding: iso-latin-1 -*-
2 ;; This file was formerly called gm-lingo.el.
4 ;; Copyright (C) 1993, 1994, 1995, 1996, 1998, 2000 Free Software Foundation, Inc.
6 ;; Author: Michael Gschwind <mike@vlsivie.tuwien.ac.at>
7 ;; Keywords: tex, iso, latin, i18n
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
27 ;; This lisp code is a general framework for translating various
28 ;; representations of the same data.
29 ;; among other things it can be used to translate TeX, HTML, and compressed
30 ;; files to ISO 8859-1. It can also be used to translate different charsets
31 ;; such as IBM PC, Macintosh or HP Roman8.
32 ;; Note that many translations use the GNU recode tool to do the actual
33 ;; conversion. So you might want to install that tool to get the full
34 ;; benefit of iso-cvt.el
37 ; Cover more cases for translation. (There is an infinite number of ways to
38 ; represent accented characters in TeX)
41 ; If you are interested in questions related to using the ISO 8859-1
42 ; characters set (configuring emacs, Unix, etc. to use ISO), then you
43 ; can get the ISO 8859-1 FAQ via anonymous ftp from
44 ; ftp.vlsivie.tuwien.ac.at in /pub/8bit/FAQ-ISO-8859-1
48 (defvar iso-spanish-trans-tab
51 ("\([a-zA-Z]\)#" "\\1ñ")
53 ("\\([-a-zA-Z\"`]\\)\"u" "\\1ü")
54 ("\\([-a-zA-Z\"`]\\)\"U" "\\1Ü")
55 ("\\([-a-zA-Z]\\)'o" "\\1ó")
56 ("\\([-a-zA-Z]\\)'O" "\\Ó")
57 ("\\([-a-zA-Z]\\)'e" "\\1é")
58 ("\\([-a-zA-Z]\\)'E" "\\1É")
59 ("\\([-a-zA-Z]\\)'a" "\\1á")
60 ("\\([-a-zA-Z]\\)'A" "\\1A")
61 ("\\([-a-zA-Z]\\)'i" "\\1í")
62 ("\\([-a-zA-Z]\\)'I" "\\1Í")
64 "Spanish translation table.")
66 (defun iso-translate-conventions (from to trans-tab)
67 "Use the translation table TRANS-TAB to translate the current buffer."
70 (narrow-to-region from to)
72 (let ((work-tab trans-tab)
73 (buffer-read-only nil)
74 (case-fold-search nil))
77 (let ((trans-this (car work-tab)))
78 (while (re-search-forward (car trans-this) nil t)
79 (replace-match (car (cdr trans-this)) t nil)))
80 (setq work-tab (cdr work-tab)))))
84 (defun iso-spanish (from to &optional buffer)
85 "Translate net conventions for Spanish to ISO 8859-1.
86 The region between FROM and TO is translated using the table TRANS-TAB.
87 Optional arg BUFFER is ignored (so that the function can can be used in
90 (iso-translate-conventions from to iso-spanish-trans-tab))
92 (defvar iso-aggressive-german-trans-tab
103 "German translation table.
104 This table uses an aggressive translation approach and may erroneously
105 translate too much.")
107 (defvar iso-conservative-german-trans-tab
109 ("\\([-a-zA-Z\"`]\\)\"a" "\\1ä")
110 ("\\([-a-zA-Z\"`]\\)\"A" "\\1Ä")
111 ("\\([-a-zA-Z\"`]\\)\"o" "\\1ö")
112 ("\\([-a-zA-Z\"`]\\)\"O" "\\1Ö")
113 ("\\([-a-zA-Z\"`]\\)\"u" "\\1ü")
114 ("\\([-a-zA-Z\"`]\\)\"U" "\\1Ü")
115 ("\\([-a-zA-Z\"`]\\)\"s" "\\1ß")
116 ("\\([-a-zA-Z\"`]\\)\\\\3" "\\1ß")
118 "German translation table.
119 This table uses a conservative translation approach and may translate too
122 (defvar iso-german-trans-tab iso-aggressive-german-trans-tab
123 "Currently active translation table for German.")
126 (defun iso-german (from to &optional buffer)
127 "Translate net conventions for German to ISO 8859-1.
128 The region between FROM and TO is translated using the table TRANS-TAB.
129 Optional arg BUFFER is ignored (so that the function can can be used in
132 (iso-translate-conventions from to iso-german-trans-tab))
134 (defvar iso-iso2tex-trans-tab
145 ("ï" "{\\\\\"\\\\i}")
189 ("\251" "{\\\\copyright}")
196 "Translation table for translating ISO 8859-1 characters to TeX sequences.")
199 (defun iso-iso2tex (from to &optional buffer)
200 "Translate ISO 8859-1 characters to TeX sequences.
201 The region between FROM and TO is translated using the table TRANS-TAB.
202 Optional arg BUFFER is ignored (so that the function can can be used in
205 (iso-translate-conventions from to iso-iso2tex-trans-tab))
207 (defvar iso-tex2iso-trans-tab
218 ("{\\\\\"\\\\i}" "ï")
320 ("\\\\\"{\\\\i}" "ï")
368 ("{\\\\copyright}" "\251")
369 ("\\\\copyright{}" "\251")
370 ("{\\\\pounds}" "£" )
373 ("\\\\pounds{}" "£" )
381 "Translation table for translating TeX sequences to ISO 8859-1 characters.
382 This table is not exhaustive (and due to TeX's power can never be). It only
383 contains commonly used sequences.")
386 (defun iso-tex2iso (from to &optional buffer)
387 "Translate TeX sequences to ISO 8859-1 characters.
388 The region between FROM and TO is translated using the table TRANS-TAB.
389 Optional arg BUFFER is ignored (so that the function can can be used in
392 (iso-translate-conventions from to iso-tex2iso-trans-tab))
394 (defvar iso-gtex2iso-trans-tab
405 ("{\\\\\"\\\\i}" "ï")
507 ("\\\\\"{\\\\i}" "ï")
555 ("{\\\\copyright}" "\251")
556 ("\\\\copyright{}" "\251")
557 ("{\\\\pounds}" "£" )
560 ("\\\\pounds{}" "£" )
576 "Translation table for translating German TeX sequences to ISO 8859-1.
577 This table is not exhaustive (and due to TeX's power can never be). It only
578 contains commonly used sequences.")
580 (defvar iso-iso2gtex-trans-tab
591 ("ï" "{\\\\\"\\\\i}")
635 ("\251" "{\\\\copyright}")
642 "Translation table for translating ISO 8859-1 characters to German TeX.")
645 (defun iso-gtex2iso (from to &optional buffer)
646 "Translate German TeX sequences to ISO 8859-1 characters.
647 The region between FROM and TO is translated using the table TRANS-TAB.
648 Optional arg BUFFER is ignored (so that the function can can be used in
651 (iso-translate-conventions from to iso-gtex2iso-trans-tab))
654 (defun iso-iso2gtex (from to &optional buffer)
655 "Translate ISO 8859-1 characters to German TeX sequences.
656 The region between FROM and TO is translated using the table TRANS-TAB.
657 Optional arg BUFFER is ignored (so that the function can can be used in
660 (iso-translate-conventions from to iso-iso2gtex-trans-tab))
662 (defvar iso-iso2duden-trans-tab
672 (defun iso-iso2duden (from to &optional buffer)
673 "Translate ISO 8859-1 characters to German TeX sequences.
674 The region between FROM and TO is translated using the table TRANS-TAB.
675 Optional arg BUFFER is ignored (so that the function can can be used in
678 (iso-translate-conventions from to iso-iso2duden-trans-tab))
680 (defvar iso-iso2sgml-trans-tab
744 (defvar iso-sgml2iso-trans-tab
809 (defun iso-iso2sgml (from to &optional buffer)
810 "Translate ISO 8859-1 characters in the region to SGML entities.
811 The entities used are from \"ISO 8879:1986//ENTITIES Added Latin 1//EN\".
812 Optional arg BUFFER is ignored (so that the function can can be used in
815 (iso-translate-conventions from to iso-iso2sgml-trans-tab))
818 (defun iso-sgml2iso (from to &optional buffer)
819 "Translate SGML entities in the region to ISO 8859-1 characters.
820 The entities used are from \"ISO 8879:1986//ENTITIES Added Latin 1//EN\".
821 Optional arg BUFFER is ignored (so that the function can can be used in
824 (iso-translate-conventions from to iso-sgml2iso-trans-tab))
827 (defun iso-cvt-read-only ()
828 "Warn that format is read-only."
830 (error "This format is read-only; specify another format for writing"))
833 (defun iso-cvt-write-only ()
834 "Warn that format is write-only."
836 (error "This format is write-only"))
839 (defun iso-cvt-define-menu ()
840 "Add submenus to the Files menu, to convert to and from various formats."
843 (define-key menu-bar-files-menu [load-as-separator] '("--"))
845 (define-key menu-bar-files-menu [load-as] '("Load As..." . load-as))
846 (defvar load-as-menu-map (make-sparse-keymap "Load As..."))
847 (fset 'load-as load-as-menu-map)
849 ;;(define-key menu-bar-files-menu [insert-as] '("Insert As..." . insert-as))
850 (defvar insert-as-menu-map (make-sparse-keymap "Insert As..."))
851 (fset 'insert-as insert-as-menu-map)
853 (define-key menu-bar-files-menu [write-as] '("Write As..." . write-as))
854 (defvar write-as-menu-map (make-sparse-keymap "Write As..."))
855 (fset 'write-as write-as-menu-map)
857 (define-key menu-bar-files-menu [translate-separator] '("--"))
859 (define-key menu-bar-files-menu [translate-to] '("Translate to..." . translate-to))
860 (defvar translate-to-menu-map (make-sparse-keymap "Translate to..."))
861 (fset 'translate-to translate-to-menu-map)
863 (define-key menu-bar-files-menu [translate-from] '("Translate from..." . translate-from))
864 (defvar translate-from-menu-map (make-sparse-keymap "Translate from..."))
865 (fset 'translate-from translate-from-menu-map)
867 (let ((file-types (reverse format-alist))
871 (setq name (car (car file-types))
872 str-name (car (cdr (car file-types)))
873 file-types (cdr file-types))
874 (if (stringp str-name)
876 (define-key load-as-menu-map (vector name)
879 (interactive (format "FFind file (as %s): " ,name))
880 (format-find-file file ',name))))
881 (define-key insert-as-menu-map (vector name)
884 (interactive (format "FInsert file (as %s): " ,name))
885 (format-insert-file file ',name))))
886 (define-key write-as-menu-map (vector name)
889 (interactive (format "FWrite file (as %s): " ,name))
890 (format-write-file file ',name))))
891 (define-key translate-to-menu-map (vector name)
895 (format-encode-buffer ',name))))
896 (define-key translate-from-menu-map (vector name)
900 (format-decode-buffer ',name)))))))))
904 ;;; iso-cvt.el ends here