Function: icalendar-unfold-region
icalendar-unfold-region is a byte-compiled function defined in
icalendar-parser.el.gz.
Signature
(icalendar-unfold-region START END &optional BUFFER)
Documentation
Unfold region between START and END in BUFFER (default: current buffer).
"Unfolding" means removing the whitespace characters inserted to
continue lines longer than 75 octets (see icalendar-fold-region
for the folding operation).
Returns the new end position after unfolding finishes. Thus this
function is a suitable FROM-FN (decoding function) for format-alist.
WARNING: Unfolding can only be done reliably before text is decoded, since decoding potentially replaces CR-LF line endings. Unfolding an already-decoded region could lead to unexpected results, such as displaying multibyte characters incorrectly, depending on the contents and the coding system used.
This function attempts to do the right thing even if the region
is already decoded. If it is still undecoded, it is better to
call icalendar-unfold-undecoded-region directly instead, and
decode it afterward.
Source Code
;; Defined in /usr/src/emacs/lisp/calendar/icalendar-parser.el.gz
(defun ical:unfold-region (start end &optional buffer)
"Unfold region between START and END in BUFFER (default: current buffer).
\"Unfolding\" means removing the whitespace characters inserted to
continue lines longer than 75 octets (see `icalendar-fold-region'
for the folding operation).
Returns the new end position after unfolding finishes. Thus this
function is a suitable FROM-FN (decoding function) for `format-alist'.
WARNING: Unfolding can only be done reliably before text is
decoded, since decoding potentially replaces CR-LF line endings.
Unfolding an already-decoded region could lead to unexpected
results, such as displaying multibyte characters incorrectly,
depending on the contents and the coding system used.
This function attempts to do the right thing even if the region
is already decoded. If it is still undecoded, it is better to
call `icalendar-unfold-undecoded-region' directly instead, and
decode it afterward."
;; TODO: also make this a command so it can be run manually?
(with-current-buffer (or buffer (current-buffer))
(let ((was-multibyte enable-multibyte-characters)
(start-char (position-bytes start))
(end-char (position-bytes end))
(end-marker (make-marker)))
;; set a marker at the original end position so we can return
;; the updated position later:
(set-marker end-marker end)
;; we put the buffer in unibyte mode and later restore its
;; previous state, so that if the buffer was already multibyte,
;; any multibyte characters where line folds broke up their
;; bytes can be reinterpreted:
(set-buffer-multibyte nil)
(with-restriction start-char end-char
(run-hooks 'ical:pre-unfolding-hook)
(goto-char (point-min))
;; since we can't be sure that line folds have a leading CR
;; in already-decoded regions, do the best we can:
(while (re-search-forward (rx (seq (zero-or-one "\r") "\n"
(or " " "\t")))
nil t)
(replace-match "" nil nil)))
;; restore previous state, possibly reinterpreting characters:
(set-buffer-multibyte was-multibyte)
;; return the new end of the region, for format.el conversion:
(marker-position end-marker))))