diff options
author | jao <jao@gnu.org> | 2020-11-25 05:04:46 +0000 |
---|---|---|
committer | jao <jao@gnu.org> | 2020-11-25 05:04:46 +0000 |
commit | 86eb7107cc89915b7d1e733953b291cee654faef (patch) | |
tree | c4877822f098b9675f7319fd3365a11b2a7f7b19 | |
parent | 10f8d7dfd552c2bfc0e237d6a5d7d8d1c5265881 (diff) | |
download | elibs-86eb7107cc89915b7d1e733953b291cee654faef.tar.gz elibs-86eb7107cc89915b7d1e733953b291cee654faef.tar.bz2 |
jao-ednc: keeping a notification stack
-rw-r--r-- | sys/jao-ednc.el | 83 |
1 files 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 |