1 ;;; latin1-disp.el --- display tables for other ISO 8859 on Latin-1 terminals -*- coding: emacs-mule -*-
3 ;; Copyright (C) 2000 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 2, or (at your option)
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; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; This package sets up display of ISO 8859-n for n>1 by substituting
28 ;; Latin-1 characters and sequences of them for characters which can't
29 ;; be displayed, either beacuse we're on a tty or beacuse we don't
30 ;; have the relevant window system fonts available. For instance,
31 ;; Latin-9 is very similar to Latin-1, so we can display most Latin-9
32 ;; characters using the Latin-1 characters at the same code point and
33 ;; fall back on more-or-less mnemonic ASCII sequences for the rest.
35 ;; For the Latin charsets the ASCII sequences are mostly consistent
36 ;; with the Quail prefix input sequences. Latin-4 uses the Quail
37 ;; postfix sequences as a prefix method isn't defined for Latin-4.
39 ;; A different approach is taken in the DOS display tables in
40 ;; term/internal.el, and the relevant ASCII sequences from there are
41 ;; available as an alternative; see `latin1-display-mnemonic'. Only
42 ;; these sequences are used for Cyrillic, Greek and Hebrew.
44 ;; If you don't even have Latin-1, see iso-ascii.el and use the
45 ;; complete tables from internal.el. The ASCII sequences used here
46 ;; are mostly in the same style as iso-ascii.
50 (defconst latin1-display-sets
'(latin-2 latin-3 latin-4 latin-5 latin-8
51 latin-9 cyrillic greek hebrew
)
52 "The ISO8859 character sets with defined Latin-1 display sequences.
53 These are the nicknames for the sets and correspond to Emacs language
56 (defgroup latin1-display
()
57 "Set up display tables for ISO8859 characters using Latin-1."
61 (defcustom latin1-display-format
"{%s}"
62 "A format string used to display the ASCII sequences.
63 The default encloses the sequence in braces, but you could just use
64 \"%s\" to avoid the braces."
65 :group
'latin1-display
69 (defcustom latin1-display nil
70 "Set up Latin-1/ASCII display for ISO8859 character sets.
71 This is done for each character set in the list `latin1-display-sets',
72 if no font is available to display it. Characters are displayed using
73 the corresponding Latin-1 characters where they match. Otherwise
74 ASCII sequences are used, mostly following the Latin prefix input
75 methods. Some different ASCII sequences are used if
76 `latin1-display-mnemonic' is non-nil.
78 Setting this variable directly does not take effect;
79 use either M-x customize of the function `latin1-display'."
80 :group
'latin1-display
83 :initialize
'custom-initialize-default
84 :set
(lambda (symbol value
)
87 #'latin1-display-setup
88 #'latin1-display-reset
)
89 latin1-display-sets
))))
92 (defun latin1-display (&rest sets
)
93 "Set up Latin-1/ASCII display for the arguments character SETS.
94 See option `latin1-display' for the method. The members of the list
95 must be in `latin1-display-sets'. With no arguments, reset the
96 display for all of `latin1-display-sets'. See also `latin1-display-setup'."
98 (mapc #'latin1-display-setup sets
)
99 (mapc #'latin1-display-reset latin1-display-sets
)))
101 (defcustom latin1-display-mnemonic nil
102 "Non-nil means to display potentially more mnemonic sequences.
103 These are taken from the tables in `internal.el' rather than the Quail
106 :group
'latin1-display
)
108 (defun latin1-display-char (char display
&optional alt-display
)
109 "Make an entry in `standard-display-table' for CHAR using string DISPLAY.
110 If ALT-DISPLAY is provided, use that instead if
111 `latin1-display-mnemonic' is non-nil. The actual string displayed is
112 formatted using `latin1-display-format'."
113 (if (and (stringp alt-display
)
114 latin1-display-mnemonic
)
115 (setq display alt-display
))
116 (if (stringp display
)
117 (standard-display-ascii char
(format latin1-display-format display
))
118 (aset standard-display-table char display
)))
120 (defun latin1-display-identities (charset)
121 "Display each character in CHARSET as the corresponding Latin-1 character.
122 CHARSET is a symbol naming a language environment using an ISO8859
124 (if (eq charset
'cyrillic
)
125 (setq charset
'cyrillic-iso
))
127 (set (car (remq 'ascii
(get-language-info charset
'charset
)))))
129 (aset standard-display-table
131 (vector (make-char 'latin-iso8859-1 i
)))
134 (defun latin1-display-reset (language)
135 "Set up the default display for each character of LANGUAGE's charset.
136 CHARSET is a symbol naming a language environment using an ISO8859
138 (if (eq language
'cyrillic
)
139 (setq language
'cyrillic-iso
))
140 (let ((charset (car (remq 'ascii
(get-language-info language
142 (standard-display-default (make-char charset
32)
143 (make-char charset
127)))
146 (defun latin1-display-check-font (language)
147 "Return non-nil if we have a font with an encoding for LANGUAGE.
148 LANGUAGE is a symbol naming a language environment using an ISO8859
149 character set: `latin-2', `hebrew' etc."
150 (if (eq language
'cyrillic
)
151 (setq language
'cyrillic-iso
))
152 (let* ((info (get-language-info language
'charset
))
153 (char (make-char (car (remq 'ascii info
)) ?\
)))
154 (latin1-char-displayable-p char
)))
156 ;; This should be moved into mule-utils or somewhere after 21.1.
157 (defun latin1-char-displayable-p (char)
159 ;; Single byte characters are always displayable.
161 ((display-multi-font-p)
162 ;; On a window system, a character is displayable if we have
163 ;; a font for that character in the default face of the
164 ;; currently selected frame.
165 (let ((fontset (frame-parameter (selected-frame) 'font
))
167 (if (query-fontset fontset
)
168 (setq font-pattern
(fontset-font fontset char
)))
170 (setq font-pattern
(fontset-font "fontset-default" char
)))
173 ;; Now FONT-PATTERN is a string or a cons of family
174 ;; field pattern and registry field pattern.
175 (or (stringp font-pattern
)
176 (setq font-pattern
(concat (or (car font-pattern
) "*")
178 (cdr font-pattern
))))
179 (x-list-fonts font-pattern
'default
(selected-frame) 1)))))
181 (let ((coding (terminal-coding-system)))
183 (let ((safe-chars (coding-system-get coding
'safe-chars
))
184 (safe-charsets (coding-system-get coding
'safe-charsets
)))
186 (aref safe-chars char
))
188 (memq (char-charset char
) safe-charsets
)))))))))
190 (defun latin1-display-setup (set &optional force
)
191 "Set up Latin-1 display for characters in the given SET.
192 SET must be a member of `latin1-display-sets'. Normally, check
193 whether a font for SET is available and don't set the display if it
194 is. If FORCE is non-nil, set up the display regardless."
198 (not (latin1-display-check-font set
)))
199 (latin1-display-identities set
)
202 (apply 'latin1-display-char l
))
253 (?
\82·
"~v" "'<") ; ?\82¢ in latin-pre
262 (?
\82·
"'<") ; Lynx's rendering of caron
267 (not (latin1-display-check-font set
)))
268 (latin1-display-identities set
)
271 (apply 'latin1-display-char l
))
299 (?
\83ÿ
"/." "^.")))))
303 (not (latin1-display-check-font set
)))
304 (latin1-display-identities set
)
307 (apply 'latin1-display-char l
))
360 (not (latin1-display-check-font set
)))
361 (latin1-display-identities set
)
364 (apply 'latin1-display-char l
))
370 (?
\8dê
"^e" "e<") ; from latin-post
372 (?
\8dï
"\"i" "i-") ; from latin-post
373 (?
\8dý
".i" "i.")))))
377 (not (latin1-display-check-font set
)))
378 (latin1-display-identities set
)
381 (apply 'latin1-display-char l
))
416 (not (latin1-display-check-font set
)))
417 (latin1-display-identities set
)
420 (apply 'latin1-display-char l
))
432 (not (latin1-display-check-font set
)))
435 (apply 'latin1-display-char l
))
496 (aset standard-display-table
(car l
) (string-to-vector (cadr l
))))
515 (not (latin1-display-check-font set
)))
516 ;; Don't start with identities, since we don't have definitions
517 ;; for a lot of Hebrew in internal.el. (Intlfonts is also
518 ;; missing some glyphs.)
521 (aset standard-display-table
522 (make-char 'hebrew-iso8859-8 i
)
523 (vector (make-char 'latin-iso8859-1 i
)))
527 (aset standard-display-table
(car l
) (string-to-vector (cadr l
))))
558 (setq set
'cyrillic-iso
)
560 (not (latin1-display-check-font set
)))
563 (apply 'latin1-display-char l
))
632 (aset standard-display-table
(car l
) (string-to-vector (cadr l
))))
663 (t (error "Unsupported character set: %S" set
)))
667 (provide 'latin1-disp
)
669 ;;; latin1-disp.el ends here