138
|
1 ;; mule-misc.el --- Miscellaneous Mule functions.
|
70
|
2
|
|
3 ;; Copyright (C) 1992,93,94,95 Free Software Foundation, Inc.
|
|
4 ;; Copyright (C) 1995 Amdahl Corporation.
|
|
5 ;; Copyright (C) 1995 Sun Microsystems.
|
|
6
|
|
7 ;; This file is part of XEmacs.
|
|
8
|
|
9 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
10 ;; under the terms of the GNU General Public License as published by
|
|
11 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
12 ;; any later version.
|
|
13
|
|
14 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
17 ;; General Public License for more details.
|
|
18
|
|
19 ;; You should have received a copy of the GNU General Public License
|
|
20 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 ;; Boston, MA 02111-1307, USA.
|
|
23
|
|
24 ;;;
|
|
25 ;;; protect specified local variables from kill-all-local-variables
|
|
26 ;;;
|
|
27
|
|
28 (defvar self-insert-after-hook nil
|
|
29 "Hook to run when extended self insertion command exits. Should take
|
|
30 two arguments START and END corresponding to character position.")
|
|
31
|
|
32 (make-variable-buffer-local 'self-insert-after-hook)
|
|
33
|
|
34 (defun toggle-display-direction ()
|
|
35 (interactive)
|
|
36 (setq display-direction (not display-direction))
|
|
37 (if (interactive-p) (redraw-display)))
|
|
38
|
|
39 ;;;
|
|
40 ;;; Utility functions for Mule
|
|
41 ;;;
|
|
42
|
|
43 ;(defun string-to-char-list (str)
|
|
44 ; (let ((len (length str))
|
|
45 ; (idx 0)
|
|
46 ; c l)
|
|
47 ; (while (< idx len)
|
|
48 ; (setq c (sref str idx))
|
|
49 ; (setq idx (+ idx (charset-dimension (char-charset c))))
|
|
50 ; (setq l (cons c l)))
|
|
51 ; (nreverse l)))
|
|
52
|
|
53 (defun string-to-char-list (str)
|
|
54 (mapcar 'identity str))
|
|
55
|
82
|
56 (defun string-width (string)
|
70
|
57 "Return number of columns STRING occupies when displayed.
|
|
58 Uses the charset-columns attribute of the characters in STRING,
|
|
59 which may not accurately represent the actual display width when
|
|
60 using a window system."
|
|
61 (let ((col 0)
|
|
62 (len (length string))
|
|
63 (i 0))
|
|
64 (while (< i len)
|
|
65 (setq col (+ col (charset-columns (char-charset (aref string i)))))
|
|
66 (setq i (1+ i)))
|
|
67 col))
|
|
68
|
82
|
69 (defalias 'string-columns 'string-width)
|
|
70 (make-obsolete 'string-columns 'string-width)
|
70
|
71
|
|
72 (defun delete-text-in-column (from to)
|
|
73 "Delete the text between column FROM and TO (exclusive) of the current line.
|
|
74 Nil of FORM or TO means the current column.
|
108
|
75
|
|
76 If there's a character across the borders, the character is replaced
|
|
77 with the same width of spaces before deleting."
|
70
|
78 (save-excursion
|
|
79 (let (p1 p2)
|
|
80 (if from
|
|
81 (progn
|
|
82 (setq p1 (move-to-column from))
|
|
83 (if (> p1 from)
|
|
84 (progn
|
|
85 (delete-char -1)
|
|
86 (insert-char ? (- p1 (current-column)))
|
|
87 (forward-char (- from p1))))))
|
|
88 (setq p1 (point))
|
|
89 (if to
|
|
90 (progn
|
|
91 (setq p2 (move-to-column to))
|
|
92 (if (> p2 to)
|
|
93 (progn
|
|
94 (delete-char -1)
|
|
95 (insert-char ? (- p2 (current-column)))
|
|
96 (forward-char (- to p2))))))
|
|
97 (setq p2 (point))
|
|
98 (delete-region p1 p2))))
|
|
99
|
|
100 ;; #### Someone translate this!!
|
|
101
|
|
102 (defun mc-normal-form-string (str)
|
|
103 "文字列 STR の漢字標準形文字列を返す."
|
|
104 (let ((i 0))
|
|
105 (while (setq i (string-match "\n" str i))
|
|
106 (if (and (<= 1 i) (< i (1- (length str)))
|
|
107 (< (aref str (1- i)) 128)
|
|
108 (< (aref str (1+ i)) 128))
|
|
109 (aset str i ? ))
|
|
110 (setq i (1+ i)))
|
|
111 (if (string-match "\n" str 0)
|
|
112 (let ((c 0) (i 0) new)
|
|
113 (while (setq i (string-match "\n" str i))
|
|
114 (setq i (1+ i))
|
|
115 (setq c (1+ c)))
|
|
116 (setq new (make-string (- (length str) c) 0))
|
|
117 (setq i 0 c 0)
|
|
118 (while (< i (length str))
|
|
119 (cond((not (= (aref str i) ?\n ))
|
|
120 (aset new c (aref str i))
|
|
121 (setq c (1+ c))))
|
|
122
|
|
123 (setq i (1+ i))
|
|
124 )
|
|
125 new)
|
|
126 str)))
|
|
127
|
|
128
|
|
129 (defun string-memq (str list)
|
|
130 "Returns non-nil if STR is an element of LIST. Comparison done with string=.
|
|
131 The value is actually the tail of LIST whose car is STR.
|
|
132 If each element of LIST is not a string, it is converted to string
|
|
133 before comparison."
|
|
134 (let (find elm)
|
|
135 (while (and (not find) list)
|
|
136 (setq elm (car list))
|
|
137 (if (numberp elm) (setq elm (char-to-string elm)))
|
|
138 (if (string= str elm)
|
|
139 (setq find list)
|
|
140 (setq list (cdr list))))
|
|
141 find))
|
|
142
|
|
143 (defun cancel-undo-boundary ()
|
|
144 "Cancel undo boundary."
|
|
145 (if (and (consp buffer-undo-list)
|
|
146 ;; if car is nil.
|
|
147 (null (car buffer-undo-list)) )
|
|
148 (setq buffer-undo-list (cdr buffer-undo-list)) ))
|
|
149
|
82
|
150
|
70
|
151 ;;; Common API emulation functions for GNU Emacs-merged Mule.
|
|
152 ;;; As suggested by MORIOKA Tomohiko
|
82
|
153
|
|
154 ;; Following definition were imported from Emacs/mule-delta.
|
|
155
|
165
|
156 ;; Function `truncate-string-to-width' was moved to mule-util.el.
|
82
|
157
|
|
158 ;; end of imported definition
|
|
159
|
70
|
160
|
|
161 (defalias 'sref 'aref)
|
|
162 (defalias 'map-char-concat 'mapcar)
|
82
|
163 (defun char-bytes (character)
|
|
164 "Return number of length a CHARACTER occupies in a string or buffer.
|
|
165 It returns only 1 in XEmacs. It is for compatibility with MULE 2.3."
|
|
166 1)
|
|
167 (defalias 'char-length 'char-bytes)
|
70
|
168
|
82
|
169 (defun char-width (character)
|
70
|
170 "Return number of columns a CHARACTER occupies when displayed."
|
|
171 (charset-columns (char-charset character)))
|
|
172
|
82
|
173 (defalias 'char-columns 'char-width)
|
|
174 (make-obsolete 'char-columns 'char-width)
|
|
175
|
70
|
176 (defalias 'charset-description 'charset-doc-string)
|
|
177
|
|
178 (defalias 'find-charset-string 'charsets-in-string)
|
|
179 (defalias 'find-charset-region 'charsets-in-region)
|
|
180
|
|
181 (defun find-non-ascii-charset-string (string)
|
|
182 "Return a list of charsets in the STRING except ascii.
|
82
|
183 It might be available for compatibility with Mule 2.3,
|
|
184 because its `find-charset-string' ignores ASCII charset."
|
70
|
185 (delq 'ascii (charsets-in-string string)))
|
|
186
|
|
187 (defun find-non-ascii-charset-region (start end)
|
82
|
188 "Return a list of charsets except ascii in the region between START and END.
|
|
189 It might be available for compatibility with Mule 2.3,
|
|
190 because its `find-charset-string' ignores ASCII charset."
|
70
|
191 (delq 'ascii (charsets-in-region start end)))
|
|
192
|
|
193
|
|
194 ;;; Language environments
|
|
195
|
|
196 (defvar current-language-environment nil)
|
|
197
|
|
198 (defvar language-environment-list nil)
|
|
199
|
|
200 (defun current-language-environment ()
|
|
201 "Return the current language environment as a symbol.
|
|
202 Returns nil if `set-language-environment' has not been called."
|
|
203 current-language-environment)
|
|
204
|
|
205 (defun language-environment-list ()
|
|
206 "Return a list of all currently defined language environments."
|
|
207 language-environment-list)
|
|
208
|
|
209 (defun language-environment-p (sym)
|
|
210 "True if SYM names a defined language environment."
|
|
211 (memq sym (language-environment-list)))
|
|
212
|
|
213 (defun set-language-environment (env)
|
|
214 "Set the current language environment to ENV."
|
|
215 (interactive
|
|
216 (list (intern (completing-read "Language environment: "
|
|
217 obarray 'language-environment-p
|
|
218 'require-match))))
|
|
219 (when (not (string= (charset-registry 'ascii) "ISO8859-1"))
|
|
220 (set-charset-registry 'ascii "ISO8859-1"))
|
|
221 (let ((func (get env 'set-lang-environ)))
|
|
222 (if (not (null func))
|
|
223 (funcall func)))
|
138
|
224 (setq current-language-environment env)
|
140
|
225 (if (featurep 'egg)
|
138
|
226 (egg-lang-switch-callback))
|
140
|
227 ;; (if (featurep 'quail)
|
138
|
228 ;; (quail-lang-switch-callback))
|
|
229 )
|
70
|
230
|
|
231 (defun define-language-environment (env-sym doc-string enable-function)
|
|
232 "Define a new language environment, named by ENV-SYM.
|
|
233 DOC-STRING should be a string describing the environment.
|
|
234 ENABLE-FUNCTION should be a function of no arguments that will be called
|
|
235 when the language environment is made current."
|
|
236 (put env-sym 'lang-environ-doc-string doc-string)
|
|
237 (put env-sym 'set-lang-environ enable-function)
|
|
238 (setq language-environment-list (cons env-sym language-environment-list)))
|
138
|
239
|
|
240 (defun define-egg-environment (env-sym doc-string enable-function)
|
|
241 "Define a new language environment for egg, named by ENV-SYM.
|
|
242 DOC-STRING should be a string describing the environment.
|
|
243 ENABLE-FUNCTION should be a function of no arguments that will be called
|
|
244 when the language environment is made current."
|
|
245 (put env-sym 'egg-environ-doc-string doc-string)
|
|
246 (put env-sym 'set-egg-environ enable-function))
|
|
247
|
|
248 (defun define-quail-environment (env-sym doc-string enable-function)
|
|
249 "Define a new language environment for quail, named by ENV-SYM.
|
|
250 DOC-STRING should be a string describing the environment.
|
|
251 ENABLE-FUNCTION should be a function of no arguments that will be called
|
|
252 when the language environment is made current."
|
|
253 (put env-sym 'quail-environ-doc-string doc-string)
|
|
254 (put env-sym 'set-quail-environ enable-function))
|
|
255
|