annotate lisp/international/mule-util.el @ 24662:5d61c3793c06

(cp-coding-system-for-codepage-1): Make the magnification parameter for the -dos encoder be 2.
author Andrew Innes <andrewi@gnu.org>
date Sun, 02 May 1999 09:48:22 +0000
parents ab39ea2168e7
children 84d705e026b4
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'."
20730
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
34 (let ((len (length string))
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
35 (i 0)
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
36 val)
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
37 (cond ((eq type 'list)
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
38 (setq val (make-list len 0))
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
39 (let ((l val))
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
40 (while (< i len)
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
41 (setcar l (aref string i))
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
42 (setq l (cdr l) i (1+ i)))))
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
43 ((eq type 'vector)
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
44 (setq val (make-vector len 0))
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
45 (while (< i len)
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
46 (aset val i (aref string i))
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
47 (setq i (1+ i))))
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
48 (t
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
49 (error "Invalid type: %s" type)))
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
50 val))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
51
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
52 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
53 (defsubst string-to-list (string)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
54 "Return a list of characters in STRING."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
55 (string-to-sequence string 'list))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
56
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
57 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
58 (defsubst string-to-vector (string)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
59 "Return a vector of characters in STRING."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
60 (string-to-sequence string 'vector))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
61
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
62 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
63 (defun store-substring (string idx obj)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
64 "Embed OBJ (string or character) at index IDX of STRING."
20730
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
65 (if (integerp obj)
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
66 (aset string idx obj)
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
67 (let ((len1 (length obj))
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
68 (len2 (length string))
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
69 (i 0))
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
70 (while (< i len1)
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
71 (aset string (+ idx i) (aref obj i))
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
72 (setq i (1+ i)))))
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
73 string)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
74
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
75 ;;;###autoload
19916
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
76 (defun truncate-string-to-width (str end-column &optional start-column padding)
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
77 "Truncate string STR to end at column END-COLUMN.
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
78 The optional 2nd arg START-COLUMN, if non-nil, specifies
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
79 the starting column; that means to return the characters occupying
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
80 columns START-COLUMN ... END-COLUMN of STR.
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
81
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
82 The optional 3rd arg PADDING, if non-nil, specifies a padding character
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
83 to add at the end of the result if STR doesn't reach column END-COLUMN,
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
84 or if END-COLUMN comes in the middle of a character in STR.
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
85 PADDING is also added at the beginning of the result
19928
7e4718c779b2 (truncate-string-to-width): Doc typo fix.
Richard M. Stallman <rms@gnu.org>
parents: 19916
diff changeset
86 if column START-COLUMN appears in the middle of a character in STR.
19916
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
87
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
88 If PADDING is nil, no padding is added in these cases, so
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
89 the resulting string may be narrower than END-COLUMN."
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
90 (or start-column
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
91 (setq start-column 0))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
92 (let ((len (length str))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
93 (idx 0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
94 (column 0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
95 (head-padding "") (tail-padding "")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
96 ch last-column last-idx from-idx)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
97 (condition-case nil
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
98 (while (< column start-column)
20730
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
99 (setq ch (aref str idx)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
100 column (+ column (char-width ch))
20730
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
101 idx (1+ idx)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
102 (args-out-of-range (setq idx len)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
103 (if (< column start-column)
19916
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
104 (if padding (make-string end-column padding) "")
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
105 (if (and padding (> column start-column))
20730
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
106 (setq head-padding (make-string (- column start-column) padding)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
107 (setq from-idx idx)
19916
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
108 (if (< end-column column)
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
109 (setq idx from-idx)
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
110 (condition-case nil
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
111 (while (< column end-column)
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
112 (setq last-column column
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
113 last-idx idx
20730
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
114 ch (aref str idx)
19916
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
115 column (+ column (char-width ch))
20730
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
116 idx (1+ idx)))
19916
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
117 (args-out-of-range (setq idx len)))
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
118 (if (> column end-column)
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
119 (setq column last-column idx last-idx))
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
120 (if (and padding (< column end-column))
f43513081277 (truncate-string-to-width):
Richard M. Stallman <rms@gnu.org>
parents: 19745
diff changeset
121 (setq tail-padding (make-string (- end-column column) padding))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
122 (setq str (substring str from-idx idx))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
123 (if padding
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
124 (concat head-padding str tail-padding)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
125 str))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
126
23196
30beacf88b75 Doc fixes.
Karl Heuer <kwzh@gnu.org>
parents: 22814
diff changeset
127 ;;; For backward compatibility ...
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
128 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
129 (defalias 'truncate-string 'truncate-string-to-width)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
130 (make-obsolete 'truncate-string 'truncate-string-to-width)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
131
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
132 ;;; Nested alist handler. Nested alist is alist whose elements are
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
133 ;;; also nested alist.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
134
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
135 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
136 (defsubst nested-alist-p (obj)
23196
30beacf88b75 Doc fixes.
Karl Heuer <kwzh@gnu.org>
parents: 22814
diff changeset
137 "Return t if OBJ is a nested alist.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
138
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
139 Nested alist is a list of the form (ENTRY . BRANCHES), where ENTRY is
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
140 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
141 (KEY-ELEMENT . NESTED-ALIST).
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
142
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
143 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
144 sequence KEYSEQ, where KEYSEQ is a sequence of KEY-ELEMENT. KEYSEQ
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
145 can be a string, a vector, or a list."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
146 (and obj (listp obj) (listp (cdr obj))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
147
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
148 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
149 (defun set-nested-alist (keyseq entry alist &optional len branches)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
150 "Set ENTRY for KEYSEQ in a nested alist ALIST.
23196
30beacf88b75 Doc fixes.
Karl Heuer <kwzh@gnu.org>
parents: 22814
diff changeset
151 Optional 4th arg LEN non-nil means the first LEN elements in KEYSEQ
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
152 is considered.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
153 Optional argument BRANCHES if non-nil is branches for a keyseq
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
154 longer than KEYSEQ.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
155 See the documentation of `nested-alist-p' for more detail."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
156 (or (nested-alist-p alist)
23196
30beacf88b75 Doc fixes.
Karl Heuer <kwzh@gnu.org>
parents: 22814
diff changeset
157 (error "Invalid argument %s" alist))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
158 (let ((islist (listp keyseq))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
159 (len (or len (length keyseq)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
160 (i 0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
161 key-elt slot)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
162 (while (< i len)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
163 (if (null (nested-alist-p alist))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
164 (error "Keyseq %s is too long for this nested alist" keyseq))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
165 (setq key-elt (if islist (nth i keyseq) (aref keyseq i)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
166 (setq slot (assoc key-elt (cdr alist)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
167 (if (null slot)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
168 (progn
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
169 (setq slot (cons key-elt (list t)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
170 (setcdr alist (cons slot (cdr alist)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
171 (setq alist (cdr slot))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
172 (setq i (1+ i)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
173 (setcar alist entry)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
174 (if branches
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
175 (if (cdr alist)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
176 (error "Can't set branches for keyseq %s" keyseq)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
177 (setcdr alist branches)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
178
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
179 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
180 (defun lookup-nested-alist (keyseq alist &optional len start nil-for-too-long)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
181 "Look up key sequence KEYSEQ in nested alist ALIST. Return the definition.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
182 Optional 1st argument LEN specifies the length of KEYSEQ.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
183 Optional 2nd argument START specifies index of the starting key.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
184 The returned value is normally a nested alist of which
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
185 car part is the entry for KEYSEQ.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
186 If ALIST is not deep enough for KEYSEQ, return number which is
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
187 how many key elements at the front of KEYSEQ it takes
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
188 to reach a leaf in ALIST.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
189 Optional 3rd argument NIL-FOR-TOO-LONG non-nil means return nil
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
190 even if ALIST is not deep enough."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
191 (or (nested-alist-p alist)
23196
30beacf88b75 Doc fixes.
Karl Heuer <kwzh@gnu.org>
parents: 22814
diff changeset
192 (error "invalid argument %s" alist))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
193 (or len
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
194 (setq len (length keyseq)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
195 (let ((i (or start 0)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
196 (if (catch 'lookup-nested-alist-tag
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
197 (if (listp keyseq)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
198 (while (< i len)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
199 (if (setq alist (cdr (assoc (nth i keyseq) (cdr alist))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
200 (setq i (1+ i))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
201 (throw 'lookup-nested-alist-tag t))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
202 (while (< i len)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
203 (if (setq alist (cdr (assoc (aref keyseq i) (cdr alist))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
204 (setq i (1+ i))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
205 (throw 'lookup-nested-alist-tag t))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
206 ;; KEYSEQ is too long.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
207 (if nil-for-too-long nil i)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
208 alist)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
209
18299
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
210
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
211 ;; Coding system related functions.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
212
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
213 ;;;###autoload
18200
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
214 (defun coding-system-eol-type-mnemonic (coding-system)
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
215 "Return mnemonic letter of eol-type of CODING-SYSTEM."
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
216 (let ((eol-type (coding-system-eol-type coding-system)))
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
217 (cond ((vectorp eol-type) eol-mnemonic-undecided)
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
218 ((eq eol-type 0) eol-mnemonic-unix)
21488
2c0815a83862 (coding-system-eol-type-mnemonic): Return correct eol-type mnemonics
Eli Zaretskii <eliz@gnu.org>
parents: 20841
diff changeset
219 ((eq eol-type 1) eol-mnemonic-dos)
2c0815a83862 (coding-system-eol-type-mnemonic): Return correct eol-type mnemonics
Eli Zaretskii <eliz@gnu.org>
parents: 20841
diff changeset
220 ((eq eol-type 2) eol-mnemonic-mac)
18200
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
221 (t ?-))))
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
222
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
223 ;;;###autoload
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
224 (defun coding-system-post-read-conversion (coding-system)
20113
00ca5f419c16 (coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents: 19932
diff changeset
225 "Return the value of CODING-SYSTEM's post-read-conversion property."
00ca5f419c16 (coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents: 19932
diff changeset
226 (coding-system-get coding-system 'post-read-conversion))
18200
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
227
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
228 ;;;###autoload
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
229 (defun coding-system-pre-write-conversion (coding-system)
20113
00ca5f419c16 (coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents: 19932
diff changeset
230 "Return the value of CODING-SYSTEM's pre-write-conversion property."
00ca5f419c16 (coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents: 19932
diff changeset
231 (coding-system-get coding-system 'pre-write-conversion))
18200
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
232
c913160e34a7 (set-coding-system-alist): Deleted.
Kenichi Handa <handa@m17n.org>
parents: 17092
diff changeset
233 ;;;###autoload
22126
97cf1cae1971 Change term unification to
Kenichi Handa <handa@m17n.org>
parents: 21554
diff changeset
234 (defun coding-system-translation-table-for-decode (coding-system)
97cf1cae1971 Change term unification to
Kenichi Handa <handa@m17n.org>
parents: 21554
diff changeset
235 "Return the value of CODING-SYSTEM's translation-table-for-decode property."
22186
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22126
diff changeset
236 (coding-system-get coding-system 'translation-table-for-decode))
19455
7cf3d42a6fd7 (coding-system-unification-table):
Kenichi Handa <handa@m17n.org>
parents: 19264
diff changeset
237
7cf3d42a6fd7 (coding-system-unification-table):
Kenichi Handa <handa@m17n.org>
parents: 19264
diff changeset
238 ;;;###autoload
22126
97cf1cae1971 Change term unification to
Kenichi Handa <handa@m17n.org>
parents: 21554
diff changeset
239 (defun coding-system-translation-table-for-encode (coding-system)
97cf1cae1971 Change term unification to
Kenichi Handa <handa@m17n.org>
parents: 21554
diff changeset
240 "Return the value of CODING-SYSTEM's translation-table-for-encode property."
22186
fc4aaf1b1772 Change term "character translation table" to "translation table".
Kenichi Handa <handa@m17n.org>
parents: 22126
diff changeset
241 (coding-system-get coding-system 'translation-table-for-encode))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
242
18299
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
243 ;;;###autoload
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
244 (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
245 "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
246 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
247 or one is an alias of the other."
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
248 (or (eq coding-system-1 coding-system-2)
20113
00ca5f419c16 (coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents: 19932
diff changeset
249 (and (equal (coding-system-spec coding-system-1)
00ca5f419c16 (coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents: 19932
diff changeset
250 (coding-system-spec coding-system-2))
00ca5f419c16 (coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents: 19932
diff changeset
251 (let ((eol-type-1 (coding-system-eol-type coding-system-1))
00ca5f419c16 (coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents: 19932
diff changeset
252 (eol-type-2 (coding-system-eol-type coding-system-2)))
00ca5f419c16 (coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents: 19932
diff changeset
253 (or (eq eol-type-1 eol-type-2)
00ca5f419c16 (coding-system-base): Moved to
Kenichi Handa <handa@m17n.org>
parents: 19932
diff changeset
254 (and (vectorp eol-type-1) (vectorp eol-type-2)))))))
18299
c6f35cac24b4 (coding-system-parent): New function.
Kenichi Handa <handa@m17n.org>
parents: 18200
diff changeset
255
20162
dc6f12ef4d47 (find-safe-coding-system): New function.
Kenichi Handa <handa@m17n.org>
parents: 20113
diff changeset
256 ;;;###autoload
20730
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
257 (defmacro detect-coding-with-priority (from to priority-list)
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
258 "Detect a coding system of the text between FROM and TO with PRIORITY-LIST.
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
259 PRIORITY-LIST is an alist of coding categories vs the corresponding
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
260 coding systems ordered by priority."
24485
ab39ea2168e7 (detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents: 24346
diff changeset
261 `(unwind-protect
ab39ea2168e7 (detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents: 24346
diff changeset
262 (let* ((prio-list ,priority-list)
ab39ea2168e7 (detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents: 24346
diff changeset
263 (coding-category-list coding-category-list)
ab39ea2168e7 (detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents: 24346
diff changeset
264 ,@(mapcar (function (lambda (x) (list x x)))
ab39ea2168e7 (detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents: 24346
diff changeset
265 coding-category-list))
ab39ea2168e7 (detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents: 24346
diff changeset
266 (mapcar (function (lambda (x) (set (car x) (cdr x))))
ab39ea2168e7 (detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents: 24346
diff changeset
267 prio-list)
ab39ea2168e7 (detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents: 24346
diff changeset
268 (set-coding-priority (mapcar (function (lambda (x) (car x)))
ab39ea2168e7 (detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents: 24346
diff changeset
269 prio-list))
ab39ea2168e7 (detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents: 24346
diff changeset
270 (detect-coding-region ,from ,to))
ab39ea2168e7 (detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents: 24346
diff changeset
271 ;; We must restore the internal database.
ab39ea2168e7 (detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents: 24346
diff changeset
272 (set-coding-priority coding-category-list)
ab39ea2168e7 (detect-coding-with-priority): Restore the internal database.
Kenichi Handa <handa@m17n.org>
parents: 24346
diff changeset
273 (update-coding-systems-internal)))
20162
dc6f12ef4d47 (find-safe-coding-system): New function.
Kenichi Handa <handa@m17n.org>
parents: 20113
diff changeset
274
20730
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
275 ;;;###autoload
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
276 (defun detect-coding-with-language-environment (from to lang-env)
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
277 "Detect a coding system of the text between FROM and TO with LANG-ENV.
23196
30beacf88b75 Doc fixes.
Karl Heuer <kwzh@gnu.org>
parents: 22814
diff changeset
278 The detection takes into account the coding system priorities for the
20730
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
279 language environment LANG-ENV."
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
280 (let ((coding-priority (get-language-info lang-env 'coding-priority)))
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
281 (if coding-priority
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
282 (detect-coding-with-priority
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
283 from to
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
284 (mapcar (function (lambda (x)
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
285 (cons (coding-system-get x 'coding-category) x)))
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
286 coding-priority))
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
287 (detect-coding-region from to))))
20162
dc6f12ef4d47 (find-safe-coding-system): New function.
Kenichi Handa <handa@m17n.org>
parents: 20113
diff changeset
288
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
289
23196
30beacf88b75 Doc fixes.
Karl Heuer <kwzh@gnu.org>
parents: 22814
diff changeset
290 ;;; Composite character manipulations.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
291
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
292 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
293 (defun compose-region (start end)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
294 "Compose all characters in the current region into one composite character.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
295 When called from a program, expects two arguments,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
296 positions (integers or markers) specifying the region."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
297 (interactive "r")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
298 (save-excursion
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
299 (let ((str (buffer-substring start end)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
300 (goto-char start)
23549
aab4ef022ffd (compose-region): Insert then delete
Kenichi Handa <handa@m17n.org>
parents: 23196
diff changeset
301 (insert (compose-string str))
aab4ef022ffd (compose-region): Insert then delete
Kenichi Handa <handa@m17n.org>
parents: 23196
diff changeset
302 (delete-char (- end start)))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
303
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
304 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
305 (defun decompose-region (start end)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
306 "Decompose all composite characters in the current region.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
307 Composite characters are broken up into individual components.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
308 When called from a program, expects two arguments,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
309 positions (integers or markers) specifying the region."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
310 (interactive "r")
24027
660b6f8b7928 (decompose-region): Do decomposition
Kenichi Handa <handa@m17n.org>
parents: 24006
diff changeset
311 (let ((buf (current-buffer))
660b6f8b7928 (decompose-region): Do decomposition
Kenichi Handa <handa@m17n.org>
parents: 24006
diff changeset
312 (cmpchar-head (char-to-string leading-code-composition)))
660b6f8b7928 (decompose-region): Do decomposition
Kenichi Handa <handa@m17n.org>
parents: 24006
diff changeset
313 (with-temp-buffer
660b6f8b7928 (decompose-region): Do decomposition
Kenichi Handa <handa@m17n.org>
parents: 24006
diff changeset
314 (insert-buffer-substring buf start end)
660b6f8b7928 (decompose-region): Do decomposition
Kenichi Handa <handa@m17n.org>
parents: 24006
diff changeset
315 (set-buffer-multibyte nil)
20730
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
316 (goto-char (point-min))
24027
660b6f8b7928 (decompose-region): Do decomposition
Kenichi Handa <handa@m17n.org>
parents: 24006
diff changeset
317 (while (search-forward cmpchar-head nil t)
660b6f8b7928 (decompose-region): Do decomposition
Kenichi Handa <handa@m17n.org>
parents: 24006
diff changeset
318 (if (looking-at "[\240-\377][\240-\377][\240-\377][\240-\377]+")
660b6f8b7928 (decompose-region): Do decomposition
Kenichi Handa <handa@m17n.org>
parents: 24006
diff changeset
319 (let* ((from (1- (point)))
660b6f8b7928 (decompose-region): Do decomposition
Kenichi Handa <handa@m17n.org>
parents: 24006
diff changeset
320 (to (match-end 0))
660b6f8b7928 (decompose-region): Do decomposition
Kenichi Handa <handa@m17n.org>
parents: 24006
diff changeset
321 (str (string-as-multibyte (buffer-substring from to))))
660b6f8b7928 (decompose-region): Do decomposition
Kenichi Handa <handa@m17n.org>
parents: 24006
diff changeset
322 (if (cmpcharp (string-to-char str))
660b6f8b7928 (decompose-region): Do decomposition
Kenichi Handa <handa@m17n.org>
parents: 24006
diff changeset
323 (progn
660b6f8b7928 (decompose-region): Do decomposition
Kenichi Handa <handa@m17n.org>
parents: 24006
diff changeset
324 (delete-region from to)
660b6f8b7928 (decompose-region): Do decomposition
Kenichi Handa <handa@m17n.org>
parents: 24006
diff changeset
325 (insert (string-as-unibyte (decompose-string str))))
660b6f8b7928 (decompose-region): Do decomposition
Kenichi Handa <handa@m17n.org>
parents: 24006
diff changeset
326 (goto-char to)))))
660b6f8b7928 (decompose-region): Do decomposition
Kenichi Handa <handa@m17n.org>
parents: 24006
diff changeset
327 (set-buffer-multibyte t)
660b6f8b7928 (decompose-region): Do decomposition
Kenichi Handa <handa@m17n.org>
parents: 24006
diff changeset
328 (let ((tempbuf (current-buffer)))
660b6f8b7928 (decompose-region): Do decomposition
Kenichi Handa <handa@m17n.org>
parents: 24006
diff changeset
329 (save-excursion
660b6f8b7928 (decompose-region): Do decomposition
Kenichi Handa <handa@m17n.org>
parents: 24006
diff changeset
330 (set-buffer buf)
660b6f8b7928 (decompose-region): Do decomposition
Kenichi Handa <handa@m17n.org>
parents: 24006
diff changeset
331 (goto-char start)
660b6f8b7928 (decompose-region): Do decomposition
Kenichi Handa <handa@m17n.org>
parents: 24006
diff changeset
332 (delete-region start end)
24338
3e873a016458 (decompose-region): Use
Kenichi Handa <handa@m17n.org>
parents: 24277
diff changeset
333 (insert-buffer-substring tempbuf))))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
334
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
335 ;;;###autoload
19264
6122dbba797f (prefer-coding-system): Moved to mule-util.el.
Kenichi Handa <handa@m17n.org>
parents: 19056
diff changeset
336 (defun decompose-string (string)
6122dbba797f (prefer-coding-system): Moved to mule-util.el.
Kenichi Handa <handa@m17n.org>
parents: 19056
diff changeset
337 "Decompose all composite characters in STRING."
20730
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
338 (let ((len (length string))
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
339 (idx 0)
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
340 (i 0)
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
341 (str-list nil)
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
342 ch)
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
343 (while (< idx len)
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
344 (setq ch (aref string idx))
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
345 (if (>= ch min-composite-char)
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
346 (progn
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
347 (if (> idx i)
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
348 (setq str-list (cons (substring string i idx) str-list)))
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
349 (setq str-list (cons (decompose-composite-char ch) str-list))
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
350 (setq i (1+ idx))))
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
351 (setq idx (1+ idx)))
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
352 (if (not str-list)
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
353 (copy-sequence string)
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
354 (if (> idx i)
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
355 (setq str-list (cons (substring string i idx) str-list)))
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
356 (apply 'concat (nreverse str-list)))))
19264
6122dbba797f (prefer-coding-system): Moved to mule-util.el.
Kenichi Handa <handa@m17n.org>
parents: 19056
diff changeset
357
6122dbba797f (prefer-coding-system): Moved to mule-util.el.
Kenichi Handa <handa@m17n.org>
parents: 19056
diff changeset
358 ;;;###autoload
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
359 (defconst reference-point-alist
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
360 '((tl . 0) (tc . 1) (tr . 2)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
361 (ml . 3) (mc . 4) (mr . 5)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
362 (bl . 6) (bc . 7) (br . 8)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
363 (top-left . 0) (top-center . 1) (top-right . 2)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
364 (mid-left . 3) (mid-center . 4) (mid-right . 5)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
365 (bottom-left . 6) (bottom-center . 7) (bottom-right . 8)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
366 (0 . 0) (1 . 1) (2 . 2)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
367 (3 . 3) (4 . 4) (5 . 5)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
368 (6 . 6) (7 . 7) (8 . 8))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
369 "Alist of reference point symbols vs reference point codes.
19048
65112b3cc989 (reference-point-alist): Doc-string modified.
Kenichi Handa <handa@m17n.org>
parents: 19016
diff changeset
370 A reference point symbol is to be used to specify a composition rule
65112b3cc989 (reference-point-alist): Doc-string modified.
Kenichi Handa <handa@m17n.org>
parents: 19016
diff changeset
371 while making a composite character by the function `compose-chars'
65112b3cc989 (reference-point-alist): Doc-string modified.
Kenichi Handa <handa@m17n.org>
parents: 19016
diff changeset
372 (which see).
65112b3cc989 (reference-point-alist): Doc-string modified.
Kenichi Handa <handa@m17n.org>
parents: 19016
diff changeset
373
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
374 Meanings of reference point codes are as follows:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
375
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
376 0----1----2 <-- ascent 0:tl or top-left
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
377 | | 1:tc or top-center
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
378 | | 2:tr or top-right
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
379 | | 3:ml or mid-left
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
380 | 4 <--+---- center 4:mc or mid-center
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
381 | | 5:mr or mid-right
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
382 --- 3 5 <-- baseline 6:bl or bottom-left
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
383 | | 7:bc or bottom-center
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
384 6----7----8 <-- descent 8:br or bottom-right
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
385
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
386 Reference point symbols are to be used to specify composition rule of
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
387 the form \(GLOBAL-REF-POINT . NEW-REF-POINT), where GLOBAL-REF-POINT
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
388 is a reference point in the overall glyphs already composed, and
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
389 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
390
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
391 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
392 overall glyph is updated as follows:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
393
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
394 +-------+--+ <--- new ascent
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
395 | | |
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
396 | global| |
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
397 | glyph | |
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
398 --- | | | <--- baseline (doesn't change)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
399 +----+--+--+
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
400 | | new |
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
401 | |glyph|
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
402 +----+-----+ <--- new descent
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
403 ")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
404
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
405 ;; Return a string for char CH to be embedded in multibyte form of
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
406 ;; composite character.
24241
31a8f281b188 (compose-chars-component): Add autoload cookie.
Kenichi Handa <handa@m17n.org>
parents: 24027
diff changeset
407 ;;;###autoload
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
408 (defun compose-chars-component (ch)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
409 (if (< ch 128)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
410 (format "\240%c" (+ ch 128))
20841
ef5fd882ca63 (compose-chars-component): Return
Kenichi Handa <handa@m17n.org>
parents: 20730
diff changeset
411 (let ((str (string-as-unibyte (char-to-string ch))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
412 (if (cmpcharp ch)
23687
9913df387dfb (compose-chars-component): Signal
Kenichi Handa <handa@m17n.org>
parents: 23549
diff changeset
413 (if (= (aref str 1) ?\xFF)
9913df387dfb (compose-chars-component): Signal
Kenichi Handa <handa@m17n.org>
parents: 23549
diff changeset
414 (error "Can't compose a rule-based composition character")
9913df387dfb (compose-chars-component): Signal
Kenichi Handa <handa@m17n.org>
parents: 23549
diff changeset
415 (substring str (if (= (aref str 1) ?\xFF) 2 1)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
416 (aset str 0 (+ (aref str 0) ?\x20))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
417 str))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
418
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
419 ;; Return a string for composition rule RULE to be embedded in
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
420 ;; multibyte form of composite character.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
421 (defsubst compose-chars-rule (rule)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
422 (char-to-string (+ ?\xA0
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
423 (* (cdr (assq (car rule) reference-point-alist)) 9)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
424 (cdr (assq (cdr rule) reference-point-alist)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
425
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
426 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
427 (defun compose-chars (first-component &rest args)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
428 "Return one char string composed from the arguments.
24250
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
429 For relative composition, each argument should be a non-composition character
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
430 or a relative-composition character.
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
431 For rule-based composition, Nth (where N is odd) argument should be
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
432 a non-composition character or a rule-based-composition character,
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
433 and Mth (where M is even) argument should be a composition rule.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
434 A composition rule has the form \(GLOBAL-REF-POINT . NEW-REF-POINT).
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
435 See the documentation of `reference-point-alist' for more detail."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
436 (if (= (length args) 0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
437 (char-to-string first-component)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
438 (let* ((with-rule (consp (car args)))
24250
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
439 (str (if (cmpcharp first-component)
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
440 (string-as-unibyte (char-to-string first-component))
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
441 (if with-rule
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
442 (concat (vector leading-code-composition ?\xFF)
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
443 (compose-chars-component first-component))
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
444 (concat (char-to-string leading-code-composition)
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
445 (compose-chars-component first-component))))))
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
446 (if (and (cmpcharp first-component)
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
447 (eq with-rule (/= (aref str 1) ?\xFF)))
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
448 (error "%s-compostion-character is not allowed in %s composition: %c"
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
449 (if with-rule "relative" "rule-based")
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
450 (if with-rule "rule-based" "relative")
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
451 first-component))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
452 (while args
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
453 (if with-rule
24250
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
454 (setq str (concat str (compose-chars-rule (car args)))
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
455 args (cdr args)))
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
456 (if (cmpcharp (car args))
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
457 (let ((cmp-str (string-as-unibyte (char-to-string (car args)))))
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
458 (if (eq with-rule (/= (aref cmp-str 1) ?\xFF))
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
459 (error "%s-compostion-character is not allowed in %s composition: %c"
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
460 (if with-rule "relative" "rule-based")
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
461 (if with-rule "rule-based" "relative")
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
462 (car args)))
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
463 (setq str (concat str (substring cmp-str
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
464 (if with-rule 2 1)))))
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
465 (setq str (concat str (compose-chars-component (car args)))))
98056b9021a6 (compose-chars): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 24241
diff changeset
466 (setq args (cdr args)))
20841
ef5fd882ca63 (compose-chars-component): Return
Kenichi Handa <handa@m17n.org>
parents: 20730
diff changeset
467 (string-as-multibyte str))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
468
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
469 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
470 (defun decompose-composite-char (char &optional type with-composition-rule)
20841
ef5fd882ca63 (compose-chars-component): Return
Kenichi Handa <handa@m17n.org>
parents: 20730
diff changeset
471 "Convert composite character CHAR to a sequence of the components.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
472 Optional 1st arg TYPE specifies the type of sequence returned.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
473 It should be `string' (default), `list', or `vector'.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
474 Optional 2nd arg WITH-COMPOSITION-RULE non-nil means the returned
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
475 sequence contains embedded composition rules if any. In this case, the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
476 order of elements in the sequence is the same as arguments for
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
477 `compose-chars' to create CHAR.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
478 If TYPE is omitted or is `string', composition rules are omitted
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
479 even if WITH-COMPOSITION-RULE is t."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
480 (or type
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
481 (setq type 'string))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
482 (let* ((len (composite-char-component-count char))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
483 (i (1- len))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
484 l)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
485 (setq with-composition-rule (and with-composition-rule
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
486 (not (eq type 'string))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
487 (composite-char-composition-rule-p char)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
488 (while (> i 0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
489 (setq l (cons (composite-char-component char i) l))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
490 (if with-composition-rule
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
491 (let ((rule (- (composite-char-composition-rule char i) ?\xA0)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
492 (setq l (cons (cons (/ rule 9) (% rule 9)) l))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
493 (setq i (1- i)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
494 (setq l (cons (composite-char-component char 0) l))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
495 (cond ((eq type 'string)
20730
42d729244a85 (find-safe-coding-system): Moved to
Kenichi Handa <handa@m17n.org>
parents: 20162
diff changeset
496 (apply 'string l))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
497 ((eq type 'list)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
498 l)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
499 (t ; i.e. TYPE is vector
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
500 (vconcat l)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
501
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
502 ;;; mule-util.el ends here