5

When I run hg commit (or git commit, same difference...) from the command line without supplying a commit message it pops up an emacs buffer with the following contents:

.
.
HG: Enter commit message.  Lines beginning with 'HG:' are removed.
HG: Leave message empty to abort commit.
HG: --
HG: user: Myself <me@example.com>
HG: branch 'default'
HG: changed filename

But when I use Emacs' C-x v v the message buffer is empty.

How can I have the vc message buffer pre-populated with useful information, but have it stripped out of the final message before commit?

It doesn't have to be the message that mercurial (or git) supplies. In fact, in the case above I would prefer if a diffstat were included.

Malabarba
  • 22,878
  • 6
  • 78
  • 163
  • Nice question. This is (obviously) not an answer, but: why not use Magit? It doesn't do this as well, but selecting diff hunks for staging is close. – mbork Oct 22 '14 at 13:46
  • 4
    @mbork Because magit won't work for mercurial? – T. Verron Oct 22 '14 at 13:50
  • @T.Verron: (1) http://ananthakumaran.in/monky/index.html (2) This is even farther from an actual answer, but it seems a good idea to switch to Git, which is better. (And yes, I am aware that it is not always an option - I also use Hg on some projects due to factors I don't control.) – mbork Oct 22 '14 at 14:50

1 Answers1

4

C-x v v does not call hg commit as you'd do from the terminal. Instead it lets you enter a message first, and only then runs hg commit -m MESSAGE with the whole message.

Hence, if you'd like to have some message in that buffer, you'd need to implement it yourself. You'd need to define a new major mode vc-hg-log-edit-mode, deriving from log-edit-mode. VC will automatically use this major mode for Mercurial commit messages.

In the mode function you can then call out to Mercurial to obtain a diffstat and insert that into the buffer. Before committing, you need to remove this again, lest it ends up in the commit.

Hence, your mode needs to have a keymap which overrides the original log-edit-done binding at C-c C-c. Your own binding would first remove whatever you inserted automatically into the buffer, and then call real log-edit-done.

itsjeyd
  • 14,586
  • 3
  • 58
  • 87