diff options
-rw-r--r-- | git-email.el | 70 |
1 files changed, 18 insertions, 52 deletions
diff --git a/git-email.el b/git-email.el index 0779176..4c5d4e4 100644 --- a/git-email.el +++ b/git-email.el @@ -38,8 +38,6 @@ ;; * Add proper syntax highlighting to diffs in the message buffer. ;; -;; * Fix `message-header-format-alist' parsing of the 'References' header. -;; ;; * Add wrapper for 'git format-patch' that automatically marks the ;; the newly generated patch files. @@ -57,14 +55,12 @@ :group 'git-email :type 'symbol) -(defcustom git-email-pre-compose-email-hook - '(git-email--set-message-header-format) +(defcustom git-email-pre-compose-email-hook nil "A list of functions called before running `git-email--compose-message'." :type 'hook :group 'git-email) -(defcustom git-email-post-compose-email-hook - '(git-email--reset-message-header-format) +(defcustom git-email-post-compose-email-hook nil "A list of functions called after running `git-email--compose-message'." :type 'hook :group 'git-email) @@ -77,47 +73,6 @@ in you git config. If the variable is not set, the 'to' address will be empty." :group 'git-email :type '(string)) -(defun git-email--set-message-header-format () - "Set `message-header-format-alist' to parse the 'references' header correctly. -This will be run as a `git-email-pro-compose-email-hook' hook." - (setq message-header-format-alist - '((From) - (Newsgroups) - (To) - (Cc) - (Subject) - (In-Reply-To) - (Fcc) - (Bcc) - (Date) - (Organization) - (Distribution) - (Lines) - (Expires) - (Message-ID) - (References) - (User-Agent)))) - -(defun git-email--reset-message-header-format () - "Reset `message-header-format-alist' to the its default value." - (setq message-header-format-alist - '((From) - (Newsgroups) - (To) - (Cc) - (Subject) - (In-Reply-To) - (Fcc) - (Bcc) - (Date) - (Organization) - (Distribution) - (Lines) - (Expires) - (Message-ID) - (References . message-shorten-references) - (User-Agent)))) - (defun git-email--extract-header (header) "Extract HEADER from current buffer." (goto-char (point-min)) @@ -189,27 +144,38 @@ 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"))) + (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 them into the message buffer." (let* ((default-directory (cdr (project-current))) (headers (git-email--extract-headers patch-file)) - (used-headers (seq-filter + (used-headers (mapcar 'git-email--format-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))) - (funcall git-email-compose-email-function to (cadr (assoc "subject" used-headers)) - used-headers) + (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)) (let ((body (or (re-search-forward "<#part \\(encrypt\\|sign\\)=.*mime>" nil t) (re-search-forward "--text follows this line--" nil t)))) |