diff options
author | yoctocell <public@yoctocell.xyz> | 2021-01-04 09:49:49 +0100 |
---|---|---|
committer | yoctocell <public@yoctocell.xyz> | 2021-01-04 09:49:49 +0100 |
commit | 21928217f1d8092edc03dfe67175657aaf15e91c (patch) | |
tree | 1d9ce780ba54e801679e70a2713437b4db743b2c | |
parent | a9906d4ee23df0368e363d3b7c4c4f8cb5fdb1f5 (diff) |
Re-work header extraction
Let the user be able to customize which headers to insert.
* git-email.el (git-email--extract-header):
(git-email-headers):
(git-email--extract-headers):
(git-email-send-email):
-rw-r--r-- | git-email.el | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/git-email.el b/git-email.el index 0eb9a66..aed11a0 100644 --- a/git-email.el +++ b/git-email.el @@ -51,17 +51,31 @@ :group 'git-email :type 'symbol) -(defun git-email--extract-header (header patch-file) - "Extract HEADER from PATCH-FILE. +(defcustom git-email-headers + '("subject" "from" "in-reply-to" "message-id" "references") + "List of headers that should get inserted into the message buffer. +The 'to' address will always be inserted based on the 'sendemail.to' variable +in you git config. If the variable is not set, the 'to' address will be empty." + :group 'git-email + :type '(string)) + +(defun git-email--extract-header (header) + "Extract HEADER from current buffer." + (goto-char (point-min)) + (buffer-substring-no-properties + (if (re-search-forward (format " *%s: +" header) nil t) + (point) + (point-at-eol)) + (point-at-eol))) + +(defun git-email--extract-headers (patch-file) + "Extract headers from PATCH-FILE. If the header is not found, return an empty string." (with-temp-buffer (insert-file-contents patch-file) - (goto-char (point-min)) - (buffer-substring-no-properties - (if (re-search-forward (format " *%s: +" header) nil t) - (point) - (point-at-eol)) - (point-at-eol)))) + (mapcar (lambda (header) + `(,header ,(git-email--extract-header header))) + git-email-headers))) (defun git-email--extract-diff (patch-file) "Extract the diff from PATCH-FILE." @@ -78,20 +92,19 @@ Extracts the relevant headers and the diff from the PATCH-FILE and inserts them into the message buffer." (interactive) (let* ((default-directory (cdr (project-current))) - (subject (git-email--extract-header "subject" patch-file)) - (from (git-email--extract-header "from" patch-file)) + (headers (git-email--extract-headers patch-file)) + (used-headers (seq-filter + (lambda (header) + (not (string-equal (car (cdr header)) ""))) + headers)) (sendemail-to (shell-command-to-string "git config --list | grep sendemail.to")) (to (if (string-equal sendemail-to "") "to" (substring sendemail-to 13 -1))) ; Remove newline - (in-reply-to (git-email--extract-header "in-reply-to" patch-file)) - (msg-id (git-email--extract-header "message-id" patch-file)) (diff (git-email--extract-diff patch-file))) - (funcall git-email--compose-message-function to subject - `(("in-reply-to" ,in-reply-to) - ("message-id" ,msg-id) - ("from" ,from))) + (funcall git-email--compose-message-function to (cadr (assoc "subject" used-headers)) + used-headers) ;; (let ((body (or (re-search-forward "<#part .*>") ;; (re-search-forward "--text follows this line--")))) (goto-char (point-max)) |