# Emacs git-mode feature request: support fill-paragraph correctly

8 messages from 2009-01-26 to 2009-01-29. Participants: Peter Simons, Bruce Stephens, Alexandre Julliard, Junio C Hamano.
Thread: https://gitlist.dev/t/17369

## Peter Simons, 2009-01-26 11:57

Subject: Emacs git-mode feature request: support fill-paragraph correctly
Message-ID: <87tz7mth3g.fsf@write-only.cryp.to>
URL: https://gitlist.dev/e/87tz7mth3g.fsf%40write-only.cryp.to

```
Hi,

when I choose to commit in Emacs' git mode, I'm prompted to enter a
commit message in a buffer that looks something like this:

   Author: Joe Doe <joe.doe@example.org>
   --- log message follows this line ---
   foo.txt: lots of important changes

Now, when I hit M-q (fill-paragraph), Emacs doesn't recognize that
the "--- log message ..." line ought to be considered a paragraph
separator. As a result, the re-filled buffer is messed up:

   Author: Joe Doe <joe.doe@example.org> --- log message follows
   this line --- foo.txt: lots of important changes

Other modes, such as message-mode, do support that kind of thing
correctly, so apparently it is possible to configure what the editor
considers as a paragraph. Is there some Emacs wizard out there who'd
be kind enough to improve git-mode accordingly?

Take care,
Peter

```

## Bruce Stephens, 2009-01-26 12:15

Subject: Re: Emacs git-mode feature request: support fill-paragraph correctly
Message-ID: <808woyz2k7.fsf@tiny.isode.net>
URL: https://gitlist.dev/e/808woyz2k7.fsf%40tiny.isode.net
In-Reply-To: <87tz7mth3g.fsf@write-only.cryp.to>

```
Peter Simons <simons@cryp.to> writes:

[...]

> Other modes, such as message-mode, do support that kind of thing
> correctly, so apparently it is possible to configure what the editor
> considers as a paragraph. Is there some Emacs wizard out there who'd
> be kind enough to improve git-mode accordingly?

I suspect this doesn't directly relate to git-mode.  What mode does
emacs say you're in at this point?  I'm guessing the buffer name is
COMMIT_EDITMSG and the mode is fundamental-mode?

In that case you could stick this in your .emacs if you wanted to use
message-mode:

(setq auto-mode-alist (cons '("COMMIT_EDITMSG" . message-mode) auto-mode-alist))

```

## Peter Simons, 2009-01-26 17:46

Subject: Re: Emacs git-mode feature request: support fill-paragraph correctly
Message-ID: <87mydet0yg.fsf@write-only.cryp.to>
URL: https://gitlist.dev/e/87mydet0yg.fsf%40write-only.cryp.to
In-Reply-To: <808woyz2k7.fsf@tiny.isode.net>

```
Bruce Stephens <bruce.stephens@isode.com> writes:

 >> Other modes, such as message-mode, do support that kind of thing
 >> correctly, so apparently it is possible to configure what the
 >> editor considers as a paragraph. Is there some Emacs wizard out
 >> there who'd be kind enough to improve git-mode accordingly?
 >
 > I suspect this doesn't directly relate to git-mode. What mode
 > does emacs say you're in at this point? I'm guessing the buffer
 > name is COMMIT_EDITMSG and the mode is fundamental-mode?

The buffer is in "log-edit" mode.

 > In that case you could stick this in your .emacs if you wanted to
 > use message-mode:
 >
 > (setq auto-mode-alist (cons '("COMMIT_EDITMSG" . message-mode) auto-mode-alist))

Unfortunately, it's not that easy. I'm not an Emacs expert, but I'd
assume that switching into a different mode would change the meaning
of C-c C-c.

Peter

```

## Bruce Stephens, 2009-01-26 19:11

Subject: Re: Emacs git-mode feature request: support fill-paragraph correctly
Message-ID: <8063k1zxts.fsf@tiny.isode.net>
URL: https://gitlist.dev/e/8063k1zxts.fsf%40tiny.isode.net
In-Reply-To: <87mydet0yg.fsf@write-only.cryp.to>

```
Peter Simons <simons@cryp.to> writes:

[...]

> The buffer is in "log-edit" mode.

Ah, OK.  That makes sense.

>  > In that case you could stick this in your .emacs if you wanted to
>  > use message-mode:
>  >
>  > (setq auto-mode-alist (cons '("COMMIT_EDITMSG" . message-mode) auto-mode-alist))
>
> Unfortunately, it's not that easy.

True.  I don't use git-mode (well, not much).  I use git commit from
the command line, which runs emacsclient as its editor.

> I'm not an Emacs expert, but I'd assume that switching into a
> different mode would change the meaning of C-c C-c.

Yep.  Quite likely other things, too.

OK, something like this:

(add-hook 'log-edit-mode-hook (lambda ()
		(let ((regexp "--text follows this line--$\\|[  ]*$\\|-- $\\|---+$\\|^\f$\\|.*wrote:$\\|\\(\\([         ]*[-_.[:word:]]+>+\\|[  ]*[]>|}+]\\)+\\)[  ]*$\\|<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
                   (setq paragraph-start regexp
                         paragraph-separate regexp)))

I copied the regexp from the value in message-mode.  (In a junk buffer
use M-x message-mode, then C-h v paragraph-start and copy & paste.)

I imagine large parts of the regexp aren't relevant for your purposes
so you could remove them if you wanted.  You might also define a
function rather than using lambda---that would make it a bit easier to
test.

```

