[mew-dist 20177] Re: mew-charset-m17n

Tatsuya Kinoshita tats at example.com
2002年 1月 30日 (水) 20:26:23 JST


In message [mew-dist 20098], on Thu, 17 Jan 2002,
Tatsuya Kinoshita <tats at example.com> wrote:

> rangeに含まれていない場合、エラーで戻るのではなく、自動判定して
> yes/noで確認するのがいいと思う。

とりあえずad hocな.mew.elを書いてみました。

my-mew-charset-ask:

エンコード前の確認。確認のいらない分はmy-mew-charset-noask-listで
指定しておく。

my-mew-cs-unify:

本文中の同じ文字を統合。たとえばiso-8859-2のCURRENCY SIGNは
iso-8859-1のCURRENCY SIGNに統合される。iso-8859-2のBREVEは
iso-8859-1にないので変換されない。なお、Mule-UCSが必要。

my-mew-cs-force-convert-region:

リージョンを強制変換。my-mew-cs-unifyとは異なり、別の文字であって
も強制的に変換される。たとえばiso-8859-2のBREVE (0xA2)は
iso-8859-1のCENT SIGN (0xA2)になる。C-uを付けるとctextとは別の変
換先(たとえばiso-8859-2)を指定できる。(対象とする文字と変換先との
関係によっては文字化けしてしまうので要注意)

-- 
木下達也
-------------- next part --------------
;;; sample.mew.el --- a sample of .mew.el related to coding system

;; This work is written by Tatsuya Kinoshita.  Copyright is disclaimed.
;; You can add this to your ~/.mew.el, but there is NO WARRANTY.

(add-hook 'mew-make-message-hook 'my-mew-check-message)
(define-key mew-draft-body-map "\C-cu" 'my-mew-cs-unify)
(define-key mew-draft-body-map "\C-ce" 'my-mew-cs-force-convert-region)
(setq my-mew-charset-noask-list '("us-ascii" "iso-8859-1" "iso-2022-jp"))
(setq my-mew-cs-force-convert-default-cs mew-cs-m17n);; convert to iso-8859-1
(defun my-mew-check-message ()
  ;;(my-mew-cs-unify)
  (my-mew-charset-ask))
(defun my-mew-charset-ask ()
  (save-excursion
    (save-window-excursion
      (switch-to-buffer (current-buffer))
      (delete-other-windows)
      (let ((chset (my-mew-charset-guess-body)))
	(if (and (mew-coding-system-p (mew-charset-to-cs chset))
		 (not (member chset my-mew-charset-noask-list))
		 (not (y-or-n-p
		       (format "Really encode with charset=%s? " chset))))
	    (mew-encode-error "Edit body"))))))
(defun my-mew-cs-unify ()
  (interactive)
  (let ((pos (point)))
    (message "Evaluating (require 'un-define)...")
    (require 'un-define);; Mule-UCS
    (message "Evaluating (require 'un-define)...done")
    (message "Unifying...")
    (when (mew-coding-system-p 'utf-8)
      (mew-cs-encode-region (my-mew-body-min) (my-mew-body-max) 'utf-8)
      (mew-cs-decode-region (my-mew-body-min) (my-mew-body-max) 'utf-8))
    (goto-char pos)
    (message "Unifying...done (charset=%s)" (my-mew-charset-guess-body))))
(defun my-mew-cs-force-convert-region (beg end &optional arg)
  (interactive "r\nP")
  (let* ((count (- end beg))
	 (default-cs my-mew-cs-force-convert-default-cs)
	 (tocs (if arg
		   (read-coding-system
		    (format "Coding-system (%s): " (symbol-name default-cs))
		    default-cs)
		 default-cs))
	 enc-beg cs-cur cs-next)
    (if (not (mew-coding-system-p tocs))
	(error "Unknown coding system %s" (symbol-name tocs)))
    (message "Converting to %s..." (symbol-name tocs))
    (push-mark end t t)
    (goto-char beg)
    (insert "\n");; for separating
    (setq enc-beg (point))
    (setq cs-cur nil)
    (while (> count 0)
      (setq cs-next (my-mew-cs-guess-region (point) (1+ (point))))
      (when (not (equal cs-cur cs-next))
	(mew-cs-encode-region enc-beg (point) cs-cur)
	(setq enc-beg (point))
	(setq cs-cur cs-next))
      (goto-char (1+ (point)))
      (setq count (1- count)))
    (mew-cs-encode-region enc-beg (point) cs-cur)
    (mew-cs-decode-region (1+ beg) (point) tocs)
    (goto-char beg)
    (delete-char 1);; delete "\n"
    (message "Converting to %s...done" (symbol-name tocs))))
(defun my-mew-cs-guess-region (beg end)
  (interactive "r")
  (mew-charset-to-cs (mew-charset-guess-region beg end)))
(defun my-mew-charset-guess-body ()
  (interactive)
  (mew-charset-guess-region (my-mew-body-min) (my-mew-body-max)))
(defun my-mew-body-min ()
  (interactive)
  (save-excursion
   (mew-header-goto-body)
   (point)))
(defun my-mew-body-max ()
  (interactive)
  (save-excursion
   (if (not (mew-attach-p))
       (point-max)
     (mew-attach-move-onto-body)
     (setq max (point)))))

;;; ends here


Mew-dist メーリングリストの案内