Mercurial > hg > xemacs-beta
comparison lisp/descr-text.el @ 5186:b36d089cbed5
Don't error if describe-char-use-cache t and database not readable, descr-text
2010-04-02 Aidan Kehoe <kehoea@parhasard.net>
* descr-text.el (describe-char-unicode-data):
Don't give up if describe-char-use-cache is t and the database
isn't readable, warn and insert the entire UnicodeData.txt file
instead.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Fri, 02 Apr 2010 13:23:31 +0100 |
parents | b50624d3ae55 |
children | 09f8ed0933c7 |
comparison
equal
deleted
inserted
replaced
5185:e785e579b084 | 5186:b36d089cbed5 |
---|---|
684 ;; XEmacs change; accept a character argument, use the cache if | 684 ;; XEmacs change; accept a character argument, use the cache if |
685 ;; appropriate. | 685 ;; appropriate. |
686 (when (characterp char) | 686 (when (characterp char) |
687 (setq char (encode-char char 'ucs))) | 687 (setq char (encode-char char 'ucs))) |
688 (with-temp-buffer | 688 (with-temp-buffer |
689 (if describe-char-use-cache | 689 (let ((coding-system-for-read coding-system-for-read) |
690 ;; Use the database info. | 690 database-handle key lookup) |
691 (let ((database-handle (open-database | 691 (if (and describe-char-use-cache |
692 (unidata-generate-database-file-name | 692 (prog1 |
693 describe-char-unicodedata-file | 693 (setq database-handle |
694 (eighth (file-attributes | 694 (open-database |
695 describe-char-unicodedata-file)) | 695 (unidata-generate-database-file-name |
696 unidata-database-format) | 696 describe-char-unicodedata-file |
697 unidata-database-format | 697 (eighth (file-attributes |
698 nil "r" | 698 describe-char-unicodedata-file)) |
699 #o644 'no-conversion-unix)) | 699 unidata-database-format) |
700 (coding-system-for-read 'no-conversion-unix) | 700 unidata-database-format |
701 key lookup) | 701 nil "r" |
702 (unless database-handle | 702 #o644 'no-conversion-unix)) |
703 (error 'io-error | 703 (unless database-handle |
704 (format "Could not open %s as a %s database" | 704 (warn "Could not open %s as a %s database" |
705 (unidata-generate-database-file-name | 705 (unidata-generate-database-file-name |
706 describe-char-unicodedata-file | 706 describe-char-unicodedata-file |
707 (eighth (file-attributes | 707 (eighth (file-attributes |
708 describe-char-unicodedata-file)) | 708 describe-char-unicodedata-file)) |
709 unidata-database-format) | 709 unidata-database-format) |
710 unidata-database-format))) | 710 unidata-database-format)))) |
711 (setq key (format "%04X" char) | 711 (progn |
712 lookup (get-database key database-handle)) | 712 ;; Use the database info. |
713 (if lookup | 713 (setq coding-system-for-read 'no-conversion-unix |
714 ;; Okay, we have information on that character in particular. | 714 key (format "%04X" char) |
715 (progn (setq lookup (read lookup)) | 715 lookup (get-database key database-handle)) |
716 (insert-file-contents describe-char-unicodedata-file nil | 716 (if lookup |
717 (first lookup) (second lookup))) | 717 ;; Okay, we have information on that character in particular. |
718 ;; No information on that character in particular. Do we have | 718 (progn (setq lookup (read lookup)) |
719 ;; range information? If so, load and check for our desired | 719 (insert-file-contents describe-char-unicodedata-file |
720 ;; character. | 720 nil (first lookup) |
721 (setq lookup (get-database "range-information" database-handle) | 721 (second lookup))) |
722 lookup (if lookup (read lookup)) | 722 ;; No information on that character in particular. Do we |
723 lookup (if lookup (get-range-table char lookup))) | 723 ;; have range information? If so, load and check for our |
724 (when lookup | 724 ;; desired character. |
725 (insert-file-contents describe-char-unicodedata-file nil | 725 (setq lookup (get-database "range-information" database-handle) |
726 (first lookup) (second lookup)))) | 726 lookup (if lookup (read lookup)) |
727 (close-database database-handle)) | 727 lookup (if lookup (get-range-table char lookup))) |
728 | 728 (when lookup |
729 ;; Otherwise, insert the whole file (the FSF approach). | 729 (insert-file-contents describe-char-unicodedata-file nil |
730 (set-buffer (get-buffer-create " *Unicode Data*")) | 730 (first lookup) (second lookup)))) |
731 (when (zerop (buffer-size)) | 731 (close-database database-handle)) |
732 ;; Don't use -literally in case of DOS line endings. | 732 ;; Otherwise, insert the whole file (the FSF approach). |
733 (insert-file-contents describe-char-unicodedata-file))) | 733 (set-buffer (get-buffer-create " *Unicode Data*")) |
734 | 734 (when (zerop (buffer-size)) |
735 ;; Don't use -literally in case of DOS line endings. | |
736 (insert-file-contents describe-char-unicodedata-file)))) | |
735 (goto-char (point-min)) | 737 (goto-char (point-min)) |
736 (let ((hex (format "%04X" char)) | 738 (let ((hex (format "%04X" char)) |
737 found first last unihan-match unihan-info unihan-database-handle | 739 found first last unihan-match unihan-info unihan-database-handle |
738 (coding-system-for-read 'no-conversion-unix)) | 740 (coding-system-for-read 'no-conversion-unix)) |
739 (if (re-search-forward (concat "^" hex) nil t) | 741 (if (re-search-forward (concat "^" hex) nil t) |