1 ;;; iso-cvt.-el -- translate ISO 8859-1 from/to various encodings
2 ;; This file was formerly called gm-lingo.el.
4 ;; Copyright (C) 1993, 1994, 1995, 1996, 1998 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 2, or (at your option)
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; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
27 ;; This lisp code is a general framework for translating various
28 ;; representations of the same data.
29 ;; among other things it can be used to translate TeX, HTML, and compressed
30 ;; files to ISO 8859-1. It can also be used to translate different charsets
31 ;; such as IBM PC, Macintosh or HP Roman8.
32 ;; Note that many translations use the GNU recode tool to do the actual
33 ;; conversion. So you might want to install that tool to get the full
34 ;; 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/bit/FAQ-ISO-8859-1
52 (defvar iso-spanish-trans-tab
55 ("\([a-zA-Z]\)#" "\\1ñ")
57 ("\\([-a-zA-Z\"`]\\)\"u" "\\1ü")
58 ("\\([-a-zA-Z\"`]\\)\"U" "\\1Ü")
59 ("\\([-a-zA-Z]\\)'o" "\\1ó")
60 ("\\([-a-zA-Z]\\)'O" "\\Ó")
61 ("\\([-a-zA-Z]\\)'e" "\\1é")
62 ("\\([-a-zA-Z]\\)'E" "\\1É")
63 ("\\([-a-zA-Z]\\)'a" "\\1á")
64 ("\\([-a-zA-Z]\\)'A" "\\1A")
65 ("\\([-a-zA-Z]\\)'i" "\\1í")
66 ("\\([-a-zA-Z]\\)'I" "\\1Í")
68 "Spanish translation table.")
70 (defun iso-translate-conventions (from to trans-tab
)
71 "Use the translation table TRANS-TAB to translate the current buffer."
74 (narrow-to-region from to
)
76 (let ((work-tab trans-tab
)
77 (buffer-read-only nil
)
78 (case-fold-search nil
))
81 (let ((trans-this (car work-tab
)))
82 (while (re-search-forward (car trans-this
) nil t
)
83 (replace-match (car (cdr trans-this
)) t nil
)))
84 (setq work-tab
(cdr work-tab
)))))
88 (defun iso-spanish (from to
&optional buffer
)
89 "Translate net conventions for Spanish to ISO 8859-1.
90 The region between FROM and TO is translated using the table TRANS-TAB.
91 Optional arg BUFFER is ignored (so that the function can can be used in
94 (iso-translate-conventions from to iso-spanish-trans-tab
))
96 (defvar iso-aggressive-german-trans-tab
107 "German translation table.
108 This table uses an aggressive translation approach and may erroneously
109 translate too much.")
111 (defvar iso-conservative-german-trans-tab
113 ("\\([-a-zA-Z\"`]\\)\"a" "\\1ä")
114 ("\\([-a-zA-Z\"`]\\)\"A" "\\1Ä")
115 ("\\([-a-zA-Z\"`]\\)\"o" "\\1ö")
116 ("\\([-a-zA-Z\"`]\\)\"O" "\\1Ö")
117 ("\\([-a-zA-Z\"`]\\)\"u" "\\1ü")
118 ("\\([-a-zA-Z\"`]\\)\"U" "\\1Ü")
119 ("\\([-a-zA-Z\"`]\\)\"s" "\\1ß")
120 ("\\([-a-zA-Z\"`]\\)\\\\3" "\\1ß")
122 "German translation table.
123 This table uses a conservative translation approach and may translate too
126 (defvar iso-german-trans-tab iso-aggressive-german-trans-tab
127 "Currently active translation table for German.")
130 (defun iso-german (from to
&optional buffer
)
131 "Translate net conventions for German to ISO 8859-1.
132 The region between FROM and TO is translated using the table TRANS-TAB.
133 Optional arg BUFFER is ignored (so that the function can can be used in
136 (iso-translate-conventions from to iso-german-trans-tab
))
138 (defvar iso-iso2tex-trans-tab
149 ("ï" "{\\\\\"\\\\i}")
193 ("\251" "{\\\\copyright}")
200 "Translation table for translating ISO 8859-1 characters to TeX sequences.")
203 (defun iso-iso2tex (from to
&optional buffer
)
204 "Translate ISO 8859-1 characters to TeX sequences.
205 The region between FROM and TO is translated using the table TRANS-TAB.
206 Optional arg BUFFER is ignored (so that the function can can be used in
209 (iso-translate-conventions from to iso-iso2tex-trans-tab
))
211 (defvar iso-tex2iso-trans-tab
222 ("{\\\\\"\\\\i}" "ï")
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 (so that the function can can be used in
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). It only
582 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 The region between FROM and TO is translated using the table TRANS-TAB.
652 Optional arg BUFFER is ignored (so that the function can can be used in
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 The region between FROM and TO is translated using the table TRANS-TAB.
661 Optional arg BUFFER is ignored (so that the function can can be used in
664 (iso-translate-conventions from to iso-iso2gtex-trans-tab
))
666 (defvar iso-iso2duden-trans-tab
676 (defun iso-iso2duden (from to
&optional buffer
)
677 "Translate ISO 8859-1 characters to German TeX sequences.
678 The region between FROM and TO is translated using the table TRANS-TAB.
679 Optional arg BUFFER is ignored (so that the function can can be used in
682 (iso-translate-conventions from to iso-iso2duden-trans-tab
))
685 (defun iso-cvt-read-only ()
686 "Warn that format is read-only."
688 (error "This format is read-only; specify another format for writing"))
691 (defun iso-cvt-write-only ()
692 "Warn that format is write-only."
694 (error "This format is write-only"))
697 (defun iso-cvt-define-menu ()
698 "Add submenus to the Files menu, to convert to and from various formats."
701 (define-key menu-bar-files-menu
[load-as-separator
] '("--"))
703 (define-key menu-bar-files-menu
[load-as
] '("Load As..." . load-as
))
704 (defvar load-as-menu-map
(make-sparse-keymap "Load As..."))
705 (fset 'load-as load-as-menu-map
)
707 ;;(define-key menu-bar-files-menu [insert-as] '("Insert As..." . insert-as))
708 (defvar insert-as-menu-map
(make-sparse-keymap "Insert As..."))
709 (fset 'insert-as insert-as-menu-map
)
711 (define-key menu-bar-files-menu
[write-as
] '("Write As..." . write-as
))
712 (defvar write-as-menu-map
(make-sparse-keymap "Write As..."))
713 (fset 'write-as write-as-menu-map
)
715 (define-key menu-bar-files-menu
[translate-separator
] '("--"))
717 (define-key menu-bar-files-menu
[translate-to
] '("Translate to..." . translate-to
))
718 (defvar translate-to-menu-map
(make-sparse-keymap "Translate to..."))
719 (fset 'translate-to translate-to-menu-map
)
721 (define-key menu-bar-files-menu
[translate-from
] '("Translate from..." . translate-from
))
722 (defvar translate-from-menu-map
(make-sparse-keymap "Translate from..."))
723 (fset 'translate-from translate-from-menu-map
)
725 (let ((file-types (reverse format-alist
))
729 (setq name
(car (car file-types
))
730 str-name
(car (cdr (car file-types
)))
731 file-types
(cdr file-types
))
732 (if (stringp str-name
)
734 (define-key load-as-menu-map
(vector name
)
736 (list 'lambda
'(file) (list 'interactive
(format "FFind file (as %s): " name
))
737 (list 'format-find-file
'file
(list 'quote name
)))))
738 (define-key insert-as-menu-map
(vector name
)
740 (list 'lambda
'(file) (list 'interactive
(format "FInsert file (as %s): " name
))
741 (list 'format-insert-file
'file
(list 'quote name
)))))
742 (define-key write-as-menu-map
(vector name
)
744 (list 'lambda
'(file) (list 'interactive
(format "FWrite file (as %s): " name
))
745 (list 'format-write-file
'file
(list 'quote
(list name
))))))
746 (define-key translate-to-menu-map
(vector name
)
748 (list 'lambda
'() '(interactive)
749 (list 'format-encode-buffer
(list 'quote name
)))))
750 (define-key translate-from-menu-map
(vector name
)
752 (list 'lambda
'() '(interactive)
753 (list 'format-decode-buffer
(list 'quote
(list name
))))))
756 ;;; iso-cvt.el ends here