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-1998, 2000-2013 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 3 of the License, or
14 ;; (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>.
25 ;; This lisp code is a general framework for translating various
26 ;; representations of the same data.
27 ;; among other things it can be used to translate TeX, HTML, and compressed
28 ;; files to ISO 8859-1. It can also be used to translate different charsets
29 ;; such as IBM PC, Macintosh or HP Roman8.
30 ;; Note that many translations use the GNU recode tool to do the actual
31 ;; conversion. So you might want to install that tool to get the full
32 ;; benefit of iso-cvt.el
35 ; Cover more cases for translation. (There is an infinite number of ways to
36 ; represent accented characters in TeX)
39 ; If you are interested in questions related to using the ISO 8859-1
40 ; characters set (configuring emacs, Unix, etc. to use ISO), then you
41 ; can get the ISO 8859-1 FAQ via anonymous ftp from
42 ; ftp.vlsivie.tuwien.ac.at in /pub/8bit/FAQ-ISO-8859-1
46 (defvar iso-spanish-trans-tab
49 ("\([a-zA-Z]\)#" "\\1ñ")
51 ("\\([-a-zA-Z\"`]\\)\"u" "\\1ü")
52 ("\\([-a-zA-Z\"`]\\)\"U" "\\1Ü")
53 ("\\([-a-zA-Z]\\)'o" "\\1ó")
54 ("\\([-a-zA-Z]\\)'O" "\\Ó")
55 ("\\([-a-zA-Z]\\)'e" "\\1é")
56 ("\\([-a-zA-Z]\\)'E" "\\1É")
57 ("\\([-a-zA-Z]\\)'a" "\\1á")
58 ("\\([-a-zA-Z]\\)'A" "\\1A")
59 ("\\([-a-zA-Z]\\)'i" "\\1í")
60 ("\\([-a-zA-Z]\\)'I" "\\1Í")
62 "Spanish translation table.")
64 (defun iso-translate-conventions (from to trans-tab
)
65 "Translate between FROM and TO using the translation table TRANS-TAB."
68 (narrow-to-region from to
)
70 (let ((work-tab trans-tab
)
71 (buffer-read-only nil
)
72 (case-fold-search nil
))
75 (let ((trans-this (car work-tab
)))
76 (while (re-search-forward (car trans-this
) nil t
)
77 (replace-match (car (cdr trans-this
)) t nil
)))
78 (setq work-tab
(cdr work-tab
)))))
82 (defun iso-spanish (from to
&optional buffer
)
83 "Translate net conventions for Spanish to ISO 8859-1.
84 Translate the region between FROM and TO using the table
85 `iso-spanish-trans-tab'.
86 Optional arg BUFFER is ignored (for use in `format-alist')."
88 (iso-translate-conventions from to iso-spanish-trans-tab
))
90 (defvar iso-aggressive-german-trans-tab
101 "German translation table.
102 This table uses an aggressive translation approach
103 and may erroneously translate too much.")
105 (defvar iso-conservative-german-trans-tab
107 ("\\([-a-zA-Z\"`]\\)\"a" "\\1ä")
108 ("\\([-a-zA-Z\"`]\\)\"A" "\\1Ä")
109 ("\\([-a-zA-Z\"`]\\)\"o" "\\1ö")
110 ("\\([-a-zA-Z\"`]\\)\"O" "\\1Ö")
111 ("\\([-a-zA-Z\"`]\\)\"u" "\\1ü")
112 ("\\([-a-zA-Z\"`]\\)\"U" "\\1Ü")
113 ("\\([-a-zA-Z\"`]\\)\"s" "\\1ß")
114 ("\\([-a-zA-Z\"`]\\)\\\\3" "\\1ß")
116 "German translation table.
117 This table uses a conservative translation approach
118 and may translate too little.")
120 (defvar iso-german-trans-tab iso-aggressive-german-trans-tab
121 "Currently active translation table for German.")
124 (defun iso-german (from to
&optional buffer
)
125 "Translate net conventions for German to ISO 8859-1.
126 Translate the region FROM and TO using the table
127 `iso-german-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 Translate the region between FROM and TO using the table
200 `iso-iso2tex-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).
387 It only contains commonly used sequences.")
390 (defun iso-tex2iso (from to
&optional buffer
)
391 "Translate TeX sequences to ISO 8859-1 characters.
392 Translate the region between FROM and TO using the table
393 `iso-tex2iso-trans-tab'.
394 Optional arg BUFFER is ignored (for use in `format-alist')."
396 (iso-translate-conventions from to iso-tex2iso-trans-tab
))
398 (defvar iso-gtex2iso-trans-tab
409 ("{\\\\\"\\\\i}" "ï")
511 ("\\\\\"{\\\\i}" "ï")
559 ("{\\\\copyright}" "\251")
560 ("\\\\copyright{}" "\251")
561 ("{\\\\pounds}" "£" )
564 ("\\\\pounds{}" "£" )
580 "Translation table for translating German TeX sequences to ISO 8859-1.
581 This table is not exhaustive (and due to TeX's power can never be).
582 It only contains commonly used sequences.")
584 (defvar iso-iso2gtex-trans-tab
595 ("ï" "{\\\\\"\\\\i}")
639 ("\251" "{\\\\copyright}")
646 "Translation table for translating ISO 8859-1 characters to German TeX.")
649 (defun iso-gtex2iso (from to
&optional buffer
)
650 "Translate German TeX sequences to ISO 8859-1 characters.
651 Translate the region between FROM and TO using the table
652 `iso-gtex2iso-trans-tab'.
653 Optional arg BUFFER is ignored (for use in `format-alist')."
655 (iso-translate-conventions from to iso-gtex2iso-trans-tab
))
658 (defun iso-iso2gtex (from to
&optional buffer
)
659 "Translate ISO 8859-1 characters to German TeX sequences.
660 Translate the region between FROM and TO using the table
661 `iso-iso2gtex-trans-tab'.
662 Optional arg BUFFER is ignored (for use in `format-alist')."
664 (iso-translate-conventions from to iso-iso2gtex-trans-tab
))
666 (defvar iso-iso2duden-trans-tab
674 "Translation table for translating ISO 8859-1 characters to Duden sequences.")
677 (defun iso-iso2duden (from to
&optional buffer
)
678 "Translate ISO 8859-1 characters to Duden sequences.
679 Translate the region between FROM and TO using the table
680 `iso-iso2duden-trans-tab'.
681 Optional arg BUFFER is ignored (for use in `format-alist')."
683 (iso-translate-conventions from to iso-iso2duden-trans-tab
))
685 (defvar iso-iso2sgml-trans-tab
749 (defvar iso-sgml2iso-trans-tab
815 (defun iso-iso2sgml (from to
&optional buffer
)
816 "Translate ISO 8859-1 characters in the region to SGML entities.
817 Use entities from \"ISO 8879:1986//ENTITIES Added Latin 1//EN\".
818 Optional arg BUFFER is ignored (for use in `format-alist')."
820 (iso-translate-conventions from to iso-iso2sgml-trans-tab
))
823 (defun iso-sgml2iso (from to
&optional buffer
)
824 "Translate SGML entities in the region to ISO 8859-1 characters.
825 Use entities from \"ISO 8879:1986//ENTITIES Added Latin 1//EN\".
826 Optional arg BUFFER is ignored (for use in `format-alist')."
828 (iso-translate-conventions from to iso-sgml2iso-trans-tab
))
831 (defun iso-cvt-read-only (&rest ignore
)
832 "Warn that format is read-only."
834 (error "This format is read-only; specify another format for writing"))
837 (defun iso-cvt-write-only (&rest ignore
)
838 "Warn that format is write-only."
840 (error "This format is write-only"))
843 (defun iso-cvt-define-menu ()
844 "Add submenus to the File menu, to convert to and from various formats."
847 (let ((load-as-menu-map (make-sparse-keymap "Load As..."))
848 (insert-as-menu-map (make-sparse-keymap "Insert As..."))
849 (write-as-menu-map (make-sparse-keymap "Write As..."))
850 (translate-to-menu-map (make-sparse-keymap "Translate to..."))
851 (translate-from-menu-map (make-sparse-keymap "Translate from..."))
852 (menu menu-bar-file-menu
))
854 (define-key menu
[load-as-separator
] '("--"))
856 (define-key menu
[load-as
] '("Load As..." . iso-cvt-load-as
))
857 (fset 'iso-cvt-load-as load-as-menu-map
)
859 ;;(define-key menu [insert-as] '("Insert As..." . iso-cvt-insert-as))
860 (fset 'iso-cvt-insert-as insert-as-menu-map
)
862 (define-key menu
[write-as
] '("Write As..." . iso-cvt-write-as
))
863 (fset 'iso-cvt-write-as write-as-menu-map
)
865 (define-key menu
[translate-separator
] '("--"))
867 (define-key menu
[translate-to
] '("Translate to..." . iso-cvt-translate-to
))
868 (fset 'iso-cvt-translate-to translate-to-menu-map
)
870 (define-key menu
[translate-from
] '("Translate from..." . iso-cvt-translate-from
))
871 (fset 'iso-cvt-translate-from translate-from-menu-map
)
873 (dolist (file-type (reverse format-alist
))
874 (let ((name (car file-type
))
875 (str-name (cadr file-type
)))
876 (if (stringp str-name
)
878 (define-key load-as-menu-map
(vector name
)
881 (interactive ,(format "FFind file (as %s): " name
))
882 (format-find-file file
',name
))))
883 (define-key insert-as-menu-map
(vector name
)
886 (interactive (format "FInsert file (as %s): " ,name
))
887 (format-insert-file file
',name
))))
888 (define-key write-as-menu-map
(vector name
)
891 (interactive (format "FWrite file (as %s): " ,name
))
892 (format-write-file file
',name
))))
893 (define-key translate-to-menu-map
(vector name
)
897 (format-encode-buffer ',name
))))
898 (define-key translate-from-menu-map
(vector name
)
902 (format-decode-buffer ',name
))))))))))
906 ;;; iso-cvt.el ends here