Commit | Line | Data |
---|---|---|
7d354dd5 DL |
1 | ;;; latin1-disp.el --- display tables for other ISO 8859 on Latin-1 terminals -*- coding: emacs-mule -*- |
2 | ||
3 | ;; Copyright (C) 2000 Free Software Foundation, Inc. | |
4 | ||
5 | ;; Author: Dave Love <fx@gnu.org> | |
6 | ;; Keywords: i18n | |
7 | ||
8 | ;; This file is part of GNU Emacs. | |
9 | ||
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) | |
13 | ;; any later version. | |
14 | ||
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. | |
19 | ||
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. | |
24 | ||
25 | ;;; Commentary: | |
26 | ||
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 | |
4e22d295 | 29 | ;; be displayed, either because we're on a tty or because we don't |
7d354dd5 DL |
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. | |
34 | ||
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. | |
38 | ||
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. | |
43 | ||
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. | |
47 | ||
48 | ;;; Code: | |
49 | ||
9eaf396b DL |
50 | ;; Ensure `standard-display-table' is set up: |
51 | (require 'disp-table) | |
52 | ||
7d354dd5 DL |
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 | |
57 | environments.") | |
58 | ||
59 | (defgroup latin1-display () | |
60 | "Set up display tables for ISO8859 characters using Latin-1." | |
61 | :version "21.1" | |
62 | :group 'i18n) | |
63 | ||
64 | (defcustom latin1-display-format "{%s}" | |
65 | "A format string used to display the ASCII sequences. | |
66 | The default encloses the sequence in braces, but you could just use | |
67 | \"%s\" to avoid the braces." | |
68 | :group 'latin1-display | |
69 | :type 'string) | |
70 | ||
71 | ;;;###autoload | |
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. | |
80 | ||
81 | Setting this variable directly does not take effect; | |
82 | use either M-x customize of the function `latin1-display'." | |
83 | :group 'latin1-display | |
84 | :type 'boolean | |
85 | :require 'latin1-disp | |
86 | :initialize 'custom-initialize-default | |
87 | :set (lambda (symbol value) | |
9eaf396b DL |
88 | (set-default symbol value) |
89 | (mapc (if value | |
90 | #'latin1-display-setup | |
91 | #'latin1-display-reset) | |
92 | latin1-display-sets) | |
93 | (redraw-display))) | |
7d354dd5 DL |
94 | |
95 | ;;;###autoload | |
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 `latin1-display-setup'." | |
101 | (if sets | |
102 | (mapc #'latin1-display-setup sets) | |
103 | (mapc #'latin1-display-reset latin1-display-sets))) | |
104 | ||
105 | (defcustom latin1-display-mnemonic nil | |
106 | "Non-nil means to display potentially more mnemonic sequences. | |
107 | These are taken from the tables in `internal.el' rather than the Quail | |
108 | input sequences." | |
109 | :type 'boolean | |
110 | :group 'latin1-display) | |
111 | ||
112 | (defun latin1-display-char (char display &optional alt-display) | |
113 | "Make an entry in `standard-display-table' for CHAR using string DISPLAY. | |
114 | If ALT-DISPLAY is provided, use that instead if | |
115 | `latin1-display-mnemonic' is non-nil. The actual string displayed is | |
116 | formatted using `latin1-display-format'." | |
117 | (if (and (stringp alt-display) | |
118 | latin1-display-mnemonic) | |
119 | (setq display alt-display)) | |
120 | (if (stringp display) | |
121 | (standard-display-ascii char (format latin1-display-format display)) | |
122 | (aset standard-display-table char display))) | |
123 | ||
124 | (defun latin1-display-identities (charset) | |
125 | "Display each character in CHARSET as the corresponding Latin-1 character. | |
126 | CHARSET is a symbol naming a language environment using an ISO8859 | |
127 | character set." | |
128 | (if (eq charset 'cyrillic) | |
129 | (setq charset 'cyrillic-iso)) | |
130 | (let ((i 32) | |
131 | (set (car (remq 'ascii (get-language-info charset 'charset))))) | |
132 | (while (<= i 127) | |
133 | (aset standard-display-table | |
134 | (make-char set i) | |
135 | (vector (make-char 'latin-iso8859-1 i))) | |
136 | (setq i (1+ i))))) | |
137 | ||
138 | (defun latin1-display-reset (language) | |
139 | "Set up the default display for each character of LANGUAGE's charset. | |
140 | CHARSET is a symbol naming a language environment using an ISO8859 | |
141 | character set." | |
142 | (if (eq language 'cyrillic) | |
143 | (setq language 'cyrillic-iso)) | |
144 | (let ((charset (car (remq 'ascii (get-language-info language | |
145 | 'charset))))) | |
146 | (standard-display-default (make-char charset 32) | |
147 | (make-char charset 127))) | |
148 | (sit-for 0)) | |
149 | ||
7d354dd5 DL |
150 | (defun latin1-display-check-font (language) |
151 | "Return non-nil if we have a font with an encoding for LANGUAGE. | |
152 | LANGUAGE is a symbol naming a language environment using an ISO8859 | |
153 | character set: `latin-2', `hebrew' etc." | |
154 | (if (eq language 'cyrillic) | |
155 | (setq language 'cyrillic-iso)) | |
fa2c768f DL |
156 | (let* ((info (get-language-info language 'charset)) |
157 | (char (make-char (car (remq 'ascii info)) ?\ ))) | |
158 | (latin1-char-displayable-p char))) | |
159 | ||
160 | ;; This should be moved into mule-utils or somewhere after 21.1. | |
161 | (defun latin1-char-displayable-p (char) | |
162 | (cond ((< char 256) | |
163 | ;; Single byte characters are always displayable. | |
164 | t) | |
c8e6a854 | 165 | ((display-multi-font-p) |
fa2c768f DL |
166 | ;; On a window system, a character is displayable if we have |
167 | ;; a font for that character in the default face of the | |
168 | ;; currently selected frame. | |
169 | (let ((fontset (frame-parameter (selected-frame) 'font)) | |
170 | font-pattern) | |
171 | (if (query-fontset fontset) | |
172 | (setq font-pattern (fontset-font fontset char))) | |
173 | (or font-pattern | |
174 | (setq font-pattern (fontset-font "fontset-default" char))) | |
175 | (if font-pattern | |
176 | (progn | |
177 | ;; Now FONT-PATTERN is a string or a cons of family | |
b2bc32fc | 178 | ;; field pattern and registry field pattern. |
fa2c768f DL |
179 | (or (stringp font-pattern) |
180 | (setq font-pattern (concat (or (car font-pattern) "*") | |
181 | "-*-" | |
182 | (cdr font-pattern)))) | |
183 | (x-list-fonts font-pattern 'default (selected-frame) 1))))) | |
184 | (t | |
185 | (let ((coding (terminal-coding-system))) | |
186 | (if coding | |
187 | (let ((safe-chars (coding-system-get coding 'safe-chars)) | |
188 | (safe-charsets (coding-system-get coding 'safe-charsets))) | |
189 | (or (and safe-chars | |
190 | (aref safe-chars char)) | |
191 | (and safe-charsets | |
192 | (memq (char-charset char) safe-charsets))))))))) | |
7d354dd5 DL |
193 | |
194 | (defun latin1-display-setup (set &optional force) | |
195 | "Set up Latin-1 display for characters in the given SET. | |
196 | SET must be a member of `latin1-display-sets'. Normally, check | |
197 | whether a font for SET is available and don't set the display if it | |
198 | is. If FORCE is non-nil, set up the display regardless." | |
199 | (cond | |
200 | ((eq set 'latin-2) | |
201 | (when (or force | |
202 | (not (latin1-display-check-font set))) | |
203 | (latin1-display-identities set) | |
204 | (mapc | |
205 | (lambda (l) | |
206 | (apply 'latin1-display-char l)) | |
207 |