summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2020-11-21 21:45:30 +0000
committerjao <jao@gnu.org>2020-11-21 21:45:30 +0000
commit776cfd788ed89a4705155fa077f2d8dd21ae50e2 (patch)
treec2750b0c6598ef0f944973c0ae8e9f2fca5da0cf
parent3f2ec4edd01fa4d948270ce3280c4139695ff148 (diff)
downloadelibs-776cfd788ed89a4705155fa077f2d8dd21ae50e2.tar.gz
elibs-776cfd788ed89a4705155fa077f2d8dd21ae50e2.tar.bz2
jao-ednc: simple register of per-app notification handlers
-rw-r--r--misc/jao-ednc.el32
1 files changed, 24 insertions, 8 deletions
diff --git a/misc/jao-ednc.el b/misc/jao-ednc.el
index 6a28658..48223d8 100644
--- a/misc/jao-ednc.el
+++ b/misc/jao-ednc.el
@@ -47,15 +47,31 @@
(let ((no (length (ednc-notifications))))
(if (> no 0) (format jao-ednc--count-format no) "")))
-(defun jao-ednc--on-notify (old new)
- (when old
+(defvar jao-ednc--handlers ())
+
+(defun jao-ednc-add-handler (app handler)
+ (add-to-list 'jao-ednc--handlers (cons app handler)))
+
+(defun jao-ednc--default-handler (notification newp)
+ (if newp
+ (progn
+ (tracking-add-buffer (get-buffer ednc-log-name) '(jao-ednc-tracking))
+ (setq jao-ednc--last-notification notification)
+ (jao-minibuffer-push-notification '(:eval (jao-ednc--format-last))))
(tracking-remove-buffer (get-buffer ednc-log-name))
(setq jao-ednc--last-notification nil)
- (jao-minibuffer-pop-notification))
- (when new
- (tracking-add-buffer (get-buffer ednc-log-name))
- (setq jao-ednc--last-notification new)
- (jao-minibuffer-push-notification '(:eval (jao-ednc--format-last)))))
+ (jao-minibuffer-pop-notification)))
+
+(defun jao-ednc--handler (notification)
+ (alist-get (ednc-notification-app-name notification)
+ jao-ednc--handlers
+ #'jao-ednc--default-handler
+ nil
+ 'string=))
+
+(defun jao-ednc--on-notify (old new)
+ (when old (funcall (jao-ednc--handler old) old nil))
+ (when new (funcall (jao-ednc--handler new) new t)))
;;;###autoload
(defun jao-ednc-setup ()
@@ -64,7 +80,7 @@
(add-to-list 'tracking-faces-priorities 'jao-ednc-tracking)
(when (listp tracking-shorten-modes)
(add-to-list 'tracking-shorten-modes 'ednc-view-mode)))
- (jao-minibuffer-add-variable '(jao-ednc--count) t)
+ ;; (jao-minibuffer-add-variable '(jao-ednc--count) t)
(add-hook 'ednc-notification-presentation-functions #'jao-ednc--on-notify)
(ednc-mode))