From 776cfd788ed89a4705155fa077f2d8dd21ae50e2 Mon Sep 17 00:00:00 2001 From: jao Date: Sat, 21 Nov 2020 21:45:30 +0000 Subject: jao-ednc: simple register of per-app notification handlers --- misc/jao-ednc.el | 32 ++++++++++++++++++++++++-------- 1 file 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)) -- cgit v1.2.3