git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Emacs git-mode feature request: support fill-paragraph correctly
@ 2009-01-26 11:57 Peter Simons
  2009-01-26 12:15 ` Bruce Stephens
  2009-01-27 11:03 ` Alexandre Julliard
  0 siblings, 2 replies; 8+ messages in thread
From: Peter Simons @ 2009-01-26 11:57 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Emacs git-mode feature request: support fill-paragraph correctly
  2009-01-26 11:57 Emacs git-mode feature request: support fill-paragraph correctly Peter Simons
@ 2009-01-26 12:15 ` Bruce Stephens
  2009-01-26 17:46   ` Peter Simons
  2009-01-27 11:03 ` Alexandre Julliard
  1 sibling, 1 reply; 8+ messages in thread
From: Bruce Stephens @ 2009-01-26 12:15 UTC (permalink / raw)
  To: Peter Simons; +Cc: git

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))

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Emacs git-mode feature request: support fill-paragraph correctly
  2009-01-26 12:15 ` Bruce Stephens
@ 2009-01-26 17:46   ` Peter Simons
  2009-01-26 19:11     ` Bruce Stephens
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Simons @ 2009-01-26 17:46 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Emacs git-mode feature request: support fill-paragraph correctly
  2009-01-26 17:46   ` Peter Simons
@ 2009-01-26 19:11     ` Bruce Stephens
  0 siblings, 0 replies; 8+ messages in thread
From: Bruce Stephens @ 2009-01-26 19:11 UTC (permalink / raw)
  To: Peter Simons; +Cc: git

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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Emacs git-mode feature request: support fill-paragraph correctly
  2009-01-26 11:57 Emacs git-mode feature request: support fill-paragraph correctly Peter Simons
  2009-01-26 12:15 ` Bruce Stephens
@ 2009-01-27 11:03 ` Alexandre Julliard
  2009-01-27 14:07   ` Peter Simons
  1 sibling, 1 reply; 8+ messages in thread
From: Alexandre Julliard @ 2009-01-27 11:03 UTC (permalink / raw)
  To: Peter Simons; +Cc: git

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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: Emacs git-mode feature request: support fill-paragraph correctly
  2009-01-27 11:03 ` Alexandre Julliard
@ 2009-01-27 14:07   ` Peter Simons
  2009-01-28 21:32     ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Simons @ 2009-01-27 14:07 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Emacs git-mode feature request: support fill-paragraph correctly
  2009-01-27 14:07   ` Peter Simons
@ 2009-01-28 21:32     ` Junio C Hamano
  2009-01-29 10:42       ` Alexandre Julliard
  0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2009-01-28 21:32 UTC (permalink / raw)
  To: Alexandre Julliard; +Cc: git, Peter Simons

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?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Emacs git-mode feature request: support fill-paragraph correctly
  2009-01-28 21:32     ` Junio C Hamano
@ 2009-01-29 10:42       ` Alexandre Julliard
  0 siblings, 0 replies; 8+ messages in thread
From: Alexandre Julliard @ 2009-01-29 10:42 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Peter Simons

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-01-29 10:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-26 11:57 Emacs git-mode feature request: support fill-paragraph correctly Peter Simons
2009-01-26 12:15 ` Bruce Stephens
2009-01-26 17:46   ` Peter Simons
2009-01-26 19:11     ` Bruce Stephens
2009-01-27 11:03 ` Alexandre Julliard
2009-01-27 14:07   ` Peter Simons
2009-01-28 21:32     ` Junio C Hamano
2009-01-29 10:42       ` Alexandre Julliard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).