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 (for use in `format-alist')."
89 (iso-translate-conventions from to iso-spanish-trans-tab
))
91 (defvar iso-aggressive-german-trans-tab
102 "German translation table.
103 This table uses an aggressive translation approach and may erroneously
104 translate too much.")
106 (defvar iso-conservative-german-trans-tab
108 ("\\([-a-zA-Z\"`]\\)\"a" "\\1ä")
109 ("\\([-a-zA-Z\"`]\\)\"A" "\\1Ä")
110 ("\\([-a-zA-Z\"`]\\)\"o" "\\1ö")
111 ("\\([-a-zA-Z\"`]\\)\"O" "\\1Ö")
112 ("\\([-a-zA-Z\"`]\\)\"u" "\\1ü")
113 ("\\([-a-zA-Z\"`]\\)\"U" "\\1Ü")
114 ("\\([-a-zA-Z\"`]\\)\"s" "\\1ß")
115 ("\\([-a-zA-Z\"`]\\)\\\\3" "\\1ß")
117 "German translation table.
118 This table uses a conservative translation approach and may translate too
121 (defvar iso-german-trans-tab iso-aggressive-german-trans-tab
122 "Currently active translation table for German.")
125 (defun iso-german (from to
&optional buffer
)
126 "Translate net conventions for German to ISO 8859-1.
127 The region between FROM and TO is translated using the table TRANS-TAB.
128 Optional arg BUFFER is ignored (for use in `format-alist')."
130 (iso-translate-conventions from to iso-german-trans-tab
))
132 (defvar iso-iso2tex-trans-tab
143 ("ï" "{\\\\\"\\\\i}")
187 ("\251" "{\\\\copyright}")
194 "Translation table for translating ISO 8859-1 characters to TeX sequences.")
197 (defun iso-iso2tex (from to
&optional buffer
)
198 "Translate ISO 8859-1 characters to TeX sequences.
199 The region between FROM and TO is translated using the table TRANS-TAB.
200 Optional arg BUFFER is ignored (for use in `format-alist')."
202 (iso-translate-conventions from to iso-iso2tex-trans-tab
))
204 (defvar iso-tex2iso-trans-tab
215 ("{\\\\\"\\\\i}" "ï")
317 ("\\\\\"{\\\\i}" "ï")
365 ("{\\\\copyright}" "\251")
366 ("\\\\copyright{}" "\251")
367 ("{\\\\pounds}" "£" )
370 ("\\\\pounds{}" "£" )
378 "Translation table for translating TeX sequences to ISO 8859-1 characters.
379 This table is not exhaustive (and due to TeX's power can never be). It only
380 contains commonly used sequences.")
383 (defun iso-tex2iso (from to
&optional buffer
)
384 "Translate TeX sequences to ISO 8859-1 characters.
385 The region between FROM and TO is translated using the table TRANS-TAB.
386 Optional arg BUFFER is ignored (for use in `format-alist')."
388 (iso-translate-conventions from to iso-tex2iso-trans-tab
))
390 (defvar iso-gtex2iso-trans-tab
401 ("{\\\\\"\\\\i}" "ï")
503 ("\\\\\"{\\\\i}" "ï")
551 ("{\\\\copyright}" "\251")
552 ("\\\\copyright{}" "\251")
553 ("{\\\\pounds}" "£" )
556 ("\\\\pounds{}" "£" )
572 "Translation table for translating German TeX sequences to ISO 8859-1.
573 This table is not exhaustive (and due to TeX's power can never be). It only
574 contains commonly used sequences.")
576 (defvar iso-iso2gtex-trans-tab
587 ("ï" "{\\\\\"\\\\i}")
631 ("\251" "{\\\\copyright}")
638 "Translation table for translating ISO 8859-1 characters to German TeX.")
641 (defun iso-gtex2iso (from to
&optional buffer
)
642 "Translate German TeX sequences to ISO 8859-1 characters.
643 The region between FROM and TO is translated using the table TRANS-TAB.
644 Optional arg BUFFER is ignored (for use in `format-alist')."
646 (iso-translate-conventions from to iso-gtex2iso-trans-tab
))
649 (defun iso-iso2gtex (from to
&optional buffer
)
650 "Translate ISO 8859-1 characters to German TeX sequences.
651 The region between FROM and TO is translated using the table TRANS-TAB.
652 Optional arg BUFFER is ignored (for use in `format-alist')."
654 (iso-translate-conventions from to iso-iso2gtex-trans-tab
))
656 (defvar iso-iso2duden-trans-tab
666 (defun iso-iso2duden (from to
&optional buffer
)
667 "Translate ISO 8859-1 characters to German TeX sequences.
668 The region between FROM and TO is translated using the table TRANS-TAB.
669 Optional arg BUFFER is ignored (for use in `format-alist')."
671 (iso-translate-conventions from to iso-iso2duden-trans-tab
))
673 (defvar iso-iso2sgml-trans-tab
737 (defvar iso-sgml2iso-trans-tab
802 (defun iso-iso2sgml (from to
&optional buffer
)
803 "Translate ISO 8859-1 characters in the region to SGML entities.
804 The entities used are from \"ISO 8879:1986//ENTITIES Added Latin 1//EN\".
805 Optional arg BUFFER is ignored (for use in `format-alist')."
807 (iso-translate-conventions from to iso-iso2sgml-trans-tab
))
810 (defun iso-sgml2iso (from to
&optional buffer
)
811 "Translate SGML entities in the region to ISO 8859-1 characters.
812 The entities used are from \"ISO 8879:1986//ENTITIES Added Latin 1//EN\".
813 Optional arg BUFFER is ignored (for use in `format-alist')."
815 (iso-translate-conventions from to iso-sgml2iso-trans-tab
))
818 (defun iso-cvt-read-only ()
819 "Warn that format is read-only."
821 (error "This format is read-only; specify another format for writing"))
824 (defun iso-cvt-write-only ()
825 "Warn that format is write-only."
827 (error "This format is write-only"))
830 (defun iso-cvt-define-menu ()
831 "Add submenus to the Files menu, to convert to and from various formats."
834 (define-key menu-bar-files-menu
[load-as-separator
] '("--"))
836 (define-key menu-bar-files-menu
[load-as
] '("Load As..." . load-as
))
837 (defvar load-as-menu-map
(make-sparse-keymap "Load As..."))
838 (fset 'load-as load-as-menu-map
)
840 ;;(define-key menu-bar-files-menu [insert-as] '("Insert As..." . insert-as))
841 (defvar insert-as-menu-map
(make-sparse-keymap "Insert As..."))
842 (fset 'insert-as insert-as-menu-map
)
844 (define-key menu-bar-files-menu
[write-as
] '("Write As..." . write-as
))
845 (defvar write-as-menu-map
(make-sparse-keymap "Write As..."))
846 (fset 'write-as write-as-menu-map
)
848 (define-key menu-bar-files-menu
[translate-separator
] '("--"))
850 (define-key menu-bar-files-menu
[translate-to
] '("Translate to..." . translate-to
))
851 (defvar translate-to-menu-map
(make-sparse-keymap "Translate to..."))
852 (fset 'translate-to translate-to-menu-map
)
854 (define-key menu-bar-files-menu
[translate-from
] '("Translate from..." . translate-from
))
855 (defvar translate-from-menu-map
(make-sparse-keymap "Translate from..."))
856 (fset 'translate-from translate-from-menu-map
)
858 (let ((file-types (reverse format-alist
))
862 (setq name
(car (car file-types
))
863 str-name
(car (cdr (car file-types
)))
864 file-types
(cdr file-types
))
865 (if (stringp str-name
)
867 (define-key load-as-menu-map
(vector name
)
870 (interactive (format "FFind file (as %s): " ,name
))
871 (format-find-file file
',name
))))
872 (define-key insert-as-menu-map
(vector name
)
875 (interactive (format "FInsert file (as %s): " ,name
))
876 (format-insert-file file
',name
))))
877 (define-key write-as-menu-map
(vector name
)
880 (interactive (format "FWrite file (as %s): " ,name
))
881 (format-write-file file
',name
))))
882 (define-key translate-to-menu-map
(vector name
)
886 (format-encode-buffer ',name
))))
887 (define-key translate-from-menu-map
(vector name
)
891 (format-decode-buffer ',name
)))))))))
895 ;;; iso-cvt.el ends here