diff options
-rw-r--r-- | git-email.el | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/git-email.el b/git-email.el index 0fc0e43..fedd03d 100644 --- a/git-email.el +++ b/git-email.el @@ -231,13 +231,38 @@ Falls back to `default-directory'." ;;;; Get contents from patch (defun git-email--extract-header (header) - "Extract HEADER from current buffer." + "Extract HEADER from the 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))) + (if (eq header 'subject) + (git-email--extract-subject) + (buffer-substring-no-properties + (if (re-search-forward (format " *%s: +" header) nil t) + (point) + (point-at-eol)) + (point-at-eol)))) + +(defvar git-email-subject-regexp + (rx bol "Subject:" + (zero-or-more space) "[" + (zero-or-more (not (any "]" "\n"))) + "PATCH" + (zero-or-more (not (any "]" "\n"))) + "]" (one-or-more space) + (one-or-more not-newline) + (or (and eol (= 2 space) + (one-or-more (not (any "\n" "\t" "$"))) eol) + eol))) + +(defun git-email--extract-subject () + "Extract the subject from the current buffer. git-format-patch +will add a newline in the subject if the subject is too long. +Just using `git-email--extract-header' would result in part of +the subject being cut of. See what I did there? ;-)" + (let ((string (buffer-substring-no-properties (point-min) (point-max)))) + (string-match git-email-subject-regexp string) + (string-remove-prefix + "Subject: " (replace-regexp-in-string + "\n" "" (match-string-no-properties 0 string))))) (defun git-email--extract-headers (patch-file) "Extract headers from PATCH-FILE. |