aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXinglu Chen <public@yoctocell.xyz>2021-02-06 14:48:13 +0100
committerXinglu Chen <public@yoctocell.xyz>2021-02-06 15:05:23 +0100
commit539b1e7c03d00fb6939279b479adbe2d0a24da78 (patch)
treeb1e7d712b5d60960d81a58d1c4d0113ee7bacfa1
parent59d673bbf24a94d4cbf2e9b3e2f01896ad0ee244 (diff)
piem: Add integration
This adds integration with piem [1]. It will make git-email read the `piem-inboxes` variable to determine the “to” address. * git-email-piem.el (git-email-piem-get-to-address): Add function. (git-email-piem-inbox-by-coderepo): Add function. (git-email-piem-mode): Add minor mode Signed-off-by: Xinglu Chen <public@yoctocell.xyz>
-rw-r--r--git-email-piem.el71
1 files changed, 71 insertions, 0 deletions
diff --git a/git-email-piem.el b/git-email-piem.el
new file mode 100644
index 0000000..d910d46
--- /dev/null
+++ b/git-email-piem.el
@@ -0,0 +1,71 @@
+;;; git-email-piem.el --- Piem integration for git-email -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2021 yoctocell
+
+;; Author: yoctocell <public@yoctocell.xyz>
+;; URL: https://git.sr.ht/~yoctocell/git-email
+;; Version: 0.2.0
+;; Package-Requires: ((emacs "27") (piem "0.1.0"))
+;; Keywords: git mail
+;; License: GNU General Public License >= 3
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This library sets some variables for git-email to make it work
+;; better with Piem.
+
+;;; Code:
+
+(require 'git-email)
+(require 'piem)
+
+(defun git-email-piem-get-to-address ()
+ "Return the \"to\" address for the current project.
+This will read the `piem-inboxes' variable."
+ (let ((inbox (git-email-piem-inbox-by-coderepo)))
+ (piem-inbox-get :address inbox)))
+
+(defun git-email-piem-inbox-by-coderepo ()
+ "Return the inbox based on the current project."
+ (catch 'hit
+ (dolist (inbox piem-inboxes)
+ (let* ((info (cdr inbox))
+ (dir (run-hook-with-args-until-success
+ 'git-email-get-current-project-functions))
+ (repo (plist-get info :coderepo)))
+ (when (string-equal repo dir)
+ (throw 'hit (car inbox)))))))
+
+;;;###autoload
+(define-minor-mode git-email-piem-mode
+ "Piem integration for git-email.
+If called interactively, toggle the mode. A positive prefix ARG
+enables the mode, any other prefix ARG disabled it. If called
+from Lisp, enable the mode if ARG is omitted or nil.
+
+This will make git-email read the `piem-inboxes' variable to
+determine the \"to\" address."
+ :group 'git-email
+ :global t
+ :init-value nil
+ (if git-email-piem-mode
+ (progn
+ (add-to-list 'git-email-get-to-address-functions
+ #'git-email-piem-get-to-address))
+ (setq git-email-get-to-address-functions
+ (delete 'git-email-piem--get-to-address
+ git-email-get-to-address-functions))))
+