aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1997-06-12 05:22:15 +0000
committerRichard M. Stallman1997-06-12 05:22:15 +0000
commit48cd9fe9ec7989256bd7fa9ff715b40d0bbf4a3b (patch)
tree6caac9842c87edfe2364a52db56ef29ded92ddca
parenta984234637e1e118404b78a056a082d204abd8a8 (diff)
downloademacs-48cd9fe9ec7989256bd7fa9ff715b40d0bbf4a3b.tar.gz
emacs-48cd9fe9ec7989256bd7fa9ff715b40d0bbf4a3b.zip
Require `format'.
(iso-translate-conventions): Take bounds as args. (iso-spanish, iso-german): Take bounds as args. (iso-iso2tex, iso-tex2iso, iso-gtex2iso, iso-iso2gtex): Likewise. (iso-iso2duden-trans-tab): New variable. (iso-iso2duden): New command. (iso-cvt-read-only, iso-cvt-write-only): New commands. (is-german-tex-p): Function deleted. (iso-fix-iso2tex, iso-fix-tex2iso): Functions deleted. (iso-cvt-ffh, iso-cvt-wfh, iso-cvt-ash): Functions deleted. (iso-cvt-define-menu): New function.
-rw-r--r--lisp/international/iso-cvt.el248
1 files changed, 130 insertions, 118 deletions
diff --git a/lisp/international/iso-cvt.el b/lisp/international/iso-cvt.el
index 150eed2a9f6..09576ae201d 100644
--- a/lisp/international/iso-cvt.el
+++ b/lisp/international/iso-cvt.el
@@ -1,7 +1,7 @@
1;;; iso-cvt.el --- translate to ISO 8859-1 from/to net/TeX conventions 1;;; iso-cvt.-el -- translate ISO 8859-1 from/to various encodings
2;; This file was formerly called gm-lingo.el. 2;; This file was formerly called gm-lingo.el.
3 3
4;; Copyright (C) 1993, 1994 Free Software Foundation, Inc. 4;; Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
5 5
6;; Author: Michael Gschwind <mike@vlsivie.tuwien.ac.at> 6;; Author: Michael Gschwind <mike@vlsivie.tuwien.ac.at>
7;; Keywords: tex, iso, latin, i18n 7;; Keywords: tex, iso, latin, i18n
@@ -24,49 +24,30 @@
24;; Boston, MA 02111-1307, USA. 24;; Boston, MA 02111-1307, USA.
25 25
26;;; Commentary: 26;;; Commentary:
27 27;; This lisp code is a general framework for translating various
28;; This lisp code serves two purposes, both of which involve 28;; representations of the same data.
29;; the translation of various conventions for representing European 29;; among other things it can be used to translate TeX, HTML, and compressed
30;; character sets to ISO 8859-1. 30;; files to ISO 8859-1. It can also be used to translate different charsets
31 31;; such as IBM PC, Macintosh or HP Roman8.
32;; Net support: 32;; Note that many translations use the GNU recode tool to do the actual
33;; Various conventions exist in Newsgroups on how to represent national 33;; conversion. So you might want to install that tool to get the full
34;; characters. The functions provided here translate these net conventions 34;; benefit of iso-cvt.el
35;; to ISO. 35;
36;; 36
37;; Calling `iso-german' will turn the net convention for umlauts ("a etc.) 37; TO DO:
38;; into ISO latin1 umlauts for easy reading. 38; Cover more cases for translation (There is an infinite number of ways to
39;; 'iso-spanish' will turn net conventions for representing spanish 39; represent accented characters in TeX)
40;; to ISO latin1. (Note that accents are omitted in news posts most 40
41;; of the time, only enye is escaped.) 41;; SEE ALSO:
42 42; If you are interested in questions related to using the ISO 8859-1
43;; TeX support 43; characters set (configuring emacs, Unix, etc. to use ISO), then you
44;; This mode installs hooks which change TeX files to ISO Latin-1 for 44; can get the ISO 8859-1 FAQ via anonymous ftp from
45;; simplified editing. When the TeX file is saved, ISO latin1 characters are 45; ftp.vlsivie.tuwien.ac.at in /pub/bit/FAQ-ISO-8859-1
46;; translated back to escape sequences.
47;;
48;; An alternative is a TeX style that handles 8 bit ISO files
49;; (available on ftp.vlsivie.tuwien.ac.at in /pub/8bit)
50;; - but these files are difficult to transmit ... so while the net is
51;; still @ 7 bit this may be useful
52
53;;; TO DO:
54;; The net support should install hooks (like TeX support does)
55;; which recognizes certain news groups and translates all articles from
56;; those groups.
57;;
58;; Cover more cases for translation (There is an infinite number of ways to
59;; represent accented characters in TeX)
60
61;;; SEE ALSO:
62;; If you are interested in questions related to using the ISO 8859-1
63;; characters set (configuring emacs, Unix, etc. to use ISO), then you
64;; can get the ISO 8859-1 FAQ via anonymous ftp from
65;; ftp.vlsivie.tuwien.ac.at in /pub/bit/FAQ-ISO-8859-1
66 46
67;;; Code: 47;;; Code:
68 48
69(provide 'iso-cvt) 49(provide 'iso-cvt)
50(require 'format)
70 51
71(defvar iso-spanish-trans-tab 52(defvar iso-spanish-trans-tab
72 '( 53 '(
@@ -86,24 +67,27 @@
86 ) 67 )
87 "Spanish translation table.") 68 "Spanish translation table.")
88 69
89(defun iso-translate-conventions (trans-tab) 70(defun iso-translate-conventions (from to trans-tab)
90 "Use the translation table TRANS-TAB to translate the current buffer." 71 "Use the translation table TRANS-TAB to translate the current buffer."
91 (save-excursion 72 (save-excursion
92 (goto-char (point-min)) 73 (save-restriction
93 (let ((work-tab trans-tab) 74 (narrow-to-region from to)
94 (buffer-read-only nil) 75 (goto-char from)
95 (case-fold-search nil)) 76 (let ((work-tab trans-tab)
96 (while work-tab 77 (buffer-read-only nil)
97 (save-excursion 78 (case-fold-search nil))
98 (let ((trans-this (car work-tab))) 79 (while work-tab
99 (while (re-search-forward (car trans-this) nil t) 80 (save-excursion
100 (replace-match (car (cdr trans-this)) t nil))) 81 (let ((trans-this (car work-tab)))
101 (setq work-tab (cdr work-tab))))))) 82 (while (re-search-forward (car trans-this) nil t)
102 83 (replace-match (car (cdr trans-this)) t nil)))
103(defun iso-spanish () 84 (setq work-tab (cdr work-tab)))))
85 (point-max))))
86
87(defun iso-spanish (from to)
104 "Translate net conventions for Spanish to ISO 8859-1." 88 "Translate net conventions for Spanish to ISO 8859-1."
105 (interactive) 89 (interactive)
106 (iso-translate-conventions iso-spanish-trans-tab)) 90 (iso-translate-conventions from to iso-spanish-trans-tab))
107 91
108(defvar iso-aggressive-german-trans-tab 92(defvar iso-aggressive-german-trans-tab
109 '( 93 '(
@@ -139,10 +123,10 @@ little.")
139(defvar iso-german-trans-tab iso-aggressive-german-trans-tab 123(defvar iso-german-trans-tab iso-aggressive-german-trans-tab
140 "Currently active translation table for German.") 124 "Currently active translation table for German.")
141 125
142(defun iso-german () 126(defun iso-german (from to)
143 "Translate net conventions for German to ISO 8859-1." 127 "Translate net conventions for German to ISO 8859-1."
144 (interactive) 128 (interactive)
145 (iso-translate-conventions iso-german-trans-tab)) 129 (iso-translate-conventions from to iso-german-trans-tab))
146 130
147(defvar iso-iso2tex-trans-tab 131(defvar iso-iso2tex-trans-tab
148 '( 132 '(
@@ -211,10 +195,10 @@ little.")
211 195
212 196
213 197
214(defun iso-iso2tex () 198(defun iso-iso2tex (from to)
215 "Translate ISO 8859-1 characters to TeX sequences." 199 "Translate ISO 8859-1 characters to TeX sequences."
216 (interactive) 200 (interactive)
217 (iso-translate-conventions iso-iso2tex-trans-tab)) 201 (iso-translate-conventions from to iso-iso2tex-trans-tab))
218 202
219 203
220(defvar iso-tex2iso-trans-tab 204(defvar iso-tex2iso-trans-tab
@@ -395,10 +379,10 @@ little.")
395This table is not exhaustive (and due to TeX's power can never be). It only 379This table is not exhaustive (and due to TeX's power can never be). It only
396contains commonly used sequences.") 380contains commonly used sequences.")
397 381
398(defun iso-tex2iso () 382(defun iso-tex2iso (from to)
399 "Translate TeX sequences to ISO 8859-1 characters." 383 "Translate TeX sequences to ISO 8859-1 characters."
400 (interactive) 384 (interactive)
401 (iso-translate-conventions iso-tex2iso-trans-tab)) 385 (iso-translate-conventions from to iso-tex2iso-trans-tab))
402 386
403(defvar iso-gtex2iso-trans-tab 387(defvar iso-gtex2iso-trans-tab
404 '( 388 '(
@@ -650,68 +634,96 @@ contains commonly used sequences.")
650 ) 634 )
651 "Translation table for translating ISO 8859-1 characters to German TeX.") 635 "Translation table for translating ISO 8859-1 characters to German TeX.")
652 636
653(defun iso-gtex2iso () 637(defun iso-gtex2iso (from to)
654 "Translate German TeX sequences to ISO 8859-1 characters." 638 "Translate German TeX sequences to ISO 8859-1 characters."
655 (interactive) 639 (interactive)
656 (iso-translate-conventions iso-gtex2iso-trans-tab)) 640 (iso-translate-conventions from to iso-gtex2iso-trans-tab))
657 641
658 642
659(defun iso-iso2gtex () 643(defun iso-iso2gtex (from to)
644 "Translate ISO 8859-1 characters to German TeX sequences."
645 (interactive)
646 (iso-translate-conventions from to iso-iso2gtex-trans-tab))
647
648(defvar iso-iso2duden-trans-tab
649 '(("ä" "ae")
650 ("Ä" "Ae")
651 ("ö" "oe")
652 ("Ö" "Oe")
653 ("ü" "ue")
654 ("Ü" "Ue")
655 ("ß" "ss")))
656
657(defun iso-iso2duden (from to)
660 "Translate ISO 8859-1 characters to German TeX sequences." 658 "Translate ISO 8859-1 characters to German TeX sequences."
661 (interactive) 659 (interactive)
662 (iso-translate-conventions iso-iso2gtex-trans-tab)) 660 (iso-translate-conventions from to iso-iso2duden-trans-tab))
663 661
664 662(defun iso-cvt-read-only ()
665(defun iso-german-tex-p () 663 (interactive)
666 "Check if tex buffer is German LaTeX." 664 (error "This format is read-only; specify another format for writing"))
667 (save-excursion 665
668 (save-restriction 666(defun iso-cvt-write-only ()
669 (widen) 667 (interactive)
670 (goto-char (point-min)) 668 (error "This format is write-only"))
671 (re-search-forward "\\\\documentstyle\\[.*german.*\\]" nil t)))) 669
672 670(defun iso-cvt-define-menu ()
673(defun iso-fix-iso2tex () 671 "Add submenus to the Files menu, to convert to and from various formats."
674 "Turn ISO 8859-1 (aka. ISO Latin-1) buffer into TeX sequences. 672 (interactive)
675If German TeX is used, German TeX sequences are generated." 673
676 (if (or (equal major-mode 'latex-mode) 674 (define-key menu-bar-files-menu [load-as-separator] '("--"))
677 (equal major-mode 'LaTeX-mode)) ; AucTeX wants this 675
678 (if (iso-german-tex-p) 676 (define-key menu-bar-files-menu [load-as] '("Load As..." . load-as))
679 (iso-iso2gtex) 677 (defvar load-as-menu-map (make-sparse-keymap "Load As..."))
680 (iso-iso2tex))) 678 (fset 'load-as load-as-menu-map)
681 (if (or (equal major-mode 'tex-mode) 679
682 (equal major-mode 'TeX-mode) ; AucTeX wants this 680 ;;(define-key menu-bar-files-menu [insert-as] '("Insert As..." . insert-as))
683 (equal major-mode 'plain-tex-mode)) 681 (defvar insert-as-menu-map (make-sparse-keymap "Insert As..."))
684 (iso-iso2tex))) 682 (fset 'insert-as insert-as-menu-map)
685 683
686(defun iso-fix-tex2iso () 684 (define-key menu-bar-files-menu [write-as] '("Write As..." . write-as))
687 "Turn TeX sequences into ISO 8859-1 (aka. ISO Latin-1) characters. 685 (defvar write-as-menu-map (make-sparse-keymap "Write As..."))
688This function recognizes German TeX buffers." 686 (fset 'write-as write-as-menu-map)
689 (if (or (equal major-mode 'latex-mode) 687
690 (equal major-mode 'Latex-mode)) ; AucTeX wants this 688 (define-key menu-bar-files-menu [translate-separator] '("--"))
691 (if (iso-german-tex-p) 689
692 (iso-gtex2iso) 690 (define-key menu-bar-files-menu [translate-to] '("Translate to..." . translate-to))
693 (iso-tex2iso))) 691 (defvar translate-to-menu-map (make-sparse-keymap "Translate to..."))
694 (if (or (equal major-mode 'tex-mode) 692 (fset 'translate-to translate-to-menu-map)
695 (equal major-mode 'TeX-mode) ; AucTeX wants this 693
696 (equal major-mode 'plain-tex-mode)) 694 (define-key menu-bar-files-menu [translate-from] '("Translate from..." . translate-from))
697 (iso-tex2iso))) 695 (defvar translate-from-menu-map (make-sparse-keymap "Translate from..."))
698 696 (fset 'translate-from translate-from-menu-map)
699(defun iso-cvt-ffh () 697
700 "find-file-hook for iso-cvt.el." 698 (let ((file-types (reverse format-alist))
701 (iso-fix-tex2iso) 699 name
702 (set-buffer-modified-p nil)) 700 str-name)
703 701 (while file-types
704(defun iso-cvt-wfh () 702 (setq name (car (car file-types))
705 "write file hook for iso-cvt.el." 703 str-name (car (cdr (car file-types)))
706 (iso-fix-iso2tex)) 704 file-types (cdr file-types))
707 705 (if (stringp str-name)
708(defun iso-cvt-ash () 706 (progn
709 "after save hook for iso-cvt.el." 707 (define-key load-as-menu-map (vector name)
710 (iso-fix-tex2iso) 708 (cons str-name
711 (set-buffer-modified-p nil)) 709 (list 'lambda '(file) (list 'interactive (format "FFind file (as %s): " name))
712 710 (list 'format-find-file 'file (list 'quote name)))))
713(add-hook 'find-file-hooks 'iso-cvt-ffh) 711 (define-key insert-as-menu-map (vector name)
714(add-hook 'write-file-hooks 'iso-cvt-wfh) 712 (cons str-name
715(add-hook 'after-save-hook 'iso-cvt-ash) 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)
716 (cons str-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)
720 (cons str-name
721 (list 'lambda '() '(interactive)
722 (list 'format-encode-buffer (list 'quote name)))))
723 (define-key translate-from-menu-map (vector name)
724 (cons str-name
725 (list 'lambda '() '(interactive)
726 (list 'format-decode-buffer (list 'quote (list name))))))
727 )))))
716 728
717;;; iso-cvt.el ends here 729;;; iso-cvt.el ends here