diff options
author | Dmitry Gutov <dgutov@yandex.ru> | 2019-04-21 00:39:36 +0300 |
---|---|---|
committer | Dmitry Gutov <dgutov@yandex.ru> | 2019-04-21 00:39:36 +0300 |
commit | 70f3175738225252acc5041b210c5b39376af1a1 (patch) | |
tree | 2e54a2eb90aa3647b28f3794e96d374fc2bf11ec | |
parent | 6d1025f944128391a27b388d4cb34d187a0a26b9 (diff) | |
download | emacs-70f3175738225252acc5041b210c5b39376af1a1.tar.gz |
Support amending the last commit using VC-Hg
* lisp/vc/log-edit.el (log-edit--toggle-amend): Extract from
vc-git-log-edit-toggle-amend (bug#34944).
* lisp/vc/vc-hg.el (vc-hg-log-edit-toggle-amend): New function.
Use the aforementioned.
(vc-hg-log-edit-mode-map): New variable.
(vc-hg-log-edit-mode): New major mode.
-rw-r--r-- | lisp/vc/log-edit.el | 16 | ||||
-rw-r--r-- | lisp/vc/vc-git.el | 25 | ||||
-rw-r--r-- | lisp/vc/vc-hg.el | 37 |
3 files changed, 55 insertions, 23 deletions
diff --git a/lisp/vc/log-edit.el b/lisp/vc/log-edit.el index ba5a1a3d572..91e18c1ec5c 100644 --- a/lisp/vc/log-edit.el +++ b/lisp/vc/log-edit.el @@ -1087,6 +1087,22 @@ line of MSG." (if summary (insert summary "\n\n")) (cons (buffer-string) res)))) +(defun log-edit--toggle-amend (last-msg-fn) + (when (log-edit-toggle-header "Amend" "yes") + (goto-char (point-max)) + (unless (bolp) (insert "\n")) + (insert (funcall last-msg-fn)) + (save-excursion + (rfc822-goto-eoh) + (forward-line 1) + (let ((pt (point))) + (and (zerop (forward-line 1)) + (looking-at "\n\\|\\'") + (let ((summary (buffer-substring-no-properties pt (1- (point))))) + (skip-chars-forward " \n") + (delete-region pt (point)) + (log-edit-set-header "Summary" summary))))))) + (provide 'log-edit) ;;; log-edit.el ends here diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index a921ff1bb88..192e6cf68f6 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -750,7 +750,7 @@ The car of the list is the current branch." (declare-function log-edit-mode "log-edit" ()) (declare-function log-edit-toggle-header "log-edit" (header value)) (declare-function log-edit-extract-headers "log-edit" (headers string)) -(declare-function log-edit-set-header "log-edit" (header value &optional toggle)) +(declare-function log-edit--toggle-amend "log-edit" (last-msg-fn)) (defun vc-git-log-edit-toggle-signoff () "Toggle whether to add the \"Signed-off-by\" line at the end of @@ -767,23 +767,12 @@ the commit message." "Toggle whether this will amend the previous commit. If toggling on, also insert its message into the buffer." (interactive) - (when (log-edit-toggle-header "Amend" "yes") - (goto-char (point-max)) - (unless (bolp) (insert "\n")) - (insert (with-output-to-string - (vc-git-command - standard-output 1 nil - "log" "--max-count=1" "--pretty=format:%B" "HEAD"))) - (save-excursion - (rfc822-goto-eoh) - (forward-line 1) - (let ((pt (point))) - (and (zerop (forward-line 1)) - (looking-at "\n\\|\\'") - (let ((summary (buffer-substring-no-properties pt (1- (point))))) - (skip-chars-forward " \n") - (delete-region pt (point)) - (log-edit-set-header "Summary" summary))))))) + (log-edit--toggle-amend + (lambda () + (with-output-to-string + (vc-git-command + standard-output 1 nil + "log" "--max-count=1" "--pretty=format:%B" "HEAD"))))) (defvar vc-git-log-edit-mode-map (let ((map (make-sparse-keymap "Git-Log-Edit"))) diff --git a/lisp/vc/vc-hg.el b/lisp/vc/vc-hg.el index 6b17e861dda..d3f132dae70 100644 --- a/lisp/vc/vc-hg.el +++ b/lisp/vc/vc-hg.el @@ -1104,15 +1104,42 @@ hg binary." (vc-hg-command nil 0 file "forget")) (declare-function log-edit-extract-headers "log-edit" (headers string)) +(declare-function log-edit-mode "log-edit" ()) +(declare-function log-edit--toggle-amend "log-edit" (last-msg-fn)) + +(defun vc-hg-log-edit-toggle-amend () + "Toggle whether this will amend the previous commit. +If toggling on, also insert its message into the buffer." + (interactive) + (log-edit--toggle-amend + (lambda () + (with-output-to-string + (vc-hg-command + standard-output 1 nil + "log" "--limit=1" "--template" "{desc}"))))) + +(defvar vc-hg-log-edit-mode-map + (let ((map (make-sparse-keymap "Hg-Log-Edit"))) + (define-key map "\C-c\C-e" 'vc-hg-log-edit-toggle-amend) + map)) + +(define-derived-mode vc-hg-log-edit-mode log-edit-mode "Log-Edit/hg" + "Major mode for editing Hg log messages. +It is based on `log-edit-mode', and has Hg-specific extensions.") (defun vc-hg-checkin (files comment &optional _rev) "Hg-specific version of `vc-backend-checkin'. REV is ignored." - (apply 'vc-hg-command nil 0 files - (nconc (list "commit" "-m") - (log-edit-extract-headers '(("Author" . "--user") - ("Date" . "--date")) - comment)))) + (let ((amend-extract-fn + (lambda (value) + (when (equal value "yes") + (list "--amend"))))) + (apply 'vc-hg-command nil 0 files + (nconc (list "commit" "-m") + (log-edit-extract-headers `(("Author" . "--user") + ("Date" . "--date") + ("Amend" . ,amend-extract-fn)) + comment))))) (defun vc-hg-find-revision (file rev buffer) (let ((coding-system-for-read 'binary) |