(point-at-bol): New function.
[elisp/apel.git] / emu-mule.el
index 6a3e853..59cc665 100644 (file)
@@ -28,9 +28,9 @@
 ;;; @ version specific features
 ;;;
 
+(require 'poe)
+
 (cond (running-emacs-19
-       (require 'emu-e19)
-       
        ;; Suggested by SASAKI Osamu <osamu@shuugr.bekkoame.or.jp>
        ;; (cf. [os2-emacs-ja:78])
        (defun fontset-pixel-size (fontset)
@@ -49,7 +49,6 @@
               ))))
        )
       (running-emacs-18
-       (require 'emu-18)
        (defun make-overlay (beg end &optional buffer type))
        (defun overlay-put (overlay prop value))
        ))
@@ -98,7 +97,7 @@
   (if coding-system
       (code-convert-string str *internal* coding-system)
     ;;(code-convert-string str *internal* nil) returns nil instead of str.
-    str)
+    str))
 
 ;; XXX: Should we support optional NOCOPY argument? (only in Emacs 20.x)
 (defun decode-coding-string (str coding-system)
                                 coding-system *internal*))))
          (setq len (1- len)))
        (concat ret (substring str len)))
-    str)
+    str))
 
 (defalias 'detect-coding-region 'code-detect-region)
 
@@ -245,10 +244,21 @@ find-file-hooks, etc.
 
 (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)))
+         (progn
+           (if (setq newline (cdr (assq lbt '((CRLF . "\r\n") (CR . "\r")))))
+               (save-excursion
+                 (save-restriction
+                   (narrow-to-region start end)
+                   (goto-char (point-min))
+                   (while (search-forward newline nil t)
+                     (replace-match "\n")))
+                 (code-convert (point-min) (point-max) cs *internal*))
+             (code-convert start end cs *internal*)))))))
 
 (defun encode-mime-charset-string (string charset)
   "Encode the STRING as MIME CHARSET."
@@ -259,10 +269,22 @@ find-file-hooks, etc.
 
 (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)
-      string)))
+      (if (and lbt (setq cs (mime-charset-to-coding-system charset)))
+         (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))
+             (decode-coding-string string cs)))
+       string))))
 
 (cond
  (running-emacs-19_29-or-later
@@ -290,6 +312,8 @@ find-file-hooks, etc.
 ;;; @@ to coding-system
 ;;;
 
+(require 'cyrillic)
+
 (defvar mime-charset-coding-system-alist
   '((iso-8859-1      . *ctext*)
     (x-ctext         . *ctext*)
@@ -490,7 +514,7 @@ Optional non-nil arg START-COLUMN specifies the starting column.
 
 ;;; @ CCL
 ;;;
-(require 'ccl)
+(eval-when-compile (require 'ccl))
 
 (defconst ccl-use-symbol-as-program nil
   "t if CCL related builtins accept symbol as CCL program.
@@ -553,7 +577,7 @@ If CCL-PROG is symbol, it is dereferenced.
 \[Emacs 20.3 emulating function]"
   (exec-ccl-string
    (if (symbolp ccl-prog) (symbol-value ccl-prog) ccl-prog)
-   string status))
+   status string))
 
 
 ;;; @ end