summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2020-11-01 02:13:04 +0000
committerjao <jao@gnu.org>2020-11-01 02:13:04 +0000
commitb7d2cd9b5bda2c322ea5333913f17fe5c46f8566 (patch)
tree3816ab06661d41f9b020e6d7e3a9983332b2aba3
parent05ffe94a09be090270eefaa331e15bcad23311b4 (diff)
downloadelibs-b7d2cd9b5bda2c322ea5333913f17fe5c46f8566.tar.gz
elibs-b7d2cd9b5bda2c322ea5333913f17fe5c46f8566.tar.bz2
jao-ednc: emacs as the system notification daemon
-rw-r--r--misc/jao-ednc.el75
-rw-r--r--misc/jao-minibuffer.el29
2 files changed, 97 insertions, 7 deletions
diff --git a/misc/jao-ednc.el b/misc/jao-ednc.el
new file mode 100644
index 0000000..255aa19
--- /dev/null
+++ b/misc/jao-ednc.el
@@ -0,0 +1,75 @@
+;;; jao-ednc.el --- Minibuffer notifications using EDNC -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2020 jao
+
+;; Author: jao <mail@jao.io>
+;; Keywords: tools, abbrev
+
+;; 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:
+
+;; Use the ednc package to provide a notification daemon that uses
+;; the minibuffer to display them.
+
+;;; Code:
+
+(require 'ednc)
+(require 'jao-minibuffer)
+
+(defvar jao-ednc--count-format "{%d}")
+(defvar jao-ednc--last-notification nil)
+
+(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))))
+
+(defun jao-ednc--count ()
+ (let ((no (length (ednc-notifications))))
+ (if (> no 0) (format jao-ednc--count-format no) "")))
+
+(defun jao-ednc--on-notify (old new)
+ (when old
+ (setq jao-ednc--last-notification nil)
+ (jao-minibuffer-pop-notification))
+ (when new
+ (setq jao-ednc--last-notification new)
+ (jao-minibuffer-push-notification '(:eval (jao-ednc--format-last)))))
+
+;;;###autoload
+(defun jao-ednc-setup ()
+ (with-eval-after-load "jao-notify"
+ (defun jao-ednc--notify (msg &optional title _)
+ (message "%s%s%s" (or title "") (if title " " "") msg))
+ (advice-add 'jao-notify :override #'jao-ednc--notify))
+ (jao-minibuffer-add-variable '(jao-ednc-count) t)
+ (add-hook 'ednc-notification-presentation-functions #'jao-ednc--on-notify)
+ (ednc-mode))
+
+;;;###autoload
+(defun jao-ednc-show ()
+ (interactive)
+ (pop-to-buffer-same-window "*ednc-log*"))
+
+;;;###autoload
+(defun jao-ednc-invoke-last-action ()
+ (interactive)
+ (if jao-ednc--last-notification
+ (ednc-invoke-action jao-ednc--last-notification)
+ (message "No active notifications"))
+ (jao-minibuffer-pop-notification))
+
+(provide 'jao-ednc)
+;;; jao-ednc.el ends here
diff --git a/misc/jao-minibuffer.el b/misc/jao-minibuffer.el
index 70829bb..6af3730 100644
--- a/misc/jao-minibuffer.el
+++ b/misc/jao-minibuffer.el
@@ -25,6 +25,7 @@
;;; Code:
(defvar jao-minibuffer-info ())
+(defvar jao-minibuffer-notification nil)
(defvar jao-minibuffer-align-right-p t)
(defvar jao-minibuffer-right-margin 2)
(defvar jao-minibuffer-maximized-frames-p t)
@@ -37,22 +38,25 @@
(substring s 0 w)))
(defun jao-minibuffer--aligned (&optional w)
- (let ((msg (format-mode-line jao-minibuffer-info)))
+ (let ((msg (string-trim (format-mode-line (or jao-minibuffer-notification
+ jao-minibuffer-info)))))
(when (not (string-empty-p msg))
(if jao-minibuffer-align-right-p
(let* ((mw (if jao-minibuffer-maximized-frames-p
(frame-width)
(window-width (minibuffer-window))))
- (w (- mw (or w 0) jao-minibuffer-right-margin)))
+ (w (mod (or w 0) mw))
+ (w (- mw w jao-minibuffer-right-margin)))
(if (> w 0) (jao-minibuffer--trim msg w) ""))
(concat " ยท " msg)))))
(defun jao-minibuffer--message (old-func &rest args)
- (let ((msg (let ((inhibit-message t)) (apply old-func args))))
- (when (not inhibit-message)
- (let ((message-log-max nil)
- (new-msg (concat msg (jao-minibuffer--aligned (length msg)))))
- (funcall old-func "%s" new-msg)))
+ (let* ((msg (let ((inhibit-message t)) (apply old-func args)))
+ (msg (if inhibit-message "" msg))
+ (new-msg (concat msg (jao-minibuffer--aligned (length msg))))
+ (message-log-max nil)
+ (inhibit-message nil))
+ (funcall old-func "%s" new-msg)
msg))
(advice-add #'message :around #'jao-minibuffer--message)
@@ -68,5 +72,16 @@
(defun jao-minibuffer-add-variable (variable-name &optional append)
(add-to-list 'jao-minibuffer-info `(:eval ,variable-name) append))
+;;;###autoload
+(defun jao-minibuffer-push-notification (msg)
+ (setq jao-minibuffer-notification msg)
+ (jao-minibuffer-refresh))
+
+;;;###autoload
+(defun jao-minibuffer-pop-notification ()
+ (interactive)
+ (setq jao-minibuffer-notification nil)
+ (jao-minibuffer-refresh))
+
(provide 'jao-minibuffer)
;;; jao-minibuffer.el ends here