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 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, 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., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, 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 "Translate between FROM and TO using the translation table TRANS-TAB."
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 Translate the region between FROM and TO using the table
88 `iso-spanish-trans-tab'.
89 Optional arg BUFFER is ignored (for use in `format-alist')."
91 (iso-translate-conventions from to iso-spanish-trans-tab
))
93 (defvar iso-aggressive-german-trans-tab
104 "German translation table.
105 This table uses an aggressive translation approach
106 and may erroneously translate too much.")
108 (defvar iso-conservative-german-trans-tab
110 ("\\([-a-zA-Z\"`]\\)\"a" "\\1ä")
111 ("\\([-a-zA-Z\"`]\\)\"A" "\\1Ä")
112 ("\\([-a-zA-Z\"`]\\)\"o" "\\1ö")
113 ("\\([-a-zA-Z\"`]\\)\"O" "\\1Ö")
114 ("\\([-a-zA-Z\"`]\\)\"u" "\\1ü")
115 ("\\([-a-zA-Z\"`]\\)\"U" "\\1Ü")
116 ("\\([-a-zA-Z\"`]\\)\"s" "\\1ß")
117 ("\\([-a-zA-Z\"`]\\)\\\\3" "\\1ß")
119 "German translation table.
120 This table uses a conservative translation approach
121 and may translate too little.")
123 (defvar iso-german-trans-tab iso-aggressive-german-trans-tab
124 "Currently active translation table for German.")
127 (defun iso-german (from to
&optional buffer
)
128 "Translate net conventions for German to ISO 8859-1.
129 Translate the region FROM and TO using the table
130 `iso-german-trans-tab'.
131 Optional arg BUFFER is ignored (for use in `format-alist')."
133 (iso-translate-conventions from to iso-german-trans-tab
))
135 (defvar iso-iso2tex-trans-tab
146 ("ï" "{\\\\\"\\\\i}")
190 ("\251" "{\\\\copyright}")
197 "Translation table for translating ISO 8859-1 characters to TeX sequences.")
200 (defun iso-iso2tex (from to
&optional buffer
)
201 "Translate ISO 8859-1 characters to TeX sequences.
202 Translate the region between FROM and TO using the table
203 `iso-iso2tex-trans-tab'.
204 Optional arg BUFFER is ignored (for use in `format-alist')."
206 (iso-translate-conventions from to iso-iso2tex-trans-tab
))
208 (defvar iso-tex2iso-trans-tab
219 ("{\\\\\"\\\\i}" "ï")
271 ;; Discard spaces and/or one EOF after macro \i.
272 ;; Converting it back will use braces.
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?" "í")
279 ("\\\\^\\\\i *\n\n" "î\n\n")
280 ("\\\\^\\\\i *\n?" "î")
327 ("\\\\\"{\\\\i}" "ï")
375 ("{\\\\copyright}" "\251")
376 ("\\\\copyright{}" "\251")
377 ("{\\\\pounds}" "£" )
380 ("\\\\pounds{}" "£" )
388 "Translation table for translating TeX sequences to ISO 8859-1 characters.
389 This table is not exhaustive (and due to TeX's power can never be).
390 It only contains commonly used sequences.")
393 (defun iso-tex2iso (from to
&optional buffer
)
394 "Translate TeX sequences to ISO 8859-1 characters.
395 Translate the region between FROM and TO using the table
396 `iso-tex2iso-trans-tab'.
397 Optional arg BUFFER is ignored (for use in `format-alist')."
399 (iso-translate-conventions from to iso-tex2iso-trans-tab
))
401 (defvar iso-gtex2iso-trans-tab
412 ("{\\\\\"\\\\i}" "ï")
514 ("\\\\\"{\\\\i}" "ï")
562 ("{\\\\copyright}" "\251")
563 ("\\\\copyright{}" "\251")
564 ("{\\\\pounds}" "£" )
567 ("\\\\pounds{}" "£" )
583 "Translation table for translating German TeX sequences to ISO 8859-1.
584 This table is not exhaustive (and due to TeX's power can never be).
585 It only contains commonly used sequences.")
587 (defvar iso-iso2gtex-trans-tab
598 ("ï" "{\\\\\"\\\\i}")
642 ("\251" "{\\\\copyright}")
649 "Translation table for translating ISO 8859-1 characters to German TeX.")
652 (defun iso-gtex2iso (from to
&optional buffer
)
653 "Translate German TeX sequences to ISO 8859-1 characters.
654 Translate the region between FROM and TO using the table
655 `iso-gtex2iso-trans-tab'.
656 Optional arg BUFFER is ignored (for use in `format-alist')."
658 (iso-translate-conventions from to iso-gtex2iso-trans-tab
))
661 (defun iso-iso2gtex (from to
&optional buffer
)
662 "Translate ISO 8859-1 characters to German TeX sequences.
663 Translate the region between FROM and TO using the table
664 `iso-iso2gtex-trans-tab'.
665 Optional arg BUFFER is ignored (for use in `format-alist')."
667 (iso-translate-conventions from to iso-iso2gtex-trans-tab
))
669 (defvar iso-iso2duden-trans-tab
677 "Translation table for translating ISO 8859-1 characters to Duden sequences.")
680 (defun iso-iso2duden (from to
&optional buffer
)
681 "Translate ISO 8859-1 characters to Duden sequences.
682 Translate the region between FROM and TO using the table
683 `iso-iso2duden-trans-tab'.
684 Optional arg BUFFER is ignored (for use in `format-alist')."
686 (iso-translate-conventions from to iso-iso2duden-trans-tab
))
688 (defvar iso-iso2sgml-trans-tab
752 (defvar iso-sgml2iso-trans-tab
818 (defun iso-iso2sgml (from to
&optional buffer
)
819 "Translate ISO 8859-1 characters in the region to SGML entities.
820 Use entities from \"ISO 8879:1986//ENTITIES Added Latin 1//EN\".
821 Optional arg BUFFER is ignored (for use in `format-alist')."
823 (iso-translate-conventions from to iso-iso2sgml-trans-tab
))
826 (defun iso-sgml2iso (from to
&optional buffer
)
827 "Translate SGML entities in the region to ISO 8859-1 characters.
828 Use entities from \"ISO 8879:1986//ENTITIES Added Latin 1//EN\".
829 Optional arg BUFFER is ignored (for use in `format-alist')."
831 (iso-translate-conventions from to iso-sgml2iso-trans-tab
))
834 (defun iso-cvt-read-only (&rest ignore
)
835 "Warn that format is read-only."
837 (error "This format is read-only; specify another format for writing"))
840 (defun iso-cvt-write-only (&rest ignore
)
841 "Warn that format is write-only."
843 (error "This format is write-only"))
846 (defun iso-cvt-define-menu ()
847 "Add submenus to the File menu, to convert to and from various formats."
850 (let ((load-as-menu-map (make-sparse-keymap "Load As..."))
851 (insert-as-menu-map (make-sparse-keymap "Insert As..."))
852 (write-as-menu-map (make-sparse-keymap "Write As..."))
853 (translate-to-menu-map (make-sparse-keymap "Translate to..."))
854 (translate-from-menu-map (make-sparse-keymap "Translate from..."))
855 (menu menu-bar-file-menu
))
857 (define-key menu
[load-as-separator
] '("--"))
859 (define-key menu
[load-as
] '("Load As..." . iso-cvt-load-as
))
860 (fset 'iso-cvt-load-as load-as-menu-map
)
862 ;;(define-key menu [insert-as] '("Insert As..." . iso-cvt-insert-as))
863 (fset 'iso-cvt-insert-as insert-as-menu-map
)
865 (define-key menu
[write-as
] '("Write As..." . iso-cvt-write-as
))
866 (fset 'iso-cvt-write-as write-as-menu-map
)
868 (define-key menu
[translate-separator
] '("--"))
870 (define-key menu
[translate-to
] '("Translate to..." . iso-cvt-translate-to
))
871 (fset 'iso-cvt-translate-to translate-to-menu-map
)
873 (define-key menu
[translate-from
] '("Translate from..." . iso-cvt-translate-from
))
874 (fset 'iso-cvt-translate-from translate-from-menu-map
)
876 (dolist (file-type (reverse format-alist
))
877 (let ((name (car file-type
))
878 (str-name (cadr file-type
)))
879 (if (stringp str-name
)
881 (define-key load-as-menu-map
(vector name
)
884 (interactive ,(format "FFind file (as %s): " name
))
885 (format-find-file file
',name
))))
886 (define-key insert-as-menu-map
(vector name
)
889 (interactive (format "FInsert file (as %s): " ,name
))
890 (format-insert-file file
',name
))))
891 (define-key write-as-menu-map
(vector name
)
894 (interactive (format "FWrite file (as %s): " ,name
))
895 (format-write-file file
',name
))))
896 (define-key translate-to-menu-map
(vector name
)
900 (format-encode-buffer ',name
))))
901 (define-key translate-from-menu-map
(vector name
)
905 (format-decode-buffer ',name
))))))))))
909 ;; arch-tag: 64ae843f-ed0e-43e1-ba50-ffd581b90840
910 ;;; iso-cvt.el ends here