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, 2001,
5 ;; 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 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 3 of the License, or
15 ;; (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>.
26 ;; This lisp code is a general framework for translating various
27 ;; representations of the same data.
28 ;; among other things it can be used to translate TeX, HTML, and compressed
29 ;; files to ISO 8859-1. It can also be used to translate different charsets
30 ;; such as IBM PC, Macintosh or HP Roman8.
31 ;; Note that many translations use the GNU recode tool to do the actual
32 ;; conversion. So you might want to install that tool to get the full
33 ;; benefit of iso-cvt.el
36 ; Cover more cases for translation. (There is an infinite number of ways to
37 ; represent accented characters in TeX)
40 ; If you are interested in questions related to using the ISO 8859-1
41 ; characters set (configuring emacs, Unix, etc. to use ISO), then you
42 ; can get the ISO 8859-1 FAQ via anonymous ftp from
43 ; ftp.vlsivie.tuwien.ac.at in /pub/8bit/FAQ-ISO-8859-1
47 (defvar iso-spanish-trans-tab
50 ("\([a-zA-Z]\)#" "\\1ñ")
52 ("\\([-a-zA-Z\"`]\\)\"u" "\\1ü")
53 ("\\([-a-zA-Z\"`]\\)\"U" "\\1Ü")
54 ("\\([-a-zA-Z]\\)'o" "\\1ó")
55 ("\\([-a-zA-Z]\\)'O" "\\Ó")
56 ("\\([-a-zA-Z]\\)'e" "\\1é")
57 ("\\([-a-zA-Z]\\)'E" "\\1É")
58 ("\\([-a-zA-Z]\\)'a" "\\1á")
59 ("\\([-a-zA-Z]\\)'A" "\\1A")
60 ("\\([-a-zA-Z]\\)'i" "\\1í")
61 ("\\([-a-zA-Z]\\)'I" "\\1Í")
63 "Spanish translation table.")
65 (defun iso-translate-conventions (from to trans-tab
)
66 "Translate between FROM and TO using the translation table TRANS-TAB."
69 (narrow-to-region from to
)
71 (let ((work-tab trans-tab
)
72 (buffer-read-only nil
)
73 (case-fold-search nil
))
76 (let ((trans-this (car work-tab
)))
77 (while (re-search-forward (car trans-this
) nil t
)
78 (replace-match (car (cdr trans-this
)) t nil
)))
79 (setq work-tab
(cdr work-tab
)))))
83 (defun iso-spanish (from to
&optional buffer
)
84 "Translate net conventions for Spanish to ISO 8859-1.
85 Translate the region between FROM and TO using the table
86 `iso-spanish-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
104 and may erroneously 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
119 and may translate too little.")
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 Translate the region FROM and TO using the table
128 `iso-german-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 Translate the region between FROM and TO using the table
201 `iso-iso2tex-trans-tab'.
202 Optional arg BUFFER is ignored (for use in `format-alist')."
204 (iso-translate-conventions from to iso-iso2tex-trans-tab
))
206 (defvar iso-tex2iso-trans-tab
217 ("{\\\\\"\\\\i}" "ï")
269 ;; Discard spaces and/or one EOF after macro \i.
270 ;; Converting it back will use braces.
271 ("\\\\\"\\\\i *\n\n" "ï\n\n")
272 ("\\\\\"\\\\i *\n?" "ï")
273 ("\\\\`\\\\i *\n\n" "ì\n\n")
274 ("\\\\`\\\\i *\n?" "ì")
275 ("\\\\'\\\\i *\n\n" "í\n\n")
276 ("\\\\'\\\\i *\n?" "í")
277 ("\\\\^\\\\i *\n\n" "î\n\n")
278 ("\\\\^\\\\i *\n?" "î")
325 ("\\\\\"{\\\\i}" "ï")
373 ("{\\\\copyright}" "\251")
374 ("\\\\copyright{}" "\251")
375 ("{\\\\pounds}" "£" )
378 ("\\\\pounds{}" "£" )
386 "Translation table for translating TeX sequences to ISO 8859-1 characters.
387 This table is not exhaustive (and due to TeX's power can never be).
388 It only contains commonly used sequences.")
391 (defun iso-tex2iso (from to
&optional buffer
)
392 "Translate TeX sequences to ISO 8859-1 characters.
393 Translate the region between FROM and TO using the table
394 `iso-tex2iso-trans-tab'.
395 Optional arg BUFFER is ignored (for use in `format-alist')."
397 (iso-translate-conventions from to iso-tex2iso-trans-tab
))
399 (defvar iso-gtex2iso-trans-tab
410 ("{\\\\\"\\\\i}" "ï")
512 ("\\\\\"{\\\\i}" "ï")
560 ("{\\\\copyright}" "\251")
561 ("\\\\copyright{}" "\251")
562 ("{\\\\pounds}" "£" )
565 ("\\\\pounds{}" "£" )
581 "Translation table for translating German TeX sequences to ISO 8859-1.
582 This table is not exhaustive (and due to TeX's power can never be).
583 It only contains commonly used sequences.")
585 (defvar iso-iso2gtex-trans-tab
596 ("ï" "{\\\\\"\\\\i}")
640 ("\251" "{\\\\copyright}")
647 "Translation table for translating ISO 8859-1 characters to German TeX.")
650 (defun iso-gtex2iso (from to
&optional buffer
)
651 "Translate German TeX sequences to ISO 8859-1 characters.
652 Translate the region between FROM and TO using the table
653 `iso-gtex2iso-trans-tab'.
654 Optional arg BUFFER is ignored (for use in `format-alist')."
656 (iso-translate-conventions from to iso-gtex2iso-trans-tab
))
659 (defun iso-iso2gtex (from to
&optional buffer
)
660 "Translate ISO 8859-1 characters to German TeX sequences.
661 Translate the region between FROM and TO using the table
662 `iso-iso2gtex-trans-tab'.
663 Optional arg BUFFER is ignored (for use in `format-alist')."
665 (iso-translate-conventions from to iso-iso2gtex-trans-tab
))
667 (defvar iso-iso2duden-trans-tab
675 "Translation table for translating ISO 8859-1 characters to Duden sequences.")
678 (defun iso-iso2duden (from to
&optional buffer
)
679 "Translate ISO 8859-1 characters to Duden sequences.
680 Translate the region between FROM and TO using the table
681 `iso-iso2duden-trans-tab'.
682 Optional arg BUFFER is ignored (for use in `format-alist')."
684 (iso-translate-conventions from to iso-iso2duden-trans-tab
))
686 (defvar iso-iso2sgml-trans-tab
750 (defvar iso-sgml2iso-trans-tab
816 (defun iso-iso2sgml (from to
&optional buffer
)
817 "Translate ISO 8859-1 characters in the region to SGML entities.
818 Use entities from \"ISO 8879:1986//ENTITIES Added Latin 1//EN\".
819 Optional arg BUFFER is ignored (for use in `format-alist')."
821 (iso-translate-conventions from to iso-iso2sgml-trans-tab
))
824 (defun iso-sgml2iso (from to
&optional buffer
)
825 "Translate SGML entities in the region to ISO 8859-1 characters.
826 Use entities from \"ISO 8879:1986//ENTITIES Added Latin 1//EN\".
827 Optional arg BUFFER is ignored (for use in `format-alist')."
829 (iso-translate-conventions from to iso-sgml2iso-trans-tab
))
832 (defun iso-cvt-read-only (&rest ignore
)
833 "Warn that format is read-only."
835 (error "This format is read-only; specify another format for writing"))
838 (defun iso-cvt-write-only (&rest ignore
)
839 "Warn that format is write-only."
841 (error "This format is write-only"))
844 (defun iso-cvt-define-menu ()
845 "Add submenus to the File menu, to convert to and from various formats."
848 (let ((load-as-menu-map (make-sparse-keymap "Load As..."))
849 (insert-as-menu-map (make-sparse-keymap "Insert As..."))
850 (write-as-menu-map (make-sparse-keymap "Write As..."))
851 (translate-to-menu-map (make-sparse-keymap "Translate to..."))
852 (translate-from-menu-map (make-sparse-keymap "Translate from..."))
853 (menu menu-bar-file-menu
))
855 (define-key menu
[load-as-separator
] '("--"))
857 (define-key menu
[load-as
] '("Load As..." . iso-cvt-load-as
))
858 (fset 'iso-cvt-load-as load-as-menu-map
)
860 ;;(define-key menu [insert-as] '("Insert As..." . iso-cvt-insert-as))
861 (fset 'iso-cvt-insert-as insert-as-menu-map
)
863 (define-key menu
[write-as
] '("Write As..." . iso-cvt-write-as
))
864 (fset 'iso-cvt-write-as write-as-menu-map
)
866 (define-key menu
[translate-separator
] '("--"))
868 (define-key menu
[translate-to
] '("Translate to..." . iso-cvt-translate-to
))
869 (fset 'iso-cvt-translate-to translate-to-menu-map
)
871 (define-key menu
[translate-from
] '("Translate from..." . iso-cvt-translate-from
))
872 (fset 'iso-cvt-translate-from translate-from-menu-map
)
874 (dolist (file-type (reverse format-alist
))
875 (let ((name (car file-type
))
876 (str-name (cadr file-type
)))
877 (if (stringp str-name
)
879 (define-key load-as-menu-map
(vector name
)
882 (interactive ,(format "FFind file (as %s): " name
))
883 (format-find-file file
',name
))))
884 (define-key insert-as-menu-map
(vector name
)
887 (interactive (format "FInsert file (as %s): " ,name
))
888 (format-insert-file file
',name
))))
889 (define-key write-as-menu-map
(vector name
)
892 (interactive (format "FWrite file (as %s): " ,name
))
893 (format-write-file file
',name
))))
894 (define-key translate-to-menu-map
(vector name
)
898 (format-encode-buffer ',name
))))
899 (define-key translate-from-menu-map
(vector name
)
903 (format-decode-buffer ',name
))))))))))
907 ;; arch-tag: 64ae843f-ed0e-43e1-ba50-ffd581b90840
908 ;;; iso-cvt.el ends here