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, 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}" "ï")
318 ("\\\\\"{\\\\i}" "ï")
366 ("{\\\\copyright}" "\251")
367 ("\\\\copyright{}" "\251")
368 ("{\\\\pounds}" "£" )
371 ("\\\\pounds{}" "£" )
379 "Translation table for translating TeX sequences to ISO 8859-1 characters.
380 This table is not exhaustive (and due to TeX's power can never be). It only
381 contains commonly used sequences.")
384 (defun iso-tex2iso (from to &optional buffer)
385 "Translate TeX sequences to ISO 8859-1 characters.
386 The region between FROM and TO is translated using the table TRANS-TAB.
387 Optional arg BUFFER is ignored (for use in `format-alist')."
389 (iso-translate-conventions from to iso-tex2iso-trans-tab))
391 (defvar iso-gtex2iso-trans-tab
402 ("{\\\\\"\\\\i}" "ï")
504 ("\\\\\"{\\\\i}" "ï")
552 ("{\\\\copyright}" "\251")
553 ("\\\\copyright{}" "\251")
554 ("{\\\\pounds}" "£" )
557 ("\\\\pounds{}" "£" )
573 "Translation table for translating German TeX sequences to ISO 8859-1.
574 This table is not exhaustive (and due to TeX's power can never be). It only
575 contains commonly used sequences.")
577 (defvar iso-iso2gtex-trans-tab
588 ("ï" "{\\\\\"\\\\i}")
632 ("\251" "{\\\\copyright}")
639 "Translation table for translating ISO 8859-1 characters to German TeX.")
642 (defun iso-gtex2iso (from to &optional buffer)
643 "Translate German TeX sequences to ISO 8859-1 characters.
644 The region between FROM and TO is translated using the table TRANS-TAB.
645 Optional arg BUFFER is ignored (for use in `format-alist')."
647 (iso-translate-conventions from to iso-gtex2iso-trans-tab))
650 (defun iso-iso2gtex (from to &optional buffer)
651 "Translate ISO 8859-1 characters to German TeX sequences.
652 The region between FROM and TO is translated using the table TRANS-TAB.
653 Optional arg BUFFER is ignored (for use in `format-alist')."
655 (iso-translate-conventions from to iso-iso2gtex-trans-tab))
657 (defvar iso-iso2duden-trans-tab
667 (defun iso-iso2duden (from to &optional buffer)
668 "Translate ISO 8859-1 characters to German TeX sequences.
669 The region between FROM and TO is translated using the table TRANS-TAB.
670 Optional arg BUFFER is ignored (for use in `format-alist')."
672 (iso-translate-conventions from to iso-iso2duden-trans-tab))
674 (defvar iso-iso2sgml-trans-tab
738 (defvar iso-sgml2iso-trans-tab
803 (defun iso-iso2sgml (from to &optional buffer)
804 "Translate ISO 8859-1 characters in the region to SGML entities.
805 The entities used are from \"ISO 8879:1986//ENTITIES Added Latin 1//EN\".
806 Optional arg BUFFER is ignored (for use in `format-alist')."
808 (iso-translate-conventions from to iso-iso2sgml-trans-tab))
811 (defun iso-sgml2iso (from to &optional buffer)
812 "Translate SGML entities in the region to ISO 8859-1 characters.
813 The entities used are from \"ISO 8879:1986//ENTITIES Added Latin 1//EN\".
814 Optional arg BUFFER is ignored (for use in `format-alist')."
816 (iso-translate-conventions from to iso-sgml2iso-trans-tab))
819 (defun iso-cvt-read-only ()
820 "Warn that format is read-only."
822 (error "This format is read-only; specify another format for writing"))
825 (defun iso-cvt-write-only ()
826 "Warn that format is write-only."
828 (error "This format is write-only"))
831 (defun iso-cvt-define-menu ()
832 "Add submenus to the File menu, to convert to and from various formats."
835 (let ((load-as-menu-map (make-sparse-keymap "Load As..."))
836 (insert-as-menu-map (make-sparse-keymap "Insert As..."))
837 (write-as-menu-map (make-sparse-keymap "Write As..."))
838 (translate-to-menu-map (make-sparse-keymap "Translate to..."))
839 (translate-from-menu-map (make-sparse-keymap "Translate from..."))
840 (menu menu-bar-file-menu))
842 (define-key menu [load-as-separator] '("--"))
844 (define-key menu [load-as] '("Load As..." . iso-cvt-load-as))
845 (fset 'iso-cvt-load-as load-as-menu-map)
847 ;;(define-key menu [insert-as] '("Insert As..." . iso-cvt-insert-as))
848 (fset 'iso-cvt-insert-as insert-as-menu-map)
850 (define-key menu [write-as] '("Write As..." . iso-cvt-write-as))
851 (fset 'iso-cvt-write-as write-as-menu-map)
853 (define-key menu [translate-separator] '("--"))
855 (define-key menu [translate-to] '("Translate to..." . iso-cvt-translate-to))
856 (fset 'iso-cvt-translate-to translate-to-menu-map)
858 (define-key menu [translate-from] '("Translate from..." . iso-cvt-translate-from))
859 (fset 'iso-cvt-translate-from translate-from-menu-map)
861 (dolist (file-type (reverse format-alist))
862 (let ((name (car file-type))
863 (str-name (cadr file-type)))
864 (if (stringp str-name)
866 (define-key load-as-menu-map (vector name)
869 (interactive ,(format "FFind file (as %s): " name))
870 (format-find-file file ',name))))
871 (define-key insert-as-menu-map (vector name)
874 (interactive (format "FInsert file (as %s): " ,name))
875 (format-insert-file file ',name))))
876 (define-key write-as-menu-map (vector name)
879 (interactive (format "FWrite file (as %s): " ,name))
880 (format-write-file file ',name))))
881 (define-key translate-to-menu-map (vector name)
885 (format-encode-buffer ',name))))
886 (define-key translate-from-menu-map (vector name)
890 (format-decode-buffer ',name))))))))))
894 ;; arch-tag: 64ae843f-ed0e-43e1-ba50-ffd581b90840
895 ;;; iso-cvt.el ends here