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, 1997, 1998, 2000, 2003, 2004
5 ;; Free Software Foundation, Inc.
7 ;; Author: Michael Gschwind <mike@vlsivie.tuwien.ac.at>
8 ;; Keywords: tex, iso, latin, i18n
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
28 ;; This lisp code is a general framework for translating various
29 ;; representations of the same data.
30 ;; among other things it can be used to translate TeX, HTML, and compressed
31 ;; files to ISO 8859-1. It can also be used to translate different charsets
32 ;; such as IBM PC, Macintosh or HP Roman8.
33 ;; Note that many translations use the GNU recode tool to do the actual
34 ;; conversion. So you might want to install that tool to get the full
35 ;; benefit of iso-cvt.el
38 ; Cover more cases for translation. (There is an infinite number of ways to
39 ; represent accented characters in TeX)
42 ; If you are interested in questions related to using the ISO 8859-1
43 ; characters set (configuring emacs, Unix, etc. to use ISO), then you
44 ; can get the ISO 8859-1 FAQ via anonymous ftp from
45 ; ftp.vlsivie.tuwien.ac.at in /pub/8bit/FAQ-ISO-8859-1
49 (defvar iso-spanish-trans-tab
52 ("\([a-zA-Z]\)#" "\\1ñ")
54 ("\\([-a-zA-Z\"`]\\)\"u" "\\1ü")
55 ("\\([-a-zA-Z\"`]\\)\"U" "\\1Ü")
56 ("\\([-a-zA-Z]\\)'o" "\\1ó")
57 ("\\([-a-zA-Z]\\)'O" "\\Ó")
58 ("\\([-a-zA-Z]\\)'e" "\\1é")
59 ("\\([-a-zA-Z]\\)'E" "\\1É")
60 ("\\([-a-zA-Z]\\)'a" "\\1á")
61 ("\\([-a-zA-Z]\\)'A" "\\1A")
62 ("\\([-a-zA-Z]\\)'i" "\\1í")
63 ("\\([-a-zA-Z]\\)'I" "\\1Í")
65 "Spanish translation table.")
67 (defun iso-translate-conventions (from to trans-tab
)
68 "Use the translation table TRANS-TAB to translate the current buffer."
71 (narrow-to-region from to
)
73 (let ((work-tab trans-tab
)
74 (buffer-read-only nil
)
75 (case-fold-search nil
))
78 (let ((trans-this (car work-tab
)))
79 (while (re-search-forward (car trans-this
) nil t
)
80 (replace-match (car (cdr trans-this
)) t nil
)))
81 (setq work-tab
(cdr work-tab
)))))
85 (defun iso-spanish (from to
&optional buffer
)
86 "Translate net conventions for Spanish to ISO 8859-1.
87 The region between FROM and TO is translated using the table TRANS-TAB.
88 Optional arg BUFFER is ignored (for use in `format-alist')."
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 (for use in `format-alist')."
131 (iso-translate-conventions from to iso-german-trans-tab
))
133 (defvar iso-iso2tex-trans-tab
144 ("ï" "{\\\\\"\\\\i}")
188 ("\251" "{\\\\copyright}")
195 "Translation table for translating ISO 8859-1 characters to TeX sequences.")
198 (defun iso-iso2tex (from to
&optional buffer
)
199 "Translate ISO 8859-1 characters to TeX sequences.
200 The region between FROM and TO is translated using the table TRANS-TAB.
201 Optional arg BUFFER is ignored (for use in `format-alist')."
203 (iso-translate-conventions from to iso-iso2tex-trans-tab
))
205 (defvar iso-tex2iso-trans-tab
216 ("{\\\\\"\\\\i}" "ï")
268 ;; Discard spaces and/or one EOF after macro \i.
269 ;; Converting it back will use braces.
270 ("\\\\\"\\\\i *\n\n" "ï\n\n")
271 ("\\\\\"\\\\i *\n?" "ï")
272 ("\\\\`\\\\i *\n\n" "ì\n\n")
273 ("\\\\`\\\\i *\n?" "ì")
274 ("\\\\'\\\\i *\n\n" "í\n\n")
275 ("\\\\'\\\\i *\n?" "í")
276 ("\\\\^\\\\i *\n\n" "î\n\n")
277 ("\\\\^\\\\i *\n?" "î")
324 ("\\\\\"{\\\\i}" "ï")
372 ("{\\\\copyright}" "\251")
373 ("\\\\copyright{}" "\251")
374 ("{\\\\pounds}" "£" )
377 ("\\\\pounds{}" "£" )
385 "Translation table for translating TeX sequences to ISO 8859-1 characters.
386 This table is not exhaustive (and due to TeX's power can never be). It only
387 contains commonly used sequences.")
390 (defun iso-tex2iso (from to
&optional buffer
)
391 "Translate TeX sequences to ISO 8859-1 characters.
392 The region between FROM and TO is translated using the table TRANS-TAB.
393 Optional arg BUFFER is ignored (for use in `format-alist')."
395 (iso-translate-conventions from to iso-tex2iso-trans-tab
))
397 (defvar iso-gtex2iso-trans-tab
408 ("{\\\\\"\\\\i}" "ï")
510 ("\\\\\"{\\\\i}" "ï")
558 ("{\\\\copyright}" "\251")
559 ("\\\\copyright{}" "\251")
560 ("{\\\\pounds}" "£" )
563 ("\\\\pounds{}" "£" )
579 "Translation table for translating German TeX sequences to ISO 8859-1.
580 This table is not exhaustive (and due to TeX's power can never be). It only
581 contains commonly used sequences.")
583 (defvar iso-iso2gtex-trans-tab
594 ("ï" "{\\\\\"\\\\i}")
638 ("\251" "{\\\\copyright}")
645 "Translation table for translating ISO 8859-1 characters to German TeX.")
648 (defun iso-gtex2iso (from to
&optional buffer
)
649 "Translate German TeX sequences to ISO 8859-1 characters.
650 The region between FROM and TO is translated using the table TRANS-TAB.
651 Optional arg BUFFER is ignored (for use in `format-alist')."
653 (iso-translate-conventions from to iso-gtex2iso-trans-tab
))
656 (defun iso-iso2gtex (from to
&optional buffer
)
657 "Translate ISO 8859-1 characters to German TeX sequences.
658 The region between FROM and TO is translated using the table TRANS-TAB.
659 Optional arg BUFFER is ignored (for use in `format-alist')."
661 (iso-translate-conventions from to iso-iso2gtex-trans-tab
))
663 (defvar iso-iso2duden-trans-tab
673 (defun iso-iso2duden (from to
&optional buffer
)
674 "Translate ISO 8859-1 characters to German TeX sequences.
675 The region between FROM and TO is translated using the table TRANS-TAB.
676 Optional arg BUFFER is ignored (for use in `format-alist')."
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 (for use in `format-alist')."
814 (iso-translate-conventions from to iso-iso2sgml-trans-tab
))
817 (defun iso-sgml2iso (from to
&optional buffer
)
818 "Translate SGML entities in the region to ISO 8859-1 characters.
819 The entities used are from \"ISO 8879:1986//ENTITIES Added Latin 1//EN\".
820 Optional arg BUFFER is ignored (for use in `format-alist')."
822 (iso-translate-conventions from to iso-sgml2iso-trans-tab
))
825 (defun iso-cvt-read-only ()
826 "Warn that format is read-only."
828 (error "This format is read-only; specify another format for writing"))
831 (defun iso-cvt-write-only ()
832 "Warn that format is write-only."
834 (error "This format is write-only"))
837 (defun iso-cvt-define-menu ()
838 "Add submenus to the File menu, to convert to and from various formats."
841 (let ((load-as-menu-map (make-sparse-keymap "Load As..."))
842 (insert-as-menu-map (make-sparse-keymap "Insert As..."))
843 (write-as-menu-map (make-sparse-keymap "Write As..."))
844 (translate-to-menu-map (make-sparse-keymap "Translate to..."))
845 (translate-from-menu-map (make-sparse-keymap "Translate from..."))
846 (menu menu-bar-file-menu
))
848 (define-key menu
[load-as-separator
] '("--"))
850 (define-key menu
[load-as
] '("Load As..." . iso-cvt-load-as
))
851 (fset 'iso-cvt-load-as load-as-menu-map
)
853 ;;(define-key menu [insert-as] '("Insert As..." . iso-cvt-insert-as))
854 (fset 'iso-cvt-insert-as insert-as-menu-map
)
856 (define-key menu
[write-as
] '("Write As..." . iso-cvt-write-as
))
857 (fset 'iso-cvt-write-as write-as-menu-map
)
859 (define-key menu
[translate-separator
] '("--"))
861 (define-key menu
[translate-to
] '("Translate to..." . iso-cvt-translate-to
))
862 (fset 'iso-cvt-translate-to translate-to-menu-map
)
864 (define-key menu
[translate-from
] '("Translate from..." . iso-cvt-translate-from
))
865 (fset 'iso-cvt-translate-from translate-from-menu-map
)
867 (dolist (file-type (reverse format-alist
))
868 (let ((name (car file-type
))
869 (str-name (cadr file-type
)))
870 (if (stringp str-name
)
872 (define-key load-as-menu-map
(vector name
)
875 (interactive ,(format "FFind file (as %s): " name
))
876 (format-find-file file
',name
))))
877 (define-key insert-as-menu-map
(vector name
)
880 (interactive (format "FInsert file (as %s): " ,name
))
881 (format-insert-file file
',name
))))
882 (define-key write-as-menu-map
(vector name
)
885 (interactive (format "FWrite file (as %s): " ,name
))
886 (format-write-file file
',name
))))
887 (define-key translate-to-menu-map
(vector name
)
891 (format-encode-buffer ',name
))))
892 (define-key translate-from-menu-map
(vector name
)
896 (format-decode-buffer ',name
))))))))))
900 ;; arch-tag: 64ae843f-ed0e-43e1-ba50-ffd581b90840
901 ;;; iso-cvt.el ends here