Emacs git-mode feature request: support fill-paragraph correctly
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 <[email protected]>
--- 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 <[email protected]> --- 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
Peter Simons <[email protected]> writes:
[...]
Quoted 4 lines
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))
Quoted 8 lines · Bruce Stephens
Quoted 4 lines
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_EDITMSGand the mode is fundamental-mode?
The buffer is in "log-edit" mode.
Quoted 4 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. 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
Peter Simons <[email protected]> writes:
[...]
Quoted 1 line
The buffer is in "log-edit" mode.
Ah, OK. That makes sense.
Quoted 6 lines
Quoted 4 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.
Quoted 2 lines
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.
Quoted 4 lines · Peter Simons
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:
contrib/emacs/git.el +1 -0
@@ -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))))
Signature · 2 lines
Alexandre Julliard [email protected]
Hi Alexandre,
contrib/emacs/git.el Return the list of files that haven't been handled." · line 1336
Quoted 11 lines
contrib/emacs/git.el +1
-0@@ -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
Quoted 17 lines · Peter Simons
Hi Alexandre,
contrib/emacs/git.el Return the list of files that haven't been handled." · line 1336
Quoted 11 lines
contrib/emacs/git.el +1
-0@@ -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.
Quoted 2 lines
Now, I'd be hugely in favor of applying that change to the repository so that future versions of GIT have it.
Alexandre?
Quoted 9 lines · Junio C Hamano
Quoted 5 lines · Peter Simons
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.
Signature · 2 lines
Alexandre Julliard [email protected]