1 ;;; latin1-disp.el --- display tables for other ISO 8859 on Latin-1 terminals -*-coding: utf-8;-*-
3 ;; Copyright (C) 2000-2013 Free Software Foundation, Inc.
5 ;; Author: Dave Love <fx@gnu.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; This package sets up display of ISO 8859-n for n>1 by substituting
26 ;; Latin-1 characters and sequences of them for characters which can't
27 ;; be displayed, either because we're on a tty or because we don't
28 ;; have the relevant window system fonts available. For instance,
29 ;; Latin-9 is very similar to Latin-1, so we can display most Latin-9
30 ;; characters using the Latin-1 characters at the same code point and
31 ;; fall back on more-or-less mnemonic ASCII sequences for the rest.
33 ;; For the Latin charsets the ASCII sequences are mostly consistent
34 ;; with the Quail prefix input sequences. Latin-4 uses the Quail
35 ;; postfix sequences since a prefix method isn't defined for Latin-4.
37 ;; [A different approach is taken in the DOS display tables in
38 ;; term/internal.el, and the relevant ASCII sequences from there are
39 ;; available as an alternative; see `latin1-display-mnemonic'. Only
40 ;; these sequences are used for Arabic, Cyrillic, Greek and Hebrew.]
42 ;; If you don't even have Latin-1, see iso-ascii.el and use the
43 ;; complete tables from internal.el. The ASCII sequences used here
44 ;; are mostly in the same style as iso-ascii.
48 ;; Ensure `standard-display-table' is set up:
51 (defconst latin1-display-sets
'(latin-2 latin-3 latin-4 latin-5 latin-8
52 latin-9 arabic cyrillic greek hebrew
)
53 "The ISO8859 character sets with defined Latin-1 display sequences.
54 These are the nicknames for the sets and correspond to Emacs language
57 (defgroup latin1-display
()
58 "Set up display tables for ISO8859 characters using Latin-1."
60 :link
'(emacs-commentary-link "latin1-disp")
63 (defcustom latin1-display-format
"{%s}"
64 "A format string used to display the ASCII sequences.
65 The default encloses the sequence in braces, but you could just use
66 \"%s\" to avoid the braces, maybe with a non-default value of
67 `latin1-display-face'."
68 :group
'latin1-display
72 (defcustom latin1-display nil
73 "Set up Latin-1/ASCII display for ISO8859 character sets.
74 This is done for each character set in the list `latin1-display-sets',
75 if no font is available to display it. Characters are displayed using
76 the corresponding Latin-1 characters where they match. Otherwise
77 ASCII sequences are used, mostly following the Latin prefix input
78 methods. Some different ASCII sequences are used if
79 `latin1-display-mnemonic' is non-nil.
81 This option also treats some characters in the `mule-unicode-...'
82 charsets if you don't have a Unicode font with which to display them.
84 Setting this variable directly does not take effect;
85 use either \\[customize] or the function `latin1-display'."
86 :group
'latin1-display
89 :initialize
'custom-initialize-default
90 :set
(lambda (symbol value
)
92 (apply #'latin1-display latin1-display-sets
)
96 (defun latin1-display (&rest sets
)
97 "Set up Latin-1/ASCII display for the arguments character SETS.
98 See option `latin1-display' for the method. The members of the list
99 must be in `latin1-display-sets'. With no arguments, reset the
100 display for all of `latin1-display-sets'. See also
101 `latin1-display-setup'."
104 (mapc #'latin1-display-setup sets
)
105 (unless (char-displayable-p #x101
) ; a with macron
106 ;; Extra stuff for windows-1252, in particular.
109 (apply 'latin1-display-char l
))
110 '((?\‚
",") ;; SINGLE LOW-9 QUOTATION MARK
111 (?\„
",,") ;; DOUBLE LOW-9 QUOTATION MARK
112 (?\…
"...") ;; HORIZONTAL ELLIPSIS
113 (?\‰
"o/oo") ;; PER MILLE SIGN
114 (?\‹
"<") ;; SINGLE LEFT-POINTING ANGLE QUOTATION MARK
115 (?\“
"``") ;; LEFT DOUBLE QUOTATION MARK
116 (?\”
"''") ;; RIGHT DOUBLE QUOTATION MARK
118 (?\—
"--") ;; EM DASH
119 (?\™
"TM") ;; TRADE MARK SIGN
120 (?\›
">") ;; SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
123 (setq latin1-display t
))
124 (mapc #'latin1-display-reset latin1-display-sets
)
125 (set-char-table-range standard-display-table
'(#x0100 .
#x33FF
) nil
)
126 (set-char-table-range standard-display-table
'(#xE000 .
#xFFFF
) nil
)
127 (setq latin1-display nil
)
130 (defcustom latin1-display-mnemonic nil
131 "Non-nil means to display potentially more mnemonic sequences.
132 These are taken from the tables in `internal.el' rather than the Quail
135 :group
'latin1-display
)
137 (defcustom latin1-display-face
'default
138 "Face to use for displaying substituted ASCII sequences."
141 :group
'latin1-display
)
143 (defun latin1-display-char (char display
&optional alt-display
)
144 "Make an entry in `standard-display-table' for CHAR using string DISPLAY.
145 If ALT-DISPLAY is provided, use that instead if
146 `latin1-display-mnemonic' is non-nil. The actual string displayed is
147 formatted using `latin1-display-format'.
149 DISPLAY and ALT-DISPLAY are either strings or vectors. String values
150 are formatted using `latin1-display-format' and passed to
151 `standard-display-ascii'; vectors are put into `standard-display-table'
153 (if (and (stringp alt-display
)
154 latin1-display-mnemonic
)
155 (setq display alt-display
))
156 (if (stringp display
)
157 (if (eq 'default latin1-display-face
)
158 (standard-display-ascii char
(format latin1-display-format display
))
159 (aset standard-display-table char
160 (vconcat (mapcar (lambda (c) (make-glyph-code c latin1-display-face
))
162 (aset standard-display-table char
163 (make-glyph-code display latin1-display-face
))))
165 (defun latin1-display-identities (charset)
166 "Display each character in CHARSET as the corresponding Latin-1 character.
167 CHARSET is a symbol which is the nickname of a language environment
168 using an ISO8859 character set."
169 (if (eq charset
'cyrillic
)
170 (setq charset
'cyrillic-iso
))
172 (set (car (remq 'ascii
(get-language-info charset
'charset
)))))
174 (let ((ch (decode-char set i
)))
176 (aset standard-display-table ch
(vector i
))))
179 (defun latin1-display-reset (language)
180 "Set up the default display for each character of LANGUAGE's charset.
181 LANGUAGE is a symbol naming a language environment using an ISO8859
183 (if (eq language
'cyrillic
)
184 (setq language
'cyrillic-iso
))
185 (let ((charset (if (eq language
'arabic
)
187 (car (remq 'ascii
(get-language-info language
189 (map-charset-chars #'(lambda (range arg
)
190 (standard-display-default (car range
) (cdr range
)))
194 (defun latin1-display-check-font (language)
195 "Return non-nil if we have a font with an encoding for LANGUAGE.
196 LANGUAGE is a symbol naming a language environment using an ISO8859
197 character set: `latin-2', `hebrew' etc."
198 (if (eq language
'cyrillic
)
199 (setq language
'cyrillic-iso
))
200 (let* ((info (get-language-info language
'charset
))
201 (char (and info
(decode-char (car (remq 'ascii info
)) ?\
))))
202 (and char
(char-displayable-p char
))))
204 ;; Backwards compatibility.
205 (define-obsolete-function-alias 'latin1-char-displayable-p
206 'char-displayable-p
"22.1")
208 (defun latin1-display-setup (set &optional force
)
209 "Set up Latin-1 display for characters in the given SET.
210 SET must be a member of `latin1-display-sets'. Normally, check
211 whether a font for SET is available and don't set the display if it
212 is. If FORCE is non-nil, set up the display regardless."
215 (latin1-display-identities set
)
218 (or (char-displayable-p (car l
))
219 (apply 'latin1-display-char l
)))
270 (?ˇ
"~v" "'<") ; ?˘ in latin-pre
279 (?ˇ
"'<") ; Lynx's rendering of caron
283 (latin1-display-identities set
)
286 (or (char-displayable-p (car l
))
287 (apply 'latin1-display-char l
)))
318 (latin1-display-identities set
)
321 (or (char-displayable-p (car l
))
322 (apply 'latin1-display-char l
)))
374 (latin1-display-identities set
)
377 (or (char-displayable-p (car l
))
378 (apply 'latin1-display-char l
)))
384 (?ê
"^e" "e<") ; from latin-post
386 (?ï
"\"i" "i-") ; from latin-post
390 (latin1-display-identities set
)
393 (or (char-displayable-p (car l
))
394 (apply 'latin1-display-char l
)))
428 (latin1-display-identities set
)
431 (or (char-displayable-p (car l
))
432 (apply 'latin1-display-char l
)))
445 (or (char-displayable-p (car l
))
446 (apply 'latin1-display-char l
)))
507 (or (char-displayable-p (car l
))
508 (aset standard-display-table
(car l
) (string-to-vector (cadr l
)))))
526 ;; Don't start with identities, since we don't have definitions
527 ;; for a lot of Hebrew in internal.el. (Intlfonts is also
528 ;; missing some glyphs.)
531 (let ((ch (decode-char 'hebrew-iso8859-8 i
)))
533 (aset standard-display-table ch
534 (vector (decode-char 'latin-iso8859-1 i
)))))
538 (or (char-displayable-p (car l
))
539 (aset standard-display-table
(car l
) (string-to-vector (cadr l
)))))
569 ;; Arabic probably isn't so useful in the absence of Arabic
570 ;; language support...
573 (or (char-displayable-p ?
)
574 (aset standard-display-table ?
" "))
575 (or (char-displayable-p ?¤
)
576 (aset standard-display-table ?¤
"¤"))
577 (or (char-displayable-p ?
)
578 (aset standard-display-table ?
""))
580 (or (char-displayable-p (car l
))
581 (apply 'latin1-display-char l
)))
632 (setq set
'cyrillic-iso
)
635 (or (char-displayable-p (car l
))
636 (apply 'latin1-display-char l
)))
705 (or (char-displayable-p (car l
))
706 (aset standard-display-table
(car l
) (string-to-vector (cadr l
)))))
737 (t (error "Unsupported character set: %S" set
)))
742 (defcustom latin1-display-ucs-per-lynx nil
743 "Set up Latin-1/ASCII display for Unicode characters.
744 This uses the transliterations of the Lynx browser. The display isn't
745 changed if the display can render Unicode characters.
747 Setting this variable directly does not take effect;
748 use either \\[customize] or the function `latin1-display'."
749 :group
'latin1-display
751 :require
'latin1-disp
752 :initialize
'custom-initialize-default
753 :set
(lambda (symbol value
)
755 (latin1-display-ucs-per-lynx 1)
756 (latin1-display-ucs-per-lynx -
1))))
758 (defun latin1-display-ucs-per-lynx (arg)
759 "Set up Latin-1/ASCII display for Unicode characters.
760 This uses the transliterations of the Lynx browser.
762 With argument ARG, turn such display on if ARG is positive, otherwise
763 turn it off and display Unicode characters literally. The display
764 isn't changed if the display can render Unicode characters."
767 (unless (char-displayable-p #x101
) ; a with macron
768 ;; It doesn't look as though we have a Unicode font.
769 (let ((latin1-display-format "%s"))
772 (apply 'latin1-display-char l
))
773 ;; Table derived by running Lynx on a suitable list of
774 ;; characters in a utf-8 file, except for some added by
2332 (?\⊲
" NORMAL SUBGROUP OF ")
2333 (?\⊳
" CONTAINS AS NORMAL SUBGROUP ")
2334 (?\⊴
" NORMAL SUBGROUP OF OR EQUAL TO ")
2335 (?\⊵
" CONTAINS AS NORMAL SUBGROUP OR EQUAL TO ")
2337 (?\⊺
" INTERCALATE ")
3187 (aset standard-display-table
3188 (make-char 'mule-unicode-0100-24ff
) nil
)
3189 (aset standard-display-table
3190 (make-char 'mule-unicode-2500-33ff
) nil
)
3191 (aset standard-display-table
3192 (make-char 'mule-unicode-e000-ffff
) nil
))
3193 (setq latin1-display-ucs-per-lynx
(not latin1-display-ucs-per-lynx
))
3196 (provide 'latin1-disp
)
3198 ;;; latin1-disp.el ends here