diff options
author | Xinglu Chen <public@yoctocell.xyz> | 2021-06-09 15:52:43 +0200 |
---|---|---|
committer | Xinglu Chen <public@yoctocell.xyz> | 2021-06-09 15:56:35 +0200 |
commit | 8869449d81bf881f18dc23fb2055feb242b6ef23 (patch) | |
tree | 54eb7d3c2a9edb38f9ddca67e811557d1d433b03 | |
parent | 78faa0b14eea70d00151972e984b2ddba7d4732d (diff) |
git-email: Add function to extract multi-line subjects.
‘git-format-patch’ adds a newline in the subject if it is too long, if
we just use ‘git-email--extract-header’, part of the subject is going
to be cut off.
Subject: [PATCH] services: configuration: Show default value when it is a
package.
* git-email.el (git-email-subject-regexp): New variable.
(git-email--extract-subject): New function.
(git-email--extract-header): Use it.
Signed-off-by: Xinglu Chen <public@yoctocell.xyz>
-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. |