(insert-file-contents-as-binary): Return value.
[elisp/apel.git] / emu-latin1.el
index 3091507..45bc9a6 100644 (file)
 
 ;;; Code:
 
-;;; @ version and variant specific features
+;;; @ buffer representation
 ;;;
 
-;; (cond (running-xemacs
-;;        (require 'emu-xemacs))
-;;       (running-emacs-19
-;;        (require 'emu-e19)
-;;        ))
+(defmacro-maybe set-buffer-multibyte (flag)
+  "Set the multibyte flag of the current buffer to FLAG.
+If FLAG is t, this makes the buffer a multibyte buffer.
+If FLAG is nil, this makes the buffer a single-byte buffer.
+The buffer contents remain unchanged as a sequence of bytes
+but the contents viewed as characters do change.
+\[Emacs 20.3 emulating macro]"
+  )
 
 
 ;;; @ character set
   "Set buffer-file-coding-system of the current buffer to CODING-SYSTEM."
   )
 
-(defmacro as-binary-process (&rest body)
-  (` (let (selective-display)  ; Disable ^M to nl translation.
-       (,@ body)
-       )))
-
-(defmacro as-binary-input-file (&rest body)
-  (` (let ((emx-binary-mode t)) ; Stop CRLF to LF conversion in OS/2
-       (,@ body)
-       )))
-
-(defmacro as-binary-output-file (&rest body)
-  (` (let ((emx-binary-mode t)) ; Stop CRLF to LF conversion in OS/2
-       (,@ body)
-       )))
-
 
 ;;; @@ for old MULE emulation
 ;;;
@@ -145,9 +133,31 @@ else returns nil. [emu-latin1.el; old MULE emulating function]"
   t)
 
 
-;;; @ binary access
+;;; @ without code-conversion
 ;;;
 
+(defmacro as-binary-process (&rest body)
+  (` (let (selective-display)  ; Disable ^M to nl translation.
+       (,@ body)
+       )))
+
+(defmacro as-binary-input-file (&rest body)
+  (` (let ((emx-binary-mode t)) ; Stop CRLF to LF conversion in OS/2
+       (,@ body)
+       )))
+
+(defmacro as-binary-output-file (&rest body)
+  (` (let ((emx-binary-mode t)) ; Stop CRLF to LF conversion in OS/2
+       (,@ body)
+       )))
+
+(defun write-region-as-binary (start end filename
+                                    &optional append visit lockname)
+  "Like `write-region', q.v., but don't code conversion."
+  (let ((emx-binary-mode t))
+    (write-region start end filename append visit lockname)
+    ))
+
 (defun insert-file-contents-as-binary (filename
                                       &optional visit beg end replace)
   "Like `insert-file-contents', q.v., but don't code and format conversion.
@@ -174,12 +184,20 @@ find-file-hooks, etc.
     (insert-file-contents-literally filename visit beg end replace)
     ))
 
-(defun write-region-as-binary (start end filename
-                                    &optional append visit lockname)
-  "Like `write-region', q.v., but don't code conversion."
-  (let ((emx-binary-mode t))
-    (write-region start end filename append visit lockname)
-    ))
+(defalias 'insert-file-contents-as-raw-text 'insert-file-contents)
+
+(defun write-region-as-raw-text-CRLF (start end filename
+                                           &optional append visit lockname)
+  "Like `write-region', q.v., but write as network representation."
+  (let ((the-buf (current-buffer)))
+    (with-temp-buffer
+      (insert-buffer-substring the-buf start end)
+      (goto-char (point-min))
+      (while (re-search-forward "\\(\\=\\|[^\r]\\)\n" nil t)
+       (replace-match "\\1\r\n")
+       )
+      (write-region (point-min)(point-max) filename append visit lockname)
+      )))
 
 
 ;;; @ MIME charset
@@ -211,17 +229,33 @@ find-file-hooks, etc.
   "Encode the text between START and END as MIME CHARSET."
   )
 
-(defun decode-mime-charset-region (start end charset)
+(defun decode-mime-charset-region (start end charset &optional lbt)
   "Decode the text between START and END as MIME CHARSET."
+  (cond ((eq lbt 'CRLF)
+        (save-excursion
+          (save-restriction
+            (narrow-to-region start end)
+            (goto-char (point-min))
+            (while (search-forward "\r\n" nil t)
+              (replace-match "\n"))
+            ))))
   )
 
 (defun encode-mime-charset-string (string charset)
   "Encode the STRING as MIME CHARSET."
   string)
 
-(defun decode-mime-charset-string (string charset)
+(defun decode-mime-charset-string (string charset &optional lbt)
   "Decode the STRING as MIME CHARSET."
-  string)
+  (if lbt
+      (with-temp-buffer
+       (insert string)
+       (decode-mime-charset-region (point-min)(point-max) charset lbt)
+       (buffer-string)
+       )
+    string))
+
+(defalias 'write-region-as-mime-charset 'write-region)
 
 
 ;;; @ character
@@ -241,6 +275,11 @@ find-file-hooks, etc.
   "Return number of columns a CHAR occupies when displayed."
   1)
 
+(defun split-char (character)
+  "Return list of charset and one or two position-codes of CHARACTER."
+  (cons (char-charset character) character)
+  )
+
 (defalias 'char-length 'char-bytes)
 
 (defmacro char-next-index (char index)
@@ -270,6 +309,8 @@ Optional non-nil arg START-COLUMN specifies the starting column.
   (substring str start-column width)
   )
 
+(defalias 'looking-at-as-unibyte 'looking-at)
+
 ;;; @@ obsoleted aliases
 ;;;
 ;;; You should not use them.