branch: externals/vc-hgcmd
commit 7e4fc392a03cbd26c90a3cce48f5148b3d4818c8
Author: muffinmad <[email protected]>
Commit: muffinmad <[email protected]>
Custom function to edit initial commit message
---
README.md | 12 ++++++++++++
vc-hgcmd.el | 43 +++++++++++++++++++++++++++++++++++++------
2 files changed, 49 insertions(+), 6 deletions(-)
diff --git a/README.md b/README.md
index 0a454aa..57bf0b0 100644
--- a/README.md
+++ b/README.md
@@ -69,6 +69,18 @@ If `vc-create-tag` is invoked with prefix argument then
named branch will be cre
While committing merge changes commit message will be set to `merged <branch>`
if
different branch was merged or to `merged <node>`.
+Additionally predefined commit message passed to custom function
`vc-hgcmd-log-edit-message-function` so one can change it. For example, to
include current task in commit message:
+
+```elisp
+(defun my/hg-commit-message (original-message)
+ (if org-clock-current-task
+ (concat org-clock-current-task " " original-message)
+ original-message))
+
+(custom-set-variables
+ '(vc-hgcmd-log-edit-message-function 'my/hg-commit-message))
+```
+
## Installation
`vc-hgcmd` available on [MELPA](http://melpa.org):
diff --git a/vc-hgcmd.el b/vc-hgcmd.el
index a716c1e..fa365db 100644
--- a/vc-hgcmd.el
+++ b/vc-hgcmd.el
@@ -5,7 +5,7 @@
;; Author: Andrii Kolomoiets <[email protected]>
;; Keywords: vc
;; URL: https://github.com/muffinmad/emacs-vc-hgcmd
-;; Package-Version: 1.2
+;; Package-Version: 1.3
;; Package-Requires: ((emacs "25.1"))
;; This file is NOT part of GNU Emacs.
@@ -72,7 +72,20 @@
;;
;; - Predefined commit message
;; While committing merge changes commit message will be set to 'merged
<branch>' if
-;; different branch was merged or to 'merged <node>'
+;; different branch was merged or to 'merged <node>'.
+;;
+;; Additionally predefined commit message passed to custom function
+;; `vc-hgcmd-log-edit-message-function' so one can change it.
+;; For example, to include current task in commit message:
+;;
+;; (defun my/hg-commit-message (original-message)
+;; (if org-clock-current-task
+;; (concat org-clock-current-task " " original-message)
+;; original-message))
+;;
+;; (custom-set-variables
+;; '(vc-hgcmd-log-edit-message-function 'my/hg-commit-message))
+
;;; Code:
@@ -106,6 +119,15 @@ You can edit this arguments for specific pull command by
invoke `vc-pull' with p
"Initial value for hg push arguments when asked."
:type '(string))
+(defcustom vc-hgcmd-log-edit-message-function nil
+ "Function to return string that will be used as initial value for log edit.
+First param will be commit message computed by backend: 'merged <branch>' if
+named branch was merged to current branch or 'merged <node>' if two heads on
+same branch was merged."
+ :type '(choice
+ (function)
+ (const :tag "Default commit message" nil)))
+
;;;; Consts. Customizing this can lead to unexpected behaviour
@@ -752,16 +774,25 @@ Insert 'Running command' and display buffer text if
COMMAND"
(declare-function log-edit-mode "log-edit" ())
-(defun vc-hgcmd--set-log-edit-summary ()
- "Set summary of commit message to 'merged ...' if committing after merge."
+(defun vc-hgcmd--log-edit-default-message ()
+ "Return 'merged ...' if there are two parents."
(let* ((parents (split-string (vc-hgcmd-command "log" "-r" "p1()+p2()"
"--template" "{node}\\0{branch}\n") "\n"))
(p1 (car parents))
(p2 (cadr parents)))
(when p2
(let ((p1 (split-string p1 "\0"))
(p2 (split-string p2 "\0")))
- (save-excursion
- (insert (concat "merged " (if (string= (cadr p1) (cadr p2)) (car p2)
(cadr p2)))))))))
+ (concat "merged " (if (string= (cadr p1) (cadr p2)) (car p2) (cadr
p2)))))))
+
+(defun vc-hgcmd--set-log-edit-summary ()
+ "Set summary of commit message to 'merged ...' if committing after merge."
+ (let* ((message (or (vc-hgcmd--log-edit-default-message) ""))
+ (message (if vc-hgcmd-log-edit-message-function
+ (funcall vc-hgcmd-log-edit-message-function message)
+ message)))
+ (when (and message (length message))
+ (save-excursion
+ (insert message)))))
(defun vc-hgcmd-log-edit-toggle-close-branch ()
"Toggle --close-branch commit option."