## Alexandre Julliard, 2009-01-27 11:03

Subject: Re: Emacs git-mode feature request: support fill-paragraph correctly
Message-ID: <873af59fkm.fsf@wine.dyndns.org>
URL: https://gitlist.dev/e/873af59fkm.fsf%40wine.dyndns.org
In-Reply-To: <87tz7mth3g.fsf@write-only.cryp.to>

```
Peter Simons <simons@cryp.to> writes:

> Other modes, such as message-mode, do support that kind of thing
> correctly, so apparently it is possible to configure what the editor
> considers as a paragraph. Is there some Emacs wizard out there who'd
> be kind enough to improve git-mode accordingly?

You could try something like this:

diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index 3c37d0d..e314c44 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -1331,6 +1331,7 @@ Return the list of files that haven't been handled."
 					 (log-edit-diff-function . git-log-edit-diff)) buffer)
 	(log-edit 'git-do-commit nil 'git-log-edit-files buffer))
       (setq font-lock-keywords (font-lock-compile-keywords git-log-edit-font-lock-keywords))
+      (setq paragraph-separate (concat (regexp-quote git-log-msg-separator) "$\\|Author: \\|Date: \\|Merge: \\|Signed-off-by: \\|\f\\|[ 	]*$"))
       (setq buffer-file-coding-system coding-system)
       (re-search-forward (regexp-quote (concat git-log-msg-separator "\n")) nil t))))
 

-- 
Alexandre Julliard
julliard@winehq.org

```

## Peter Simons, 2009-01-27 14:07

Subject: Re: Emacs git-mode feature request: support fill-paragraph correctly
Message-ID: <878wow7sgx.fsf@write-only.cryp.to>
URL: https://gitlist.dev/e/878wow7sgx.fsf%40write-only.cryp.to
In-Reply-To: <873af59fkm.fsf@wine.dyndns.org>

```
Hi Alexandre,

 > diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
 > index 3c37d0d..e314c44 100644
 > --- a/contrib/emacs/git.el
 > +++ b/contrib/emacs/git.el
 > @@ -1331,6 +1331,7 @@ Return the list of files that haven't been handled."
 >  					 (log-edit-diff-function . git-log-edit-diff)) buffer)
 >  	(log-edit 'git-do-commit nil 'git-log-edit-files buffer))
 >        (setq font-lock-keywords (font-lock-compile-keywords git-log-edit-font-lock-keywords))
 > +      (setq paragraph-separate (concat (regexp-quote git-log-msg-separator) "$\\|Author: \\|Date: \\|Merge: \\|Signed-off-by: \\|\f\\|[ 	]*$"))
 >        (setq buffer-file-coding-system coding-system)
 >        (re-search-forward (regexp-quote (concat git-log-msg-separator "\n")) nil t))))

that patch has the desired effect (tested with GNU Emacs 22.3.1 and
GIT 1.6.1). Thank you very much.

Now, I'd be hugely in favor of applying that change to the repository
so that future versions of GIT have it.

Take care,
Peter

```

## Junio C Hamano, 2009-01-28 21:32

Subject: Re: Emacs git-mode feature request: support fill-paragraph correctly
Message-ID: <7vk58fktfy.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vk58fktfy.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <878wow7sgx.fsf@write-only.cryp.to>

```
Peter Simons <simons@cryp.to> writes:

> Hi Alexandre,
>
>  > diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
>  > index 3c37d0d..e314c44 100644
>  > --- a/contrib/emacs/git.el
>  > +++ b/contrib/emacs/git.el
>  > @@ -1331,6 +1331,7 @@ Return the list of files that haven't been handled."
>  >  					 (log-edit-diff-function . git-log-edit-diff)) buffer)
>  >  	(log-edit 'git-do-commit nil 'git-log-edit-files buffer))
>  >        (setq font-lock-keywords (font-lock-compile-keywords git-log-edit-font-lock-keywords))
>  > +      (setq paragraph-separate (concat (regexp-quote git-log-msg-separator) "$\\|Author: \\|Date: \\|Merge: \\|Signed-off-by: \\|\f\\|[ 	]*$"))
>  >        (setq buffer-file-coding-system coding-system)
>  >        (re-search-forward (regexp-quote (concat git-log-msg-separator "\n")) nil t))))
>
> that patch has the desired effect (tested with GNU Emacs 22.3.1 and
> GIT 1.6.1). Thank you very much.
>
> Now, I'd be hugely in favor of applying that change to the repository
> so that future versions of GIT have it.

Alexandre?

```

## Alexandre Julliard, 2009-01-29 10:42

Subject: Re: Emacs git-mode feature request: support fill-paragraph correctly
Message-ID: <87tz7i4cn1.fsf@wine.dyndns.org>
URL: https://gitlist.dev/e/87tz7i4cn1.fsf%40wine.dyndns.org
In-Reply-To: <7vk58fktfy.fsf@gitster.siamese.dyndns.org>

```
Junio C Hamano <gitster@pobox.com> writes:

> Peter Simons <simons@cryp.to> writes:
>
>> that patch has the desired effect (tested with GNU Emacs 22.3.1 and
>> GIT 1.6.1). Thank you very much.
>>
>> Now, I'd be hugely in favor of applying that change to the repository
>> so that future versions of GIT have it.
>
> Alexandre?

Sure, I'll include it in my next pull request.

-- 
Alexandre Julliard
julliard@winehq.org

```
