From 86eb7107cc89915b7d1e733953b291cee654faef Mon Sep 17 00:00:00 2001 From: jao Date: Wed, 25 Nov 2020 05:04:46 +0000 Subject: jao-ednc: keeping a notification stack --- sys/jao-ednc.el | 83 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 30 deletions(-) diff --git a/sys/jao-ednc.el b/sys/jao-ednc.el index 06ed986..0dc8e4e 100644 --- a/sys/jao-ednc.el +++ b/sys/jao-ednc.el @@ -31,23 +31,29 @@ (declare-function tracking-add-buffer "tracking") (declare-function tracking-remove-buffer "tracking") -(defvar jao-ednc--count-format "{%d}") -(defvar jao-ednc--last-notification nil) +(defvar jao-ednc--count-format " {%d} ") +(defvar jao-ednc--notifications ()) +(defvar jao-ednc--handlers ()) + +(defvar jao-ednc-use-minibuffer-notifications nil) +(defvar jao-ednc-use-tracking t) (defface jao-ednc-tracking '((t :inherit warning)) "Tracking notifications face" :group 'jao-ednc) +(defun jao-ednc--last-notification () (car jao-ednc--notifications)) + (defun jao-ednc--format-last () - (when jao-ednc--last-notification - (let ((s (ednc-format-notification jao-ednc--last-notification t))) - (replace-regexp-in-string "\n" " " s)))) + (when (jao-ednc--last-notification) + (let ((s (ednc-format-notification (jao-ednc--last-notification) t))) + (replace-regexp-in-string "\n" " " (substring-no-properties s))))) (defun jao-ednc--count () - (let ((no (length (ednc-notifications)))) - (if (> no 0) (format jao-ednc--count-format no) ""))) - -(defvar jao-ednc--handlers ()) + (let ((no (length jao-ednc--notifications))) + (if (> no 0) + (propertize (format jao-ednc--count-format no) 'face 'warning) + ""))) (defun jao-ednc-add-handler (app handler) (add-to-list 'jao-ednc--handlers (cons app handler))) @@ -55,15 +61,29 @@ (defun jao-ednc-ignore-app (app) (jao-ednc-add-handler app (lambda (not _) (ednc-dismiss-notification not)))) +(defun jao-ednc--pop-minibuffer () + (if jao-ednc-use-minibuffer-notifications + (jao-minibuffer-pop-notification) + (jao-minibuffer-refresh))) + +(defun jao-ednc--clean (&optional notification) + (tracking-remove-buffer (get-buffer ednc-log-name)) + (if notification + (remove notification jao-ednc--notifications) + (pop jao-ednc--notifications)) + (jao-ednc--pop-minibuffer)) + +(defun jao-ednc--show-last () + (if jao-ednc-use-minibuffer-notifications + (jao-minibuffer-push-notification '(:eval (jao-ednc--format-last))) + (message "%s" (jao-ednc--format-last)))) + (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))) + (if (not newp) + (jao-ednc--clean notification) + (tracking-add-buffer (get-buffer ednc-log-name) '(jao-ednc-tracking)) + (push notification jao-ednc--notifications) + (jao-ednc--show-last))) (defun jao-ednc--handler (notification) (alist-get (ednc-notification-app-name notification) @@ -80,10 +100,11 @@ (defun jao-ednc-setup () (setq jao-notify-use-messages-p t) (with-eval-after-load "tracking" - (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) + (when jao-ednc-use-tracking + (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) (add-hook 'ednc-notification-presentation-functions #'jao-ednc--on-notify) (ednc-mode)) @@ -95,24 +116,26 @@ ;;;###autoload (defun jao-ednc-show () (interactive) - (if jao-ednc--last-notification - (ednc-pop-to-notification-in-log-buffer jao-ednc--last-notification) - (jao-ednc-pop))) + (if (not (jao-ednc--last-notification)) + (jao-ednc-pop) + (jao-ednc--show-last))) ;;;###autoload (defun jao-ednc-invoke-last-action () (interactive) - (if jao-ednc--last-notification - (ednc-invoke-action jao-ednc--last-notification) + (if (jao-ednc--last-notification) + (ednc-invoke-action (jao-ednc--last-notification)) (message "No active notifications")) - (jao-minibuffer-pop-notification)) + (jao-ednc--clean)) ;;;###autoload (defun jao-ednc-dismiss () (interactive) - (if jao-ednc--last-notification - (ednc-dismiss-notification jao-ednc--last-notification) - (jao-minibuffer-pop-notification))) + (when (jao-ednc--last-notification) + (ignore-errors + (with-current-buffer ednc-log-name + (ednc-dismiss-notification (jao-ednc--last-notification))))) + (jao-ednc--clean)) (provide 'jao-ednc) ;;; jao-ednc.el ends here -- cgit v1.2.3