latin1-disp.el 14.5 KB
Newer Older
Dave Love's avatar
Dave Love committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637
;;; latin1-disp.el --- display tables for other ISO 8859 on Latin-1 terminals -*- coding: emacs-mule -*-

;; Copyright (C) 2000 Free Software Foundation, Inc.

;; Author: Dave Love <fx@gnu.org>
;; Keywords: i18n

;; This file is part of GNU Emacs.

;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Commentary:

;; This package sets up display of ISO 8859-n for n>1 by substituting
;; Latin-1 characters and sequences of them for characters which can't
;; be displayed, either beacuse we're on a tty or beacuse we don't
;; have the relevant window system fonts available.  For instance,
;; Latin-9 is very similar to Latin-1, so we can display most Latin-9
;; characters using the Latin-1 characters at the same code point and
;; fall back on more-or-less mnemonic ASCII sequences for the rest.

;; For the Latin charsets the ASCII sequences are mostly consistent
;; with the Quail prefix input sequences.  Latin-4 uses the Quail
;; postfix sequences as a prefix method isn't defined for Latin-4.

;; A different approach is taken in the DOS display tables in
;; term/internal.el, and the relevant ASCII sequences from there are
;; available as an alternative; see `latin1-display-mnemonic'.  Only
;; these sequences are used for Cyrillic, Greek and Hebrew.

;; If you don't even have Latin-1, see iso-ascii.el and use the
;; complete tables from internal.el.  The ASCII sequences used here
;; are mostly in the same style as iso-ascii.

;;; Code:

(defconst latin1-display-sets '(latin-2 latin-3 latin-4 latin-5 latin-8
		                latin-9 cyrillic greek hebrew)
  "The ISO8859 character sets with defined Latin-1 display sequences.
These are the nicknames for the sets and correspond to Emacs language
environments.")

(defgroup latin1-display ()
  "Set up display tables for ISO8859 characters using Latin-1."
  :version "21.1"
  :group 'i18n)

(defcustom latin1-display-format "{%s}"
  "A format string used to display the ASCII sequences.
The default encloses the sequence in braces, but you could just use
\"%s\" to avoid the braces."
  :group 'latin1-display
  :type 'string)

;;;###autoload
(defcustom latin1-display nil
  "Set up Latin-1/ASCII display for ISO8859 character sets.
This is done for each character set in the list `latin1-display-sets',
if no font is available to display it.  Characters are displayed using
the corresponding Latin-1 characters where they match.  Otherwise
ASCII sequences are used, mostly following the Latin prefix input
methods.  Some different ASCII sequences are used if
`latin1-display-mnemonic' is non-nil.

Setting this variable directly does not take effect;
use either M-x customize of the function `latin1-display'."
  :group 'latin1-display
  :type 'boolean
  :require 'latin1-disp
  :initialize 'custom-initialize-default
  :set (lambda (symbol value)
	 (if value
	     (mapc (if value
		       #'latin1-display-setup
		     #'latin1-display-reset)
		   latin1-display-sets))))

