Synch with Gnus.
[elisp/gnus.git-] / lisp / message.el
index cd223db..ace7718 100644 (file)
@@ -437,7 +437,8 @@ The provided functions are:
   :type 'regexp)
 
 (defcustom message-cite-prefix-regexp
-  "[ \t]*\\(\\(\\w\\|[_-\\.]\\)+>+[ \t]*\\|[]>»|:}+ ]*[]>»|:}+][ \t]*\\)+"
+  ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
+  "\\([ \t]*\\(\\w\\|[-_.]\\)+>+\\|[ \t]*[]>»|:}+]\\)+"
   "*Regexp matching the longest possible citation prefix on a line."
   :group 'message-insertion
   :type 'regexp)
@@ -647,7 +648,8 @@ The function `message-supersede' runs this hook."
 
 ;;;###autoload
 (defcustom message-yank-prefix "> "
-  "*Prefix inserted on the lines of yanked messages."
+  "*Prefix inserted on the lines of yanked messages.
+Fix `message-cite-prefix-regexp' if it is set to an abnormal value."
   :type 'string
   :group 'message-insertion)
 
@@ -1758,6 +1760,7 @@ Point is left at the beginning of the narrowed-to region."
   (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
   (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
   (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
+  (define-key message-mode-map "\M-q" 'message-fill-paragraph)
 
   (define-key message-mode-map "\t" 'message-tab)
 
@@ -1903,12 +1906,9 @@ M-RET    message-newline-and-reformat (break the line and reformat)."
   (make-local-variable 'adaptive-fill-first-line-regexp)
   (make-local-variable 'auto-fill-inhibit-regexp)
   (let ((quote-prefix-regexp
-        (concat
-         "[ \t]*"                      ; possible initial space
-         "\\(\\(" (regexp-quote message-yank-prefix) "\\|" ; user's prefix
-         "\\w+>\\|"                    ; supercite-style prefix
-         "[|:>]"                       ; standard prefix
-         "\\)[ \t]*\\)+")))            ; possible space after each prefix
+        ;; User should change message-cite-prefix-regexp if
+        ;; message-yank-prefix is set to an abnormal value.
+        (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
     (setq paragraph-start
          (concat
           (regexp-quote mail-header-separator) "$\\|"
@@ -2125,24 +2125,88 @@ With the prefix argument FORCE, insert the header anyway."
     (unless (bolp)
       (insert "\n"))))
 
-(defun message-newline-and-reformat ()
+(defun message-newline-and-reformat (&optional not-break)
   "Insert four newlines, and then reformat if inside quoted text."
   (interactive)
-  (let (quoted point)
-    (unless (bolp)
-      (save-excursion
-       (beginning-of-line)
-       (when (looking-at message-cite-prefix-regexp)
-         (setq quoted (match-string 0))))
-      (insert "\n"))
+  (let (quoted point beg end leading-space)
     (setq point (point))
-    (insert "\n\n\n")
-    (delete-region (point) (re-search-forward "[ \t]*"))
-    (when quoted
-      (insert quoted))
-    (fill-paragraph nil)
+    (beginning-of-line)
+    (setq 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))
+      (looking-at "[ \t]*")
+      (setq leading-space (match-string 0)))
+    (if (and quoted
+            (not not-break)
+            (< (- point beg) (length quoted)))
+       ;; break in 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]*")
+           (if (> (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)
-    (forward-line 1)))
+    (save-restriction
+      (narrow-to-region beg end)
+      (if not-break
+         (setq point nil)
+       (insert "\n\n")
+       (setq point (point))
+       (insert "\n\n")
+       (delete-region (point) (re-search-forward "[ \t]*"))
+       (when quoted
+         (insert quoted leading-space)))
+      (if quoted
+         (let* ((adaptive-fill-regexp 
+                (regexp-quote (concat quoted leading-space)))
+                (adaptive-fill-first-line-regexp 
+                 adaptive-fill-regexp ))
+           (fill-paragraph nil))
+       (fill-paragraph nil))
+      (if point (goto-char point)))))
+
+(defun message-fill-paragraph ()
+  "Like `fill-paragraph'."
+  (interactive)
+  (message-newline-and-reformat t))
 
 (defun message-insert-signature (&optional force)
   "Insert a signature.  See documentation for the `message-signature' variable."
@@ -3113,9 +3177,12 @@ to find out how to use this."
     (backward-char 1)
     (run-hooks 'message-send-mail-hook)
     (if recipients
-       (let ((result (smtp-via-smtp user-mail-address
-                                    recipients
-                                    (current-buffer))))
+       (let ((result (static-if (fboundp 'smtp-send-buffer)
+                         (smtp-send-buffer user-mail-address recipients
+                                           (current-buffer))
+                       (smtp-via-smtp user-mail-address
+                                      recipients
+                                      (current-buffer)))))
          (unless (eq result t)
            (error "Sending failed; " result)))
       (error "Sending failed; no recipients"))))