Function: message-newline-and-reformat
message-newline-and-reformat is an interactive and byte-compiled
function defined in message.el.gz.
Signature
(message-newline-and-reformat &optional ARG NOT-BREAK)
Documentation
Insert four newlines, and then reformat if inside quoted text.
Prefix arg means justify as well.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/gnus/message.el.gz
(defun message-newline-and-reformat (&optional arg not-break)
"Insert four newlines, and then reformat if inside quoted text.
Prefix arg means justify as well."
(interactive (list (if current-prefix-arg 'full)) message-mode)
(unless (message-in-body-p)
(error "This command only works in the body of the message"))
(let (quoted point beg end leading-space bolp fill-paragraph-function)
(setq point (point))
(beginning-of-line)
(setq beg (point))
(setq bolp (= beg point))
;; Find first line of the paragraph.
(if not-break
(while (and (not (eobp))
(not (looking-at message-cite-prefix-regexp))
(looking-at paragraph-start))
(forward-line 1)))
;; Find the prefix
(when (looking-at message-cite-prefix-regexp)
(setq quoted (match-string 0))
(goto-char (match-end 0))
(let ((after (point)))
;; This is a line with no text after the cite prefix. In that
;; case, the trailing space is commonly not present, so look
;; around for other lines that have some data.
(when (looking-at-p "\n")
(let ((regexp (concat "^" message-cite-prefix-regexp "[ \t]")))
(when (or (re-search-backward regexp nil t)
(re-search-forward regexp nil t))
(goto-char (1- (match-end 0))))))
(looking-at "[ \t]*")
(setq leading-space (match-string 0))
(goto-char after)))
(if (and quoted
(not not-break)
(not bolp)
(< (- point beg) (length quoted)))
;; break inside the cite prefix.
(setq quoted nil
end nil))
(if quoted
(progn
(forward-line 1)
(while (and (not (eobp))
(not (looking-at paragraph-separate))
(looking-at message-cite-prefix-regexp)
(equal quoted (match-string 0)))
(goto-char (match-end 0))
(looking-at "[ \t]*")
(when (> (length leading-space) (length (match-string 0)))
(setq leading-space (match-string 0)))
(forward-line 1))
(setq end (point))
(goto-char beg)
(while (and (if (bobp) nil (forward-line -1) t)
(not (looking-at paragraph-start))
(looking-at message-cite-prefix-regexp)
(equal quoted (match-string 0)))
(setq beg (point))
(goto-char (match-end 0))
(looking-at "[ \t]*")
(if (> (length leading-space) (length (match-string 0)))
(setq leading-space (match-string 0)))))
(while (and (not (eobp))
(not (looking-at paragraph-separate))
(not (looking-at message-cite-prefix-regexp)))
(forward-line 1))
(setq end (point))
(goto-char beg)
(while (and (if (bobp) nil (forward-line -1) t)
(not (looking-at paragraph-start))
(not (looking-at message-cite-prefix-regexp)))
(setq beg (point))))
(goto-char point)
(save-restriction
(narrow-to-region beg end)
(if not-break
(setq point nil)
(if bolp
(newline)
(newline)
(newline))
(setq point (point))
;; (newline 2) doesn't mark both newline's as hard, so call
;; newline twice. -jas
(newline)
(newline)
(delete-region (point) (re-search-forward "[ \t]*"))
(when (and quoted (not bolp))
(insert quoted leading-space)))
(undo-boundary)
(if quoted
(let* ((adaptive-fill-regexp
(regexp-quote (concat quoted leading-space)))
(adaptive-fill-first-line-regexp
adaptive-fill-regexp ))
(fill-paragraph arg))
(fill-paragraph arg))
(if point (goto-char point)))))