Function: erc--split-line

erc--split-line is a byte-compiled function defined in erc-backend.el.gz.

Signature

(erc--split-line LONGLINE)

Source Code

;; Defined in /usr/src/emacs/lisp/erc/erc-backend.el.gz
(defun erc--split-line (longline)
  (let* ((coding (erc-coding-system-for-target nil))
         (original-window-buf (window-buffer (selected-window)))
         out)
    (when (consp coding)
      (setq coding (car coding)))
    (setq coding (coding-system-change-eol-conversion coding 'unix))
    (with-temp-buffer
      (unwind-protect
          (progn
            (set-window-buffer (selected-window) (current-buffer))
            (insert longline)
            (goto-char (point-min))
            (while (not (eobp))
              (let ((upper (filepos-to-bufferpos erc-split-line-length
                                                 'exact coding)))
                (goto-char (or upper (point-max)))
                (unless (eobp)
                  (skip-chars-backward "^ \t"))
                (when (bobp)
                  (when erc--reject-unbreakable-lines
                    (user-error
                     (substitute-command-keys
                      (concat "Unbreakable line encountered (Recover input"
                              " with \\[erc-previous-command])"))))
                  (goto-char upper))
                (when-let* ((cmp (find-composition (point) (1+ (point)))))
                  (if (= (car cmp) (point-min))
                      (goto-char (nth 1 cmp))
                    (goto-char (car cmp)))))
              (when (= (point-min) (point))
                (goto-char (point-max)))
              (push (buffer-substring-no-properties (point-min) (point)) out)
              (delete-region (point-min) (point)))
            (or (nreverse out) (list "")))
        (set-window-buffer (selected-window) original-window-buf)))))