aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXinglu Chen <public@yoctocell.xyz>2021-02-05 14:41:02 +0100
committerXinglu Chen <public@yoctocell.xyz>2021-02-05 14:41:02 +0100
commitadbf7b3dd87b7dc2de49a8ad3eab74eba5162aff (patch)
tree99e49265d2a7e4c1e52c22ead159c68be8b2760d
parent121d2e860397e428ffb296571ca5c2198b0f46ff (diff)
Add general function to get project root
This will try to get the root of the project using `projectile`, `project.el`, and `vc`, in that order. If all of the above fail, fall back to `default-directory`. * git-email.el (git-email-get-current-project-functions): Add variable. (git-email--get-current-project): Add function. (git-email--minibuffer-get-revision): Utilize the aforementioned functionality.
-rw-r--r--git-email.el26
1 files changed, 25 insertions, 1 deletions
diff --git a/git-email.el b/git-email.el
index 92de56e..2a4addc 100644
--- a/git-email.el
+++ b/git-email.el
@@ -74,6 +74,13 @@ not set, the 'to' address will be empty."
:type '(symbol)
:group 'git-email)
+(defcustom git-email-get-current-project-functions
+ '(git-email--get-current-project)
+ "Hooks to run to get the path to the current project.
+The path should end with a trailing \"/\"."
+ :type 'hook
+ :group 'git-email)
+
(defcustom git-email-get-files-functions
'(git-email--dired-files
git-email--ibuffer-files
@@ -122,6 +129,7 @@ If none of the functions return non-nil value,
:type 'hook
:group 'git-email)
+
;;;; Remove Compiler warnings
(declare-function dired-get-filename "dired.el")
(declare-function dired-map-over-marks "dired.el")
@@ -130,6 +138,7 @@ If none of the functions return non-nil value,
(declare-function vc-dir-current-file "vc-dir.el")
(declare-function log-view-current-entry "log-view.el")
+
;;;; Get files to send
(defun git-email--check-file (file)
"Check if FILE is a patch."
@@ -180,6 +189,18 @@ If no marks are found, return the filename at point."
(when (mapcar #'git-email--check-file files)
files)))
+(defun git-email--get-current-project ()
+ "Return the path of the current project.
+Falls back to `default-directory'."
+ (let ((dir (or (and (bound-and-true-p projectile-known-projects)
+ (projectile-project-root))
+ (and (bound-and-true-p project-list-file)
+ (cdr (project-current)))
+ (vc-root-dir)
+ (default-directory))))
+ dir))
+
+
;;;; Get contents from patch
(defun git-email--extract-header (header)
"Extract HEADER from current buffer."
@@ -281,11 +302,13 @@ them into the message buffer."
(re-search-backward "\\*\\*\\* SUBJECT HERE \\*\\*\\*" nil t))
(kill-line))))
+
;;;; Format patches
(defun git-email--minibuffer-get-revision ()
"Let the user choose a git revision from the minibuffer."
(interactive)
- (let* ((default-directory (cdr (project-current)))
+ (let* ((default-directory (run-hook-with-args-until-success
+ 'git-email-get-current-project-functions))
;; Last element is an empty string
(revs (split-string
(shell-command-to-string
@@ -352,6 +375,7 @@ default behavior is to delete them after sending the message."
(unless keep
(mapc #'delete-file files))))
+
;;;; Operate on emails
(defun git-email-send-all ()
"Send all unsent emails."