annotate lisp/mule/mule-misc.el @ 108:360340f9fd5f r20-1b6

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