Function: rmail-output-as-babyl

rmail-output-as-babyl is a byte-compiled function defined in rmailout.el.gz.

Signature

(rmail-output-as-babyl FILE-NAME NOMSG)

Documentation

Convert the current buffer's text to Babyl and output to FILE-NAME.

Alters the current buffer's text, so it should be a temporary buffer. If a buffer is visiting FILE-NAME, adds the text to that buffer rather than saving the file directly. If the buffer is an Rmail buffer, updates it accordingly. If no buffer is visiting FILE-NAME, appends the text directly to FILE-NAME, and displays a "Wrote file" message unless NOMSG is a symbol (neither nil nor t).

Source Code

;; Defined in /usr/src/emacs/lisp/mail/rmailout.el.gz
(defun rmail-output-as-babyl (file-name nomsg)
  "Convert the current buffer's text to Babyl and output to FILE-NAME.
Alters the current buffer's text, so it should be a temporary buffer.
If a buffer is visiting FILE-NAME, adds the text to that buffer
rather than saving the file directly.  If the buffer is an Rmail buffer,
updates it accordingly.  If no buffer is visiting FILE-NAME, appends
the text directly to FILE-NAME, and displays a \"Wrote file\" message
unless NOMSG is a symbol (neither nil nor t)."
  (let ((coding-system-for-write 'emacs-mule-unix))
    (save-restriction
      (goto-char (point-min))
      (search-forward "\n\n" nil 'move)
      (narrow-to-region (point-min) (point))
      (if rmail-fields-not-to-output
	  (rmail-delete-unwanted-fields nil)))

    ;; Convert to Babyl format.
    (rmail-convert-to-babyl-format)
    ;; Write it into the file, or its buffer.
    (let ((buf (find-buffer-visiting file-name))
	  (tembuf (current-buffer)))
      (if (null buf)
	  (write-region (point-min) (point-max) file-name t nomsg)
	(if (eq buf (current-buffer))
	    (error "Can't output message to same file it's already in"))
	;; File has been visited, in buffer BUF.
	(set-buffer buf)
	(let ((inhibit-read-only t)
	      (msg (bound-and-true-p rmail-current-message)))
	  ;; If MSG is non-nil, buffer is in RMAIL mode.
	  (if msg
	      (rmail-output-to-babyl-buffer tembuf msg)
	    ;; Output file not in rmail mode => just insert at the end.
	    (narrow-to-region (point-min) (1+ (buffer-size)))
	    (goto-char (point-max))
	    (insert-buffer-substring tembuf)))))))