comparison lisp/language/ind-util.el @ 42056:6ef6e34cdba4

Don't require cl. (indian-glyph-char, indian-glyph-max-char) (indian-char-glyph): Moved from indian.el (indian--puthash-char, mapthread): Don't quote lambda. (indian--map): New function. (indian--puthash-v, indian--puthash-c, indian--puthash-m) (indian--puthash-cv): Use it.
author Dave Love <fx@gnu.org>
date Sat, 15 Dec 2001 17:59:27 +0000
parents a43bf477cba7
children f3b460667d31
comparison
equal deleted inserted replaced
42055:d0521c771e5a 42056:6ef6e34cdba4
37 ;; The followings provide the various transliteration schemes (such as 37 ;; The followings provide the various transliteration schemes (such as
38 ;; ITRANS, kyoto-harvard, and Aiba) of Indian scripts. They are also 38 ;; ITRANS, kyoto-harvard, and Aiba) of Indian scripts. They are also
39 ;; used in quail/indian.el for typing Indian script in Emacs. 39 ;; used in quail/indian.el for typing Indian script in Emacs.
40 40
41 (eval-and-compile 41 (eval-and-compile
42 (require 'cl)
43 42
44 (defun range (from to) 43 (defun range (from to)
45 "Make the list of the integers of range FROM to TO." 44 "Make the list of the integers of range FROM to TO."
46 (let (result) 45 (let (result)
47 (while (<= from to) (setq result (cons to result) to (1- to))) result)) 46 (while (<= from to) (setq result (cons to result) to (1- to))) result))
50 "Returns the regular expression of hashtable keys." 49 "Returns the regular expression of hashtable keys."
51 (let ((max-specpdl-size 1000)) 50 (let ((max-specpdl-size 1000))
52 (regexp-opt 51 (regexp-opt
53 (sort 52 (sort
54 (let (dummy) 53 (let (dummy)
55 (maphash (function (lambda (key val) (setq dummy (cons key dummy)))) hashtbl) 54 (maphash (function (lambda (key val) (setq dummy (cons key dummy))))
55 hashtbl)
56 dummy) 56 dummy)
57 (function (lambda (x y) (> (length x) (length y)))))))) 57 (function (lambda (x y) (> (length x) (length y))))))))
58 58
59 (defvar indian-dev-base-table 59 (defvar indian-dev-base-table
60 '( 60 '(
203 (if seqrest 203 (if seqrest
204 (mapcar 204 (mapcar
205 (lambda (x) 205 (lambda (x)
206 (apply 206 (apply
207 'mapthread 207 'mapthread
208 `(lambda (&rest y) (apply (quote ,function) ,x y)) 208 (lambda (&rest y) (apply function x y))
209 seqrest)) 209 seqrest))
210 seq1) 210 seq1)
211 (mapcar function seq1))) 211 (mapcar function seq1)))
212 212
213 (defun indian--puthash-char (char trans-char hashtbls) 213 (defun indian--puthash-char (char trans-char hashtbls)
219 (when (and char trans-char) 219 (when (and char trans-char)
220 (if (stringp trans-char) (setq trans-char (list trans-char))) 220 (if (stringp trans-char) (setq trans-char (list trans-char)))
221 (if (char-valid-p char) (setq char (char-to-string char))) 221 (if (char-valid-p char) (setq char (char-to-string char)))
222 (puthash char (car trans-char) encode-hash) 222 (puthash char (car trans-char) encode-hash)
223 (mapc 223 (mapc
224 '(lambda (trans) 224 (lambda (trans)
225 (puthash trans char decode-hash)) 225 (puthash trans char decode-hash))
226 trans-char)))) 226 trans-char))))
227 227
228 (defun indian--map (f l1 l2)
229 (while l1
230 (funcall f (pop l1) (pop l2))))
231
228 (defun indian--puthash-v (v trans-v hashtbls) 232 (defun indian--puthash-v (v trans-v hashtbls)
229 (mapcar* 233 (indian--map
230 '(lambda (v trans-v) 234 (lambda (v trans-v)
231 (indian--puthash-char (car v) trans-v hashtbls)) 235 (indian--puthash-char (car v) trans-v hashtbls))
232 v trans-v)) 236 v trans-v))
233 237
234 (defun indian--puthash-c (c trans-c halant hashtbls) 238 (defun indian--puthash-c (c trans-c halant hashtbls)
235 (mapcar* 239 (indian--map
236 '(lambda (c trans-c) 240 (lambda (c trans-c)
237 (if (char-valid-p c) (setq c (char-to-string c))) 241 (if (char-valid-p c) (setq c (char-to-string c)))
238 (indian--puthash-char (concat c halant) trans-c hashtbls)) 242 (indian--puthash-char (concat c halant) trans-c hashtbls))
239 c trans-c)) 243 c trans-c))
240 244
241 (defun indian--puthash-m (m trans-m hashtbls) 245 (defun indian--puthash-m (m trans-m hashtbls)
242 (mapcar* 246 (indian--map
243 '(lambda (m trans-m) 247 (lambda (m trans-m)
244 (indian--puthash-char m trans-m hashtbls)) 248 (indian--puthash-char m trans-m hashtbls))
245 m trans-m)) 249 m trans-m))
246 250
247 (defun indian--puthash-cv (c trans-c v trans-v hashtbls) 251 (defun indian--puthash-cv (c trans-c v trans-v hashtbls)
248 (mapcar* 252 (indian--map
249 '(lambda (c trans-c) 253 (lambda (c trans-c)
250 (mapcar* 254 (indian--map
251 (lambda (v trans-v) 255 (lambda (v trans-v)
252 (when (and c trans-c v trans-v) 256 (when (and c trans-c v trans-v)
253 (if (char-valid-p c) (setq c (char-to-string c))) 257 (if (char-valid-p c) (setq c (char-to-string c)))
254 (setq v (if (char-valid-p (cadr v)) (char-to-string (cadr v)) "")) 258 (setq v (if (char-valid-p (cadr v)) (char-to-string (cadr v)) ""))
255 (if (stringp trans-c) (setq trans-c (list trans-c))) 259 (if (stringp trans-c) (setq trans-c (list trans-c)))
256 (if (stringp trans-v) (setq trans-v (list trans-v))) 260 (if (stringp trans-v) (setq trans-v (list trans-v)))
257 (indian--puthash-char 261 (indian--puthash-char
258 (concat c v) 262 (concat c v)
259 (apply 'append 263 (apply 'append
260 (mapthread 'concat trans-c trans-v)) 264 (mapthread 'concat trans-c trans-v))
261 hashtbls))) 265 hashtbls)))
262 v trans-v)) 266 v trans-v))
263 c trans-c)) 267 c trans-c))
264 268
265 (defun indian-make-hash (table trans-table) 269 (defun indian-make-hash (table trans-table)
266 "Indian Transliteration Hash for decode/encode" 270 "Indian Transliteration Hash for decode/encode"
267 (let* ((encode-hash (makehash 'equal)) 271 (let* ((encode-hash (makehash 'equal))
304 (cdr (eval hashtable)))))) 308 (cdr (eval hashtable))))))
305 (narrow-to-region from to) 309 (narrow-to-region from to)
306 (goto-char (point-min)) 310 (goto-char (point-min))
307 (while (re-search-forward regexp nil t) 311 (while (re-search-forward regexp nil t)
308 (let ((matchstr (gethash (match-string 0) 312 (let ((matchstr (gethash (match-string 0)
309 (if ,encode-p (car ,hashtable) (cdr ,hashtable))))) 313 (if ,encode-p
314 (car ,hashtable)
315 (cdr ,hashtable)))))
310 (if matchstr (replace-match matchstr)))))))) 316 (if matchstr (replace-match matchstr))))))))
311 317
312 ;;; 318 ;;;
313 319
314 (defun indian-dev-itrans-v5-encode-region (from to) 320 (defun indian-dev-itrans-v5-encode-region (from to)
985 (goto-char (point-min)) 991 (goto-char (point-min))
986 (while (re-search-forward indian-2-column-to-ucs-regexp nil t) 992 (while (re-search-forward indian-2-column-to-ucs-regexp nil t)
987 (let ((len (- (match-end 0) (match-beginning 0))) 993 (let ((len (- (match-end 0) (match-beginning 0)))
988 subst) 994 subst)
989 (if (= len 1) 995 (if (= len 1)
990 (setq subst (aref indian-2-column-to-ucs-chartable (char-after (match-beginning 0)))) 996 (setq subst (aref indian-2-column-to-ucs-chartable
997 (char-after (match-beginning 0))))
991 (setq subst (assoc (match-string 0) alist))) 998 (setq subst (assoc (match-string 0) alist)))
992 (replace-match (if subst subst "?")))) 999 (replace-match (if subst subst "?"))))
993 (indian-compose-region (point-min) (point-max)))))) 1000 (indian-compose-region (point-min) (point-max))))))
1001
1002 ;;;###autoload
1003 (defun indian-glyph-char (index &optional script)
1004 "Return character of charset `indian-glyph' made from glyph index INDEX.
1005 The variable `indian-default-script' specifies the script of the glyph.
1006 Optional argument SCRIPT, if non-nil, overrides `indian-default-script'.
1007 See also the function `indian-char-glyph'."
1008 (or script
1009 (setq script indian-default-script))
1010 (let ((offset (get script 'indian-glyph-code-offset)))
1011 (or (integerp offset)
1012 (error "Invalid script name: %s" script))
1013 (or (and (>= index 0) (< index 256))
1014 (error "Invalid glyph index: %d" index))
1015 (setq index (+ offset index))
1016 (make-char 'indian-glyph (+ (/ index 96) 32) (+ (% index 96) 32))))
1017
1018 (defvar indian-glyph-max-char
1019 (indian-glyph-char
1020 255 (aref indian-script-table (1- (length indian-script-table))))
1021 "The maximum valid code of characters in the charset `indian-glyph'.")
1022
1023 ;;;###autoload
1024 (defun indian-char-glyph (char)
1025 "Return information about the glphy code for CHAR of `indian-glyph' charset.
1026 The value is (INDEX . SCRIPT), where INDEX is the glyph index
1027 in the font that Indian script name SCRIPT specifies.
1028 See also the function `indian-glyph-char'."
1029 (let ((split (split-char char))
1030 code)
1031 (or (eq (car split) 'indian-glyph)
1032 (error "Charset of `%c' is not indian-glyph" char))
1033 (or (<= char indian-glyph-max-char)
1034 (error "Invalid indian-glyph char: %d" char))
1035 (setq code (+ (* (- (nth 1 split) 32) 96) (nth 2 split) -32))
1036 (cons (% code 256) (aref indian-script-table (/ code 256)))))
994 1037
995 (provide 'ind-util) 1038 (provide 'ind-util)
996 1039
997 ;;; ind-util.el ends here 1040 ;;; ind-util.el ends here