Function: vc-prepare-patch

vc-prepare-patch is an autoloaded, interactive and byte-compiled function defined in vc.el.gz.

Signature

(vc-prepare-patch ADDRESSEE SUBJECT REVISIONS)

Documentation

Compose an Email sending patches for REVISIONS to ADDRESSEE.

If vc-prepare-patches-separately is nil, use SUBJECT as the default subject for the message, or prompt a subject when invoked interactively. Otherwise compose a separate message for each revision, with SUBJECT derived from each revision subject. When invoked with a numerical prefix argument, use the last N revisions. When invoked interactively in a Log View buffer with marked revisions, use those.

View in manual

Probably introduced at or before Emacs version 29.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/vc/vc.el.gz
;;;###autoload
(defun vc-prepare-patch (addressee subject revisions)
  "Compose an Email sending patches for REVISIONS to ADDRESSEE.
If `vc-prepare-patches-separately' is nil, use SUBJECT as the
default subject for the message, or prompt a subject when invoked
interactively.  Otherwise compose a separate message for each
revision, with SUBJECT derived from each revision subject.
When invoked with a numerical prefix argument, use the last N
revisions.
When invoked interactively in a Log View buffer with
marked revisions, use those."
  (interactive
   (let* ((revs (vc-prepare-patch-prompt-revisions))
          (subject
           (and (length= revs 1)
                (plist-get
                 (vc-call-backend
                  (vc-responsible-backend default-directory)
                  'prepare-patch (car revs))
                 :subject)))
          to)
     (require 'message)
     (while (null (setq to (completing-read-multiple
                            (format-prompt
                             "Addressee"
                             vc-default-patch-addressee)
                            (message--name-table "")
                            nil nil nil nil
                            vc-default-patch-addressee)))
       (message "At least one addressee required.")
       (sit-for blink-matching-delay))
     (list (string-join to ", ")
           (and (not vc-prepare-patches-separately)
                (read-string "Subject: " (or subject "[PATCH] ") nil nil t))
           revs)))
  (save-current-buffer
    (let ((patches (mapcar (lambda (rev)
                             (vc-call-backend
                              (vc-responsible-backend default-directory)
                              'prepare-patch rev))
                           revisions)))
      (if vc-prepare-patches-separately
          (cl-loop with l = (length patches)
                   for patch in (reverse patches) do
                   (compose-mail addressee
                                 (plist-get patch :subject)
                                 nil nil nil nil
                                 `((kill-buffer ,(plist-get patch :buffer))))
                   (rfc822-goto-eoh) (forward-line)
                   (save-excursion      ;don't jump to the end
                     (insert-buffer-substring
                      (plist-get patch :buffer)
                      (plist-get patch :body-start)
                      (plist-get patch :body-end)))
                   finally (message (ngettext "Prepared %d patch..."
                                              "Prepared %d patches..."
                                              l)
                                    l))
        (compose-mail addressee subject nil nil nil nil
                      (mapcar
                       (lambda (p)
                         (list #'kill-buffer (plist-get p :buffer)))
                       patches))
        (rfc822-goto-eoh)
        (forward-line)
        (save-excursion
          (let ((i 0))
            (dolist (patch patches)
              (let* ((patch-subject (plist-get patch :subject))
                     (filename
                      (vc--subject-to-file-name patch-subject)))
                (mml-attach-buffer
                 (buffer-name (plist-get patch :buffer))
                 "text/x-patch"
                 patch-subject
                 "attachment"
                 (format "%04d-%s" (incf i) filename))))))
        (open-line 2)))))