threads / discuss / 17369

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

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

## tl;dr

8 messages between Jan 26, 2009 and Jan 29, 2009.

replies: 7people: 4as markdown or json

Peter Simons· Jan 26, 2009, 11:57 UTC · lore
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· Jan 26, 2009, 12:15 UTC · re: Peter Simons · lore

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

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· Jan 26, 2009, 17:46 UTC · re: Bruce Stephens · lore

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

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· Jan 26, 2009, 19:11 UTC · re: Peter Simons · lore

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

Peter Simons <simons@cryp.to> writes:
[...]
> The buffer is in "log-edit" mode.
Ah, OK.  That makes sense.
Show 6 quoted lines
>  > 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· Jan 27, 2009, 11:03 UTC · re: Peter Simons · lore

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

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· Jan 27, 2009, 14:07 UTC · re: Alexandre Julliard · lore

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

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· Jan 28, 2009, 21:32 UTC · re: Peter Simons · lore

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

Peter Simons <simons@cryp.to> writes:
Show 19 quoted lines
> 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· Jan 29, 2009, 10:42 UTC · re: Junio C Hamano · lore

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

Junio C Hamano <gitster@pobox.com> writes:
Show 9 quoted lines
> 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

← back to recent threads