annotate lisp/international/mule-util.el @ 18595:14f25d37d137

Some files are in different directories.
author Richard M. Stallman <rms@gnu.org>
date Fri, 04 Jul 1997 04:59:58 +0000
parents 8b4a66c66dd6
children 754d9d9e851e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1 ;;; mule-util.el --- Utility functions for mulitilingual environment (mule)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
18377
8b4a66c66dd6 Change copyright notice.
Richard M. Stallman <rms@gnu.org>
parents: 18313
diff changeset
4 ;; Licensed to the Free Software Foundation.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6 ;; Keywords: mule, multilingual
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
9
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
13 ;; any later version.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
14
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
19
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
17071
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
23 ;; Boston, MA 02111-1307, USA.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
24
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
25 ;;; Code:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
26
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
27 ;;; String manipulations while paying attention to multibyte
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
28 ;;; characters.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
29
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
30 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
31 (defun string-to-sequence (string type)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
32 "Convert STRING to a sequence of TYPE which contains characters in STRING.
18200
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
33 TYPE should be `list' or `vector'."
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
34 (or (eq type 'list) (eq type 'vector)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
35 (error "Invalid type: %s" type))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
36 (let* ((len (length string))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
37 (i 0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
38 l ch)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
39 (while (< i len)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
40 (setq ch (sref string i))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
41 (setq l (cons ch l))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
42 (setq i (+ i (char-bytes ch))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
43 (setq l (nreverse l))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
44 (if (eq type 'list)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
45 l
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
46 (vconcat l))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
47
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
48 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
49 (defsubst string-to-list (string)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
50 "Return a list of characters in STRING."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
51 (string-to-sequence string 'list))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
52
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
53 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
54 (defsubst string-to-vector (string)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
55 "Return a vector of characters in STRING."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
56 (string-to-sequence string 'vector))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
57
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
58 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
59 (defun store-substring (string idx obj)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
60 "Embed OBJ (string or character) at index IDX of STRING."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
61 (let* ((str (cond ((stringp obj) obj)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
62 ((integerp obj) (char-to-string obj))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
63 (t (error
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
64 "Invalid argument (should be string or character): %s"
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
65 obj))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
66 (string-len (length string))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
67 (len (length str))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
68 (i 0))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
69 (while (and (< i len) (< idx string-len))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
70 (aset string idx (aref str i))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
71 (setq idx (1+ idx) i (1+ i)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
72 string))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
73
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
74 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
75 (defun truncate-string-to-width (str width &optional start-column padding)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
76 "Truncate string STR to fit in WIDTH columns.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
77 Optional 1st arg START-COLUMN if non-nil specifies the starting column.
17092
e7920fdc4948 (truncate-string-to-width): Argument PADDING can be a padding character.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
78 Optional 2nd arg PADDING if non-nil is a padding character to be padded at
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
79 the head and tail of the resulting string to fit in WIDTH if necessary.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
80 If PADDING is nil, the resulting string may be narrower than WIDTH."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
81 (or start-column
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
82 (setq start-column 0))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
83 (let ((len (length str))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
84 (idx 0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
85 (column 0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
86 (head-padding "") (tail-padding "")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
87 ch last-column last-idx from-idx)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
88 (condition-case nil
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
89 (while (< column start-column)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
90 (setq ch (sref str idx)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
91 column (+ column (char-width ch))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
92 idx (+ idx (char-bytes ch))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
93 (args-out-of-range (setq idx len)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
94 (if (< column start-column)
17092
e7920fdc4948 (truncate-string-to-width): Argument PADDING can be a padding character.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
95 (if padding (make-string width padding) "")
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
96 (if (and padding (> column start-column))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
97 (setq head-padding (make-string (- column start-column) ?\ )))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
98 (setq from-idx idx)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
99 (condition-case nil
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
100 (while (< column width)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
101 (setq last-column column
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
102 last-idx idx
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
103 ch (sref str idx)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
104 column (+ column (char-width ch))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
105 idx (+ idx (char-bytes ch))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
106 (args-out-of-range (setq idx len)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
107 (if (> column width)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
108 (setq column last-column idx last-idx))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
109 (if (and padding (< column width))
17092
e7920fdc4948 (truncate-string-to-width): Argument PADDING can be a padding character.
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
110 (setq tail-padding (make-string (- width column) padding)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
111 (setq str (substring str from-idx idx))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
112 (if padding
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
113 (concat head-padding str tail-padding)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
114 str))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
115
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
116 ;;; For backward compatiblity ...
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
117 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
118 (defalias 'truncate-string 'truncate-string-to-width)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
119 (make-obsolete 'truncate-string 'truncate-string-to-width)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
120
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
121 ;;; Nested alist handler. Nested alist is alist whose elements are
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
122 ;;; also nested alist.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
123
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
124 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
125 (defsubst nested-alist-p (obj)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
126 "Return t if OBJ is a nesetd alist.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
127
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
128 Nested alist is a list of the form (ENTRY . BRANCHES), where ENTRY is
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
129 any Lisp object, and BRANCHES is a list of cons cells of the form
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
130 (KEY-ELEMENT . NESTED-ALIST).
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
131
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
132 You can use a nested alist to store any Lisp object (ENTRY) for a key
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
133 sequence KEYSEQ, where KEYSEQ is a sequence of KEY-ELEMENT. KEYSEQ
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
134 can be a string, a vector, or a list."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
135 (and obj (listp obj) (listp (cdr obj))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
136
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
137 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
138 (defun set-nested-alist (keyseq entry alist &optional len branches)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
139 "Set ENTRY for KEYSEQ in a nested alist ALIST.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
140 Optional 4th arg LEN non-nil means the firlst LEN elements in KEYSEQ
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
141 is considered.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
142 Optional argument BRANCHES if non-nil is branches for a keyseq
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
143 longer than KEYSEQ.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
144 See the documentation of `nested-alist-p' for more detail."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
145 (or (nested-alist-p alist)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
146 (error "Invalid arguement %s" alist))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
147 (let ((islist (listp keyseq))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
148 (len (or len (length keyseq)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
149 (i 0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
150 key-elt slot)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
151 (while (< i len)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
152 (if (null (nested-alist-p alist))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
153 (error "Keyseq %s is too long for this nested alist" keyseq))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
154 (setq key-elt (if islist (nth i keyseq) (aref keyseq i)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
155 (setq slot (assoc key-elt (cdr alist)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
156 (if (null slot)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
157 (progn
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
158 (setq slot (cons key-elt (list t)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
159 (setcdr alist (cons slot (cdr alist)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
160 (setq alist (cdr slot))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
161 (setq i (1+ i)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
162 (setcar alist entry)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
163 (if branches
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
164 (if (cdr alist)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
165 (error "Can't set branches for keyseq %s" keyseq)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
166 (setcdr alist branches)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
167
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
168 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
169 (defun lookup-nested-alist (keyseq alist &optional len start nil-for-too-long)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
170 "Look up key sequence KEYSEQ in nested alist ALIST. Return the definition.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
171 Optional 1st argument LEN specifies the length of KEYSEQ.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
172 Optional 2nd argument START specifies index of the starting key.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
173 The returned value is normally a nested alist of which
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
174 car part is the entry for KEYSEQ.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
175 If ALIST is not deep enough for KEYSEQ, return number which is
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
176 how many key elements at the front of KEYSEQ it takes
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
177 to reach a leaf in ALIST.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
178 Optional 3rd argument NIL-FOR-TOO-LONG non-nil means return nil
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
179 even if ALIST is not deep enough."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
180 (or (nested-alist-p alist)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
181 (error "invalid arguement %s" alist))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
182 (or len
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
183 (setq len (length keyseq)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
184 (let ((i (or start 0)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
185 (if (catch 'lookup-nested-alist-tag
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
186 (if (listp keyseq)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
187 (while (< i len)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
188 (if (setq alist (cdr (assoc (nth i keyseq) (cdr alist))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
189 (setq i (1+ i))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
190 (throw 'lookup-nested-alist-tag t))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
191 (while (< i len)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
192 (if (setq alist (cdr (assoc (aref keyseq i) (cdr alist))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
193 (setq i (1+ i))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
194 (throw 'lookup-nested-alist-tag t))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
195 ;; KEYSEQ is too long.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
196 (if nil-for-too-long nil i)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
197 alist)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
198
18299
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
199
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
200 ;; Coding system related functions.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
201
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
202 ;;;###autoload
18200
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
203 (defun coding-system-base (coding-system)
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
204 "Return a base of CODING-SYSTEM.
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
205 The base is a coding system of which coding-system property is a
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
206 coding-spec (see the function `make-coding-system')."
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
207 (let ((coding-spec (get coding-system 'coding-system)))
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
208 (if (vectorp coding-spec)
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
209 coding-system
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
210 (coding-system-base coding-spec))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
211
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
212 ;;;###autoload
18200
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
213 (defun coding-system-eol-type-mnemonic (coding-system)
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
214 "Return mnemonic letter of eol-type of CODING-SYSTEM."
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
215 (let ((eol-type (coding-system-eol-type coding-system)))
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
216 (cond ((vectorp eol-type) eol-mnemonic-undecided)
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
217 ((eq eol-type 0) eol-mnemonic-unix)
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
218 ((eq eol-type 1) eol-mnemonic-unix)
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
219 ((eq eol-type 2) eol-mnemonic-unix)
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
220 (t ?-))))
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
221
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
222 ;;;###autoload
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
223 (defun coding-system-post-read-conversion (coding-system)
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
224 "Return post-read-conversion property of CODING-SYSTEM."
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
225 (and coding-system
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
226 (symbolp coding-system)
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
227 (or (get coding-system 'post-read-conversion)
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
228 (coding-system-post-read-conversion
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
229 (get coding-system 'coding-system)))))
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
230
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
231 ;;;###autoload
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
232 (defun coding-system-pre-write-conversion (coding-system)
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
233 "Return pre-write-conversion property of CODING-SYSTEM."
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
234 (and coding-system
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
235 (symbolp coding-system)
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
236 (or (get coding-system 'pre-write-conversion)
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
237 (coding-system-pre-write-conversion
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
238 (get coding-system 'coding-system)))))
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
239
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
240 ;;;###autoload
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
241 (defun coding-system-unification-table (coding-system)
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
242 "Return unification-table property of CODING-SYSTEM."
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
243 (and coding-system
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
244 (symbolp coding-system)
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
245 (or (get coding-system 'unification-table)
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
246 (coding-system-unification-table
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
247 (get coding-system 'coding-system)))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
248
18299
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
249 (defun coding-system-lessp (x y)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
250 (cond ((eq x 'no-conversion) t)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
251 ((eq y 'no-conversion) nil)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
252 ((eq x 'emacs-mule) t)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
253 ((eq y 'emacs-mule) nil)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
254 ((eq x 'undecided) t)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
255 ((eq y 'undecided) nil)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
256 (t (let ((c1 (coding-system-mnemonic x))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
257 (c2 (coding-system-mnemonic y)))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
258 (or (< (downcase c1) (downcase c2))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
259 (and (not (> (downcase c1) (downcase c2)))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
260 (< c1 c2)))))))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
261
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
262 ;;;###autoload
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
263 (defun coding-system-list (&optional base-only)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
264 "Return a list of all existing coding systems.
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
265 If optional arg BASE-ONLY is non-nil, only base coding systems are listed."
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
266 (let (l)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
267 (mapatoms (lambda (x) (if (get x 'coding-system) (setq l (cons x l)))))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
268 (let* ((codings (sort l 'coding-system-lessp))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
269 (tail (cons nil codings))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
270 coding)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
271 ;; At first, remove subsidiary coding systems (eol variants) and
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
272 ;; alias coding systems (if necessary).
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
273 (while (cdr tail)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
274 (setq coding (car (cdr tail)))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
275 (if (or (get coding 'eol-variant)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
276 (and base-only (coding-system-parent coding)))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
277 (setcdr tail (cdr (cdr tail)))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
278 (setq tail (cdr tail))))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
279 codings)))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
280
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
281 ;;;###autoload
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
282 (defun modify-coding-system-alist (target-type regexp coding-system)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
283 "Modify one of look up tables for finding a coding system on I/O operation.
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
284 There are three of such tables, file-coding-system-alist,
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
285 process-coding-system-alist, and network-coding-system-alist.
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
286
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
287 TARGET-TYPE specifies which of them to modify.
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
288 If it is `file', it affects file-coding-system-alist (which see).
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
289 If it is `process', it affects process-coding-system-alist (which see).
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
290 If it is `network', it affects network-codign-system-alist (which see).
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
291
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
292 REGEXP is a regular expression matching a target of I/O operation.
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
293 The target is a file name if TARGET-TYPE is `file', a program name if
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
294 TARGET-TYPE is `process', or a network service name or a port number
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
295 to connect to if TARGET-TYPE is `network'.
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
296
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
297 CODING-SYSTEM is a coding system to perform code conversion on the I/O
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
298 operation, or a cons of coding systems for decoding and encoding
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
299 respectively, or a function symbol which returns the cons."
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
300 (or (memq target-type '(file process network))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
301 (error "Invalid target type: %s" target-type))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
302 (or (stringp regexp)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
303 (and (eq target-type 'network) (integerp regexp))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
304 (error "Invalid regular expression: %s" regexp))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
305 (if (symbolp coding-system)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
306 (if (not (fboundp coding-system))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
307 (progn
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
308 (check-coding-system coding-system)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
309 (setq coding-system (cons coding-system coding-system))))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
310 (check-coding-system (car coding-system))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
311 (check-coding-system (cdr coding-system)))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
312 (cond ((eq target-type 'file)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
313 (let ((slot (assoc regexp file-coding-system-alist)))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
314 (if slot
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
315 (setcdr slot coding-system)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
316 (setq file-coding-system-alist
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
317 (cons (cons regexp coding-system)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
318 file-coding-system-alist)))))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
319 ((eq target-type 'process)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
320 (let ((slot (assoc regexp process-coding-system-alist)))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
321 (if slot
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
322 (setcdr slot coding-system)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
323 (setq process-coding-system-alist
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
324 (cons (cons regexp coding-system)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
325 process-coding-system-alist)))))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
326 (t
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
327 (let ((slot (assoc regexp network-coding-system-alist)))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
328 (if slot
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
329 (setcdr slot coding-system)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
330 (setq network-coding-system-alist
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
331 (cons (cons regexp coding-system)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
332 network-coding-system-alist)))))))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
333
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
334 ;;;###autoload
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
335 (defun coding-system-plist (coding-system)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
336 "Return property list of CODING-SYSTEM."
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
337 (let ((found nil)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
338 coding-spec eol-type
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
339 post-read-conversion pre-write-conversion
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
340 unification-table)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
341 (while (not found)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
342 (or eol-type
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
343 (setq eol-type (get coding-system 'eol-type)))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
344 (or post-read-conversion
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
345 (setq post-read-conversion
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
346 (get coding-system 'post-read-conversion)))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
347 (or pre-write-conversion
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
348 (setq pre-write-conversion
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
349 (get coding-system 'pre-write-conversion)))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
350 (or unification-table
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
351 (setq unification-table
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
352 (get coding-system 'unification-table)))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
353 (setq coding-spec (get coding-system 'coding-system))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
354 (if (and coding-spec (symbolp coding-spec))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
355 (setq coding-system coding-spec)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
356 (setq found t)))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
357 (if (not coding-spec)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
358 (error "Invalid coding system: %s" coding-system))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
359 (list 'coding-spec coding-spec
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
360 'eol-type eol-type
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
361 'post-read-conversion post-read-conversion
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
362 'pre-write-conversion pre-write-conversion
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
363 'unification-table unification-table)))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
364
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
365 ;;;###autoload
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
366 (defun coding-system-equal (coding-system-1 coding-system-2)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
367 "Return t if and only if CODING-SYSTEM-1 and CODING-SYSTEM-2 are identical.
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
368 Two coding systems are identical if two symbols are equal
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
369 or one is an alias of the other."
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
370 (or (eq coding-system-1 coding-system-2)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
371 (equal (coding-system-plist coding-system-1)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
372 (coding-system-plist coding-system-2))))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
373
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
374 ;;;###autoload
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
375 (defun prefer-coding-system (coding-system)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
376 (interactive "zPrefered coding system: ")
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
377 (if (not (and coding-system (coding-system-p coding-system)))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
378 (error "Invalid coding system `%s'" coding-system))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
379 (let ((coding-category (coding-system-category coding-system))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
380 (parent (coding-system-parent coding-system)))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
381 (if (not coding-category)
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
382 ;; CODING-SYSTEM is no-conversion or undecided.
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
383 (error "Can't prefer the coding system `%s'" coding-system))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
384 (set coding-category (or parent coding-system))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
385 (if (not (eq coding-category (car coding-category-list)))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
386 ;; We must change the order.
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
387 (setq coding-category-list
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
388 (cons coding-category
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
389 (delq coding-category coding-category-list))))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
390 (if (and parent (interactive-p))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
391 (message "Highest priority is set to %s (parent of %s)"
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
392 parent coding-system))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
393 ))
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
394
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
395
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
396 ;;; Composite charcater manipulations.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
397
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
398 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
399 (defun compose-region (start end)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
400 "Compose all characters in the current region into one composite character.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
401 When called from a program, expects two arguments,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
402 positions (integers or markers) specifying the region."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
403 (interactive "r")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
404 (save-excursion
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
405 (let ((str (buffer-substring start end)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
406 (goto-char start)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
407 (delete-region start end)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
408 (insert (compose-string str)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
409
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
410 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
411 (defun decompose-region (start end)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
412 "Decompose all composite characters in the current region.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
413 Composite characters are broken up into individual components.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
414 When called from a program, expects two arguments,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
415 positions (integers or markers) specifying the region."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
416 (interactive "r")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
417 (save-restriction
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
418 (narrow-to-region start end)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
419 (goto-char (point-min))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
420 (let ((enable-multibyte-characters nil)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
421 ;; This matches the whole bytes of single composite character.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
422 (re-cmpchar "\200[\240-\377]+")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
423 p ch str)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
424 (while (re-search-forward re-cmpchar nil t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
425 (setq str (buffer-substring (match-beginning 0) (match-end 0)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
426 (delete-region (match-beginning 0) (match-end 0))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
427 (insert (decompose-composite-char (string-to-char str)))))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
428
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
429 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
430 (defconst reference-point-alist
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
431 '((tl . 0) (tc . 1) (tr . 2)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
432 (ml . 3) (mc . 4) (mr . 5)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
433 (bl . 6) (bc . 7) (br . 8)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
434 (top-left . 0) (top-center . 1) (top-right . 2)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
435 (mid-left . 3) (mid-center . 4) (mid-right . 5)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
436 (bottom-left . 6) (bottom-center . 7) (bottom-right . 8)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
437 (0 . 0) (1 . 1) (2 . 2)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
438 (3 . 3) (4 . 4) (5 . 5)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
439 (6 . 6) (7 . 7) (8 . 8))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
440 "Alist of reference point symbols vs reference point codes.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
441 Meanings of reference point codes are as follows:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
442
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
443 0----1----2 <-- ascent 0:tl or top-left
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
444 | | 1:tc or top-center
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
445 | | 2:tr or top-right
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
446 | | 3:ml or mid-left
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
447 | 4 <--+---- center 4:mc or mid-center
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
448 | | 5:mr or mid-right
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
449 --- 3 5 <-- baseline 6:bl or bottom-left
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
450 | | 7:bc or bottom-center
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
451 6----7----8 <-- descent 8:br or bottom-right
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
452
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
453 Reference point symbols are to be used to specify composition rule of
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
454 the form \(GLOBAL-REF-POINT . NEW-REF-POINT), where GLOBAL-REF-POINT
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
455 is a reference point in the overall glyphs already composed, and
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
456 NEW-REF-POINT is a reference point in the new glyph to be added.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
457
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
458 For instance, if GLOBAL-REF-POINT is 8 and NEW-REF-POINT is 1, the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
459 overall glyph is updated as follows:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
460
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
461 +-------+--+ <--- new ascent
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
462 | | |
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
463 | global| |
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
464 | glyph | |
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
465 --- | | | <--- baseline (doesn't change)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
466 +----+--+--+
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
467 | | new |
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
468 | |glyph|
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
469 +----+-----+ <--- new descent
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
470 ")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
471
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
472 ;; Return a string for char CH to be embedded in multibyte form of
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
473 ;; composite character.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
474 (defun compose-chars-component (ch)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
475 (if (< ch 128)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
476 (format "\240%c" (+ ch 128))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
477 (let ((str (char-to-string ch)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
478 (if (cmpcharp ch)
18299
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
479 (substring str (if (= (aref str 1) ?\xFF) 2 1))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
480 (aset str 0 (+ (aref str 0) ?\x20))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
481 str))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
482
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
483 ;; Return a string for composition rule RULE to be embedded in
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
484 ;; multibyte form of composite character.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
485 (defsubst compose-chars-rule (rule)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
486 (char-to-string (+ ?\xA0
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
487 (* (cdr (assq (car rule) reference-point-alist)) 9)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
488 (cdr (assq (cdr rule) reference-point-alist)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
489
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
490 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
491 (defun compose-chars (first-component &rest args)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
492 "Return one char string composed from the arguments.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
493 Each argument is a character (including a composite chararacter)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
494 or a composition rule.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
495 A composition rule has the form \(GLOBAL-REF-POINT . NEW-REF-POINT).
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
496 See the documentation of `reference-point-alist' for more detail."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
497 (if (= (length args) 0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
498 (char-to-string first-component)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
499 (let* ((with-rule (consp (car args)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
500 (str (if with-rule (concat (vector leading-code-composition ?\xFF))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
501 (char-to-string leading-code-composition))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
502 (setq str (concat str (compose-chars-component first-component)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
503 (while args
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
504 (if with-rule
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
505 (progn
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
506 (if (not (consp (car args)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
507 (error "Invalid composition rule: %s" (car args)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
508 (setq str (concat str (compose-chars-rule (car args))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
509 (compose-chars-component (car (cdr args))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
510 args (cdr (cdr args))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
511 (setq str (concat str (compose-chars-component (car args)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
512 args (cdr args))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
513 str)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
514
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
515 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
516 (defun decompose-composite-char (char &optional type with-composition-rule)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
517 "Convert composite character CHAR to a string containing components of CHAR.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
518 Optional 1st arg TYPE specifies the type of sequence returned.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
519 It should be `string' (default), `list', or `vector'.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
520 Optional 2nd arg WITH-COMPOSITION-RULE non-nil means the returned
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
521 sequence contains embedded composition rules if any. In this case, the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
522 order of elements in the sequence is the same as arguments for
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
523 `compose-chars' to create CHAR.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
524 If TYPE is omitted or is `string', composition rules are omitted
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
525 even if WITH-COMPOSITION-RULE is t."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
526 (or type
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
527 (setq type 'string))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
528 (let* ((len (composite-char-component-count char))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
529 (i (1- len))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
530 l)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
531 (setq with-composition-rule (and with-composition-rule
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
532 (not (eq type 'string))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
533 (composite-char-composition-rule-p char)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
534 (while (> i 0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
535 (setq l (cons (composite-char-component char i) l))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
536 (if with-composition-rule
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
537 (let ((rule (- (composite-char-composition-rule char i) ?\xA0)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
538 (setq l (cons (cons (/ rule 9) (% rule 9)) l))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
539 (setq i (1- i)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
540 (setq l (cons (composite-char-component char 0) l))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
541 (cond ((eq type 'string)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
542 (apply 'concat-chars l))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
543 ((eq type 'list)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
544 l)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
545 (t ; i.e. TYPE is vector
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
546 (vconcat l)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
547
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
548 ;;; mule-util.el ends here