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 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
)))))
87 (defun iso-spanish (from to
)
88 "Translate net conventions for Spanish to ISO 8859-1."
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
123 (defvar iso-german-trans-tab iso-aggressive-german-trans-tab
124 "Currently active translation table for German.")
126 (defun iso-german (from to
)
127 "Translate net conventions for German to ISO 8859-1."
129 (iso-translate-conventions from to iso-german-trans-tab
))
131 (defvar iso-iso2tex-trans-tab
142 ("ï" "{\\\\\"\\\\i}")
186 ("\251" "{\\\\copyright}")
193 "Translation table for translating ISO 8859-1 characters to TeX sequences.")
198 (defun iso-iso2tex (from to
)
199 "Translate ISO 8859-1 characters to TeX sequences."
201 (iso-translate-conventions from to iso-iso2tex-trans-tab
))
204 (defvar iso-tex2iso-trans-tab
215 ("{\\\\\"\\\\i}" "ï")
317 ("\\\\\"{\\\\i}" "ï")
365 ("{\\\\copyright}" "\251")
366 ("\\\\copyright{}" "\251")
367 ("{\\\\pounds}" "£" )
370 ("\\\\pounds{}" "£" )
378 "Translation table for translating TeX sequences to ISO 8859-1 characters.
379 This table is not exhaustive (and due to TeX's power can never be). It only
380 contains commonly used sequences.")
382 (defun iso-tex2iso (from to
)
383 "Translate TeX sequences to ISO 8859-1 characters."
385 (iso-translate-conventions from to iso-tex2iso-trans-tab
))
387 (defvar iso-gtex2iso-trans-tab
398 ("{\\\\\"\\\\i}" "ï")
500 ("\\\\\"{\\\\i}" "ï")
548 ("{\\\\copyright}" "\251")
549 ("\\\\copyright{}" "\251")
550 ("{\\\\pounds}" "£" )
553 ("\\\\pounds{}" "£" )
569 "Translation table for translating German TeX sequences to ISO 8859-1.
570 This table is not exhaustive (and due to TeX's power can never be). It only
571 contains commonly used sequences.")
573 (defvar iso-iso2gtex-trans-tab
584 ("ï" "{\\\\\"\\\\i}")
628 ("\251" "{\\\\copyright}")
635 "Translation table for translating ISO 8859-1 characters to German TeX.")
637 (defun iso-gtex2iso (from to
)
638 "Translate German TeX sequences to ISO 8859-1 characters."
640 (iso-translate-conventions from to iso-gtex2iso-trans-tab
))
643 (defun iso-iso2gtex (from to
)
644 "Translate ISO 8859-1 characters to German TeX sequences."
646 (iso-translate-conventions from to iso-iso2gtex-trans-tab
))
648 (defvar iso-iso2duden-trans-tab
657 (defun iso-iso2duden (from to
)
658 "Translate ISO 8859-1 characters to German TeX sequences."
660 (iso-translate-conventions from to iso-iso2duden-trans-tab
))
662 (defun iso-cvt-read-only ()
664 (error "This format is read-only; specify another format for writing"))
666 (defun iso-cvt-write-only ()
668 (error "This format is write-only"))
670 (defun iso-cvt-define-menu ()
671 "Add submenus to the Files menu, to convert to and from various formats."
674 (define-key menu-bar-files-menu
[load-as-separator
] '("--"))
676 (define-key menu-bar-files-menu
[load-as
] '("Load As..." . load-as
))
677 (defvar load-as-menu-map
(make-sparse-keymap "Load As..."))
678 (fset 'load-as load-as-menu-map
)
680 ;;(define-key menu-bar-files-menu [insert-as] '("Insert As..." . insert-as))
681 (defvar insert-as-menu-map
(make-sparse-keymap "Insert As..."))
682 (fset 'insert-as insert-as-menu-map
)
684 (define-key menu-bar-files-menu
[write-as
] '("Write As..." . write-as
))
685 (defvar write-as-menu-map
(make-sparse-keymap "Write As..."))
686 (fset 'write-as write-as-menu-map
)
688 (define-key menu-bar-files-menu
[translate-separator
] '("--"))
690 (define-key menu-bar-files-menu
[translate-to
] '("Translate to..." . translate-to
))
691 (defvar translate-to-menu-map
(make-sparse-keymap "Translate to..."))
692 (fset 'translate-to translate-to-menu-map
)
694 (define-key menu-bar-files-menu
[translate-from
] '("Translate from..." . translate-from
))
695 (defvar translate-from-menu-map
(make-sparse-keymap "Translate from..."))
696 (fset 'translate-from translate-from-menu-map
)
698 (let ((file-types (reverse format-alist
))
702 (setq name
(car (car file-types
))
703 str-name
(car (cdr (car file-types
)))
704 file-types
(cdr file-types
))
705 (if (stringp str-name
)
707 (define-key load-as-menu-map
(vector name
)
709 (list 'lambda
'(file) (list 'interactive
(format "FFind file (as %s): " name
))
710 (list 'format-find-file
'file
(list 'quote name
)))))
711 (define-key insert-as-menu-map
(vector name
)
713 (list 'lambda
'(file) (list 'interactive
(format "FInsert file (as %s): " name
))
714 (list 'format-insert-file
'file
(list 'quote name
)))))
715 (define-key write-as-menu-map
(vector name
)
717 (list 'lambda
'(file) (list 'interactive
(format "FWrite file (as %s): " name
))
718 (list 'format-write-file
'file
(list 'quote
(list name
))))))
719 (define-key translate-to-menu-map
(vector name
)
721 (list 'lambda
'() '(interactive)
722 (list 'format-encode-buffer
(list 'quote name
)))))
723 (define-key translate-from-menu-map
(vector name
)
725 (list 'lambda
'() '(interactive)
726 (list 'format-decode-buffer
(list 'quote
(list name
))))))
729 ;;; iso-cvt.el ends here