diff options
author | Xinglu Chen <public@yoctocell.xyz> | 2021-01-28 20:41:52 +0100 |
---|---|---|
committer | Xinglu Chen <public@yoctocell.xyz> | 2021-01-28 20:41:52 +0100 |
commit | d179f9c2529e9e3152bcf5ac6e8be491dfce2260 (patch) | |
tree | 5ad486ce72b7c10cd730be31a3b2fc74f9dd1369 | |
parent | 4a67600fce8eeae5a49b65617c3450bec3702bf7 (diff) |
Add `git-email-get-address-function' variable
This makes it possible for users to use their own function to get the
“to” address. This could also be used for integration with piem.el.
* doc/git-email.org (Sending email): Add bullet point.
* git-email.el (git-email-get-to-address-function): Add variable.
(git-email--get-to-address): Add function.
(git-email--compose-email): Call the relevant function.
-rw-r--r-- | doc/git-email.org | 5 | ||||
-rw-r--r-- | git-email.el | 20 |
2 files changed, 22 insertions, 3 deletions
diff --git a/doc/git-email.org b/doc/git-email.org index 8a8c343..84b1d23 100644 --- a/doc/git-email.org +++ b/doc/git-email.org @@ -94,6 +94,11 @@ You can see all the customizable variables running =M-x customize-group= - =git-email-get-files-functions= is a list of functions to run to get a list of patches to send. The default, there is already support for dired, ibuffer and vc-dir. + +- =git-email-get-to-address-function= is a function that returns the + “to” address for a message. The default function runs =git config + --list= to get the address, this will not work unless you are in a + git repository. ** Format patches - =git-email-format-patch-default-args= is a string of arguments to give diff --git a/git-email.el b/git-email.el index 7ed4e43..2c90fd3 100644 --- a/git-email.el +++ b/git-email.el @@ -82,6 +82,12 @@ not set, the 'to' address will be empty." :type '(list symbol) :group 'git-email) +(defcustom git-email-get-to-address-function + 'git-email--get-to-address + "Function to run to get the \“to\" address of a message." + :type 'symbol + :group 'git-email) + (defcustom git-email-format-patch-default-args "" "Default arguments to give to 'git format-patch'." :type 'string @@ -230,6 +236,15 @@ If the header is not found, return an empty string." "Remove HEADER if it is the subject." (not (string-equal (symbol-name (car header)) "subject"))) +(defun git-email--get-to-address () + "Get the \"to\" address of the message. + +This runs \“git config --list\" in the current directory +so might not always work." + (substring + (shell-command-to-string "git config --list | grep sendemail.to") + 13 -1)) ; Remove newline + (defun git-email--compose-email (patch-file) "Given a PATCH-FILE, compose an email. Extracts the relevant headers and the diff from the PATCH-FILE and inserts @@ -240,12 +255,11 @@ them into the message buffer." (lambda (header) (not (string-equal (car (cdr header)) ""))) headers)) + (sendemail-to (funcall git-email-get-to-address-function)) ;; Get 'to' address from git. - (sendemail-to - (shell-command-to-string "git config --list | grep sendemail.to")) (to (if (string-equal sendemail-to "") "*** TO ADDRESS HERE ***" - (substring sendemail-to 13 -1))) ; Remove newline + sendemail-to)) (diff (git-email--extract-diff patch-file))) (funcall git-email-compose-email-function to ;; Remove 'subject' header, otherwise two subject headers will be |