1 ;;; latin1-disp.el --- display tables for other ISO 8859 on Latin-1 terminals -*- coding: emacs-mule -*-
3 ;; Copyright (C) 2000, 2001 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 because we're on a tty or because 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 since 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 ;; Ensure `standard-display-table' is set up:
53 (defconst latin1-display-sets '(latin-2 latin-3 latin-4 latin-5 latin-8
54 latin-9 cyrillic greek hebrew)
55 "The ISO8859 character sets with defined Latin-1 display sequences.
56 These are the nicknames for the sets and correspond to Emacs language
59 (defgroup latin1-display ()
60 "Set up display tables for ISO8859 characters using Latin-1."
62 :link '(emacs-commentary-link "latin1-disp")
65 (defcustom latin1-display-format "{%s}"
66 "A format string used to display the ASCII sequences.
67 The default encloses the sequence in braces, but you could just use
68 \"%s\" to avoid the braces."
69 :group 'latin1-display
73 (defcustom latin1-display nil
74 "Set up Latin-1/ASCII display for ISO8859 character sets.
75 This is done for each character set in the list `latin1-display-sets',
76 if no font is available to display it. Characters are displayed using
77 the corresponding Latin-1 characters where they match. Otherwise
78 ASCII sequences are used, mostly following the Latin prefix input
79 methods. Some different ASCII sequences are used if
80 `latin1-display-mnemonic' is non-nil.
82 Setting this variable directly does not take effect;
83 use either M-x customize of the function `latin1-display'."
84 :group 'latin1-display
87 :initialize 'custom-initialize-default
88 :set (lambda (symbol value)
89 (set-default symbol value)
91 #'latin1-display-setup
92 #'latin1-display-reset)
97 (defun latin1-display (&rest sets)
98 "Set up Latin-1/ASCII display for the arguments character SETS.
99 See option `latin1-display' for the method. The members of the list
100 must be in `latin1-display-sets'. With no arguments, reset the
101 display for all of `latin1-display-sets'. See also `latin1-display-setup'."
103 (progn (mapc #'latin1-display-setup sets)
104 (setq latin1-display t))
105 (mapc #'latin1-display-reset latin1-display-sets)
106 (setq latin1-display nil))
109 (defcustom latin1-display-mnemonic nil
110 "Non-nil means to display potentially more mnemonic sequences.
111 These are taken from the tables in `internal.el' rather than the Quail
114 :group 'latin1-display)
116 (defun latin1-display-char (char display &optional alt-display)
117 "Make an entry in `standard-display-table' for CHAR using string DISPLAY.
118 If ALT-DISPLAY is provided, use that instead if
119 `latin1-display-mnemonic' is non-nil. The actual string displayed is
120 formatted using `latin1-display-format'."
121 (if (and (stringp alt-display)
122 latin1-display-mnemonic)
123 (setq display alt-display))
124 (if (stringp display)
125 (standard-display-ascii char (format latin1-display-format display))
126 (aset standard-display-table char display)))
128 (defun latin1-display-identities (charset)
129 "Display each character in CHARSET as the corresponding Latin-1 character.
130 CHARSET is a symbol which is the nickname of a language environment
131 using an ISO8859 character set."
132 (if (eq charset 'cyrillic)
133 (setq charset 'cyrillic-iso))
135 (set (car (remq 'ascii (get-language-info charset 'charset)))))
137 (aset standard-display-table
139 (vector (make-char 'latin-iso8859-1 i)))
142 (defun latin1-display-reset (language)
143 "Set up the default display for each character of LANGUAGE's charset.
144 LANGUAGE is a symbol naming a language environment using an ISO8859
146 (if (eq language 'cyrillic)
147 (setq language 'cyrillic-iso))
148 (let ((charset (car (remq 'ascii (get-language-info language
150 (standard-display-default (make-char charset 32)
151 (make-char charset 127)))
154 (defun latin1-display-check-font (language)
155 "Return non-nil if we have a font with an encoding for LANGUAGE.
156 LANGUAGE is a symbol naming a language environment using an ISO8859
157 character set: `latin-2', `hebrew' etc."
158 (if (eq language 'cyrillic)
159 (setq language 'cyrillic-iso))
160 (let* ((info (get-language-info language 'charset))
161 (char (make-char (car (remq 'ascii info)) ?\ )))
162 (latin1-char-displayable-p char)))
164 ;; This should be moved into mule-utils or somewhere after 21.1.
165 (defun latin1-char-displayable-p (char)
167 ;; Single byte characters are always displayable.
169 ((display-multi-font-p)
170 ;; On a window system, a character is displayable if we have
171 ;; a font for that character in the default face of the
172 ;; currently selected frame.
173 (let ((fontset (frame-parameter (selected-frame) 'font))
175 (if (query-fontset fontset)
176 (setq font-pattern (fontset-font fontset char)))
178 (setq font-pattern (fontset-font "fontset-default" char)))
181 ;; Now FONT-PATTERN is a string or a cons of family
182 ;; field pattern and registry field pattern.
183 (or (stringp font-pattern)
184 (setq font-pattern (concat "-"
185 (or (car font-pattern) "*")
187 (cdr font-pattern))))
188 (x-list-fonts font-pattern 'default (selected-frame) 1)))))
190 (let ((coding (terminal-coding-system)))
192 (let ((safe-chars (coding-system-get coding 'safe-chars))
193 (safe-charsets (coding-system-get coding 'safe-charsets)))
195 (aref safe-chars char))
197 (memq (char-charset char) safe-charsets)))))))))
199 (defun latin1-display-setup (set &optional force)
200 "Set up Latin-1 display for characters in the given SET.
201 SET must be a member of `latin1-display-sets'. Normally, check
202 whether a font for SET is available and don't set the display if it
203 is. If FORCE is non-nil, set up the display regardless."
207 (not (latin1-display-check-font set)))
208 (latin1-display-identities set)
211 (apply 'latin1-display-char l))
262 (?
\82· "~v" "'<") ; ?
\82¢ in latin-pre
271 (?
\82· "'<") ; Lynx's rendering of caron
276 (not (latin1-display-check-font set)))
277 (latin1-display-identities set)
280 (apply 'latin1-display-char l))
308 (?
\83ÿ "/." "^.")))))
312 (not (latin1-display-check-font set)))
313 (latin1-display-identities set)
316 (apply 'latin1-display-char l))
369 (not (latin1-display-check-font set)))
370 (latin1-display-identities set)
373 (apply 'latin1-display-char l))
379 (?
\8dê "^e" "e<") ; from latin-post
381 (?
\8dï "\"i" "i-") ; from latin-post
382 (?
\8dý ".i" "i.")))))
386 (not (latin1-display-check-font set)))
387 (latin1-display-identities set)
390 (apply 'latin1-display-char l))
425 (not (latin1-display-check-font set)))
426 (latin1-display-identities set)
429 (apply 'latin1-display-char l))
441 (not (latin1-display-check-font set)))
444 (apply 'latin1-display-char l))
505 (aset standard-display-table (car l) (string-to-vector (cadr l))))
524 (not (latin1-display-check-font set)))
525 ;; Don't start with identities, since we don't have definitions
526 ;; for a lot of Hebrew in internal.el. (Intlfonts is also
527 ;; missing some glyphs.)
530 (aset standard-display-table
531 (make-char 'hebrew-iso8859-8 i)
532 (vector (make-char 'latin-iso8859-1 i)))
536 (aset standard-display-table (car l) (string-to-vector (cadr l))))
567 (setq set 'cyrillic-iso)
569 (not (latin1-display-check-font set)))
572 (apply 'latin1-display-char l))
641 (aset standard-display-table (car l) (string-to-vector (cadr l))))
672 (t (error "Unsupported character set: %S" set)))
676 (provide 'latin1-disp)
678 ;;; latin1-disp.el ends here