~yoctocell/git-email

1b2f4219e9375642491d490ce0c421f8ec966524 — Xinglu Chen 3 months ago e6a8567
git-email: Make it possible to customize message buffer names.

* git-email.el (git-email-generate-message-buffer): New defcustom.
(git-email-generate-message-buffer-name): New function
(git-email--send-files): Likewise.
(git-email-format-patch): Refactor to use ‘git-email--send-files’.
(git-email-send-email): Likewise.
* doc/git-email.texi (Miscellaneous): Document it.

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

M doc/git-email.texi
M git-email.el
M doc/git-email.texi => doc/git-email.texi +9 -0
@@ 325,6 325,15 @@ revision of under point if you are in a VC log buffer.
@samp{git-email-get-current-project-functions} is a hook that is executed
to get the path of the current project.  The path must include a
trailing @samp{/}.

@vindex git-email-generate-message-buffer
@item
@code{git-email-generate-message-buffer} controls how message buffer
names are generated.  See the documentation for
@code{message-generate-new-buffers} for more information.

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

@node Integration with other packages

M git-email.el => git-email.el +35 -8
@@ 157,6 157,23 @@ If none of the functions return non-nil value,
  :group 'git-email
  :package-version '(git-email . "0.2.0"))

(defcustom git-email-generate-message-buffer
  #'git-email-generate-message-buffer-name
  "Function for generating the name of a message buffer.
The function must take three arguments: the type, the \"To\"
address, and the group name.  See `message-generate-new-buffers'
for more information.

By default it will be \"*git-email unsent patch to *** TO ADDRESS
HERE *** *\"."
  :type '(choice (const nil)
		 (sexp :tag "unique" :format "unique\n" :value unique
		       :match (lambda (widget value) (memq value '(unique t))))
		 (const unsent)
		 (const standard)
		 (function :format "\n    %{%t%}: %v"))
  :group 'git-email
  :package-version '(git-email . "0.3.0"))

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


@@ 434,13 451,18 @@ default behavior is to delete them after sending the message."
                            (format "git format-patch %s %s"
                                    args range))
                           "\n")))))
    (dolist (file files)
      (run-hooks 'git-email-pre-compose-email-hook)
      (git-email--compose-email file)
      (run-hooks 'git-email-post-compose-email-hook))
    (git-email--send-files files)
    (unless keep
      (mapc #'delete-file files))))


;;;; Misc

(defun git-email-generate-message-buffer-name (_type address _group)
  "Generate a buffer name that looks like this:

\"* git-email unsent patch to *** TO ADDRESS HERE *** *\""
  (concat "*git-email unsent patch to " address " *"))


;;;; Operate on emails


@@ 481,6 503,14 @@ default behavior is to delete them after sending the message."
          (re-search-forward "^Subject: .*$")
          (insert "\n" (concat (capitalize header) ": " value)))))))

(defun git-email--send-files (files)
  (dolist (file files)
    (run-hooks 'git-email-pre-compose-email-hook)
    (let ((message-generate-new-buffers
           git-email-generate-message-buffer))
      (git-email--compose-email file))
    (run-hooks 'git-email-post-compose-email-hook)))

;;;###autoload
(defun git-email-rewrite-header (header value &optional append)
  "Re-write the value of HEADER to VALUE, if HEADER doesn't exist


@@ 510,10 540,7 @@ give you an address to send your patches to."
(defun git-email-send-email (files)
  "Send FILES as patch(es) to someone using your MUA."
  (interactive (list (git-email--get-files)))
  (dolist (file files)
    (run-hooks 'git-email-pre-compose-email-hook)
    (git-email--compose-email file)
    (run-hooks 'git-email-post-compose-email-hook)))
  (git-email--send-files files))

(provide 'git-email)
;;; git-email.el ends here