Skip to content

Commit

Permalink
(default-mime-charset-for-write): New variable.
Browse files Browse the repository at this point in the history
(detect-mime-charset-region): Return `default-mime-charset-for-write'
if suitable mime-charset is not found.
  • Loading branch information
morioka committed Dec 24, 1998
1 parent 589fe0d commit 3dbf4fe
Showing 1 changed file with 20 additions and 50 deletions.
70 changes: 20 additions & 50 deletions mcs-om.el
Expand Up @@ -26,38 +26,22 @@

(require 'poem)

(defsubst lbt-to-string (lbt)
(cdr (assq lbt '((nil . nil)
(CRLF . "\r\n")
(CR . "\r")
(dos . "\r\n")
(mac . "\r"))))
)

(defun encode-mime-charset-region (start end charset &optional lbt)
(defun encode-mime-charset-region (start end charset)
"Encode the text between START and END as MIME CHARSET."
(let ((cs (mime-charset-to-coding-system charset lbt)))
(let ((cs (mime-charset-to-coding-system charset)))
(if cs
(code-convert start end *internal* cs)
(if (and lbt (setq cs (mime-charset-to-coding-system charset)))
(let ((newline (lbt-to-string lbt)))
(save-excursion
(save-restriction
(narrow-to-region start end)
(code-convert (point-min) (point-max) *internal* cs)
(if newline
(goto-char (point-min))
(while (search-forward "\n" nil t)
(replace-match newline))))))))))
)))

(defun decode-mime-charset-region (start end charset &optional lbt)
"Decode the text between START and END as MIME CHARSET."
(let ((cs (mime-charset-to-coding-system charset lbt)))
(let ((cs (mime-charset-to-coding-system charset lbt))
newline)
(if cs
(code-convert start end cs *internal*)
(if (and lbt (setq cs (mime-charset-to-coding-system charset)))
(let ((newline (lbt-to-string lbt)))
(if newline
(progn
(if (setq newline (cdr (assq lbt '((CRLF . "\r\n") (CR . "\r")))))
(save-excursion
(save-restriction
(narrow-to-region start end)
Expand All @@ -67,39 +51,29 @@
(code-convert (point-min) (point-max) cs *internal*))
(code-convert start end cs *internal*)))))))

(defun encode-mime-charset-string (string charset &optional lbt)
(defun encode-mime-charset-string (string charset)
"Encode the STRING as MIME CHARSET."
(let ((cs (mime-charset-to-coding-system charset lbt)))
(let ((cs (mime-charset-to-coding-system charset)))
(if cs
(code-convert-string string *internal* cs)
(if (and lbt (setq cs (mime-charset-to-coding-system charset)))
(let ((newline (lbt-to-string lbt)))
(if newline
(with-temp-buffer
(insert string)
(code-convert (point-min) (point-max) *internal* cs)
(goto-char (point-min))
(while (search-forward "\n" nil t)
(replace-match newline))
(buffer-string))
(decode-coding-string string cs)))
string))))
string)))

(defun decode-mime-charset-string (string charset &optional lbt)
"Decode the STRING which is encoded in MIME CHARSET."
(let ((cs (mime-charset-to-coding-system charset lbt)))
(let ((cs (mime-charset-to-coding-system charset lbt))
newline)
(if cs
(decode-coding-string string cs)
(if (and lbt (setq cs (mime-charset-to-coding-system charset)))
(let ((newline (lbt-to-string lbt)))
(if newline
(progn
(if (setq newline (cdr (assq lbt '((CRLF . "\r\n") (CR . "\r")))))
(with-temp-buffer
(insert string)
(goto-char (point-min))
(while (search-forward newline nil t)
(replace-match "\n"))
(code-convert (point-min) (point-max) cs *internal*)
(buffer-string))
(insert string)
(goto-char (point-min))
(while (search-forward newline nil t)
(replace-match "\n"))
(code-convert (point-min) (point-max) cs *internal*)
(buffer-string))
(decode-coding-string string cs)))
string))))

Expand Down Expand Up @@ -145,10 +119,6 @@
))

(defsubst mime-charset-to-coding-system (charset &optional lbt)
"Return coding-system corresponding with CHARSET.
CHARSET is a symbol whose name is MIME charset.
If optional argument LBT (`CRLF', `LF', `CR', `unix', `dos' or `mac')
is specified, it is used as line break code type of coding-system."
(if (stringp charset)
(setq charset (intern (downcase charset)))
)
Expand Down

0 comments on commit 3dbf4fe

Please sign in to comment.