Subject: bug#12439: closed (Re: bug#12439: 24.2.50; mail-abbrev fills long aliasee uglily)

From: [email-masked] (GNU bug Tracking System)
Date: Sun, 16 Sep 2012 23:18:02 +0000

Your bug report

#12439: 24.2.50; mail-abbrev fills long aliasee uglily

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
12439: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=12439
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#12439: 24.2.50; mail-abbrev fills long aliasee uglily
From: Katsumi Yamaoka <[email-masked]>
To: [email-masked]
Date: Mon, 17 Sep 2012 08:16:21 +0900
List-Id: <debbugs-submit.debbugs.gnu.org>

Katsumi Yamaoka <[email-masked]> wrote:
> By default message.el uses mail-abbrev to expand mail aliases in
> headers in a draft.  If an aliasee is longer than fill-column,
> it will be expanded like the following:

> To: [email-masked], [email-masked], [email-masked], [email-masked],
>     [email-masked],
>     [email-masked],
>     [email-masked],
>     [email-masked]

> To reproduce this, try the "foo" alias specified as follows:

> (define-mail-abbrev "foo"
>   "[email-masked], [email-masked], [email-masked], [email-masked],\
>  [email-masked], [email-masked], [email-masked], [email-masked]")

> The point is that the latter half addresses in an aliasee are
> put line by line.  Moreover, I think a SPC is enough for LWSP
> preceding to the latter half (message.el uses TAB in some fill
> function, though), rather than the one indent-relative generates.

> A patch I tried is attached below.

I've installed my patch to the trunk.

Subject: 24.2.50; mail-abbrev fills long aliasee uglily
From: Katsumi Yamaoka <[email-masked]>
To: [email-masked]
Date: Fri, 14 Sep 2012 17:53:15 +0900
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi,

By default message.el uses mail-abbrev to expand mail aliases in
headers in a draft.  If an aliasee is longer than fill-column,
it will be expanded like the following:

To: [email-masked], [email-masked], [email-masked], [email-masked],
    [email-masked],
    [email-masked],
    [email-masked],
    [email-masked]

To reproduce this, try the "foo" alias specified as follows:

(define-mail-abbrev "foo"
  "[email-masked], [email-masked], [email-masked], [email-masked],\
 [email-masked], [email-masked], [email-masked], [email-masked]")

The point is that the latter half addresses in an aliasee are
put line by line.  Moreover, I think a SPC is enough for LWSP
preceding to the latter half (message.el uses TAB in some fill
function, though), rather than the one indent-relative generates.

A patch I tried is attached below.

--- mailabbrev.el~	2012-05-06 21:58:55.506179000 +0000
+++ mailabbrev.el	2012-09-14 08:38:38.323389500 +0000
@@ -391,35 +391,24 @@
 (defun mail-abbrev-expand-hook ()
   "For use as the fourth arg to `define-abbrev'.
 After expanding a mail-abbrev, if Auto Fill mode is on and we're past the
-fill-column, break the line at the previous comma, and indent the next line."
-  ;; Disable abbrev mode to avoid recursion in indent-relative expanding
-  ;; part of the abbrev expansion as an abbrev itself.
-  (let ((abbrev-mode nil))
-    (save-excursion
-      (let ((p (point))
-	    bol comma fp)
-	(beginning-of-line)
-	(setq bol (point))
-	(goto-char p)
-	(while (and auto-fill-function
-		    (>= (current-column) fill-column)
-		    (search-backward "," bol t))
-	  (setq comma (point))
-	  (forward-char 1)		; Now we are just past the comma.
-	  (insert "\n")
-	  (delete-horizontal-space)
-	  (setq p (point))
-	  (indent-relative)
-	  (setq fp (buffer-substring p (point)))
-	  ;; Go to the end of the new line.
-	  (end-of-line)
-	  (if (> (current-column) fill-column)
-	      ;; It's still too long; do normal auto-fill.
-	      (let ((fill-prefix (or fp "\t")))
-		(do-auto-fill)))
-	  ;; Resume the search.
-	  (goto-char comma)
-	  )))))
+fill-column, break the line at the previous comma, and indent the next line
+with a space."
+  (when auto-fill-function
+    (let (p)
+      (save-excursion
+	(while (>= (current-column) fill-column)
+	  (while (and (search-backward "," (point-at-bol) 'move)
+		      (>= (current-column) (1- fill-column))
+		      (setq p (point))))
+	  (when (or (not (bolp))
+		    (and p (goto-char p)))
+	    (setq p nil)
+	    (forward-char 1)
+	    (insert "\n")
+	    (when (looking-at "[\t ]+")
+	      (delete-region (point) (match-end 0)))
+	    (insert " ")
+	    (end-of-line)))))))
 
 ;;; Syntax tables and abbrev-expansion