diff options
| author | Kenichi Handa | 2000-07-27 06:08:14 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2000-07-27 06:08:14 +0000 |
| commit | c11a8f77487bd153b4efd4fedf76bff9003064bc (patch) | |
| tree | 042369f7c0702ff9cde45fcc4557bf0ec3c88a52 | |
| parent | 91ae87510562d5a6987bd5c3ae75c650b465c1c3 (diff) | |
| download | emacs-c11a8f77487bd153b4efd4fedf76bff9003064bc.tar.gz emacs-c11a8f77487bd153b4efd4fedf76bff9003064bc.zip | |
(register-char-codings): New function.
(make-coding-system): Handle `safe-chars' specification in the arg
PROPERTY.
| -rw-r--r-- | lisp/international/mule.el | 92 |
1 files changed, 78 insertions, 14 deletions
diff --git a/lisp/international/mule.el b/lisp/international/mule.el index 809015c5e23..66107adb0cd 100644 --- a/lisp/international/mule.el +++ b/lisp/international/mule.el | |||
| @@ -351,6 +351,12 @@ See also the documentation of make-char." | |||
| 351 | ;; | 351 | ;; |
| 352 | ;; The value is a translation table to be applied on encoding. | 352 | ;; The value is a translation table to be applied on encoding. |
| 353 | ;; | 353 | ;; |
| 354 | ;; o safe-chars | ||
| 355 | ;; | ||
| 356 | ;; The value is a char table. If a character has non-nil value in it, | ||
| 357 | ;; the character is safely supported by the coding system. This | ||
| 358 | ;; overrides the specification of safe-charsets. | ||
| 359 | |||
| 354 | ;; o safe-charsets | 360 | ;; o safe-charsets |
| 355 | ;; | 361 | ;; |
| 356 | ;; The value is a list of charsets safely supported by the coding | 362 | ;; The value is a list of charsets safely supported by the coding |
| @@ -492,8 +498,11 @@ coding system whose eol-type is N." | |||
| 492 | (setcdr tem (cons coding-system (cdr tem)))))) | 498 | (setcdr tem (cons coding-system (cdr tem)))))) |
| 493 | 499 | ||
| 494 | (defun coding-system-list (&optional base-only) | 500 | (defun coding-system-list (&optional base-only) |
| 495 | "Return a list of all existing coding systems. | 501 | "Return a list of all existing non-subsidiary coding systems. |
| 496 | If optional arg BASE-ONLY is non-nil, only base coding systems are listed." | 502 | If optional arg BASE-ONLY is non-nil, only base coding systems are listed. |
| 503 | The value doesn't include subsidiary coding systems which are what | ||
| 504 | made from bases and aliases automatically for various end-of-line | ||
| 505 | formats (e.g. iso-latin-1-unix, koi8-r-dos)." | ||
| 497 | (let* ((codings (copy-sequence coding-system-list)) | 506 | (let* ((codings (copy-sequence coding-system-list)) |
| 498 | (tail (cons nil codings))) | 507 | (tail (cons nil codings))) |
| 499 | ;; Remove subsidiary coding systems (eol variants) and alias | 508 | ;; Remove subsidiary coding systems (eol variants) and alias |
| @@ -510,6 +519,23 @@ If optional arg BASE-ONLY is non-nil, only base coding systems are listed." | |||
| 510 | (setq tail (cdr tail))))) | 519 | (setq tail (cdr tail))))) |
| 511 | codings)) | 520 | codings)) |
| 512 | 521 | ||
| 522 | (defun register-char-codings (coding-system safe-chars) | ||
| 523 | (let ((general (char-table-extra-slot char-coding-system-table 0))) | ||
| 524 | (if (eq safe-chars t) | ||
| 525 | (or (memq coding-system general) | ||
| 526 | (set-char-table-extra-slot char-coding-system-table 0 | ||
| 527 | (cons coding-system general))) | ||
| 528 | (map-char-table | ||
| 529 | (function | ||
| 530 | (lambda (key val) | ||
| 531 | (if (and (>= key 128) val) | ||
| 532 | (let ((codings (aref char-coding-system-table key))) | ||
| 533 | (or (memq coding-system codings) | ||
| 534 | (aset char-coding-system-table key | ||
| 535 | (cons coding-system codings))))))) | ||
| 536 | safe-chars)))) | ||
| 537 | |||
| 538 | |||
| 513 | ;; Make subsidiary coding systems (eol-type variants) of CODING-SYSTEM. | 539 | ;; Make subsidiary coding systems (eol-type variants) of CODING-SYSTEM. |
| 514 | (defun make-subsidiary-coding-system (coding-system) | 540 | (defun make-subsidiary-coding-system (coding-system) |
| 515 | (let ((coding-spec (coding-system-spec coding-system)) | 541 | (let ((coding-spec (coding-system-spec coding-system)) |
| @@ -579,7 +605,8 @@ FLAGS specifies more detailed information of the coding system as follows: | |||
| 579 | DESIGNATION-BOL non-nil means designation sequences should be placed | 605 | DESIGNATION-BOL non-nil means designation sequences should be placed |
| 580 | at beginning of line on output. | 606 | at beginning of line on output. |
| 581 | SAFE non-nil means convert unsafe characters to `?' on output. | 607 | SAFE non-nil means convert unsafe characters to `?' on output. |
| 582 | Unsafe characters are what not specified in SAFE-CHARSET. | 608 | Characters not specified in the property `safe-charsets' nor |
| 609 | `safe-chars' are unsafe. | ||
| 583 | ACCEPT-LATIN-EXTRA-CODE non-nil means code-detection routine accepts | 610 | ACCEPT-LATIN-EXTRA-CODE non-nil means code-detection routine accepts |
| 584 | a code specified in `latin-extra-code-table' (which see) as a valid | 611 | a code specified in `latin-extra-code-table' (which see) as a valid |
| 585 | code of the coding system. | 612 | code of the coding system. |
| @@ -718,13 +745,45 @@ a value of `safe-charsets' in PLIST." | |||
| 718 | (not (consp (car properties))))) | 745 | (not (consp (car properties))))) |
| 719 | ;; In the old version, the arg PROPERTIES is a list to be | 746 | ;; In the old version, the arg PROPERTIES is a list to be |
| 720 | ;; set in PLIST as a value of property `safe-charsets'. | 747 | ;; set in PLIST as a value of property `safe-charsets'. |
| 721 | (plist-put plist 'safe-charsets properties) | 748 | (setq properties (list (cons 'safe-charsets properties)))) |
| 722 | ;; In the current version PROPERTIES is a property list. | 749 | ;; In the current version PROPERTIES is a property list. |
| 723 | ;; Reflect it into PLIST one by one. | 750 | ;; Reflect it into PLIST one by one while handling safe-chars |
| 724 | (let ((l properties)) | 751 | ;; specially. |
| 725 | (while l | 752 | (let ((safe-charsets (cdr (assq 'safe-charsets properties))) |
| 726 | (plist-put plist (car (car l)) (cdr (car l))) | 753 | (safe-chars (cdr (assq 'safe-chars properties))) |
| 727 | (setq l (cdr l))))) | 754 | (l properties) |
| 755 | prop val) | ||
| 756 | ;; If only safe-charsets is specified, make a char-table from | ||
| 757 | ;; it, and store that char-table as the value of `safe-chars'. | ||
| 758 | (if (and (not safe-chars) safe-charsets) | ||
| 759 | (let (charset) | ||
| 760 | (if (eq safe-charsets t) | ||
| 761 | (setq safe-chars t) | ||
| 762 | (setq safe-chars (make-char-table 'safe-chars)) | ||
| 763 | (while safe-charsets | ||
| 764 | (setq charset (car safe-charsets) | ||
| 765 | safe-charsets (cdr safe-charsets)) | ||
| 766 | (cond ((eq charset 'ascii)) ; just ignore | ||
| 767 | ((eq charset 'eight-bit-control) | ||
| 768 | (let ((i 128)) | ||
| 769 | (while (< i 160) | ||
| 770 | (aset safe-chars i t) | ||
| 771 | (setq i (1+ i))))) | ||
| 772 | ((eq charset 'eight-bit-graphic) | ||
| 773 | (let ((i 160)) | ||
| 774 | (while (< i 256) | ||
| 775 | (aset safe-chars i t) | ||
| 776 | (setq i (1+ i))))) | ||
| 777 | (t | ||
| 778 | (aset safe-chars (make-char charset) t))))) | ||
| 779 | (setq l (cons (cons 'safe-chars safe-chars) l)))) | ||
| 780 | (while l | ||
| 781 | (setq prop (car (car l)) val (cdr (car l)) l (cdr l)) | ||
| 782 | (if (eq prop 'safe-chars) | ||
| 783 | (progn | ||
| 784 | (setq val safe-chars) | ||
| 785 | (register-char-codings coding-system safe-chars))) | ||
| 786 | (plist-put plist prop val))) | ||
| 728 | ;; The property `coding-category' may have been set differently | 787 | ;; The property `coding-category' may have been set differently |
| 729 | ;; through PROPERTIES. | 788 | ;; through PROPERTIES. |
| 730 | (setq coding-category (plist-get plist 'coding-category)) | 789 | (setq coding-category (plist-get plist 'coding-category)) |
| @@ -768,14 +827,19 @@ a value of `safe-charsets' in PLIST." | |||
| 768 | (if (or (eq coding-category 'coding-category-iso-8-1) | 827 | (if (or (eq coding-category 'coding-category-iso-8-1) |
| 769 | (eq coding-category 'coding-category-iso-8-2)) | 828 | (eq coding-category 'coding-category-iso-8-2)) |
| 770 | (let ((esc (intern (concat (symbol-name coding-system) "-with-esc"))) | 829 | (let ((esc (intern (concat (symbol-name coding-system) "-with-esc"))) |
| 771 | (doc (format "Same as %s but can handle any charsets by ISO's escape sequences." coding-system))) | 830 | (doc (format "Same as %s but can handle any charsets by ISO's escape sequences." coding-system)) |
| 831 | (safe-charsets (assq 'safe-charsets properties)) | ||
| 832 | (mime-charset (assq 'mime-charset properties))) | ||
| 833 | (if safe-charsets | ||
| 834 | (setcdr safe-charsets t) | ||
| 835 | (setq properties (cons (cons 'safe-charsets t) properties))) | ||
| 836 | (if mime-charset | ||
| 837 | (setcdr mime-charset nil)) | ||
| 772 | (make-coding-system esc type mnemonic doc | 838 | (make-coding-system esc type mnemonic doc |
| 773 | (if (listp (car flags)) | 839 | (if (listp (car flags)) |
| 774 | (cons (append (car flags) '(t)) (cdr flags)) | 840 | (cons (append (car flags) '(t)) (cdr flags)) |
| 775 | (cons (list (car flags) t) (cdr flags))) | 841 | (cons (list (car flags) t) (cdr flags))) |
| 776 | properties) | 842 | properties)))) |
| 777 | (coding-system-put esc 'mime-charset nil) | ||
| 778 | (coding-system-put esc 'safe-charsets t)))) | ||
| 779 | 843 | ||
| 780 | coding-system) | 844 | coding-system) |
| 781 | 845 | ||