Function: icalendar-unfolded-buffer-from-file
icalendar-unfolded-buffer-from-file is a byte-compiled function
defined in icalendar-parser.el.gz.
Signature
(icalendar-unfolded-buffer-from-file FILENAME &optional VISIT BEG END)
Documentation
Return a buffer visiting FILENAME with unfolded lines.
If an unfolded buffer is already visiting FILENAME, return
it. Otherwise, create a new buffer with the contents of FILENAME and
perform line unfolding with icalendar-unfold-undecoded-region, then
decode the buffer, setting an appropriate value for
buffer-file-coding-system, and return the new buffer. Optional
arguments VISIT, BEG, END are as in insert-file-contents.
Source Code
;; Defined in /usr/src/emacs/lisp/calendar/icalendar-parser.el.gz
(defun ical:unfolded-buffer-from-file (filename &optional visit beg end)
"Return a buffer visiting FILENAME with unfolded lines.
If an unfolded buffer is already visiting FILENAME, return
it. Otherwise, create a new buffer with the contents of FILENAME and
perform line unfolding with `icalendar-unfold-undecoded-region', then
decode the buffer, setting an appropriate value for
`buffer-file-coding-system', and return the new buffer. Optional
arguments VISIT, BEG, END are as in `insert-file-contents'."
(unless (and (file-exists-p filename)
(file-readable-p filename))
(error "File cannot be read: %s" filename))
(or (ical:find-unfolded-buffer-visiting filename)
(let ((uf-buffer
(generate-new-buffer
(concat " *UNFOLDED:" (file-name-nondirectory filename)))))
(with-current-buffer uf-buffer
(set-buffer-multibyte nil)
(insert-file-contents-literally filename visit beg end t)
(ical:unfold-undecoded-region (point-min) (point-max))
;; now proceed with decoding:
(set-buffer-multibyte t)
(decode-coding-inserted-region (point-min) (point-max) filename)
;; ensure we'll use CR-LF line endings on write, even if they weren't
;; in the source data. The standard also says UTF-8 is the default
;; encoding, so use 'prefer-utf-8-dos when last-coding-system-used
;; is nil. FIXME: for some reason, this doesn't seem to run at all!
(setq buffer-file-coding-system
(if last-coding-system-used
(coding-system-change-eol-conversion last-coding-system-used
'dos)
'prefer-utf-8-dos))
;; restore buffer name after renaming by set-visited-file-name:
(let ((bname (buffer-name)))
(set-visited-file-name filename t)
(rename-buffer bname))
;; merely unfolding should not mark the buffer as modified;
;; this prevents querying the user before killing it:
(set-buffer-modified-p nil)
;; inhibit auto-save-mode, which will otherwise create save
;; files containing the unfolded data; these are probably
;; not useful to the user and a nuisance when running tests:
(auto-save-mode -1))
uf-buffer)))