b5ebade3a48dc0ce0c85699f25800808233c73be — Xinglu Chen 3 months ago d03cda5 master
git-email: Add function for matching git-email buffers.

A user might have buffers with unsent messages that were not generated
by git-email, previously, invoking ‘git-email-send-all’ would
unconditionally send all of those messages.  By using a predicate, we
make sure to only send messages generated by git-email.

* git-email.el (git-email-buffer-p-function): New defcustom.
(git-email-buffer-p): New function.
(git-email-send-all): Use it.
* doc/git-email.texi (Miscellaneous): Document it.

Signed-off-by: Xinglu Chen <public@yoctocell.xyz>
2 files changed, 32 insertions(+), 4 deletions(-)

M doc/git-email.texi
M git-email.el
M doc/git-email.texi => doc/git-email.texi +9 -0
@@ 304,6 304,15 @@ trailing @samp{/}.
names are generated.  See the documentation for
@code{message-generate-new-buffers} for more information.

@vindex git-email-buffer-p-function
If you have changed the default value of
@code{git-email-generate-message-buffer}, you probably also want to
change the value of @code{git-email-buffer-p-function}.  It should be a
function that takes one argument---the name of a buffer, and returns
@code{t} if the buffer contains an unsent patch generated using

By default the name will have the following format @samp{git-email
unsent patch to *** TO ADDRESS HERE *** *}.
@end itemize

M git-email.el => git-email.el +23 -4
@@ 175,6 175,15 @@ HERE *** *\"."
  :group 'git-email
  :package-version '(git-email . "0.3.0"))

(defcustom git-email-buffer-p-function
  "Function used for determining if a buffer contains an unsent
patch based on the buffer name.  The function must take one
argument --- the buffer name."
  :type 'function
  :group 'git-email
  :package-version '(git-email . "0.3.0"))

;; Remove Compiler warnings
(declare-function dired-get-filename "dired.el")
(declare-function dired-map-over-marks "dired.el")

@@ 465,6 474,13 @@ default behavior is to delete them after sending the message."
   (concat "*git-email unsent patch to " address " *" )))

(defun git-email-buffer-p (name)
  "Check whether a buffer is contains an unsent patch based on its
  (if (string-match "git-email-unsent-patch" name)

;;;; Operate on emails

@@ 480,14 496,17 @@ default behavior is to delete them after sending the message."
      (> old new))))

(defun git-email-send-all ()
  "Send all unsent emails."
  "Send all unsent patches."
  ;; Sort the buffers so that [PATCH 0/N] comes first, this prevents
  ;; the ordering from getting messed up.
  (let ((buffers (sort (message-buffers) #'git-email-message-buffer-greaterp)))
    (mapc (lambda (b) (switch-to-buffer b)
  (let* ((message-buffers (seq-filter #'git-email-buffer-p
                                  (message-buffers)) )
         (sorted-buffers (sort message-buffers #'git-email-message-buffer-greaterp)))
    (mapc (lambda (b)
            (switch-to-buffer b)
            (funcall git-email-send-email-function))

(defun git-email--rewrite-header-in-buffer (buffer header value append)
  (switch-to-buffer buffer)