;;; mm-util.el --- Utility functions for Mule and low level things
;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-;; 2005, 2006, 2007 Free Software Foundation, Inc.
+;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
;;; Code:
+;; For Emacs < 22.2.
+(eval-and-compile
+ (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
+
(eval-when-compile (require 'cl))
(require 'mail-prsvr)
(require 'timer))
(require 'timer)))
+(defvar mm-mime-mule-charset-alist )
+
(eval-and-compile
- (mapcar
+ (mapc
(lambda (elem)
(let ((nfunc (intern (format "mm-%s" (car elem)))))
(if (fboundp (car elem))
(multibyte-string-p . ignore)
(insert-byte . insert-char)
(multibyte-char-to-unibyte . identity)
+ (set-buffer-multibyte . ignore)
(special-display-p
. (lambda (buffer-name)
"Returns non-nil if a buffer named BUFFER-NAME gets a special frame."
the alias. Else windows-NUMBER is used."
(interactive
(let ((completion-ignore-case t)
- (candidates (cp-supported-codepages)))
+ (candidates (if (fboundp 'cp-supported-codepages)
+ (cp-supported-codepages)
+ ;; Removed in Emacs 23 (unicode), sosignal an error:
+ (error "`codepage-setup' is obsolete in this Emacs version."))))
(list (completing-read "Setup DOS Codepage: (default 437) " candidates
nil t nil nil "437"))))
(when alias
,@(when (and (not (mm-coding-system-p 'gbk))
(mm-coding-system-p 'cp936))
'((gbk . cp936)))
- ;; ISO8859-1 is ISO-8859-1
+ ;; ISO8859-1 is a bogus name for ISO-8859-1
,@(when (and (not (mm-coding-system-p 'iso8859-1))
(mm-coding-system-p 'iso-8859-1))
'((iso8859-1 . iso-8859-1)))
(cons (symbol :tag "charset")
(symbol :tag "form"))))
:group 'mime)
+(put 'mm-charset-eval-alist 'risky-local-variable t)
(defvar mm-binary-coding-system
(cond
(iso-2022-jp latin-jisx0201 japanese-jisx0208 japanese-jisx0208-1978)
(euc-kr korean-ksc5601)
(gb2312 chinese-gb2312)
+ (gbk chinese-gbk)
+ (gb18030 gb18030-2-byte
+ gb18030-4-byte-bmp gb18030-4-byte-smp
+ gb18030-4-byte-ext-1 gb18030-4-byte-ext-2)
(big5 chinese-big5-1 chinese-big5-2)
(tibetan tibetan)
(thai-tis620 thai-tis620)
cs mime mule alist)
(while css
(setq cs (pop css)
- mime (or (coding-system-get cs :mime-charset) ; Emacs 23 (unicode)
+ mime (or (coding-system-get cs :mime-charset); Emacs 23 (unicode)
(coding-system-get cs 'mime-charset)))
(when (and mime
(not (eq t (setq mule
(autoload 'latin-unity-massage-name "latin-unity")
(autoload 'latin-unity-maybe-remap "latin-unity")
(autoload 'latin-unity-representations-feasible-region "latin-unity")
- (autoload 'latin-unity-representations-present-region "latin-unity")
- (defvar latin-unity-coding-systems)
- (defvar latin-unity-ucs-list))
+ (autoload 'latin-unity-representations-present-region "latin-unity"))
+
+(defvar latin-unity-coding-systems)
+(defvar latin-unity-ucs-list)
(defun mm-xemacs-find-mime-charset-1 (begin end)
"Determine which MIME charset to use to send region as message.
(when (featurep 'xemacs)
`(and (featurep 'mule) (mm-xemacs-find-mime-charset-1 ,begin ,end))))
+(declare-function mm-delete-duplicates "mm-util" (list))
+
(defun mm-find-mime-charset-region (b e &optional hack-charsets)
"Return the MIME charsets needed to encode the region between B and E.
nil means ASCII, a single-element list represents an appropriate MIME
;; Otherwise, we'll get nil, and the next setq will get invoked.
(setq charsets (mm-xemacs-find-mime-charset b e))
+ ;; Fixme: won't work for unibyte Emacs 23:
+
;; We're not multibyte, or a single coding system won't cover it.
(setq charsets
(mm-delete-duplicates
(memq 'iso-8859-15 charsets)
(memq 'iso-8859-15 hack-charsets)
(save-excursion (mm-iso-8859-x-to-15-region b e)))
- (mapcar (lambda (x) (setq charsets (delq (car x) charsets)))
- mm-iso-8859-15-compatible))
+ (dolist (x mm-iso-8859-15-compatible)
+ (setq charsets (delq (car x) charsets))))
(if (and (memq 'iso-2022-jp-2 charsets)
(memq 'iso-2022-jp-2 hack-charsets))
(setq charsets (delq 'iso-2022-jp charsets)))
(defmacro mm-with-unibyte-buffer (&rest forms)
"Create a temporary buffer, and evaluate FORMS there like `progn'.
Use unibyte mode for this."
- `(let (default-enable-multibyte-characters)
- (with-temp-buffer ,@forms)))
+ `(with-temp-buffer
+ (mm-disable-multibyte)
+ ,@forms))
(put 'mm-with-unibyte-buffer 'lisp-indent-function 0)
(put 'mm-with-unibyte-buffer 'edebug-form-spec '(body))
(defmacro mm-with-multibyte-buffer (&rest forms)
"Create a temporary buffer, and evaluate FORMS there like `progn'.
Use multibyte mode for this."
- `(let ((default-enable-multibyte-characters t))
- (with-temp-buffer ,@forms)))
+ `(with-temp-buffer
+ (mm-enable-multibyte)
+ ,@forms))
(put 'mm-with-multibyte-buffer 'lisp-indent-function 0)
(put 'mm-with-multibyte-buffer 'edebug-form-spec '(body))
;; Remove composition since the base charsets have been included.
;; Remove eight-bit-*, treat them as ascii.
(let ((css (find-charset-region b e)))
- (mapcar (lambda (cs) (setq css (delq cs css)))
- '(composition eight-bit-control eight-bit-graphic
- control-1))
- css))
+ (dolist (cs
+ '(composition eight-bit-control eight-bit-graphic control-1)
+ css)
+ (setq css (delq cs css)))))
(t
;; We are in a unibyte buffer or XEmacs non-mule, so we futz around a bit.
(save-excursion
inhibit-file-name-handlers)))
(write-region start end filename append visit lockname)))
+(autoload 'gmm-write-region "gmm-utils")
+
;; It is not a MIME function, but some MIME functions use it.
(if (and (fboundp 'make-temp-file)
(ignore-errors
(if (eq (point) end) 'ascii (mm-guess-charset))
(goto-char point)))))
+(declare-function mm-detect-coding-region "mm-util" (start end))
+
(if (fboundp 'coding-system-get)
(defun mm-detect-mime-charset-region (start end)
"Detect MIME charset of the text in the region between START and END."
(funcall (symbol-value 'set-auto-coding-function)
nil (- (point-max) (point-min)))
(error nil)))))
- ((featurep 'file-coding) ;; XEmacs
+ ((and (featurep 'xemacs) (featurep 'file-coding)) ;; XEmacs
(let ((case-fold-search t)
(end (point-at-eol))
codesys start)