comparison lisp/international/mule-util.el @ 99752:25fea170fd1a

* international/mule-util.el (set-nested-alist): Doc fix. Use `when'. (lookup-nested-alist): Doc fix. (with-coding-priority): Reflow docstring. (detect-coding-with-priority): Fix typos in obsolescence declaration. (char-displayable-p): Reflow docstring. Use `when'.
author Juanma Barranquero <lekktu@gmail.com>
date Thu, 20 Nov 2008 23:07:44 +0000
parents b4e36ff621b3
children a9dc0e7c3f2b
comparison
equal deleted inserted replaced
99751:5482506bbfd1 99752:25fea170fd1a
231 231
232 ;;;###autoload 232 ;;;###autoload
233 (defun set-nested-alist (keyseq entry alist &optional len branches) 233 (defun set-nested-alist (keyseq entry alist &optional len branches)
234 "Set ENTRY for KEYSEQ in a nested alist ALIST. 234 "Set ENTRY for KEYSEQ in a nested alist ALIST.
235 Optional 4th arg LEN non-nil means the first LEN elements in KEYSEQ 235 Optional 4th arg LEN non-nil means the first LEN elements in KEYSEQ
236 is considered. 236 are considered.
237 Optional argument BRANCHES if non-nil is branches for a keyseq 237 Optional 5th argument BRANCHES if non-nil is branches for a keyseq
238 longer than KEYSEQ. 238 longer than KEYSEQ.
239 See the documentation of `nested-alist-p' for more detail." 239 See the documentation of `nested-alist-p' for more detail."
240 (or (nested-alist-p alist) 240 (or (nested-alist-p alist)
241 (error "Invalid argument %s" alist)) 241 (error "Invalid argument %s" alist))
242 (let ((islist (listp keyseq)) 242 (let ((islist (listp keyseq))
246 (while (< i len) 246 (while (< i len)
247 (if (null (nested-alist-p alist)) 247 (if (null (nested-alist-p alist))
248 (error "Keyseq %s is too long for this nested alist" keyseq)) 248 (error "Keyseq %s is too long for this nested alist" keyseq))
249 (setq key-elt (if islist (nth i keyseq) (aref keyseq i))) 249 (setq key-elt (if islist (nth i keyseq) (aref keyseq i)))
250 (setq slot (assoc key-elt (cdr alist))) 250 (setq slot (assoc key-elt (cdr alist)))
251 (if (null slot) 251 (unless slot
252 (progn 252 (setq slot (cons key-elt (list t)))
253 (setq slot (cons key-elt (list t))) 253 (setcdr alist (cons slot (cdr alist))))
254 (setcdr alist (cons slot (cdr alist)))))
255 (setq alist (cdr slot)) 254 (setq alist (cdr slot))
256 (setq i (1+ i))) 255 (setq i (1+ i)))
257 (setcar alist entry) 256 (setcar alist entry)
258 (if branches 257 (if branches
259 (setcdr (last alist) branches)))) 258 (setcdr (last alist) branches))))
260 259
261 ;;;###autoload 260 ;;;###autoload
262 (defun lookup-nested-alist (keyseq alist &optional len start nil-for-too-long) 261 (defun lookup-nested-alist (keyseq alist &optional len start nil-for-too-long)
263 "Look up key sequence KEYSEQ in nested alist ALIST. Return the definition. 262 "Look up key sequence KEYSEQ in nested alist ALIST. Return the definition.
264 Optional 1st argument LEN specifies the length of KEYSEQ. 263 Optional 3rd argument LEN specifies the length of KEYSEQ.
265 Optional 2nd argument START specifies index of the starting key. 264 Optional 4th argument START specifies index of the starting key.
266 The returned value is normally a nested alist of which 265 The returned value is normally a nested alist of which
267 car part is the entry for KEYSEQ. 266 car part is the entry for KEYSEQ.
268 If ALIST is not deep enough for KEYSEQ, return number which is 267 If ALIST is not deep enough for KEYSEQ, return number which is
269 how many key elements at the front of KEYSEQ it takes 268 how many key elements at the front of KEYSEQ it takes
270 to reach a leaf in ALIST. 269 to reach a leaf in ALIST.
271 Optional 3rd argument NIL-FOR-TOO-LONG non-nil means return nil 270 Optional 5th argument NIL-FOR-TOO-LONG non-nil means return nil
272 even if ALIST is not deep enough." 271 even if ALIST is not deep enough."
273 (or (nested-alist-p alist) 272 (or (nested-alist-p alist)
274 (error "Invalid argument %s" alist)) 273 (error "Invalid argument %s" alist))
275 (or len 274 (or len
276 (setq len (length keyseq))) 275 (setq len (length keyseq)))
313 (coding-system-get coding-system :encode-translation-table)) 312 (coding-system-get coding-system :encode-translation-table))
314 313
315 ;;;###autoload 314 ;;;###autoload
316 (defmacro with-coding-priority (coding-systems &rest body) 315 (defmacro with-coding-priority (coding-systems &rest body)
317 "Execute BODY like `progn' with CODING-SYSTEMS at the front of priority list. 316 "Execute BODY like `progn' with CODING-SYSTEMS at the front of priority list.
318 CODING-SYSTEMS is a list of coding systems. See 317 CODING-SYSTEMS is a list of coding systems. See `set-coding-priority'.
319 `set-coding-priority'. This affects the implicit sorting of lists of 318 This affects the implicit sorting of lists of coding sysems returned by
320 coding sysems returned by operations such as `find-coding-systems-region'." 319 operations such as `find-coding-systems-region'."
321 (let ((current (make-symbol "current"))) 320 (let ((current (make-symbol "current")))
322 `(let ((,current (coding-system-priority-list))) 321 `(let ((,current (coding-system-priority-list)))
323 (apply #'set-coding-system-priority ,coding-systems) 322 (apply #'set-coding-system-priority ,coding-systems)
324 (unwind-protect 323 (unwind-protect
325 (progn ,@body) 324 (progn ,@body)
333 PRIORITY-LIST is an alist of coding categories vs the corresponding 332 PRIORITY-LIST is an alist of coding categories vs the corresponding
334 coding systems ordered by priority." 333 coding systems ordered by priority."
335 `(with-coding-priority (mapcar #'cdr ,priority-list) 334 `(with-coding-priority (mapcar #'cdr ,priority-list)
336 (detect-coding-region ,from ,to))) 335 (detect-coding-region ,from ,to)))
337 (make-obsolete 'detect-coding-with-priority 336 (make-obsolete 'detect-coding-with-priority
338 "Use with-coding-priority and detect-coding-region" "23.1") 337 "use `with-coding-priority' and `detect-coding-region'." "23.1")
339 338
340 ;;;###autoload 339 ;;;###autoload
341 (defun detect-coding-with-language-environment (from to lang-env) 340 (defun detect-coding-with-language-environment (from to lang-env)
342 "Detect a coding system for the text between FROM and TO with LANG-ENV. 341 "Detect a coding system for the text between FROM and TO with LANG-ENV.
343 The detection takes into account the coding system priorities for the 342 The detection takes into account the coding system priorities for the
351 350
352 ;;;###autoload 351 ;;;###autoload
353 (defun char-displayable-p (char) 352 (defun char-displayable-p (char)
354 "Return non-nil if we should be able to display CHAR. 353 "Return non-nil if we should be able to display CHAR.
355 On a multi-font display, the test is only whether there is an 354 On a multi-font display, the test is only whether there is an
356 appropriate font from the selected frame's fontset to display CHAR's 355 appropriate font from the selected frame's fontset to display
357 charset in general. Since fonts may be specified on a per-character 356 CHAR's charset in general. Since fonts may be specified on a
358 basis, this may not be accurate." 357 per-character basis, this may not be accurate."
359 (cond ((< char 128) 358 (cond ((< char 128)
360 ;; ASCII characters are always displayable. 359 ;; ASCII characters are always displayable.
361 t) 360 t)
362 ((not enable-multibyte-characters) 361 ((not enable-multibyte-characters)
363 ;; Maybe there's a font for it, but we can't put it in the buffer. 362 ;; Maybe there's a font for it, but we can't put it in the buffer.
369 (car (internal-char-font nil char))) 368 (car (internal-char-font nil char)))
370 (t 369 (t
371 ;; On a terminal, a character is displayable if the coding 370 ;; On a terminal, a character is displayable if the coding
372 ;; system for the terminal can encode it. 371 ;; system for the terminal can encode it.
373 (let ((coding (terminal-coding-system))) 372 (let ((coding (terminal-coding-system)))
374 (if coding 373 (when coding
375 (let ((cs-list (coding-system-get coding :charset-list))) 374 (let ((cs-list (coding-system-get coding :charset-list)))
376 (cond 375 (cond
377 ((listp cs-list) 376 ((listp cs-list)
378 (catch 'tag 377 (catch 'tag
379 (mapc #'(lambda (charset) 378 (mapc #'(lambda (charset)
380 (if (encode-char char charset) 379 (if (encode-char char charset)
381 (throw 'tag charset))) 380 (throw 'tag charset)))
382 cs-list) 381 cs-list)
383 nil)) 382 nil))
384 ((eq cs-list 'iso-2022) 383 ((eq cs-list 'iso-2022)
385 (catch 'tag2 384 (catch 'tag2
386 (mapc #'(lambda (charset) 385 (mapc #'(lambda (charset)
387 (if (and (plist-get (charset-plist charset) 386 (if (and (plist-get (charset-plist charset)
388 :iso-final-char) 387 :iso-final-char)
389 (encode-char char charset)) 388 (encode-char char charset))
390 (throw 'tag2 charset))) 389 (throw 'tag2 charset)))
391 charset-list) 390 charset-list)
392 nil)) 391 nil))
393 ((eq cs-list 'emacs-mule) 392 ((eq cs-list 'emacs-mule)
394 (catch 'tag3 393 (catch 'tag3
395 (mapc #'(lambda (charset) 394 (mapc #'(lambda (charset)
396 (if (and (plist-get (charset-plist charset) 395 (if (and (plist-get (charset-plist charset)
397 :emacs-mule-id) 396 :emacs-mule-id)
398 (encode-char char charset)) 397 (encode-char char charset))
399 (throw 'tag3 charset))) 398 (throw 'tag3 charset)))
400 charset-list) 399 charset-list)
401 nil))))))))) 400 nil)))))))))
402 401
403 (provide 'mule-util) 402 (provide 'mule-util)
404 403
405 ;; Local Variables: 404 ;; Local Variables:
406 ;; coding: iso-2022-7bit 405 ;; coding: iso-2022-7bit