2010-06-03 17:34:35 +02:00
|
|
|
|
;;; mule-util.el --- utility functions for multilingual environment (mule)
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
2015-01-01 14:26:41 -08:00
|
|
|
|
;; Copyright (C) 1997-1998, 2000-2015 Free Software Foundation, Inc.
|
2006-12-13 01:13:58 +00:00
|
|
|
|
;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
2011-01-02 15:50:46 -08:00
|
|
|
|
;; 2005, 2006, 2007, 2008, 2009, 2010, 2011
|
2005-05-13 06:03:46 +00:00
|
|
|
|
;; National Institute of Advanced Industrial Science and Technology (AIST)
|
|
|
|
|
;; Registration Number H14PRO021
|
2003-09-08 12:53:41 +00:00
|
|
|
|
;; Copyright (C) 2003
|
|
|
|
|
;; National Institute of Advanced Industrial Science and Technology (AIST)
|
|
|
|
|
;; Registration Number H13PRO009
|
|
|
|
|
|
1997-02-20 07:02:49 +00:00
|
|
|
|
;; Keywords: mule, multilingual
|
|
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
2008-05-06 04:29:13 +00:00
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
1997-02-20 07:02:49 +00:00
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 04:29:13 +00:00
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2008-05-06 04:29:13 +00:00
|
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
2001-07-15 19:53:53 +00:00
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
1997-02-20 07:02:49 +00:00
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
|
;;; String manipulations while paying attention to multibyte
|
|
|
|
|
;;; characters.
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defsubst string-to-list (string)
|
|
|
|
|
"Return a list of characters in STRING."
|
2001-11-18 06:49:25 +00:00
|
|
|
|
(append string nil))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defsubst string-to-vector (string)
|
|
|
|
|
"Return a vector of characters in STRING."
|
2001-11-18 06:49:25 +00:00
|
|
|
|
(vconcat string))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun store-substring (string idx obj)
|
|
|
|
|
"Embed OBJ (string or character) at index IDX of STRING."
|
1998-01-22 01:42:20 +00:00
|
|
|
|
(if (integerp obj)
|
|
|
|
|
(aset string idx obj)
|
|
|
|
|
(let ((len1 (length obj))
|
|
|
|
|
(len2 (length string))
|
|
|
|
|
(i 0))
|
|
|
|
|
(while (< i len1)
|
|
|
|
|
(aset string (+ idx i) (aref obj i))
|
|
|
|
|
(setq i (1+ i)))))
|
|
|
|
|
string)
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
2014-06-19 10:58:57 -04:00
|
|
|
|
(defvar truncate-string-ellipsis "..." ;"…"
|
|
|
|
|
"String to use to indicate truncation.")
|
|
|
|
|
|
1997-02-20 07:02:49 +00:00
|
|
|
|
;;;###autoload
|
2002-05-21 21:22:21 +00:00
|
|
|
|
(defun truncate-string-to-width (str end-column
|
|
|
|
|
&optional start-column padding ellipsis)
|
1997-09-13 08:44:55 +00:00
|
|
|
|
"Truncate string STR to end at column END-COLUMN.
|
2002-05-21 21:22:21 +00:00
|
|
|
|
The optional 3rd arg START-COLUMN, if non-nil, specifies the starting
|
|
|
|
|
column; that means to return the characters occupying columns
|
|
|
|
|
START-COLUMN ... END-COLUMN of STR. Both END-COLUMN and START-COLUMN
|
|
|
|
|
are specified in terms of character display width in the current
|
|
|
|
|
buffer; see also `char-width'.
|
|
|
|
|
|
|
|
|
|
The optional 4th arg PADDING, if non-nil, specifies a padding
|
|
|
|
|
character (which should have a display width of 1) to add at the end
|
|
|
|
|
of the result if STR doesn't reach column END-COLUMN, or if END-COLUMN
|
|
|
|
|
comes in the middle of a character in STR. PADDING is also added at
|
|
|
|
|
the beginning of the result if column START-COLUMN appears in the
|
|
|
|
|
middle of a character in STR.
|
1997-09-13 08:44:55 +00:00
|
|
|
|
|
|
|
|
|
If PADDING is nil, no padding is added in these cases, so
|
2002-05-21 21:22:21 +00:00
|
|
|
|
the resulting string may be narrower than END-COLUMN.
|
|
|
|
|
|
|
|
|
|
If ELLIPSIS is non-nil, it should be a string which will replace the
|
|
|
|
|
end of STR (including any padding) if it extends beyond END-COLUMN,
|
|
|
|
|
unless the display width of STR is equal to or less than the display
|
|
|
|
|
width of ELLIPSIS. If it is non-nil and not a string, then ELLIPSIS
|
2014-06-19 10:58:57 -04:00
|
|
|
|
defaults to `truncate-string-ellipsis'."
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(or start-column
|
|
|
|
|
(setq start-column 0))
|
2002-05-21 21:22:21 +00:00
|
|
|
|
(when (and ellipsis (not (stringp ellipsis)))
|
2014-06-19 10:58:57 -04:00
|
|
|
|
(setq ellipsis truncate-string-ellipsis))
|
2002-05-21 21:22:21 +00:00
|
|
|
|
(let ((str-len (length str))
|
|
|
|
|
(str-width (string-width str))
|
|
|
|
|
(ellipsis-len (if ellipsis (length ellipsis) 0))
|
|
|
|
|
(ellipsis-width (if ellipsis (string-width ellipsis) 0))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(idx 0)
|
|
|
|
|
(column 0)
|
|
|
|
|
(head-padding "") (tail-padding "")
|
|
|
|
|
ch last-column last-idx from-idx)
|
|
|
|
|
(condition-case nil
|
|
|
|
|
(while (< column start-column)
|
1998-01-22 01:42:20 +00:00
|
|
|
|
(setq ch (aref str idx)
|
1997-02-20 07:02:49 +00:00
|
|
|
|
column (+ column (char-width ch))
|
1998-01-22 01:42:20 +00:00
|
|
|
|
idx (1+ idx)))
|
2002-05-21 21:22:21 +00:00
|
|
|
|
(args-out-of-range (setq idx str-len)))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(if (< column start-column)
|
1997-09-13 08:44:55 +00:00
|
|
|
|
(if padding (make-string end-column padding) "")
|
2002-05-21 21:22:21 +00:00
|
|
|
|
(when (and padding (> column start-column))
|
|
|
|
|
(setq head-padding (make-string (- column start-column) padding)))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(setq from-idx idx)
|
2002-05-21 21:22:21 +00:00
|
|
|
|
(when (>= end-column column)
|
|
|
|
|
(if (and (< end-column str-width)
|
|
|
|
|
(> str-width ellipsis-width))
|
|
|
|
|
(setq end-column (- end-column ellipsis-width))
|
|
|
|
|
(setq ellipsis ""))
|
1997-09-13 08:44:55 +00:00
|
|
|
|
(condition-case nil
|
|
|
|
|
(while (< column end-column)
|
|
|
|
|
(setq last-column column
|
|
|
|
|
last-idx idx
|
1998-01-22 01:42:20 +00:00
|
|
|
|
ch (aref str idx)
|
1997-09-13 08:44:55 +00:00
|
|
|
|
column (+ column (char-width ch))
|
1998-01-22 01:42:20 +00:00
|
|
|
|
idx (1+ idx)))
|
2002-05-21 21:22:21 +00:00
|
|
|
|
(args-out-of-range (setq idx str-len)))
|
|
|
|
|
(when (> column end-column)
|
|
|
|
|
(setq column last-column
|
|
|
|
|
idx last-idx))
|
|
|
|
|
(when (and padding (< column end-column))
|
|
|
|
|
(setq tail-padding (make-string (- end-column column) padding))))
|
|
|
|
|
(concat head-padding (substring str from-idx idx)
|
|
|
|
|
tail-padding ellipsis))))
|
|
|
|
|
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
;;; Nested alist handler. Nested alist is alist whose elements are
|
|
|
|
|
;;; also nested alist.
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defsubst nested-alist-p (obj)
|
1998-09-06 14:31:49 +00:00
|
|
|
|
"Return t if OBJ is a nested alist.
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
Nested alist is a list of the form (ENTRY . BRANCHES), where ENTRY is
|
|
|
|
|
any Lisp object, and BRANCHES is a list of cons cells of the form
|
2002-06-18 22:59:30 +00:00
|
|
|
|
\(KEY-ELEMENT . NESTED-ALIST).
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
You can use a nested alist to store any Lisp object (ENTRY) for a key
|
|
|
|
|
sequence KEYSEQ, where KEYSEQ is a sequence of KEY-ELEMENT. KEYSEQ
|
|
|
|
|
can be a string, a vector, or a list."
|
|
|
|
|
(and obj (listp obj) (listp (cdr obj))))
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun set-nested-alist (keyseq entry alist &optional len branches)
|
|
|
|
|
"Set ENTRY for KEYSEQ in a nested alist ALIST.
|
1998-09-06 14:31:49 +00:00
|
|
|
|
Optional 4th arg LEN non-nil means the first LEN elements in KEYSEQ
|
2008-11-20 23:07:44 +00:00
|
|
|
|
are considered.
|
|
|
|
|
Optional 5th argument BRANCHES if non-nil is branches for a keyseq
|
1997-02-20 07:02:49 +00:00
|
|
|
|
longer than KEYSEQ.
|
|
|
|
|
See the documentation of `nested-alist-p' for more detail."
|
|
|
|
|
(or (nested-alist-p alist)
|
1998-09-06 14:31:49 +00:00
|
|
|
|
(error "Invalid argument %s" alist))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(let ((islist (listp keyseq))
|
|
|
|
|
(len (or len (length keyseq)))
|
|
|
|
|
(i 0)
|
|
|
|
|
key-elt slot)
|
|
|
|
|
(while (< i len)
|
|
|
|
|
(if (null (nested-alist-p alist))
|
|
|
|
|
(error "Keyseq %s is too long for this nested alist" keyseq))
|
|
|
|
|
(setq key-elt (if islist (nth i keyseq) (aref keyseq i)))
|
|
|
|
|
(setq slot (assoc key-elt (cdr alist)))
|
2008-11-20 23:07:44 +00:00
|
|
|
|
(unless slot
|
|
|
|
|
(setq slot (cons key-elt (list t)))
|
|
|
|
|
(setcdr alist (cons slot (cdr alist))))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(setq alist (cdr slot))
|
|
|
|
|
(setq i (1+ i)))
|
|
|
|
|
(setcar alist entry)
|
|
|
|
|
(if branches
|
1999-12-15 00:42:14 +00:00
|
|
|
|
(setcdr (last alist) branches))))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun lookup-nested-alist (keyseq alist &optional len start nil-for-too-long)
|
|
|
|
|
"Look up key sequence KEYSEQ in nested alist ALIST. Return the definition.
|
2008-11-20 23:07:44 +00:00
|
|
|
|
Optional 3rd argument LEN specifies the length of KEYSEQ.
|
|
|
|
|
Optional 4th argument START specifies index of the starting key.
|
1997-02-20 07:02:49 +00:00
|
|
|
|
The returned value is normally a nested alist of which
|
|
|
|
|
car part is the entry for KEYSEQ.
|
|
|
|
|
If ALIST is not deep enough for KEYSEQ, return number which is
|
|
|
|
|
how many key elements at the front of KEYSEQ it takes
|
|
|
|
|
to reach a leaf in ALIST.
|
2008-11-20 23:07:44 +00:00
|
|
|
|
Optional 5th argument NIL-FOR-TOO-LONG non-nil means return nil
|
1997-02-20 07:02:49 +00:00
|
|
|
|
even if ALIST is not deep enough."
|
|
|
|
|
(or (nested-alist-p alist)
|
2000-04-01 12:03:57 +00:00
|
|
|
|
(error "Invalid argument %s" alist))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(or len
|
|
|
|
|
(setq len (length keyseq)))
|
|
|
|
|
(let ((i (or start 0)))
|
|
|
|
|
(if (catch 'lookup-nested-alist-tag
|
|
|
|
|
(if (listp keyseq)
|
|
|
|
|
(while (< i len)
|
|
|
|
|
(if (setq alist (cdr (assoc (nth i keyseq) (cdr alist))))
|
|
|
|
|
(setq i (1+ i))
|
|
|
|
|
(throw 'lookup-nested-alist-tag t))))
|
|
|
|
|
(while (< i len)
|
|
|
|
|
(if (setq alist (cdr (assoc (aref keyseq i) (cdr alist))))
|
|
|
|
|
(setq i (1+ i))
|
|
|
|
|
(throw 'lookup-nested-alist-tag t))))
|
|
|
|
|
;; KEYSEQ is too long.
|
|
|
|
|
(if nil-for-too-long nil i)
|
|
|
|
|
alist)))
|
|
|
|
|
|
1997-06-18 12:55:11 +00:00
|
|
|
|
|
1997-02-20 07:02:49 +00:00
|
|
|
|
;; Coding system related functions.
|
|
|
|
|
|
1997-06-18 12:55:11 +00:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun coding-system-post-read-conversion (coding-system)
|
2001-12-15 16:43:11 +00:00
|
|
|
|
"Return the value of CODING-SYSTEM's `post-read-conversion' property."
|
2002-05-26 22:42:00 +00:00
|
|
|
|
(coding-system-get coding-system :post-read-conversion))
|
1997-06-18 12:55:11 +00:00
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun coding-system-pre-write-conversion (coding-system)
|
2001-12-15 16:43:11 +00:00
|
|
|
|
"Return the value of CODING-SYSTEM's `pre-write-conversion' property."
|
2002-05-26 22:42:00 +00:00
|
|
|
|
(coding-system-get coding-system :pre-write-conversion))
|
1997-06-18 12:55:11 +00:00
|
|
|
|
|
|
|
|
|
;;;###autoload
|
1998-05-18 01:01:00 +00:00
|
|
|
|
(defun coding-system-translation-table-for-decode (coding-system)
|
2003-09-08 12:53:41 +00:00
|
|
|
|
"Return the value of CODING-SYSTEM's `decode-translation-table' property."
|
2002-05-26 22:42:00 +00:00
|
|
|
|
(coding-system-get coding-system :decode-translation-table))
|
1997-08-22 01:22:49 +00:00
|
|
|
|
|
|
|
|
|
;;;###autoload
|
1998-05-18 01:01:00 +00:00
|
|
|
|
(defun coding-system-translation-table-for-encode (coding-system)
|
2003-09-08 12:53:41 +00:00
|
|
|
|
"Return the value of CODING-SYSTEM's `encode-translation-table' property."
|
2002-05-26 22:42:00 +00:00
|
|
|
|
(coding-system-get coding-system :encode-translation-table))
|
1997-06-18 12:55:11 +00:00
|
|
|
|
|
2003-09-08 12:53:41 +00:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(defmacro with-coding-priority (coding-systems &rest body)
|
|
|
|
|
"Execute BODY like `progn' with CODING-SYSTEMS at the front of priority list.
|
2011-02-04 11:45:46 +01:00
|
|
|
|
CODING-SYSTEMS is a list of coding systems. See `set-coding-system-priority'.
|
2011-12-11 21:32:49 -08:00
|
|
|
|
This affects the implicit sorting of lists of coding systems returned by
|
2008-11-20 23:07:44 +00:00
|
|
|
|
operations such as `find-coding-systems-region'."
|
2003-09-08 12:53:41 +00:00
|
|
|
|
(let ((current (make-symbol "current")))
|
|
|
|
|
`(let ((,current (coding-system-priority-list)))
|
|
|
|
|
(apply #'set-coding-system-priority ,coding-systems)
|
|
|
|
|
(unwind-protect
|
|
|
|
|
(progn ,@body)
|
|
|
|
|
(apply #'set-coding-system-priority ,current)))))
|
2010-02-08 16:08:18 +09:00
|
|
|
|
;;;###autoload(put 'with-coding-priority 'lisp-indent-function 1)
|
2003-09-08 12:53:41 +00:00
|
|
|
|
(put 'with-coding-priority 'edebug-form-spec t)
|
|
|
|
|
|
1997-10-23 12:05:45 +00:00
|
|
|
|
;;;###autoload
|
1998-01-22 01:42:20 +00:00
|
|
|
|
(defmacro detect-coding-with-priority (from to priority-list)
|
|
|
|
|
"Detect a coding system of the text between FROM and TO with PRIORITY-LIST.
|
|
|
|
|
PRIORITY-LIST is an alist of coding categories vs the corresponding
|
|
|
|
|
coding systems ordered by priority."
|
Use declare forms, where possible, to mark obsolete functions.
* lisp/allout.el (allout-passphrase-hint-string): Likewise.
(allout-init): Use a declare form to mark obsolete.
* lisp/calendar/calendar.el (calendar-version):
* lisp/calendar/icalendar.el (icalendar-extract-ical-from-buffer)
(icalendar-convert-diary-to-ical):
* lisp/cus-edit.el (custom-mode):
* lisp/ansi-color.el (ansi-color-unfontify-region):
* lisp/international/latin1-disp.el (latin1-char-displayable-p):
* lisp/progmodes/cwarn.el (turn-on-cwarn-mode):
* lisp/progmodes/which-func.el (which-func-update-1): Use
define-obsolete-function-alias.
* lisp/bookmark.el (bookmark-jump-noselect): Use a declare form to mark
this function obsolete.
* lisp/calendar/cal-x.el (calendar-two-frame-setup)
(calendar-only-one-frame-setup, calendar-one-frame-setup):
* lisp/calendar/calendar.el (american-calendar, european-calendar)
(calendar-for-loop):
* lisp/comint.el (comint-dynamic-simple-complete)
(comint-dynamic-complete-as-filename, comint-unquote-filename):
* lisp/desktop.el (desktop-load-default):
* lisp/dired-x.el (dired-omit-here-always)
(dired-hack-local-variables, dired-default-directory):
* lisp/emacs-lisp/derived.el (derived-mode-class):
* lisp/emacs-lisp/timer.el (timer-set-time-with-usecs):
* lisp/emacs-lock.el (toggle-emacs-lock):
* lisp/epa.el (epa-display-verify-result):
* lisp/epg.el (epg-sign-keys, epg-start-sign-keys)
(epg-passphrase-callback-function):
* lisp/eshell/esh-util.el (eshell-for):
* lisp/eshell/eshell.el (eshell-remove-from-window-buffer-names)
(eshell-add-to-window-buffer-names):
* lisp/files.el (locate-file-completion):
* lisp/imenu.el (imenu-example--create-c-index)
(imenu-example--create-lisp-index)
(imenu-example--lisp-extract-index-name)
(imenu-example--name-and-position):
* lisp/international/mule-cmds.el (princ-list):
* lisp/international/mule-diag.el (decode-codepage-char):
* lisp/international/mule-util.el (detect-coding-with-priority):
* lisp/iswitchb.el (iswitchb-read-buffer):
* lisp/mail/mailalias.el (mail-complete):
* lisp/mail/sendmail.el (mail-sent-via):
* lisp/mouse.el (mouse-popup-menubar-stuff, mouse-popup-menubar)
(mouse-major-mode-menu):
* lisp/password-cache.el (password-read-and-add):
* lisp/pcomplete.el (pcomplete-parse-comint-arguments):
* lisp/progmodes/sh-script.el (sh-maybe-here-document):
* lisp/replace.el (query-replace-regexp-eval):
* lisp/savehist.el (savehist-load):
* lisp/simple.el (choose-completion-delete-max-match):
* lisp/term.el (term-dynamic-simple-complete):
* lisp/vc/ediff-init.el (ediff-check-version):
* lisp/vc/ediff-wind.el (ediff-choose-window-setup-function-automatically):
* lisp/vc/vc.el (vc-diff-switches-list):
* lisp/view.el (view-return-to-alist-update): Likewise.
* lisp/iswitchb.el (iswitchb-read-buffer): Move code of
iswitchb-define-mode-map here, and delete that obsolete function.
* lisp/subr.el (eval-next-after-load, makehash, insert-string)
(assoc-ignore-representation, assoc-ignore-case): Use declare to
mark obsolete.
(mode-line-inverse-video): Variable deleted.
* lisp/emacs-lisp/byte-run.el (make-obsolete): Doc fix; emphasize that
this applies to functions.
* lisp/erc/erc.el (erc-send-command): Use define-obsolete-function-alias.
* lisp/international/mule-util.el (string-to-sequence): Remove.
* lisp/net/newst-backend.el (newsticker-cache-filename):
* lisp/net/newst-treeview.el (newsticker-groups-filename): Fix
incorrect obsolescence declaration.
* lisp/net/snmp-mode.el (snmp-font-lock-keywords-3): Don't use obsolete
font-lock-reference-face.
* lisp/url/url-parse.el (url-recreate-url-attributes):
* lisp/url/url-util.el (url-generate-unique-filename): Use declare to mark
obsolete.
* src/xdisp.c (mode_line_inverse_video): Delete obsolete variable.
2012-09-25 12:13:02 +08:00
|
|
|
|
(declare (obsolete with-coding-priority "23.1"))
|
2002-07-17 11:33:09 +00:00
|
|
|
|
`(with-coding-priority (mapcar #'cdr ,priority-list)
|
2002-06-29 10:46:39 +00:00
|
|
|
|
(detect-coding-region ,from ,to)))
|
1998-01-22 01:42:20 +00:00
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun detect-coding-with-language-environment (from to lang-env)
|
2003-09-11 09:51:13 +00:00
|
|
|
|
"Detect a coding system for the text between FROM and TO with LANG-ENV.
|
1998-09-06 14:31:49 +00:00
|
|
|
|
The detection takes into account the coding system priorities for the
|
1998-01-22 01:42:20 +00:00
|
|
|
|
language environment LANG-ENV."
|
|
|
|
|
(let ((coding-priority (get-language-info lang-env 'coding-priority)))
|
|
|
|
|
(if coding-priority
|
2002-05-26 22:42:00 +00:00
|
|
|
|
(with-coding-priority coding-priority
|
|
|
|
|
(detect-coding-region from to)))))
|
1997-10-23 12:05:45 +00:00
|
|
|
|
|
2008-06-12 03:56:20 +00:00
|
|
|
|
(declare-function internal-char-font "fontset.c" (position &optional ch))
|
|
|
|
|
|
2004-04-16 12:51:06 +00:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun char-displayable-p (char)
|
|
|
|
|
"Return non-nil if we should be able to display CHAR.
|
|
|
|
|
On a multi-font display, the test is only whether there is an
|
2008-11-20 23:07:44 +00:00
|
|
|
|
appropriate font from the selected frame's fontset to display
|
|
|
|
|
CHAR's charset in general. Since fonts may be specified on a
|
|
|
|
|
per-character basis, this may not be accurate."
|
2008-02-20 04:41:25 +00:00
|
|
|
|
(cond ((< char 128)
|
|
|
|
|
;; ASCII characters are always displayable.
|
2004-04-16 12:51:06 +00:00
|
|
|
|
t)
|
2004-12-06 19:04:04 +00:00
|
|
|
|
((not enable-multibyte-characters)
|
|
|
|
|
;; Maybe there's a font for it, but we can't put it in the buffer.
|
|
|
|
|
nil)
|
2004-04-16 12:51:06 +00:00
|
|
|
|
((display-multi-font-p)
|
|
|
|
|
;; On a window system, a character is displayable if we have
|
|
|
|
|
;; a font for that character in the default face of the
|
|
|
|
|
;; currently selected frame.
|
2004-04-23 02:08:22 +00:00
|
|
|
|
(car (internal-char-font nil char)))
|
2004-04-16 12:51:06 +00:00
|
|
|
|
(t
|
2008-02-20 04:41:25 +00:00
|
|
|
|
;; On a terminal, a character is displayable if the coding
|
|
|
|
|
;; system for the terminal can encode it.
|
|
|
|
|
(let ((coding (terminal-coding-system)))
|
2008-11-20 23:07:44 +00:00
|
|
|
|
(when coding
|
|
|
|
|
(let ((cs-list (coding-system-get coding :charset-list)))
|
|
|
|
|
(cond
|
|
|
|
|
((listp cs-list)
|
|
|
|
|
(catch 'tag
|
|
|
|
|
(mapc #'(lambda (charset)
|
|
|
|
|
(if (encode-char char charset)
|
|
|
|
|
(throw 'tag charset)))
|
|
|
|
|
cs-list)
|
|
|
|
|
nil))
|
|
|
|
|
((eq cs-list 'iso-2022)
|
|
|
|
|
(catch 'tag2
|
|
|
|
|
(mapc #'(lambda (charset)
|
|
|
|
|
(if (and (plist-get (charset-plist charset)
|
|
|
|
|
:iso-final-char)
|
|
|
|
|
(encode-char char charset))
|
|
|
|
|
(throw 'tag2 charset)))
|
|
|
|
|
charset-list)
|
|
|
|
|
nil))
|
|
|
|
|
((eq cs-list 'emacs-mule)
|
|
|
|
|
(catch 'tag3
|
|
|
|
|
(mapc #'(lambda (charset)
|
|
|
|
|
(if (and (plist-get (charset-plist charset)
|
|
|
|
|
:emacs-mule-id)
|
|
|
|
|
(encode-char char charset))
|
|
|
|
|
(throw 'tag3 charset)))
|
|
|
|
|
charset-list)
|
|
|
|
|
nil)))))))))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
2000-04-01 12:03:57 +00:00
|
|
|
|
(provide 'mule-util)
|
1999-12-15 00:42:14 +00:00
|
|
|
|
|
2002-05-21 21:22:21 +00:00
|
|
|
|
;; Local Variables:
|
Use UTF-8 for most files with non-ASCII characters.
* admin/notes/unicode (etc/tutorials/TUTORIAL.ko, leim/quail/hanja.el)
(leim/quail/hanja3.el, leim/quail/symbol-ksc.el):
Now utf-8, not iso-2022-7bit. Also, files that contain non-UTF-8
characters are now encoded in utf-8-emacs, not iso-2022-7bit.
* etc/tutorials/TUTORIAL.ko, tutorials/TUTORIAL.th:
Switch from iso-2022-7bit to utf-8.
* leim/quail/cyrillic.el, leim/quail/czech.el, leim/quail/ethiopic.el:
* leim/quail/greek.el, leim/quail/hanja.el, leim/quail/hanja3.el:
* leim/quail/hebrew.el, leim/quail/lao.el, leim/quail/lrt.el:
* leim/quail/slovak.el, leim/quail/symbol-ksc.el, leim/quail/thai.el:
* leim/quail/tibetan.el, leim/quail/viqr.el, leim/quail/vntelex.el:
* leim/quail/vnvni.el, leim/quail/welsh.el:
* lisp/international/latin1-disp.el, lisp/international/mule-util.el:
* lisp/language/cyril-util.el, lisp/language/european.el:
* lisp/language/ind-util.el, lisp/language/lao-util.el, lisp/language/thai.el:
* lisp/language/tibet-util.el, lisp/language/tibetan.el:
* lisp/language/viet-util.el:
Switch from iso-2022-7bit to utf-8 or (if needed) utf-8-emacs.
Fixes: debbugs:13936
2013-04-01 18:18:40 -07:00
|
|
|
|
;; coding: utf-8
|
2002-05-21 21:22:21 +00:00
|
|
|
|
;; End:
|
|
|
|
|
|
2000-04-01 12:03:57 +00:00
|
|
|
|
;;; mule-util.el ends here
|