(shuowen-radicals): Use ?宮 instead of ?宫; add ?呂, ?穴, ?㝱, ?𤕫,
[chise/xemacs-chise.git.1] / lisp / utf-2000 / char-db-util.el
1 ;;; char-db-util.el --- Character Database utility -*- coding: utf-8-er; -*-
2
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 ;;   2007, 2008 MORIOKA Tomohiko.
5
6 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
7 ;; Keywords: CHISE, Character Database, ISO/IEC 10646, UCS, Unicode, MULE.
8
9 ;; This file is part of XEmacs CHISE.
10
11 ;; XEmacs CHISE is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
15
16 ;; XEmacs CHISE is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs CHISE; see the file COPYING.  If not, write to
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Code:
27
28 (require 'alist)
29
30 (defconst unidata-normative-category-alist
31   '(("Lu" letter        uppercase)
32     ("Ll" letter        lowercase)
33     ("Lt" letter        titlecase)
34     ("Mn" mark          non-spacing)
35     ("Mc" mark          spacing-combining)
36     ("Me" mark          enclosing)
37     ("Nd" number        decimal-digit)
38     ("Nl" number        letter)
39     ("No" number        other)
40     ("Zs" separator     space)
41     ("Zl" separator     line)
42     ("Zp" separator     paragraph)
43     ("Cc" other         control)
44     ("Cf" other         format)
45     ("Cs" other         surrogate)
46     ("Co" other         private-use)
47     ("Cn" other         not-assigned)))
48
49 (defconst unidata-informative-category-alist
50   '(("Lm" letter        modifier)
51     ("Lo" letter        other)
52     ("Pc" punctuation   connector)
53     ("Pd" punctuation   dash)
54     ("Ps" punctuation   open)
55     ("Pe" punctuation   close)
56     ("Pi" punctuation   initial-quote)
57     ("Pf" punctuation   final-quote)
58     ("Po" punctuation   other)
59     ("Sm" symbol        math)
60     ("Sc" symbol        currency)
61     ("Sk" symbol        modifier)
62     ("So" symbol        other)
63     ))
64
65 (defconst ideographic-radicals
66   (let ((v (make-vector 215 nil))
67         (i 1))
68     (while (< i 215)
69       (aset v i (decode-char '=ucs (+ #x2EFF i)))
70       (setq i (1+ i)))
71     v))
72
73 (defun ideographic-radical (number)
74   (aref ideographic-radicals number))
75
76 (defconst shuowen-radicals
77   [?一 ?上 ?示 ?三 ?王 ?玉 ?玨 ?气 ?士 ?丨 ; 010
78    ?屮 ?艸 ?蓐 ?茻 ?小 ?八 ?釆 ?半 ?牛 ?犛 ; 020
79    ?告 ?口 ?凵 ?吅 ?哭 ?走 ?止 ?癶 ?步 ?此 ; 030
80    ?正 ?是 ?辵 ?彳 ?廴 ?㢟 ?行 ?齒 ?牙 ?足 ; 040
81    ?疋 ?品 ?龠 ?冊 ?㗊 ?舌 ?干 ?谷 ?只 ?㕯 ; 050
82    ?句 ?丩 ?古 ?十 ?卅 ?言 ?誩 ?音 ?䇂 ?丵 ; 060
83    ?菐 ?𠬞 ?廾 ?共 ?異 ?舁 ?𦥑 ?䢅 ?爨 ?革 ; 070
84    ?鬲 ?䰜 ?爪 ?𠃨 ?鬥 ?又 ?𠂇 ?㕜 ?支 ?𦘒 ; 080
85    ?聿 ?畫 ?隶 ?臤 ?臣 ?殳 ?殺 ?𠘧 ?寸 ?皮 ; 090
86    ?㼱 ?攴 ?敎 ?卜 ?用 ?爻 ?㸚 ?𥄎 ?目 ?䀠 ; 100
87    ?眉 ?盾 ?自 ?白 ?鼻 ?皕 ?習 ?羽 ?隹 ?奞 ; 110
88    ?萑 ?𦫳 ?苜 ?羊 ?羴 ?瞿 ?雔 ?雥 ?鳥 ?烏 ; 120
89    ?𠦒 ?冓 ?幺 ?𢆶 ?叀 ?玄 ?予 ?放 ?𠬪 ?𣦼 ; 130
90    ?歺 ?死 ?冎 ?骨 ?肉 ?筋 ?刀 ?刃 ?㓞 ?丰 ; 140
91    ?耒 ?𧢲 ?竹 ?箕 ?丌 ?左 ?工 ?㠭 ?巫 ?甘 ; 150
92    ?曰 ?乃 ?丂 ?可 ?兮 ?号 ?亏 ?旨 ?喜 ?壴 ; 160
93    ?鼓 ?豈 ?豆 ?豊 ?豐 ?䖒 ?虍 ?虎 ?虤 ?皿 ; 170
94    ?𠙴 ?去 ?血 ?丶 ?丹 ?青 ?井 ?皀 ?鬯 ?食 ; 180
95    ?亼 ?會 ?倉 ?入 ?缶 ?矢 ?高 ?冂 ?𩫏 ?京 ; 190
96    ?亯 ?𣆪 ?畗 ?㐭 ?嗇 ?來 ?麥 ?夊 ?舛 ?䑞 ; 200
97    ?韋 ?弟 ?夂 ?久 ?桀 ?木 ?東 ?林 ?才 ?叒 ; 210
98    ?之 ?帀 ?出 ?𣎵 ?生 ?乇 ?𠂹 ?𠌶 ?華 ?𥝌 ; 220
99    ?稽 ?巢 ?桼 ?束 ?㯻 ?囗 ?員 ?貝 ?邑 ?𨛜 ; 230
100    ?日 ?旦 ?倝 ?㫃 ?冥 ?晶 ?月 ?有 ?明 ?囧 ; 240
101    ?夕 ?多 ?毌 ?𢎘 ?𣐺 ?卣 ?齊 ?朿 ?片 ?鼎 ; 250
102    ?克 ?彔 ?禾 ?秝 ?黍 ?香 ?米 ?毇 ?臼 ?凶 ; 260
103    ?𣎳 ?林 ?麻 ?尗 ?耑 ?韭 ?瓜 ?瓠 ?宀 ?宮 ; 270
104    ?呂 ?穴 ?㝱 ?𤕫 ?冖 ?𠔼 ?冃 ?㒳 ?网 ?襾 ; 280
105    ])
106
107 (defun shuowen-radical (number)
108   (aref shuowen-radicals (1- number)))
109
110 (defvar char-db-file-coding-system 'utf-8-mcs-er)
111
112 (defvar char-db-feature-domains
113   '(ucs ucs/compat daikanwa cns gt jis jis/alt jis/a jis/b
114         jis-x0212 jis-x0213 cdp shinjigen misc unknown))
115
116 (defvar char-db-ignored-attributes '(ideographic-products))
117
118 (defun char-attribute-name< (ka kb)
119   (cond
120    ((eq '->denotational kb)
121     t)
122    ((eq '->subsumptive kb)
123     (not (eq '->denotational ka)))
124    ((eq '->denotational ka)
125     nil)
126    ((eq '->subsumptive ka)
127     nil)
128    ((and (symbolp ka)
129          (string-match "^->" (symbol-name ka)))
130     (cond ((and (symbolp kb)
131                 (string-match "^->" (symbol-name kb)))
132            (string< (symbol-name ka)
133                     (symbol-name kb))
134            ))
135     )
136    ((and (symbolp kb)
137          (string-match "^->" (symbol-name kb)))
138     t)
139    ((and (symbolp ka)
140          (string-match "^<-" (symbol-name ka)))
141     (cond ((symbolp kb)
142            (cond ((string-match "^<-" (symbol-name kb))
143                   (string< (symbol-name ka)
144                            (symbol-name kb))
145                   )
146                  ;; ((string-match "^->" (symbol-name kb))
147                  ;;  t)
148                  )))
149     )
150    ((and (symbolp kb)
151          (string-match "^<-" (symbol-name kb)))
152     t
153     ;; (not (string-match "^->" (symbol-name ka)))
154     )
155    ((find-charset ka)
156     (if (find-charset kb)
157         (if (<= (charset-id ka) 1)
158             (if (<= (charset-id kb) 1)
159                 (cond
160                  ((= (charset-dimension ka)
161                      (charset-dimension kb))
162                   (> (charset-id ka)(charset-id kb)))
163                  (t
164                   (> (charset-dimension ka)
165                      (charset-dimension kb))
166                   ))
167               t)
168           (if (<= (charset-id kb) 1)
169               nil
170             (< (charset-id ka)(charset-id kb))))
171       nil))
172    ((find-charset kb)
173     t)
174    ((symbolp ka)
175     (cond ((symbolp kb)
176            (string< (symbol-name ka)
177                     (symbol-name kb)))
178           (t)))
179    ((symbolp kb)
180     nil)))
181
182 (defvar char-db-coded-charset-priority-list
183   '(ascii
184     control-1
185     latin-iso8859-1
186     latin-iso8859-2
187     latin-iso8859-3
188     latin-iso8859-4
189     latin-iso8859-9
190     latin-jisx0201
191     cyrillic-iso8859-5
192     greek-iso8859-7
193     thai-tis620
194     =jis-x0208
195     =jis-x0208@1978
196     =jis-x0208@1983
197     japanese-jisx0212
198     chinese-gb2312
199     =jis-x0208@1990
200     chinese-cns11643-1
201     chinese-cns11643-2
202     chinese-cns11643-3
203     chinese-cns11643-4
204     chinese-cns11643-5
205     chinese-cns11643-6
206     chinese-cns11643-7
207     =jis-x0213-1-2000
208     =jis-x0213-2-2000
209     korean-ksc5601
210     chinese-isoir165
211     katakana-jisx0201
212     hebrew-iso8859-8
213     chinese-gb12345
214     latin-viscii
215     ethiopic-ucs
216     =big5-cdp
217     =gt
218     ideograph-daikanwa-2
219     ideograph-daikanwa
220     =cbeta
221     ideograph-hanziku-1
222     ideograph-hanziku-2
223     ideograph-hanziku-3
224     ideograph-hanziku-4
225     ideograph-hanziku-5
226     ideograph-hanziku-6
227     ideograph-hanziku-7
228     ideograph-hanziku-8
229     ideograph-hanziku-9
230     ideograph-hanziku-10
231     ideograph-hanziku-11
232     ideograph-hanziku-12
233     =gt-k
234     =ucs@iso
235     =ucs@unicode
236     =big5
237     =big5-eten
238     =jis-x0208@1997
239     =zinbun-oracle
240     =ruimoku-v6
241     =jef-china3))
242
243 (defun char-db-make-char-spec (char)
244   (let (ret char-spec)
245     (cond ((characterp char)
246            (cond ((and (setq ret (encode-char char '=ucs 'defined-only))
247                        (not (and (<= #xE000 ret)(<= ret #xF8FF))))
248                   (setq char-spec (list (cons '=ucs ret)))
249                   (cond ((setq ret (get-char-attribute char 'name))
250                          (setq char-spec (cons (cons 'name ret) char-spec))
251                          )
252                         ((setq ret (get-char-attribute char 'name*))
253                          (setq char-spec (cons (cons 'name* ret) char-spec))
254                          ))
255                   )
256                  ((setq ret
257                         (catch 'tag
258                           (let ((rest char-db-coded-charset-priority-list)
259                                 ccs)
260                             (while rest
261                               (setq ccs (charset-name
262                                          (find-charset (car rest))))
263                               (if (setq ret
264                                         (encode-char char ccs
265                                                      'defined-only))
266                                   (throw 'tag (cons ccs ret)))
267                               (setq rest (cdr rest))))))
268                   (setq char-spec (list ret))
269                   (dolist (ccs (delq (car ret) (charset-list)))
270                     (if (and (or (charset-iso-final-char ccs)
271                                  (memq ccs
272                                        '(=daikanwa
273                                          =daikanwa@rev2
274                                          ;; =gt-k
275                                          =jis-x0208@1997
276                                          )))
277                              (setq ccs (charset-name ccs))
278                              (null (assq ccs char-spec))
279                              (setq ret (encode-char char ccs 'defined-only)))
280                         (setq char-spec (cons (cons ccs ret) char-spec))))
281                   (if (null char-spec)
282                       (setq char-spec (split-char char)))
283                   (cond ((setq ret (get-char-attribute char 'name))
284                          (setq char-spec (cons (cons 'name ret) char-spec))
285                          )
286                         ((setq ret (get-char-attribute char 'name*))
287                          (setq char-spec (cons (cons 'name* ret) char-spec))
288                          ))
289                   ))
290            char-spec)
291           ((consp char)
292            char))))
293     
294 (defun char-db-insert-char-spec (char &optional readable column
295                                       required-features)
296   (unless column
297     (setq column (current-column)))
298   (let (char-spec temp-char)
299     (setq char-spec (char-db-make-char-spec char))
300     (unless (or (characterp char) ; char
301                 (condition-case nil
302                     (setq char (find-char char-spec))
303                   (error nil)))
304       ;; define temporary character
305       ;;   Current implementation is dirty.
306       (setq temp-char (define-char (cons '(ideograph-daikanwa . 0)
307                                          char-spec)))
308       (remove-char-attribute temp-char 'ideograph-daikanwa)
309       (setq char temp-char))
310     (insert-char-attributes char
311                             readable
312                             (union (mapcar #'car char-spec)
313                                    required-features))
314     (when temp-char
315       ;; undefine temporary character
316       ;;   Current implementation is dirty.
317       (setq char-spec (char-attribute-alist temp-char))
318       (while char-spec
319         (remove-char-attribute temp-char (car (car char-spec)))
320         (setq char-spec (cdr char-spec))))))
321
322 (defun char-db-insert-alist (alist &optional readable column)
323   (unless column
324     (setq column (current-column)))
325   (let ((line-breaking
326          (concat "\n" (make-string (1+ column) ?\ )))
327         name value
328         ret al ; cal
329         key
330         lbs cell rest separator)
331     (insert "(")
332     (while alist
333       (setq name (car (car alist))
334             value (cdr (car alist)))
335       (cond ((eq name 'char)
336              (insert "(char . ")
337              (if (setq ret (condition-case nil
338                                (find-char value)
339                              (error nil)))
340                  (progn
341                    (setq al nil
342                          ;; cal nil
343                          )
344                    (while value
345                      (setq key (car (car value)))
346                      ;; (if (find-charset key)
347                      ;;     (setq cal (cons key cal))
348                      (setq al (cons key al))
349                      ;; )
350                      (setq value (cdr value)))
351                    (insert-char-attributes ret
352                                            readable
353                                            (or al 'none) ; cal
354                                            ))
355                (insert (prin1-to-string value)))
356              (insert ")")
357              (insert line-breaking))
358             ((consp value)
359              (insert (format "(%-18s " name))
360              (setq lbs (concat "\n" (make-string (current-column) ?\ )))
361              (while (consp value)
362                (setq cell (car value))
363                (if (and (consp cell)
364                         (consp (car cell))
365                         (setq ret (condition-case nil
366                                       (find-char cell)
367                                     (error nil)))
368                         )
369                    (progn
370                      (setq rest cell
371                            al nil
372                            ;; cal nil
373                            )
374                      (while rest
375                        (setq key (car (car rest)))
376                        ;; (if (find-charset key)
377                        ;;     (setq cal (cons key cal))
378                        (setq al (cons key al))
379                        ;; )
380                        (setq rest (cdr rest)))
381                      (if separator
382                          (insert lbs))
383                      (insert-char-attributes ret
384                                              readable
385                                              al ; cal
386                                              )
387                      (setq separator lbs))
388                  (if separator
389                      (insert separator))
390                  (insert (prin1-to-string cell))
391                  (setq separator " "))
392                (setq value (cdr value)))
393              (insert ")")
394              (insert line-breaking))
395             (t
396              (insert (format "(%-18s . %S)%s"
397                              name value
398                              line-breaking))))
399       (setq alist (cdr alist))))
400   (insert ")"))
401
402 (defun char-db-insert-char-reference (plist &optional readable column)
403   (unless column
404     (setq column (current-column)))
405   (let ((line-breaking
406          (concat "\n" (make-string (1+ column) ?\ )))
407         (separator "")
408         name value)
409     (insert "(")
410     (while plist
411       (setq name (pop plist))
412       (setq value (pop plist))
413       (cond ((eq name :char)
414              (insert separator)
415              (insert ":char\t")
416              (cond ((numberp value)
417                     (setq value (decode-char '=ucs value)))
418                    ;; ((consp value)
419                    ;;  (setq value (or (find-char value)
420                    ;;                  value)))
421                    )
422              (char-db-insert-char-spec value readable)
423              (insert line-breaking)
424              (setq separator ""))
425             ((eq name :radical)
426              (insert (format "%s%s\t%d ; %c%s"
427                              separator
428                              name value
429                              (ideographic-radical value)
430                              line-breaking))
431              (setq separator ""))
432             (t
433              (insert (format "%s%s\t%S" separator name value))
434              (setq separator line-breaking)))
435       ))
436   (insert ")"))
437
438 (defun char-db-decode-isolated-char (ccs code-point)
439   (let (ret)
440     (setq ret
441           (cond ((eq ccs 'arabic-iso8859-6)
442                  (decode-char ccs code-point))
443                 ((and (memq ccs '(=gt-pj-1
444                                   =gt-pj-2
445                                   =gt-pj-3
446                                   =gt-pj-4
447                                   =gt-pj-5
448                                   =gt-pj-6
449                                   =gt-pj-7
450                                   =gt-pj-8
451                                   =gt-pj-9
452                                   =gt-pj-10
453                                   =gt-pj-11))
454                       (setq ret (decode-char ccs code-point))
455                       (setq ret (encode-char ret '=gt 'defined-only)))
456                  (decode-builtin-char '=gt ret))
457                 (t
458                  (decode-builtin-char ccs code-point))))
459     (cond ((and (<= 0 (char-int ret))
460                 (<= (char-int ret) #x1F))
461            (decode-char '=ucs (+ #x2400 (char-int ret))))
462           ((= (char-int ret) #x7F)
463            ?\u2421)
464           (t ret))))
465
466 (defvar char-db-convert-obsolete-format t)
467
468 (defun char-db-insert-ccs-feature (name value line-breaking)
469   (insert
470    (format
471     (cond ((or (memq name '(=daikanwa
472                             =daikanwa@rev1 =daikanwa@rev2
473                             =gt =gt-k =cbeta =zinbun-oracle))
474                (string-match "^=adobe-" (symbol-name name)))
475            "(%-18s . %05d)\t; %c")
476           ((eq name 'mojikyo)
477            "(%-18s . %06d)\t; %c")
478           ((>= (charset-dimension name) 2)
479            "(%-18s . #x%04X)\t; %c")
480           (t
481            "(%-18s . #x%02X)\t; %c"))
482     name
483     (if (= (charset-iso-graphic-plane name) 1)
484         (logior value
485                 (cond ((= (charset-dimension name) 1)
486                        #x80)
487                       ((= (charset-dimension name) 2)
488                        #x8080)
489                       ((= (charset-dimension name) 3)
490                        #x808080)
491                       (t 0)))
492       value)
493     (char-db-decode-isolated-char name value)))
494   (if (and (= (charset-chars name) 94)
495            (= (charset-dimension name) 2))
496       (insert (format " [%02d-%02d]"
497                       (- (lsh value -8) 32)
498                       (- (logand value 255) 32))))
499   (insert line-breaking))
500
501 (defun char-db-insert-relation-feature (char name value line-breaking
502                                              ccss readable)
503   (insert (format "(%-18s%s " name line-breaking))
504   (let ((lbs (concat "\n" (make-string (current-column) ?\ )))
505         separator cell sources required-features
506         ret)
507     (while (consp value)
508       (setq cell (car value))
509       (if (integerp cell)
510           (setq cell (decode-char '=ucs cell)))
511       (cond
512        ((eq name '->subsumptive)
513         (when (or (not (some (lambda (atr)
514                                (get-char-attribute cell atr))
515                              char-db-ignored-attributes))
516                   (some (lambda (ccs)
517                           (encode-char cell ccs 'defined-only))
518                         ccss))
519           (if separator
520               (insert lbs))
521           (let ((char-db-ignored-attributes
522                  (cons '<-subsumptive
523                        char-db-ignored-attributes)))
524             (insert-char-attributes cell readable))
525           (setq separator lbs))
526         )
527        ((characterp cell)
528         (setq sources
529               (get-char-attribute
530                char (intern (format "%s*sources" name))))
531         (setq required-features nil)
532         (dolist (source sources)
533           (cond
534            ((memq source '(JP JP/Jouyou shinjigen-1))
535             (setq required-features
536                   (union required-features
537                          '(=jis-x0208
538                            =jis-x0208@1990
539                            =jis-x0213-1-2000
540                            =jis-x0213-2-2000
541                            =jis-x0212
542                            =jis-x0208@1983
543                            =jis-x0208@1978))))
544            ((eq source 'CN)
545             (setq required-features
546                   (union required-features
547                          '(=gb2312
548                            =gb12345
549                            =iso-ir165)))))
550           (cond
551            ((find-charset (setq ret (intern (format "=%s" source))))
552             (setq required-features
553                   (cons ret required-features)))
554            (t (setq required-features
555                     (cons source required-features)))))
556         (cond ((string-match "@JP" (symbol-name name))
557                (setq required-features
558                      (union required-features
559                             '(=jis-x0208
560                               =jis-x0208@1990
561                               =jis-x0213-1-2000
562                               =jis-x0213-2-2000
563                               =jis-x0212
564                               =jis-x0208@1983
565                               =jis-x0208@1978))))
566               ((string-match "@CN" (symbol-name name))
567                (setq required-features
568                      (union required-features
569                             '(=gb2312
570                               =gb12345
571                               =iso-ir165)))))
572         (if separator
573             (insert lbs))
574         (if readable
575             (insert (format "%S" cell))
576           (char-db-insert-char-spec cell readable
577                                     nil
578                                     required-features))
579         (setq separator lbs))
580        ((consp cell)
581         (if separator
582             (insert lbs))
583         (if (consp (car cell))
584             (char-db-insert-char-spec cell readable)
585           (char-db-insert-char-reference cell readable))
586         (setq separator lbs))
587        (t
588         (if separator
589             (insert separator))
590         (insert (prin1-to-string cell))
591         (setq separator " ")))
592       (setq value (cdr value)))
593     (insert ")")
594     (insert line-breaking)))
595
596 (defun insert-char-attributes (char &optional readable attributes column)
597   (unless column
598     (setq column (current-column)))
599   (let (name value ; has-long-ccs-name
600         rest
601         radical strokes
602         (line-breaking
603          (concat "\n" (make-string (1+ column) ?\ )))
604         lbs cell separator ret
605         key al cal
606         dest-ccss ; sources required-features
607         ccss)
608     (let (atr-d)
609       (setq attributes
610             (sort (if attributes
611                       (if (consp attributes)
612                           (progn
613                             (dolist (name attributes)
614                               (unless (memq name char-db-ignored-attributes)
615                                 (if (find-charset name)
616                                     (push name ccss))
617                                 (push name atr-d)))
618                             atr-d))
619                     (dolist (name (char-attribute-list))
620                       (unless (memq name char-db-ignored-attributes)
621                         (if (find-charset name)
622                             (push name ccss))
623                         (push name atr-d)))
624                     atr-d)
625                   #'char-attribute-name<)))
626     (insert "(")
627     (when (memq '<-subsumptive attributes)
628       (when readable
629         (when (setq value (get-char-attribute char '<-subsumptive))
630           (char-db-insert-relation-feature char '<-subsumptive value
631                                            line-breaking
632                                            ccss readable)))
633       (setq attributes (delq '<-subsumptive attributes)))
634     (when (and (memq '<-denotational attributes)
635                (setq value (get-char-attribute char '<-denotational)))
636       (char-db-insert-relation-feature char '<-denotational value
637                                        line-breaking
638                                        ccss readable)
639       (setq attributes (delq '<-denotational attributes)))
640     (when (and (memq 'name attributes)
641                (setq value (get-char-attribute char 'name)))
642       (insert (format
643                (if (> (+ (current-column) (length value)) 48)
644                    "(name . %S)%s"
645                  "(name               . %S)%s")
646                value line-breaking))
647       (setq attributes (delq 'name attributes))
648       )
649     (when (and (memq 'name* attributes)
650                (setq value (get-char-attribute char 'name*)))
651       (insert (format
652                (if (> (+ (current-column) (length value)) 48)
653                    "(name* . %S)%s"
654                  "(name*              . %S)%s")
655                value line-breaking))
656       (setq attributes (delq 'name* attributes))
657       )
658     (when (and (memq 'script attributes)
659                (setq value (get-char-attribute char 'script)))
660       (insert (format "(script\t\t%s)%s"
661                       (mapconcat (function prin1-to-string)
662                                  value " ")
663                       line-breaking))
664       (setq attributes (delq 'script attributes))
665       )
666     (dolist (name '(=>ucs =>ucs*))
667       (when (and (memq name attributes)
668                  (setq value (get-char-attribute char name)))
669         (insert (format "(%-18s . #x%04X)\t; %c%s"
670                         name value (decode-char '=ucs value)
671                         line-breaking))
672         (setq attributes (delq name attributes))))
673     (dolist (name '(=>ucs@gb =>ucs@cns =>ucs@jis =>ucs@ks =>ucs@big5))
674       (when (and (memq name attributes)
675                  (setq value (get-char-attribute char name)))
676         (insert (format "(%-18s . #x%04X)\t; %c%s"
677                         name value
678                         (decode-char (intern
679                                       (concat "="
680                                               (substring
681                                                (symbol-name name) 2)))
682                                      value)
683                         line-breaking))
684         (setq attributes (delq name attributes))
685         ))
686     (dolist (name '(=>daikanwa))
687       (when (and (memq name attributes)
688                  (setq value (get-char-attribute char name)))
689         (insert
690          (if (integerp value)
691              (format "(%-18s . %05d)\t; %c%s"
692                      name value (decode-char '=daikanwa value)
693                      line-breaking)
694            (format "(%-18s %s)\t; %c%s"
695                    name
696                    (mapconcat (function prin1-to-string)
697                               value " ")
698                    (char-representative-of-daikanwa char)
699                    line-breaking)))
700         (setq attributes (delq name attributes))))
701     (when (and (memq 'general-category attributes)
702                (setq value (get-char-attribute char 'general-category)))
703       (insert (format
704                "(general-category\t%s) ; %s%s"
705                (mapconcat (lambda (cell)
706                             (format "%S" cell))
707                           value " ")
708                (cond ((rassoc value unidata-normative-category-alist)
709                       "Normative Category")
710                      ((rassoc value unidata-informative-category-alist)
711                       "Informative Category")
712                      (t
713                       "Unknown Category"))
714                line-breaking))
715       (setq attributes (delq 'general-category attributes))
716       )
717     (when (and (memq 'bidi-category attributes)
718                (setq value (get-char-attribute char 'bidi-category)))
719       (insert (format "(bidi-category\t. %S)%s"
720                       value
721                       line-breaking))
722       (setq attributes (delq 'bidi-category attributes))
723       )
724     (unless (or (not (memq 'mirrored attributes))
725                 (eq (setq value (get-char-attribute char 'mirrored 'empty))
726                     'empty))
727       (insert (format "(mirrored\t\t. %S)%s"
728                       value
729                       line-breaking))
730       (setq attributes (delq 'mirrored attributes))
731       )
732     (cond
733      ((and (memq 'decimal-digit-value attributes)
734            (setq value (get-char-attribute char 'decimal-digit-value)))
735       (insert (format "(decimal-digit-value . %S)%s"
736                       value
737                       line-breaking))
738       (setq attributes (delq 'decimal-digit-value attributes))
739       (when (and (memq 'digit-value attributes)
740                  (setq value (get-char-attribute char 'digit-value)))
741         (insert (format "(digit-value\t . %S)%s"
742                         value
743                         line-breaking))
744         (setq attributes (delq 'digit-value attributes))
745         )
746       (when (and (memq 'numeric-value attributes)
747                  (setq value (get-char-attribute char 'numeric-value)))
748         (insert (format "(numeric-value\t . %S)%s"
749                         value
750                         line-breaking))
751         (setq attributes (delq 'numeric-value attributes))
752         )
753       )
754      (t
755       (when (and (memq 'digit-value attributes)
756                  (setq value (get-char-attribute char 'digit-value)))
757         (insert (format "(digit-value\t. %S)%s"
758                         value
759                         line-breaking))
760         (setq attributes (delq 'digit-value attributes))
761         )
762       (when (and (memq 'numeric-value attributes)
763                  (setq value (get-char-attribute char 'numeric-value)))
764         (insert (format "(numeric-value\t. %S)%s"
765                         value
766                         line-breaking))
767         (setq attributes (delq 'numeric-value attributes))
768         )))
769     (when (and (memq 'iso-10646-comment attributes)
770                (setq value (get-char-attribute char 'iso-10646-comment)))
771       (insert (format "(iso-10646-comment\t. %S)%s"
772                       value
773                       line-breaking))
774       (setq attributes (delq 'iso-10646-comment attributes))
775       )
776     (when (and (memq 'morohashi-daikanwa attributes)
777                (setq value (get-char-attribute char 'morohashi-daikanwa)))
778       (insert (format "(morohashi-daikanwa\t%s)%s"
779                       (mapconcat (function prin1-to-string) value " ")
780                       line-breaking))
781       (setq attributes (delq 'morohashi-daikanwa attributes))
782       )
783     (setq radical nil
784           strokes nil)
785     (when (and (memq 'ideographic-radical attributes)
786                (setq value (get-char-attribute char 'ideographic-radical)))
787       (setq radical value)
788       (insert (format "(ideographic-radical . %S)\t; %c%s"
789                       radical
790                       (ideographic-radical radical)
791                       line-breaking))
792       (setq attributes (delq 'ideographic-radical attributes))
793       )
794     (when (and (memq 'shuowen-radical attributes)
795                (setq value (get-char-attribute char 'shuowen-radical)))
796       (insert (format "(shuowen-radical\t. %S)\t; %c%s"
797                       value
798                       (shuowen-radical value)
799                       line-breaking))
800       (setq attributes (delq 'shuowen-radical attributes))
801       )
802     (let (key)
803       (dolist (domain
804                (append
805                 char-db-feature-domains
806                 (let (dest domain)
807                   (dolist (feature (char-attribute-list))
808                     (setq feature (symbol-name feature))
809                     (when (string-match
810                            "\\(radical\\|strokes\\)@\\([^@*]+\\)\\(\\*\\|$\\)"
811                            feature)
812                       (setq domain (intern (match-string 2 feature)))
813                      (unless (memq domain dest)
814                        (setq dest (cons domain dest)))))
815                   (sort dest #'string<))))
816         (setq key (intern (format "%s@%s" 'ideographic-radical domain)))
817         (when (and (memq key attributes)
818                    (setq value (get-char-attribute char key)))
819           (setq radical value)
820           (insert (format "(%s . %S)\t; %c%s"
821                           key
822                           radical
823                           (ideographic-radical radical)
824                           line-breaking))
825           (setq attributes (delq key attributes))
826           )
827         (setq key (intern (format "%s@%s" 'ideographic-strokes domain)))
828         (when (and (memq key attributes)
829                    (setq value (get-char-attribute char key)))
830           (setq strokes value)
831           (insert (format "(%s . %S)%s"
832                           key
833                           strokes
834                           line-breaking))
835           (setq attributes (delq key attributes))
836           )
837         (setq key (intern (format "%s@%s" 'total-strokes domain)))
838         (when (and (memq key attributes)
839                    (setq value (get-char-attribute char key)))
840           (insert (format "(%s       . %S)%s"
841                           key
842                           value
843                           line-breaking))
844           (setq attributes (delq key attributes))
845           )
846         (dolist (feature '(ideographic-radical
847                            ideographic-strokes
848                            total-strokes))
849           (setq key (intern (format "%s@%s*sources" feature domain)))
850           (when (and (memq key attributes)
851                      (setq value (get-char-attribute char key)))
852             (insert (format "(%s%s" key line-breaking))
853             (dolist (cell value)
854               (insert (format " %s" cell)))
855             (insert ")")
856             (insert line-breaking)
857             (setq attributes (delq key attributes))
858             ))
859         ))
860     (when (and (memq 'ideographic-strokes attributes)
861                (setq value (get-char-attribute char 'ideographic-strokes)))
862       (setq strokes value)
863       (insert (format "(ideographic-strokes . %S)%s"
864                       strokes
865                       line-breaking))
866       (setq attributes (delq 'ideographic-strokes attributes))
867       )
868     (when (and (memq 'kangxi-radical attributes)
869                (setq value (get-char-attribute char 'kangxi-radical)))
870       (unless (eq value radical)
871         (insert (format "(kangxi-radical\t . %S)\t; %c%s"
872                         value
873                         (ideographic-radical value)
874                         line-breaking))
875         (or radical
876             (setq radical value)))
877       (setq attributes (delq 'kangxi-radical attributes))
878       )
879     (when (and (memq 'kangxi-strokes attributes)
880                (setq value (get-char-attribute char 'kangxi-strokes)))
881       (unless (eq value strokes)
882         (insert (format "(kangxi-strokes\t . %S)%s"
883                         value
884                         line-breaking))
885         (or strokes
886             (setq strokes value)))
887       (setq attributes (delq 'kangxi-strokes attributes))
888       )
889     (when (and (memq 'japanese-radical attributes)
890                (setq value (get-char-attribute char 'japanese-radical)))
891       (unless (eq value radical)
892         (insert (format "(japanese-radical\t . %S)\t; %c%s"
893                         value
894                         (ideographic-radical value)
895                         line-breaking))
896         (or radical
897             (setq radical value)))
898       (setq attributes (delq 'japanese-radical attributes))
899       )
900     (when (and (memq 'japanese-strokes attributes)
901                (setq value (get-char-attribute char 'japanese-strokes)))
902       (unless (eq value strokes)
903         (insert (format "(japanese-strokes\t . %S)%s"
904                         value
905                         line-breaking))
906         (or strokes
907             (setq strokes value)))
908       (setq attributes (delq 'japanese-strokes attributes))
909       )
910     (when (and (memq 'cns-radical attributes)
911                (setq value (get-char-attribute char 'cns-radical)))
912       (insert (format "(cns-radical\t . %S)\t; %c%s"
913                       value
914                       (ideographic-radical value)
915                       line-breaking))
916       (setq attributes (delq 'cns-radical attributes))
917       )
918     (when (and (memq 'cns-strokes attributes)
919                (setq value (get-char-attribute char 'cns-strokes)))
920       (unless (eq value strokes)
921         (insert (format "(cns-strokes\t . %S)%s"
922                         value
923                         line-breaking))
924         (or strokes
925             (setq strokes value)))
926       (setq attributes (delq 'cns-strokes attributes))
927       )
928     (when (and (memq 'shinjigen-1-radical attributes)
929                (setq value (get-char-attribute char 'shinjigen-1-radical)))
930       (unless (eq value radical)
931         (insert (format "(shinjigen-1-radical . %S)\t; %c%s"
932                         value
933                         (ideographic-radical value)
934                         line-breaking))
935         (or radical
936             (setq radical value)))
937       (setq attributes (delq 'shinjigen-1-radical attributes))
938       )
939     (when (and (memq 'ideographic- attributes)
940                (setq value (get-char-attribute char 'ideographic-)))
941       (insert "(ideographic-       ")
942       (setq lbs (concat "\n" (make-string (current-column) ?\ ))
943             separator nil)
944       (while (consp value)
945         (setq cell (car value))
946         (if (integerp cell)
947             (setq cell (decode-char '=ucs cell)))
948         (cond ((characterp cell)
949                (if separator
950                    (insert lbs))
951                (if readable
952                    (insert (format "%S" cell))
953                  (char-db-insert-char-spec cell readable))
954                (setq separator lbs))
955               ((consp cell)
956                (if separator
957                    (insert lbs))
958                (if (consp (car cell))
959                    (char-db-insert-char-spec cell readable)
960                  (char-db-insert-char-reference cell readable))
961                (setq separator lbs))
962               (t
963                (if separator
964                    (insert separator))
965                (insert (prin1-to-string cell))
966                (setq separator " ")))
967         (setq value (cdr value)))
968       (insert ")")
969       (insert line-breaking)
970       (setq attributes (delq 'ideographic- attributes)))
971     (when (and (memq 'total-strokes attributes)
972                (setq value (get-char-attribute char 'total-strokes)))
973       (insert (format "(total-strokes       . %S)%s"
974                       value
975                       line-breaking))
976       (setq attributes (delq 'total-strokes attributes))
977       )
978     (when (and (memq '->ideograph attributes)
979                (setq value (get-char-attribute char '->ideograph)))
980       (insert (format "(->ideograph\t%s)%s"
981                       (mapconcat (lambda (code)
982                                    (cond ((symbolp code)
983                                           (symbol-name code))
984                                          ((integerp code)
985                                           (format "#x%04X" code))
986                                          (t
987                                           (format "%s %S"
988                                                   line-breaking code))))
989                                  value " ")
990                       line-breaking))
991       (setq attributes (delq '->ideograph attributes))
992       )
993     ;; (when (and (memq '->decomposition attributes)
994     ;;            (setq value (get-char-attribute char '->decomposition)))
995     ;;   (insert (format "(->decomposition\t%s)%s"
996     ;;                   (mapconcat (lambda (code)
997     ;;                                (cond ((symbolp code)
998     ;;                                       (symbol-name code))
999     ;;                                      ((characterp code)
1000     ;;                                       (if readable
1001     ;;                                           (format "%S" code)
1002     ;;                                         (format "#x%04X"
1003     ;;                                                 (char-int code))
1004     ;;                                         ))
1005     ;;                                      ((integerp code)
1006     ;;                                       (format "#x%04X" code))
1007     ;;                                      (t
1008     ;;                                       (format "%s%S" line-breaking code))))
1009     ;;                              value " ")
1010     ;;                   line-breaking))
1011     ;;   (setq attributes (delq '->decomposition attributes))
1012     ;;   )
1013     (if (equal (get-char-attribute char '->titlecase)
1014                (get-char-attribute char '->uppercase))
1015         (setq attributes (delq '->titlecase attributes)))
1016     (when (and (memq '->mojikyo attributes)
1017                (setq value (get-char-attribute char '->mojikyo)))
1018       (insert (format "(->mojikyo\t\t. %06d)\t; %c%s"
1019                       value (decode-char 'mojikyo value)
1020                       line-breaking))
1021       (setq attributes (delq '->mojikyo attributes))
1022       )
1023     (when (and (memq 'hanyu-dazidian-vol attributes)
1024                (setq value (get-char-attribute char 'hanyu-dazidian-vol)))
1025       (insert (format "(hanyu-dazidian-vol  . %d)%s"
1026                       value line-breaking))
1027       (setq attributes (delq 'hanyu-dazidian-vol attributes))
1028       )
1029     (when (and (memq 'hanyu-dazidian-page attributes)
1030                (setq value (get-char-attribute char 'hanyu-dazidian-page)))
1031       (insert (format "(hanyu-dazidian-page . %d)%s"
1032                       value line-breaking))
1033       (setq attributes (delq 'hanyu-dazidian-page attributes))
1034       )
1035     (when (and (memq 'hanyu-dazidian-char attributes)
1036                (setq value (get-char-attribute char 'hanyu-dazidian-char)))
1037       (insert (format "(hanyu-dazidian-char . %d)%s"
1038                       value line-breaking))
1039       (setq attributes (delq 'hanyu-dazidian-char attributes))
1040       )
1041     (unless readable
1042       (dolist (ignored '(composition
1043                          ->denotational <-subsumptive ->ucs-unified
1044                          ->ideographic-component-forms))
1045         (setq attributes (delq ignored attributes))))
1046     (while attributes
1047       (setq name (car attributes))
1048       (if (setq value (get-char-attribute char name))
1049           (cond ((setq ret (find-charset name))
1050                  (setq name (charset-name ret))
1051                  (if (and (not (memq name dest-ccss))
1052                           (prog1
1053                               (setq value (get-char-attribute char name))
1054                             (setq dest-ccss (cons name dest-ccss))))
1055                      (char-db-insert-ccs-feature name value line-breaking))
1056                  )
1057                 ((string-match "^=>ucs@" (symbol-name name))
1058                  (insert (format "(%-18s . #x%04X)\t; %c%s"
1059                                  name value (decode-char '=ucs value)
1060                                  line-breaking))
1061                  )
1062                 ((eq name 'jisx0208-1978/4X)
1063                  (insert (format "(%-18s . #x%04X)%s"
1064                                  name value
1065                                  line-breaking))
1066                  )
1067                 ((and
1068                   (not readable)
1069                   (not (eq name '->subsumptive))
1070                   (not (eq name '->uppercase))
1071                   (not (eq name '->lowercase))
1072                   (not (eq name '->titlecase))
1073                   (not (eq name '->canonical))
1074                   (not (eq name '->Bopomofo))
1075                   (not (eq name '->mistakable))
1076                   (not (eq name '->ideographic-variants))
1077                   (null (get-char-attribute
1078                          char (intern (format "%s*sources" name))))
1079                   (not (string-match "\\*sources$" (symbol-name name)))
1080                   (null (get-char-attribute
1081                          char (intern (format "%s*note" name))))
1082                   (not (string-match "\\*note$" (symbol-name name)))
1083                   (or (eq name '<-identical)
1084                       (eq name '<-uppercase)
1085                       (eq name '<-lowercase)
1086                       (eq name '<-titlecase)
1087                       (eq name '<-canonical)
1088                       (eq name '<-ideographic-variants)
1089                       ;; (eq name '<-synonyms)
1090                       (string-match "^<-synonyms" (symbol-name name))
1091                       (eq name '<-mistakable)
1092                       (when (string-match "^->" (symbol-name name))
1093                         (cond
1094                          ((string-match "^->fullwidth" (symbol-name name))
1095                           (not (and (consp value)
1096                                     (characterp (car value))
1097                                     (encode-char
1098                                      (car value) '=ucs 'defined-only)))
1099                           )
1100                          (t)))
1101                       ))
1102                  )
1103                 ((or (eq name 'ideographic-structure)
1104                      (eq name 'ideographic-combination)
1105                      (eq name 'ideographic-)
1106                      (eq name '=decomposition)
1107                      (string-match "^=>decomposition" (symbol-name name))
1108                      (string-match "^\\(->\\|<-\\)[^*]*$" (symbol-name name))
1109                      (string-match "^\\(->\\|<-\\)[^*]*\\*sources$"
1110                                    (symbol-name name))
1111                      )
1112                  (char-db-insert-relation-feature char name value
1113                                                   line-breaking
1114                                                   ccss readable))
1115                 ((memq name '(ideograph=
1116                               original-ideograph-of
1117                               ancient-ideograph-of
1118                               vulgar-ideograph-of
1119                               wrong-ideograph-of
1120                               ;; simplified-ideograph-of
1121                               ideographic-variants
1122                               ;; ideographic-different-form-of
1123                               ))
1124                  (insert (format "(%-18s%s " name line-breaking))
1125                  (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1126                        separator nil)
1127                  (while (consp value)
1128                    (setq cell (car value))
1129                    (if (and (consp cell)
1130                             (consp (car cell)))
1131                        (progn
1132                          (if separator
1133                              (insert lbs))
1134                          (char-db-insert-alist cell readable)
1135                          (setq separator lbs))
1136                      (if separator
1137                          (insert separator))
1138                      (insert (prin1-to-string cell))
1139                      (setq separator " "))
1140                    (setq value (cdr value)))
1141                  (insert ")")
1142                  (insert line-breaking))
1143                 ((consp value)
1144                  (insert (format "(%-18s " name))
1145                  (setq lbs (concat "\n" (make-string (current-column) ?\ ))
1146                        separator nil)
1147                  (while (consp value)
1148                    (setq cell (car value))
1149                    (if (and (consp cell)
1150                             (consp (car cell))
1151                             (setq ret (condition-case nil
1152                                           (find-char cell)
1153                                         (error nil))))
1154                        (progn
1155                          (setq rest cell
1156                                al nil
1157                                cal nil)
1158                          (while rest
1159                            (setq key (car (car rest)))
1160                            (if (find-charset key)
1161                                (setq cal (cons key cal))
1162                              (setq al (cons key al)))
1163                            (setq rest (cdr rest)))
1164                          (if separator
1165                              (insert lbs))
1166                          (insert-char-attributes ret
1167                                                  readable
1168                                                  al cal)
1169                          (setq separator lbs))
1170                      (setq ret (prin1-to-string cell))
1171                      (if separator
1172                          (if (< (+ (current-column)
1173                                    (length ret)
1174                                    (length separator))
1175                                 76)
1176                              (insert separator)
1177                            (insert lbs)))
1178                      (insert ret)
1179                      (setq separator " "))
1180                    (setq value (cdr value)))
1181                  (insert ")")
1182                  (insert line-breaking))
1183                 (t
1184                  (insert (format "(%-18s" name))
1185                  (setq ret (prin1-to-string value))
1186                  (unless (< (+ (current-column)
1187                                (length ret)
1188                                3)
1189                             76)
1190                    (insert line-breaking))
1191                  (insert " . " ret ")" line-breaking)
1192                  ;; (insert (format "(%-18s . %S)%s"
1193                  ;;                 name value
1194                  ;;                 line-breaking))
1195                  )
1196                 ))
1197       (setq attributes (cdr attributes)))
1198     (insert ")")))
1199
1200 (defun insert-char-data (char &optional readable
1201                               attributes)
1202   (save-restriction
1203     (narrow-to-region (point)(point))
1204     (insert "(define-char
1205   '")
1206     (insert-char-attributes char readable attributes)
1207     (insert ")\n")
1208     (goto-char (point-min))
1209     (while (re-search-forward "[ \t]+$" nil t)
1210       (replace-match ""))
1211     ;; from tabify.
1212     (goto-char (point-min))
1213     (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
1214       (let ((column (current-column))
1215             (indent-tabs-mode t))
1216         (delete-region (match-beginning 0) (point))
1217         (indent-to column)))
1218     (goto-char (point-max))
1219     ;; (tabify (point-min)(point-max))
1220     ))
1221
1222 (defun insert-char-data-with-variant (char &optional printable
1223                                            no-ucs-unified
1224                                            script excluded-script)
1225   (insert-char-data char printable)
1226   (let ((variants (char-variants char))
1227         rest
1228         variant vs ret)
1229     (setq variants (sort variants #'<))
1230     (setq rest variants)
1231     (setq variants (cons char variants))
1232     (while rest
1233       (setq variant (car rest))
1234       (unless (get-char-attribute variant '<-subsumptive)
1235         (if (and (or (null script)
1236                      (null (setq vs (get-char-attribute variant 'script)))
1237                      (memq script vs))
1238                  (or (null excluded-script)
1239                      (null (setq vs (get-char-attribute variant 'script)))
1240                      (not (memq excluded-script vs))))
1241             (unless (and no-ucs-unified (get-char-attribute variant '=ucs))
1242               (insert-char-data variant printable)
1243               (if (setq ret (char-variants variant))
1244                   (while ret
1245                     (or (memq (car ret) variants)
1246                         ;; (get-char-attribute (car ret) '<-subsumptive)
1247                         (setq rest (nconc rest (list (car ret)))))
1248                     (setq ret (cdr ret)))))))
1249       (setq rest (cdr rest)))))
1250
1251 (defun insert-char-range-data (min max &optional script excluded-script)
1252   (let ((code min)
1253         char)
1254     (while (<= code max)
1255       (setq char (decode-char '=ucs code))
1256       (if (encode-char char '=ucs 'defined-only)
1257           (insert-char-data-with-variant char nil 'no-ucs-unified
1258                                          script excluded-script))
1259       (setq code (1+ code)))))
1260
1261 (defun write-char-range-data-to-file (min max file
1262                                           &optional script excluded-script)
1263   (let ((coding-system-for-write char-db-file-coding-system))
1264     (with-temp-buffer
1265       (insert (format ";; -*- coding: %s -*-\n"
1266                       char-db-file-coding-system))
1267       (insert-char-range-data min max script excluded-script)
1268       (write-region (point-min)(point-max) file))))
1269
1270 (defvar what-character-original-window-configuration)
1271
1272 ;;;###autoload
1273 (defun what-char-definition (char)
1274   (interactive (list (char-after)))
1275   (let ((buf (get-buffer-create "*Character Description*"))
1276         (the-buf (current-buffer))
1277         (win-conf (current-window-configuration)))
1278     (pop-to-buffer buf)
1279     (make-local-variable 'what-character-original-window-configuration)
1280     (setq what-character-original-window-configuration win-conf)
1281     (setq buffer-read-only nil)
1282     (erase-buffer)
1283     (condition-case err
1284         (progn
1285           (insert-char-data-with-variant char 'printable)
1286           (unless (char-attribute-alist char)
1287             (insert (format ";; = %c\n"
1288                             (let* ((rest (split-char char))
1289                                    (ccs (pop rest))
1290                                    (code (pop rest)))
1291                               (while rest
1292                                 (setq code (logior (lsh code 8)
1293                                                    (pop rest))))
1294                               (decode-char ccs code)))))
1295           ;; (char-db-update-comment)
1296           (set-buffer-modified-p nil)
1297           (view-mode the-buf (lambda (buf)
1298                                (set-window-configuration
1299                                 what-character-original-window-configuration)
1300                                ))
1301           (goto-char (point-min)))
1302       (error (progn
1303                (set-window-configuration
1304                 what-character-original-window-configuration)
1305                (signal (car err) (cdr err)))))))
1306
1307 (provide 'char-db-util)
1308
1309 ;;; char-db-util.el ends here