--- mm-util.el 21 Feb 2005 12:42:41 +0100 7.26 +++ mm-util.el 10 Mar 2005 19:31:33 +0100 @@ -142,6 +142,34 @@ ;; Is this branch ever actually useful? (car (memq cs (mm-get-coding-system-list)))))) +(defun mm-codepage-setup (number) + "Create a coding system cpNUMBER and an alias for windows-NUMBER. +The coding system is created using `codepage-setup'. The alias +is added to `mm-charset-synonym-alist'." + (interactive + (let ((completion-ignore-case t) + (candidates (cp-supported-codepages))) + (list (completing-read "Setup DOS Codepage: (default 437) " candidates + nil t nil nil "437")))) + (let* ((cp (intern (format "cp%s" number))) + (alias (intern (format "windows-%s" number)))) + (unless (mm-coding-system-p cp) + (when (codepage-setup number) + (unless (mm-coding-system-p alias) + (add-to-list 'mm-charset-synonym-alist + (cons alias cp))))))) + +(defvar mm-charset-eval-alist + '(;; (iso-8859-13 . (require 'code-pages)) + ;; Emacs 21 offers: 1250 1251 1253 1257 + (windows-1250 . (mm-codepage-setup 1250)) + (windows-1251 . (mm-codepage-setup 1251)) + (windows-1253 . (mm-codepage-setup 1253)) + (windows-1257 . (mm-codepage-setup 1257))) + "An alist of \(charset . form\) pairs. +If an article is encoded in an unknown CHARSET, FORM is evaluated. +This allows to load additional libraries providing CHARSETS.") + (defvar mm-charset-synonym-alist `( ;; Not in XEmacs, but it's not a proper MIME charset anyhow. @@ -175,7 +203,7 @@ '((ks_c_5601-1987 . cp949)) '((ks_c_5601-1987 . euc-kr)))) ) - "A mapping from invalid charset names to the real charset names.") + "A mapping from unknown or invalid charset names to the real charset names.") (defvar mm-binary-coding-system (cond @@ -400,6 +428,10 @@ (pop alist)) out))) +;; FIXME: `gnus-message' must be replaced by `message'. This is just for +;; testing. +(autoload 'gnus-message "gnus-util") + (defun mm-charset-to-coding-system (charset &optional lbt) "Return coding-system corresponding to CHARSET. CHARSET is a symbol naming a MIME charset. @@ -428,9 +460,26 @@ ;;; (eq charset (coding-system-get charset 'mime-charset)) ) charset) + ;; Eval expressions from `mm-charset-eval-alist' + ((let* ((el (assq charset mm-charset-eval-alist)) + (cs (car el)) + (form (cdr el))) + (and cs + form + ;; Avoid errors... + (condition-case nil (eval form) (error nil)) + ;; (message "Failed to eval `%s'" form)) + (mm-coding-system-p cs) + (gnus-message 7 "Added charset `%s' via `mm-charset-eval-alist'" cs) + cs))) ;; Translate invalid charsets. ((let ((cs (cdr (assq charset mm-charset-synonym-alist)))) - (and cs (mm-coding-system-p cs) cs))) + (and cs + (mm-coding-system-p cs) + (gnus-message 7 + "Using synonym `%s' from `mm-charset-synonym-alist' for `%s'" + cs charset) + cs))) ;; Last resort: search the coding system list for entries which ;; have the right mime-charset in case the canonical name isn't ;; defined (though it should be). @@ -442,6 +491,8 @@ (eq charset (or (coding-system-get c :mime-charset) (coding-system-get c 'mime-charset)))) (setq cs c))) + (unless cs + (gnus-message 7 "Unknown charset: %s" charset)) cs)))) (eval-and-compile