;;; mm-util.el --- Utility functions for Mule and low level things
-;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
+;; 2007, 2008, 2009 Free Software Foundation, Inc.
;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
((fboundp 'char-valid-p) 'char-valid-p)
(t 'identity))))
+;; `ucs-to-char' is a function that Mule-UCS provides.
+(if (featurep 'xemacs)
+ (cond ((and (fboundp 'unicode-to-char) ;; XEmacs 21.5.
+ (subrp (symbol-function 'unicode-to-char)))
+ (if (featurep 'mule)
+ (defalias 'mm-ucs-to-char 'unicode-to-char)
+ (defun mm-ucs-to-char (codepoint)
+ "Convert Unicode codepoint to character."
+ (or (unicode-to-char codepoint) ?#))))
+ ((featurep 'mule)
+ (defun mm-ucs-to-char (codepoint)
+ "Convert Unicode codepoint to character."
+ (if (fboundp 'ucs-to-char) ;; Mule-UCS is loaded.
+ (progn
+ (defalias 'mm-ucs-to-char
+ (lambda (codepoint)
+ "Convert Unicode codepoint to character."
+ (condition-case nil
+ (or (ucs-to-char codepoint) ?#)
+ (error ?#))))
+ (mm-ucs-to-char codepoint))
+ (condition-case nil
+ (or (int-to-char codepoint) ?#)
+ (error ?#)))))
+ (t
+ (defun mm-ucs-to-char (codepoint)
+ "Convert Unicode codepoint to character."
+ (condition-case nil
+ (or (int-to-char codepoint) ?#)
+ (error ?#)))))
+ (if (let ((char (make-char 'japanese-jisx0208 36 34)))
+ (eq char (decode-char 'ucs char)))
+ ;; Emacs 23.
+ (defalias 'mm-ucs-to-char 'identity)
+ (defun mm-ucs-to-char (codepoint)
+ "Convert Unicode codepoint to character."
+ (or (decode-char 'ucs codepoint) ?#))))
+
;; Fixme: This seems always to be used to read a MIME charset, so it
;; should be re-named and fixed (in Emacs) to offer completion only on
;; proper charset names (base coding systems which have a
"A table of the difference character between ISO-8859-X and ISO-8859-15.")
(defcustom mm-coding-system-priorities
- (if (boundp 'current-language-environment)
- (let ((lang (symbol-value 'current-language-environment)))
- (cond ((string= lang "Japanese")
- ;; Japanese users prefer iso-2022-jp to euc-japan or
- ;; shift_jis, however iso-8859-1 should be used when
- ;; there are only ASCII text and Latin-1 characters.
- '(iso-8859-1 iso-2022-jp iso-2022-jp-2 shift_jis utf-8)))))
+ (let ((lang (if (boundp 'current-language-environment)
+ (symbol-value 'current-language-environment))))
+ (cond (;; XEmacs without Mule but with `file-coding'.
+ (not lang) nil)
+ ;; In XEmacs 21.5 it may be the one like "Japanese (UTF-8)".
+ ((string-match "\\`Japanese" lang)
+ ;; Japanese users prefer iso-2022-jp to euc-japan or
+ ;; shift_jis, however iso-8859-1 should be used when
+ ;; there are only ASCII text and Latin-1 characters.
+ '(iso-8859-1 iso-2022-jp iso-2022-jp-2 shift_jis utf-8))))
"Preferred coding systems for encoding outgoing messages.
More than one suitable coding system may be found for some text.
(eval-and-compile
(defvar mm-emacs-mule (and (not (featurep 'xemacs))
- (boundp 'default-enable-multibyte-characters)
- default-enable-multibyte-characters
+ (boundp 'enable-multibyte-characters)
+ (default-value 'enable-multibyte-characters)
(fboundp 'set-buffer-multibyte))
"True in Emacs with Mule.")
"Return non-nil if the session is multibyte.
This affects whether coding conversion should be attempted generally."
(if (featurep 'mule)
- (if (boundp 'default-enable-multibyte-characters)
- default-enable-multibyte-characters
+ (if (boundp 'enable-multibyte-characters)
+ (default-value 'enable-multibyte-characters)
t)))
(defun mm-iso-8859-x-to-15-region (&optional b e)
(defmacro mm-with-unibyte-current-buffer (&rest forms)
"Evaluate FORMS with current buffer temporarily made unibyte.
-Also bind `default-enable-multibyte-characters' to nil.
+Also bind the default-value of `enable-multibyte-characters' to nil.
Equivalent to `progn' in XEmacs
NOTE: Use this macro with caution in multibyte buffers (it is not
(let ((,multibyte enable-multibyte-characters)
(,buffer (current-buffer)))
(unwind-protect
- (let (default-enable-multibyte-characters)
+ (letf (((default-value 'enable-multibyte-characters) nil))
(set-buffer-multibyte nil)
,@forms)
(set-buffer ,buffer)
(set-buffer-multibyte ,multibyte)))
- (let (default-enable-multibyte-characters)
+ (letf (((default-value 'enable-multibyte-characters) nil))
,@forms))))
(put 'mm-with-unibyte-current-buffer 'lisp-indent-function 0)
(put 'mm-with-unibyte-current-buffer 'edebug-form-spec '(body))
`find-file-hooks', etc.
If INHIBIT is non-nil, inhibit `mm-inhibit-file-name-handlers'.
This function ensures that none of these modifications will take place."
- (let* ((format-alist nil)
- (auto-mode-alist (if inhibit nil (mm-auto-mode-alist)))
- (default-major-mode 'fundamental-mode)
- (enable-local-variables nil)
- (after-insert-file-functions nil)
- (enable-local-eval nil)
- (inhibit-file-name-operation (if inhibit
- 'insert-file-contents
- inhibit-file-name-operation))
- (inhibit-file-name-handlers
- (if inhibit
- (append mm-inhibit-file-name-handlers
- inhibit-file-name-handlers)
- inhibit-file-name-handlers))
- (ffh (if (boundp 'find-file-hook)
- 'find-file-hook
- 'find-file-hooks))
- (val (symbol-value ffh)))
+ (letf* ((format-alist nil)
+ (auto-mode-alist (if inhibit nil (mm-auto-mode-alist)))
+ ((default-value 'major-mode) 'fundamental-mode)
+ (enable-local-variables nil)
+ (after-insert-file-functions nil)
+ (enable-local-eval nil)
+ (inhibit-file-name-operation (if inhibit
+ 'insert-file-contents
+ inhibit-file-name-operation))
+ (inhibit-file-name-handlers
+ (if inhibit
+ (append mm-inhibit-file-name-handlers
+ inhibit-file-name-handlers)
+ inhibit-file-name-handlers))
+ (ffh (if (boundp 'find-file-hook)
+ 'find-file-hook
+ 'find-file-hooks))
+ (val (symbol-value ffh)))
(set ffh nil)
(unwind-protect
(insert-file-contents filename visit beg end replace)
filename))
(mm-decompress-buffer filename nil t))))
(when decomp
- (set-buffer (let (default-enable-multibyte-characters)
- (generate-new-buffer " *temp*")))
+ (set-buffer (letf (((default-value 'enable-multibyte-characters) nil))
+ (generate-new-buffer " *temp*")))
(insert decomp)
(setq filename (file-name-sans-extension filename)))
(goto-char (point-min))