;;;###autoload
(defun latin1-display (&rest sets)
  "Set up Latin-1/ASCII display for the arguments character SETS.
See option `latin1-display' for the method.  The members of the list
must be in `latin1-display-sets'.  With no arguments, reset the
display for all of `latin1-display-sets'. See also `latin1-display-setup'."
  (if sets
      (mapc #'latin1-display-setup sets)
    (mapc #'latin1-display-reset latin1-display-sets)))

(defcustom latin1-display-mnemonic nil
  "Non-nil means to display potentially more mnemonic sequences.
These are taken from the tables in `internal.el' rather than the Quail
input sequences."
  :type 'boolean
  :group 'latin1-display)

(defun latin1-display-char (char display &optional alt-display)
  "Make an entry in `standard-display-table' for CHAR using string DISPLAY.
If ALT-DISPLAY is provided, use that instead if
`latin1-display-mnemonic' is non-nil.  The actual string displayed is
formatted using `latin1-display-format'."
  (if (and (stringp alt-display)
	   latin1-display-mnemonic)
      (setq display alt-display))
  (if (stringp display)
      (standard-display-ascii char (format latin1-display-format display))
    (aset standard-display-table char display)))

(defun latin1-display-identities (charset)
  "Display each character in CHARSET as the corresponding Latin-1 character.
CHARSET is a symbol naming a language environment using an ISO8859
character set."
  (if (eq charset 'cyrillic)
      (setq charset 'cyrillic-iso))
  (let ((i 32)
	(set (car (remq 'ascii (get-language-info charset 'charset)))))
    (while (<= i 127)
      (aset standard-display-table
	    (make-char set i)
	    (vector (make-char 'latin-iso8859-1 i)))
      (setq i (1+ i)))))

(defun latin1-display-reset (language)
  "Set up the default display for each character of LANGUAGE's charset.
CHARSET is a symbol naming a language environment using an ISO8859
character set."
  (if (eq language 'cyrillic)
      (setq language 'cyrillic-iso))
  (let ((charset (car (remq 'ascii (get-language-info language
							'charset)))))
    (standard-display-default (make-char charset 32)
			      (make-char charset 127)))
  (sit-for 0))

;; Is there a better way than this?
(defun latin1-display-check-font (language)
  "Return non-nil if we have a font with an encoding for LANGUAGE.
LANGUAGE is a symbol naming a language environment using an ISO8859
character set: `latin-2', `hebrew' etc."
  (if (eq language 'cyrillic)
      (setq language 'cyrillic-iso))
  (if window-system
      (let* ((info (get-language-info language 'charset))
	     (str (symbol-name (car (remq 'ascii info)))))
	(string-match "-iso8859-[0-9]+\\'" str)
	(x-list-fonts (concat "*" (match-string 0 str))))))

(defun latin1-display-setup (set &optional force)
  "Set up Latin-1 display for characters in the given SET.
SET must be a member of `latin1-display-sets'.  Normally, check
whether a font for SET is available and don't set the display if it
is.  If FORCE is non-nil, set up the display regardless."
  (cond
   ((eq set 'latin-2)
    (when (or force
	      (not (latin1-display-check-font set)))
      (latin1-display-identities set)
      (mapc
       (lambda (l)
	 (apply 'latin1-display-char l))
       '((? "'C" "C'")
	 (? "'D" "/D")
	 (? "'S" "S'")
	 (? "'c" "c'")
	 (? "'d" "/d")
	 (? "'L" "L'")
	 (? "'n" "n'")
	 (? "'N" "N'")
	 (? "'r" "r'")
	 (? "'R" "R'")
	 (? "'s" "s'")
	 (? "'z" "z'")
	 (? "'Z" "Z'")
	 (? "`A" "A;")
	 (? "`E" "E;")
	 (? "`L" "/L")
	 (? "`S" ",S")
	 (? "`T" ",T")
	 (? "`Z" "Z^.")
	 (? "`a" "a;")
	 (? "`l" "/l")
	 (? "`e" "e;")
	 (? "`s" ",s")
	 (? "`t" ",t")
	 (? "`z" "z^.")
	 (? "`." "'.")
	 (? "~A" "A(")
	 (? "~C" "C<")
	 (? "~D" "D<")
	 (? "~E" "E<")
	 (? "~e" "e<")
	 (? "~L" "L<")
	 (? "~N" "N<")
	 (? "~O" "O''")
	 (? "~R" "R<")
	 (? "~S" "S<")
	 (? "~T" "T<")
	 (? "~U" "U''")
	 (? "~Z" "Z<")
	 (? "~a" "a(}")
	 (? "~c" "c<")
	 (? "~d" "d<")
	 (? "~l" "l<")
	 (? "~n" "n<")
	 (? "~o" "o''")
	 (? "~r" "r<")
	 (? "~s" "s<")
	 (? "~t" "t<")
	 (? "~u" "u''")
	 (? "~z" "z<")
	 (? "~v" "'<")			; ?い in latin-pre
	 (? "~~" "'(")
	 (? "uu" "u^0")
	 (? "UU" "U^0")
	 (? "\"A")
	 (? "\"a")
	 (? "\"E" "E:")
	 (? "\"e")
	 (? "''" "'")
	 (? "'<")			; Lynx's rendering of caron
	 ))))

   ((eq set 'latin-3)
    (when (or force
	      (not (latin1-display-check-font set)))
      (latin1-display-identities set)
      (mapc
       (lambda (l)
	 (apply 'latin1-display-char l))
       '((?Γ "/H")
	 (?Δ "~`" "'(")
	 (?Θ "^H" "H^")
	 (?Ω "^h" "h^")	 (?Λ ".I" "I^.")
	 (?Μ ",S")
	 (?Ν "~G" "G(")
	 (?Ξ "^J" "J^")
	 (?Ρ ".Z" "Z^.")
	 (?Τ "/h")
	 (? ".i" "i^.")
	 (? ",s")
	 (? "~g" "g(")
	 (? "^j" "j^")
	 (?α ".Z" "z^.")
	 (?η ".c" "C^.")
	 (?θ "^C" "C^")
	 (?ψ ".G" "G^.")
	 (? "^G" "G^")
	 (? "~U" "U(")
	 (? "^S" "S^")
	 (? ".C" "c^.")
	 (? "^c" "c^")
	 (? ".g" "g^.")
	 (? "^g" "g^")
	 (? "~u" "u(")
	 (? "^s" "s^")
	 (? "/." "^.")))))

   ((eq set 'latin-4)
    (when (or force
	      (not (latin1-display-check-font set)))
      (latin1-display-identities set)
      (mapc
       (lambda (l)
	 (apply 'latin1-display-char l))
       '((? "A," "A;")
	 (? "k/" "kk")
	 (? "R," ",R")
	 (? "I~" "?I")
	 (? "L," ",L")
	 (? "S~" "S<")
	 (? "E-")
	 (? "G," ",G")
	 (? "T/" "/T")
	 (? "Z~" "Z<")
	 (? "a," "a;")
	 (? "';")
	 (? "r," ",r")
	 (? "i~" "~i")
	 (? "l," ",l")
	 (? "'<")
	 (? "s~" "s<")
	 (? "e-")
	 (? "g," ",g")
	 (? "t/" "/t")
	 (? "N/" "NG")
	 (? "z~" "z<")
	 (? "n/" "ng")
	 (? "A-")
	 (? "I," "I;")
	 (? "C~" "C<")
	 (? "E," "E;")
	 (? "E." "E^.")
	 (? "I-")
	 (? "N," ",N")
	 (? "O-")
	 (? "K," ",K")
	 (? "U," "U;")
	 (? "U~" "~U")
	 (? "U-")
	 (? "a-")
	 (? "i," "i;")
	 (? "c~" "c<")
	 (? "e," "e;")
	 (? "e." "e^.")
	 (? "i-")
	 (? "d/" "/d")
	 (? "n," ",n")
	 (? "o-")
	 (? "k," ",k")
	 (? "u," "u;")
	 (? "u~" "~u")
	 (? "u-")
	 (? "^.")))))

   ((eq set 'latin-5)
    (when (or force
	      (not (latin1-display-check-font set)))
      (latin1-display-identities set)
      (mapc
       (lambda (l)
	 (apply 'latin1-display-char l))
       '((? "~g" "g(")
	 (? "~G" "G(")
	 (? ".I" "I^.")
	 (? ",s")
	 (? ",S")
	 (? "^e" "e<")			; from latin-post
	 (? ".e" "e^.")
	 (? "\"i" "i-")		; from latin-post
	 (? ".i" "i.")))))

   ((eq set 'latin-8)
    (when (or force
	      (not (latin1-display-check-font set)))
      (latin1-display-identities set)
      (mapc
       (lambda (l)
	 (apply 'latin1-display-char l))
       '((? ".B" "B`")
	 (? ".b" "b`")
	 (? ".c" "c`")
	 (? ".C" "C`")
	 (? ".D" "D`")
	 (? ".d" "d`")
	 (? "`w")
	 (? "`W")
	 (? "'w" "w'")
	 (? "'W" "W'")
	 (? "`y")
	 (? "`Y")
	 (? ".f" "f`")
	 (? ".F" "F`")
	 (? ".g" "g`")
	 (? ".G" "G`")
	 (? ".m" "m`")
	 (? ".M" "M`")
	 (? ".p" "p`")
	 (? ".P" "P`")
	 (? ".s" "s`")
	 (? ".S" "S`")
	 (? "\"w")
	 (? "\"W")
	 (? "^w" "w^")
	 (? "^W" "W^")
	 (? ".t" "t`")
	 (? ".T" "T`")
	 (? "^y" "y^")
	 (? "^Y" "Y^")
	 (? "\"Y")))))

   ((eq set 'latin-9)
    (when (or force
	      (not (latin1-display-check-font set)))
      (latin1-display-identities set)
      (mapc
       (lambda (l)
	 (apply 'latin1-display-char l))
       '((? "~s" "s<")
	 (? "~S" "S<")
	 (? "Euro" "E=")
	 (? "~z" "z<")
	 (? "~Z" "Z<")
	 (? "\"Y")
	 (? "oe")
	 (?湿 "OE")))))

   ((eq set 'greek)
    (when (or force
	      (not (latin1-display-check-font set)))
      (mapc
       (lambda (l)
	 (apply 'latin1-display-char l))
       '((? "9'")
	 (? "'9")
	 (? "-M")
	 (? "'%")
	 (? "'A")
	 (? "'E")
	 (? "'H")
	 (? "'I")
	 (? "'O")
	 (? "'Y")
	 (? "W%")
	 (? "i3")
	 (? "G*")
	 (? "D*")
	 (? "TH")
	 (? "L*")
	 (? "C*")
	 (? "P*")
	 (? "S*")
	 (? "F*")
	 (? "Q*")
	 (? "W*")
	 (? "\"I")
	 (? "\"Y")
	 (? "a%")
	 (? "e%")
	 (? "y%")
	 (? "i%")
	 (? "u3")
	 (? "a*")
	 (? "b*")
	 (? "g*")
	 (? "d*")
	 (? "e*")
	 (? "z*")
	 (? "y*")
	 (? "h*")
	 (? "i*")
	 (? "k")
	 (? "l*")
	 (? "m*")
	 (? "n*")
	 (? "c*")
	 (? "p*")
	 (? "r*")
	 (? "*s")
	 (? "s*")
	 (? "t*")
	 (? "u")
	 (? "f*")
	 (? "x*")
	 (? "q*")
	 (? "w*")
	 (? "\"i")
	 (? "\"u")
	 (? "'o")
	 (? "'u")
	 (? "'w")))
      (mapc
       (lambda (l)
	 (aset standard-display-table (car l) (string-to-vector (cadr l))))
       '((? "A")
	 (? "B")
	 (? "E")
	 (? "Z")
	 (? "H")
	 (? "I")
	 (? "J")
	 (? "M")
	 (? "N")
	 (? "O")
	 (? "P")
	 (? "T")
	 (? "Y")
	 (? "X")
	 (? "o")))))

   ((eq set 'hebrew)
    (when (or force
	      (not (latin1-display-check-font set)))
      ;; Don't start with identities, since we don't have definitions
      ;; for a lot of Hebrew in internal.el.  (Intlfonts is also
      ;; missing some glyphs.)
      (let ((i 34))
	(while (<= i 62)
	  (aset standard-display-table
		(make-char 'hebrew-iso8859-8 i)
		(vector (make-char 'latin-iso8859-1 i)))
	  (setq i (1+ i))))
      (mapc
       (lambda (l)
	 (aset standard-display-table (car l) (string-to-vector (cadr l))))
       '((? "=2")
	 (? "A+")
	 (? "B+")
	 (? "G+")
	 (? "D+")
	 (? "H+")
	 (? "W+")
	 (? "Z+")
	 (? "X+")
	 (? "Tj")
	 (? "J+")
	 (? "K%")
	 (? "K+")
	 (? "L+")
	 (? "M%")
	 (? "M+")
	 (? "N%")
	 (? "N+")
	 (? "S+")
	 (? "E+")
	 (? "P%")
	 (? "P+")
	 (? "Zj")
	 (? "ZJ")
	 (? "Q+")
	 (? "R+")
	 (? "Sh")
	 (? "T+")))))

   ((eq set 'cyrillic)
    (setq set 'cyrillic-iso)
    (when (or force
	      (not (latin1-display-check-font set)))
      (mapc
       (lambda (l)
	 (apply 'latin1-display-char l))
       '((? "Dj")
	 (? "Gj")
	 (? "IE")
	 (? "Lj")
	 (? "Nj")
	 (? "Ts")
	 (? "Kj")
	 (? "V%")
	 (? "Dzh")
	 (? "B=")
	 (? "")
	 (? "D")
	 (? "Z%")
	 (? "3")
	 (? "U")
	 (? "J=")
	 (? "L=")
	 (? "P=")
	 (? "Y")
	 (? "")
	 (? "C=")
	 (? "C%")
	 (? "S%")
	 (? "Sc")
	 (? "=\"")
	 (? "Y=")
	 (? "%\"")
	 (? "Ee")
	 (? "Yu")
	 (? "Ya")
	 (? "b")
	 (? "v=")
	 (? "g=")
	 (? "g")
	 (? "z%")
	 (? "z=")
	 (? "u")
	 (? "j=")
	 (? "k")
	 (? "l=")
	 (? "m=")
	 (? "n=")
	 (? "n")
	 (? "p")
	 (? "t=")
	 (? "f=")
	 (? "c=")
	 (? "c%")
	 (? "s%")
	 (? "sc")
	 (? "='")
	 (? "y=")
	 (? "%'")
	 (? "ee")
	 (? "yu")
	 (? "ya")
	 (? "N0")
	 (? "dj")
	 (? "gj")
	 (? "ie")
	 (? "lj")
	 (? "nj")
	 (? "ts")
	 (? "kj")
	 (? "v%")
	 (? "dzh")))
      (mapc
       (lambda (l)
	 (aset standard-display-table (car l) (string-to-vector (cadr l))))
       '((? "⇒")
	 (? "S")
	 (? "I")
	 (? "")
	 (? "J")
	 (? "")
	 (? "〒")
	 (? "-")
	 (? "A")
	 (? "B")
	 (? "E")
	 (? "K")
	 (? "M")
	 (? "H")
	 (? "O")
	 (? "P")
	 (? "C")
	 (? "T")
	 (? "X")
	 (? "a")
	 (? "e")
	 (? "o")
	 (? "c")
	 (? "y")
	 (? "x")
	 (? "s")
	 (? "i")
	 (? "")
	 (? "j")))))

   (t (error "Unsupported character set: %S" set)))
   
  (sit-for 0))

(provide 'latin1-disp)

;;; latin1-disp.el ends here