diff options
author | yoctocell <public@yoctocell.xyz> | 2021-01-07 09:34:08 +0100 |
---|---|---|
committer | yoctocell <public@yoctocell.xyz> | 2021-01-07 09:34:08 +0100 |
commit | 785788a541e433f98fbb04cc4e77c84697e088d8 (patch) | |
tree | d1411d698cec0e7e64195ee2c736685e468293b0 /git-email.el | |
parent | 12fa36b6b635bc428d88fde4d3bbc930b0f7bfcc (diff) |
Use custom functions to get revision
Let the user specify a list of functions to run to get the desirable
revision and fallback to the minibuffer.
* git-email.el (git-email-revision-command):
(git-email-get-revision-functions):
(vc-dir-current-file):
(git-email--get-revision):
(git-email--log-get-revision):
(git-email-format-patch):
Diffstat (limited to 'git-email.el')
-rw-r--r-- | git-email.el | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/git-email.el b/git-email.el index ad75a8d..150b8a7 100644 --- a/git-email.el +++ b/git-email.el @@ -120,11 +120,18 @@ variable." :group 'git-email) (defcustom git-email-revision-command - "git log --no-color --pretty='format:%h %d %d' --abbrev-commit -n " + "git log --no-color --pretty='format:%h %d %s' --abbrev-commit -n " "Command to run to get a list of revisions." :type 'string :group 'git-email) +(defcustom git-email-get-revision-functions '(git-email--log-get-revision) + "List of functions to get the base commit for 'git format-patch'. +If none of the functions return non-nil value, +`git-email--minibuffer-get-revision' will be used as a fallback." + :type '(symbol) + :group 'git-email) + (defface git-email-revision-face '((t :inherit font-lock-comment-face)) "Face used for the revision when selecting from the minibuffer.") @@ -134,6 +141,7 @@ variable." (declare-function ibuffer-get-marked-buffers "ibuffer.el") (declare-function vc-dir-marked-files "vc-dir.el") (declare-function vc-dir-current-file "vc-dir.el") +(declare-function log-view-current-entry "log-view.el") ;;;; Get files to send (defun git-email--extract-diff (patch-file) @@ -252,17 +260,17 @@ them into the message buffer." (kill-line)))) ;;;; Format patches -(defun git-email--get-revision () +(defun git-email--minibuffer-get-revision () "Let the user choose a git revision from the minibuffer." (interactive) (let* ((default-directory (cdr (project-current))) ;; Last element is an empty string - (revs (butlast (split-string + (revs (split-string (shell-command-to-string (concat git-email-revision-command (int-to-string git-email-revision-limit))) - "\n"))) + "\n")) ;; Sort the candidates correctly. ;; See https://emacs.stackexchange.com/a/41808. (sorted-revs @@ -274,6 +282,10 @@ them into the message buffer." action revs string pred))))) (substring (completing-read "Revision: " sorted-revs) 0 7))) +(defun git-email--log-get-revision () + "Get the revision at point in `log-view-mode'." + (cadr (log-view-current-entry (point) t))) + ;;;###autoload (defun git-email-format-patch (&optional args) "Format and send patch(es) using 'git format-patch'. @@ -281,10 +293,10 @@ With optional ARGS (\\[universal-argument]) you can specify extra arguments to give to 'git format-patch'. By default, the arguments in `git-email-format-patch-default-args' will be used." (interactive "P") - (let* ((rev-at-point (cadr (log-view-current-entry (point) t))) - (rev (if rev-at-point - rev-at-point - (git-email--get-revision))) + (let* ((rev (or (seq-some (lambda (fn) + (funcall fn)) + git-email-get-revision-functions) + (git-email--minibuffer-get-revision))) ;; Extra arguments. (args (if args (apply |