From 722a52299a35644731309156ca9e1c5e1c3d5e28 Mon Sep 17 00:00:00 2001 From: yoctocell Date: Mon, 4 Jan 2021 18:24:25 +0100 Subject: Refactor `git-email-headers' Use symbols instead of strings. * git-email.el (git-email-headers): (git-email-send-email): (git-email--format-headers): (git-email--compose-email): --- git-email.el | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'git-email.el') diff --git a/git-email.el b/git-email.el index 4c5d4e4..0627639 100644 --- a/git-email.el +++ b/git-email.el @@ -66,12 +66,12 @@ :group 'git-email) (defcustom git-email-headers - '("subject" "from" "in-reply-to" "message-id") + '(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)) + :type '(symbol)) (defun git-email--extract-header (header) "Extract HEADER from current buffer." @@ -135,7 +135,7 @@ If no marks are found, return the filename at point." (git-email--ibuffer)) (t (message "Not a supported major mode")))) - + ;;;###autoload (defun git-email-send-email () "Send patch(es) to someone." @@ -144,13 +144,9 @@ If no marks are found, return the filename at point." (let ((files (git-email--get-filenames))) (prog1 (dolist (file files) - (git-email--compose-email file))))) + (git-email--compose-email file)) (run-hooks 'git-email-post-compose-email-hook)))) - -(defun git-email--format-headers (header) - "Turn the key of HEADER from string to symbol." - `(,(intern (car header)) ,(cadr header))) - + (defun git-email--remove-subject (header) "Remove HEADER if it is the subject." (not (string-equal (symbol-name (car header)) "subject"))) @@ -161,19 +157,16 @@ Extracts the relevant headers and the diff from the PATCH-FILE and inserts them into the message buffer." (let* ((default-directory (cdr (project-current))) (headers (git-email--extract-headers patch-file)) - (used-headers (mapcar 'git-email--format-headers - (seq-filter + (used-headers (seq-filter (lambda (header) (not (string-equal (car (cdr header)) ""))) - headers))) + 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 (diff (git-email--extract-diff patch-file))) - (print used-headers) - (print (assoc 'subject used-headers)) (funcall git-email-compose-email-function to (cadr (assoc 'subject used-headers)) (seq-filter 'git-email--remove-subject used-headers)) (goto-char (point-min)) -- cgit v1.2.3