From c4fa74316566fc636a7cf968f14f6a59686c55a0 Mon Sep 17 00:00:00 2001 From: yoctocell Date: Wed, 6 Jan 2021 18:26:01 +0100 Subject: Allow users to add custom function to get patches Users can add their own function to `git-email-get-files-functions' to get a list of files to send as patches. * git-email.el (git-email-get-files-functions): (git-email--dired-files): (git-email--vc-dir-files): (git-email--ibuffer-files): (git-email--get-filenames): --- git-email.el | 51 +++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 22 deletions(-) (limited to 'git-email.el') diff --git a/git-email.el b/git-email.el index d8f3069..c81e647 100644 --- a/git-email.el +++ b/git-email.el @@ -80,6 +80,14 @@ in you git config. If the variable is not set, the 'to' address will be empty." :group 'git-email :type '(symbol)) +(defcustom git-email-get-files-functions + '(git-email--dired-files + git-email--ibuffer-files + git-email--vc-dir-files) + "An list of functions to for getting a list of patches to send." + :type '(list symbol symbol) + :group 'git-email) + (defcustom git-email-format-patch-default-args "" "Default arguments to give to 'git format-patch'." :type 'string @@ -128,7 +136,7 @@ variable." (defun git-email--shell-command-on-body (command) "Get the body of the message in the current buffer and run COMMAND on it." (shell-command-on-region (point-min) (point-max) command)) - + (defun git-email--extract-header (header) "Extract HEADER from current buffer." (goto-char (point-min)) @@ -167,26 +175,29 @@ If the header is not found, return an empty string." (defun git-email--dired-files () "Return list of filenames for marked files in `dired'. If no marks are found, return the filename at point." - (delq nil - (mapcar - (lambda (f) (if (file-directory-p f) nil f)) - (dired-map-over-marks (dired-get-filename) nil)))) + (when (eq major-mode 'dired-mode) + (delq nil + (mapcar + (lambda (f) (if (file-directory-p f) nil f)) + (dired-map-over-marks (dired-get-filename) nil))))) (defun git-email--vc-dir-files () "Return list of filenames for marked files in `vc-dir'. If no marks are found, return the filename at point." - (let* ((marked-files (nreverse (vc-dir-marked-files))) - (files (if marked-files - marked-files - (list (vc-dir-current-file))))) - files)) + (when (eq major-mode 'vc-dir) + (let* ((marked-files (nreverse (vc-dir-marked-files))) + (files (if marked-files + marked-files + (list (vc-dir-current-file))))) + files))) (defun git-email--ibuffer-files () "Return list of filenames for marked files in `ibuffer'." - (let ((marked-files (nreverse - (mapcar (lambda (b) (buffer-file-name b)) - (ibuffer-get-marked-buffers))))) - marked-files)) + (when (eq major-mode 'ibuffer-mode) + (let ((marked-files (nreverse + (mapcar (lambda (b) (buffer-file-name b)) + (ibuffer-get-marked-buffers))))) + marked-files))) (defun git-email--minibuffer-file () "Prompt for a file to send as a patch." @@ -196,14 +207,10 @@ If no marks are found, return the filename at point." (defun git-email--get-filenames () "Return list of filenames for marked files in `vc-dir'. If no marks are found, return the filename at point." - (let ((files (cond ((eq major-mode 'dired-mode) - (git-email--dired-files)) - ((eq major-mode 'vc-dir-mode) - (git-email--vc-dir-files)) - ((eq major-mode 'ibuffer-mode) - (git-email--ibuffer-files)) - (t - (git-email--minibuffer-file))))) + (let ((files (or (seq-some (lambda (fn) + (funcall fn)) + git-email-get-files-functions) + (git-email--minibuffer-file)))) (when (mapcar 'git-email--check-file files) files))) -- cgit v1.2.3