[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/notmuch-indicator 1ef5c043c6 01/36: Add prototype
From: |
ELPA Syncer |
Subject: |
[elpa] externals/notmuch-indicator 1ef5c043c6 01/36: Add prototype |
Date: |
Wed, 21 Sep 2022 00:59:19 -0400 (EDT) |
branch: externals/notmuch-indicator
commit 1ef5c043c6517382bdf29990c24dd569e4808378
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>
Add prototype
---
notmuch-indicator.el | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 124 insertions(+)
diff --git a/notmuch-indicator.el b/notmuch-indicator.el
new file mode 100644
index 0000000000..0359834e9d
--- /dev/null
+++ b/notmuch-indicator.el
@@ -0,0 +1,124 @@
+;;; notmuch-indicator.el --- Add notmuch count to the global-mode-string (mode
line) -*- lexical-binding: t -*-
+
+;; Copyright (C) 2022 Free Software Foundation, Inc.
+
+;; Author: Protesilaos Stavrou <info@protesilaos.com>
+;; Maintainer: THIS-IS-A-SAMPLE Development
<~protesilaos/THIS-IS-A-SAMPLE@lists.sr.ht>
+;; URL: https://git.sr.ht/~protesilaos/notmuch-indicator
+;; Mailing-List: https://lists.sr.ht/~protesilaos/THIS-IS-A-SAMPLE
+;; Version: 0.0.0
+;; Package-Requires: ((emacs "27.1"))
+;; Keywords: convenience, mail
+
+;; This file is NOT part of GNU Emacs.
+
+;; 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:
+;;
+;; Work-in-progress.
+
+;;; Code:
+
+(defgroup notmuch-indicator ()
+ "WORK-IN-PROGRESS."
+ :group 'notmuch)
+
+;; TODO 2022-09-19: How do we actually use 'notmuch count --batch'?
+(defcustom notmuch-indicator-args
+ '(("tag:unread and tag:inbox" "@")
+ ("--output threads from:VIP" "🤡"))
+ "Arguments to format the notmuch mail indicator.
+
+Each list consists of two strings:
+
+1. The command-line arguments passed to notmuch count.
+2. A string that is prepended to the return value of the above.
+
+Multiple lists represent separate notmuch count queries. These
+are run sequentially. Their return values are joined into a
+single string.
+
+The default value thus specifies two commands, which form a
+string like: @50 🤡10."
+ :type '(repeat (list string))
+ :group 'notmuch-indicator)
+
+;; TODO 2022-09-19: If this changes, the `notmuch-indicator-mode' needs
+;; to be restarted. We can add a custom setter here. Perhaps there is
+;; also some elegant way to handle this when the variable is changed
+;; with `setq'.
+(defcustom notmuch-indicator-refresh-count (* 60 3)
+ "How often to update the indicator, in seconds."
+ :type 'number)
+
+(defun notmuch-indicator--return-count ()
+ "Parse `notmuch-indicator-args' and format them as single string."
+ (mapconcat
+ (lambda (s)
+ (format "%s%s" (or (cadr s) "")
+ (replace-regexp-in-string
+ "\n" " "
+ (shell-command-to-string
+ (format "notmuch count %s" (car s))))))
+ notmuch-indicator-args
+ " "))
+
+(defvar notmuch-indicator--last-state nil
+ "Internal variable used to store the indicator's state.")
+
+(defun notmuch-indicator--indicator ()
+ "Prepare new mail count mode line indicator."
+ (let* ((count (concat (notmuch-indicator--return-count) " "))
+ (old-indicator notmuch-indicator--last-state))
+ (when old-indicator
+ (setq global-mode-string (delete old-indicator global-mode-string)))
+ (cond
+ (count
+ (setq global-mode-string (push count global-mode-string))
+ (setq notmuch-indicator--last-state count))
+ (t
+ (setq notmuch-indicator--last-state nil))))
+ (force-mode-line-update t))
+
+(defun notmuch-indicator--running-p ()
+ "Return non-nil if `notmuch-indicator--indicator' is running."
+ (delq nil
+ (mapcar (lambda (timer)
+ (eq (timer--function timer) 'notmuch-indicator--indicator))
+ timer-list)))
+
+(defun notmuch-indicator--run ()
+ "Run the timer with a delay, starting it if necessary.
+The delay is specified by `notmuch-indicator-refresh-count'."
+ (unless (notmuch-indicator--running-p)
+ (notmuch-indicator--indicator))
+ (run-at-time t notmuch-indicator-refresh-count
#'notmuch-indicator--indicator))
+
+;;;###autoload
+(define-minor-mode notmuch-indicator-mode
+ "Enable with counter for new mail.
+
+If the `global-mode-string' is displayed on the `tab-bar-mode',
+there may be a slight delay until the information is updated."
+ :init-value nil
+ :global t
+ (if notmuch-indicator-mode
+ (notmuch-indicator--run)
+ (cancel-function-timers #'notmuch-indicator--indicator)
+ (setq global-mode-string (delete notmuch-indicator--last-state
global-mode-string))
+ (force-mode-line-update t)))
+
+(provide 'notmuch-indicator)
+;;; notmuch-indicator.el ends here
- [elpa] branch externals/notmuch-indicator created (now f4b46313c3), ELPA Syncer, 2022/09/21
- [elpa] externals/notmuch-indicator 1ef5c043c6 01/36: Add prototype,
ELPA Syncer <=
- [elpa] externals/notmuch-indicator dde1c6cb3d 03/36: Add TODO about not running many timers, ELPA Syncer, 2022/09/21
- [elpa] externals/notmuch-indicator 94e36aea91 06/36: Remove TODO about notmuch count --batch, ELPA Syncer, 2022/09/21
- [elpa] externals/notmuch-indicator 60ec338434 10/36: Fix typo in doc string, ELPA Syncer, 2022/09/21
- [elpa] externals/notmuch-indicator b749c09cb6 16/36: Hint at the notmuch-count(1) manual, ELPA Syncer, 2022/09/21
- [elpa] externals/notmuch-indicator 7d56164856 05/36: Add COPYING, ELPA Syncer, 2022/09/21
- [elpa] externals/notmuch-indicator 83e1bd3ceb 07/36: Tweak code to avoid multiple timers, ELPA Syncer, 2022/09/21
- [elpa] externals/notmuch-indicator b141304bcb 04/36: Add README, ELPA Syncer, 2022/09/21
- [elpa] externals/notmuch-indicator d24ae8718a 14/36: Add outline headings, ELPA Syncer, 2022/09/21
- [elpa] externals/notmuch-indicator f716f06aea 11/36: Use ":label" instead of ":specifier", ELPA Syncer, 2022/09/21
- [elpa] externals/notmuch-indicator e169f26958 19/36: Add notmuch-indicator-hide-empty-counters user option, ELPA Syncer, 2022/09/21