summaryrefslogtreecommitdiffhomepage
path: root/eos
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2021-01-11 01:14:36 +0000
committerjao <jao@gnu.org>2021-01-11 01:15:18 +0000
commitc9218804220c496d0c841eecaa0c8b6a92146880 (patch)
tree0758a7bd602fbb0ea0c1452cdb8b07759c70d4e0 /eos
parent3f173fedb948091cfc265ec0cdce6746cfaac034 (diff)
downloadelibs-c9218804220c496d0c841eecaa0c8b6a92146880.tar.gz
elibs-c9218804220c496d0c841eecaa0c8b6a92146880.tar.bz2
more consult functions, new jao-embark, eos
Diffstat (limited to 'eos')
-rw-r--r--eos/sys/jao-ednc.el141
-rw-r--r--eos/sys/jao-embark.el62
-rw-r--r--eos/sys/jao-minibuffer.el133
-rw-r--r--eos/sys/jao-notify.el33
-rw-r--r--eos/sys/jao-osd.el55
-rw-r--r--eos/sys/jao-sleep.el58
6 files changed, 482 insertions, 0 deletions
diff --git a/eos/sys/jao-ednc.el b/eos/sys/jao-ednc.el
new file mode 100644
index 0000000..03d4049
--- /dev/null
+++ b/eos/sys/jao-ednc.el
@@ -0,0 +1,141 @@
+;;; 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)
+
+(declare-function tracking-add-buffer "tracking")
+(declare-function tracking-remove-buffer "tracking")
+
+(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" " " (substring-no-properties s)))))
+
+(defun jao-ednc--count ()
+ (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)))
+
+(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 (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)
+ 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 (minibuffer-order)
+ (setq jao-notify-use-messages-p t)
+ (with-eval-after-load "tracking"
+ (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) minibuffer-order)
+ (add-hook 'ednc-notification-presentation-functions #'jao-ednc--on-notify)
+ (ednc-mode))
+
+;;;###autoload
+(defun jao-ednc-pop ()
+ (interactive)
+ (pop-to-buffer-same-window ednc-log-name))
+
+;;;###autoload
+(defun jao-ednc-show ()
+ (interactive)
+ (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))
+ (message "No active notifications"))
+ (jao-ednc--clean))
+
+;;;###autoload
+(defun jao-ednc-dismiss ()
+ (interactive)
+ (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
diff --git a/eos/sys/jao-embark.el b/eos/sys/jao-embark.el
new file mode 100644
index 0000000..9572489
--- /dev/null
+++ b/eos/sys/jao-embark.el
@@ -0,0 +1,62 @@
+;;; jao-embark.el --- embark actions -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2021 jao
+
+;; Author: jao <mail@jao.io>
+;; Keywords: convenience
+
+;; 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:
+
+;; Actions and utilities for embark
+
+;;; Code:
+
+(require 'embark)
+
+(defvar jao-embark-video-url-rx
+ (format "^https?://\\(?:www\\.\\)?%s/.+"
+ (regexp-opt '("youtu.be"
+ "youtube.com"
+ "blip.tv"
+ "vimeo.com"
+ "infoq.com")
+ t))
+ "A regular expression matching URLs that point to video streams")
+
+(defun jao-embark-video-finder ()
+ "Check whether we're looking at a video URL.
+Return (video-url . <URL>) if so."
+ (when-let ((url (thing-at-point-url-at-point)))
+ (when (string-match-p jao-embark-video-url-rx url)
+ (cons 'video-url url))))
+
+(defun jao-embark-play-video-url (&optional url)
+ (interactive "sURL: ")
+ (let ((cmd (format "mpv %s" (shell-quote-argument url))))
+ (start-process-shell-command "mpv" nil cmd)))
+
+(add-to-list 'embark-target-finders #'jao-embark-video-finder)
+
+(embark-define-keymap jao-embark-video-url-map
+ "Actions on URLs pointing to remote video streams."
+ ("p" jao-embark-play-video-url)
+ ("b" browse-url)
+ ("f" browse-url-firefox))
+
+(add-to-list 'embark-keymap-alist '(video-url . jao-embark-video-url-map))
+
+(provide 'jao-embark)
+;;; jao-embark.el ends here
diff --git a/eos/sys/jao-minibuffer.el b/eos/sys/jao-minibuffer.el
new file mode 100644
index 0000000..b626151
--- /dev/null
+++ b/eos/sys/jao-minibuffer.el
@@ -0,0 +1,133 @@
+;;; jao-minibuffer.el --- using the minibuffer to report status -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2020 jao
+
+;; Author: jao <mail@jao.io>
+;; Keywords: extensions
+
+;; 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:
+
+;; Simple asynchronous display of information in the minibuffer.
+
+;;; Code:
+
+(defvar jao-minibuffer-info ())
+(defvar jao-minibuffer-notification nil)
+(defvar jao-minibuffer-align-right-p t)
+(defvar jao-minibuffer-right-margin (if window-system 0 1))
+(defvar jao-minibuffer-maximized-frames-p nil)
+(defvar jao-minibuffer-frame-width nil)
+(defvar jao-minibuffer-notification-timeout 5)
+(defvar jao-minibuffer-enabled-p t)
+
+(defconst jao-minibuffer--name " *Minibuf-0*")
+
+(defun jao-minibuffer--trim (s w)
+ (if (<= (length s) w)
+ (format (format "%%%ds" (if jao-minibuffer-align-right-p w (- w))) s)
+ (substring s 0 w)))
+
+(defun jao-minibuffer--current ()
+ (with-current-buffer jao-minibuffer--name
+ (buffer-substring (point-min) (point-max))))
+
+(defun jao-minibuffer--width ()
+ (cond ((numberp jao-minibuffer-frame-width) jao-minibuffer-frame-width)
+ (jao-minibuffer-maximized-frames-p (frame-width))
+ (t (min (frame-width) (window-width (minibuffer-window))))))
+
+(defun jao-minibuffer--format-info ()
+ (mapconcat 'string-trim
+ (seq-filter (lambda (s) (not (string-blank-p s)))
+ (mapcar 'format-mode-line
+ (if jao-minibuffer-align-right-p
+ jao-minibuffer-info
+ (reverse jao-minibuffer-info))))
+ " "))
+
+(defun jao-minibuffer--aligned (&optional w currentp)
+ (let* ((msg (cond (currentp (jao-minibuffer--current))
+ (jao-minibuffer-notification
+ (format-mode-line jao-minibuffer-notification))
+ (t (jao-minibuffer--format-info))))
+ (msg (if jao-minibuffer-align-right-p
+ (string-trim msg)
+ (string-trim-left msg)))
+ (msg (propertize msg :minibuffer-message t)))
+ (when (not (string-empty-p msg))
+ (let* ((mw (jao-minibuffer--width))
+ (w (mod (or w (length (current-message))) mw))
+ (w (- mw w jao-minibuffer-right-margin)))
+ (if (> w 0) (jao-minibuffer--trim msg w) "")))))
+
+(defun jao-minibuffer--set-message (msg)
+ (let ((msg (string-trim (replace-regexp-in-string "\n" " " msg))))
+ (if jao-minibuffer-align-right-p
+ (concat msg (jao-minibuffer--aligned (length msg) t))
+ (concat (jao-minibuffer--aligned (+ 3 (length msg)) t) " " msg))))
+
+(defun jao-minibuffer--insert (msg)
+ (with-current-buffer jao-minibuffer--name
+ (erase-buffer)
+ (insert msg)))
+
+;;;###autoload
+(defun jao-minibuffer-refresh ()
+ (interactive)
+ (when jao-minibuffer-enabled-p
+ (jao-minibuffer--insert (or (jao-minibuffer--aligned) ""))))
+
+;;;###autoload
+(defun jao-minibuffer-add-variable (variable-name &optional order)
+ (add-to-ordered-list 'jao-minibuffer-info `(:eval ,variable-name) order))
+
+(defvar jao-minibuffer--notification-timer nil)
+
+(defun jao-minibuffer--start-notification-timer (timeout)
+ (interactive)
+ (when jao-minibuffer--notification-timer
+ (cancel-timer jao-minibuffer--notification-timer))
+ (setq jao-minibuffer--notification-timer
+ (run-with-idle-timer (or timeout jao-minibuffer-notification-timeout)
+ nil
+ 'jao-minibuffer-pop-notification)))
+
+;;;###autoload
+(defun jao-minibuffer-push-notification (msg &optional timeout)
+ (setq jao-minibuffer-notification msg)
+ (jao-minibuffer--start-notification-timer timeout)
+ (jao-minibuffer-refresh))
+
+;;;###autoload
+(defun jao-minibuffer-pop-notification ()
+ (interactive)
+ (setq jao-minibuffer-notification nil)
+ (jao-minibuffer-refresh))
+
+;;;###autoload
+(defun jao-minibuffer-toggle ()
+ (interactive)
+ (setq jao-minibuffer-enabled-p (not jao-minibuffer-enabled-p))
+ (if jao-minibuffer-enabled-p
+ (jao-minibuffer-refresh)
+ (jao-minibuffer--insert "")))
+
+(setq set-message-function #'jao-minibuffer--set-message)
+(setq clear-message-function #'jao-minibuffer-refresh)
+(setq resize-mini-windows nil)
+
+(provide 'jao-minibuffer)
+;;; jao-minibuffer.el ends here
diff --git a/eos/sys/jao-notify.el b/eos/sys/jao-notify.el
new file mode 100644
index 0000000..dc48ca4
--- /dev/null
+++ b/eos/sys/jao-notify.el
@@ -0,0 +1,33 @@
+;; jao-notify.el -- Interacting with notification daemon
+
+;; Copyright (c) 2017, 2019, 2020 Jose Antonio Ortega Ruiz
+
+;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
+;; Start date: Sun Jan 08, 2017 20:24
+
+
+;;; Comentary:
+
+;; Simple notifications using echo or dbus notifications
+
+;;; Code:
+
+(defvar jao-notify-use-messages-p nil)
+(defvar jao-notify-timeout 5000)
+
+(declare-function notifications-notify "notifications")
+
+(defun jao-notify (msg &optional title icon)
+ (if jao-notify-use-messages-p
+ (message "%s%s%s" (or title "") (if title ": " "") (or msg ""))
+ (let* ((args `(:timeout ,jao-notify-timeout))
+ (args (append args
+ (if title `(:title ,title :body ,msg) `(:title ,msg))))
+ (args (if (and (stringp icon) (file-exists-p icon))
+ (append args `(:app-icon ,(format "%s" icon)))
+ args)))
+ (apply 'notifications-notify args))))
+
+
+(provide 'jao-notify)
+;;; jao-notify.el ends here
diff --git a/eos/sys/jao-osd.el b/eos/sys/jao-osd.el
new file mode 100644
index 0000000..acdc629
--- /dev/null
+++ b/eos/sys/jao-osd.el
@@ -0,0 +1,55 @@
+;; candy
+(defvar jao-osd-cat-color-fg "black")
+(defvar jao-osd-cat-color-bg "white")
+(defvar jao-osd-cat-font "Andika Basic 16")
+;; (setq jao-osd-cat-font "Inconsolata 20")
+(defun jao-osd-cat-font (&optional font)
+ (or font jao-osd-cat-font))
+
+(defun jao-osd-process-args (&optional font fg bg)
+ `("-n" ,(jao-osd-cat-font font)
+ "-R" ,(or bg jao-osd-cat-color-fg) "-B" ,(or fg jao-osd-cat-color-bg)
+ "-b" "200" "-r" "255"
+ "-e" "0" "-t" "2" "-d" "10" "-p" "0" "-x" "10" "-y" "10" "-u" "5000"))
+
+(setq jao-osd-processes (make-hash-table))
+
+(defsubst jao-osd--delete-process (name)
+ (remhash name jao-osd-processes))
+
+(defun jao-osd-process (name &optional font color)
+ (let ((proc (gethash name jao-osd-processes)))
+ (or (and proc (eq (process-status proc) 'run) proc)
+ (puthash name
+ (apply 'start-process
+ `("notifications"
+ ,(format "*notifications/%s*" name)
+ "aosd_cat"
+ ,@(jao-osd-process-args)))
+ jao-osd-processes))))
+
+(defun jao-osd-cat (name lines)
+ (let* ((proc (jao-osd-process name))
+ (lines (if (listp lines) lines (list lines)))
+ (trail (- 5 (length lines))))
+ (when proc
+ (dolist (line lines)
+ (send-string proc (format "%s\n" line))))))
+ ; (when (> trail 0) (send-string proc (make-string trail ?\n))))))
+
+(defun jao-osd--names ()
+ (let (names)
+ (maphash (lambda (n k) (push n names)) jao-osd-processes)
+ (reverse names)))
+
+(defun jao-osd-kill (name)
+ (let ((proc (gethash name jao-osd-processes)))
+ (when (processp proc)
+ (kill-process proc))))
+
+(defun jao-osd-kill-notifiers ()
+ (interactive)
+ (maphash (lambda (n p) (ignore-errors (kill-process p))) jao-osd-processes)
+ (clrhash jao-osd-processes))
+
+(provide 'jao-osd)
diff --git a/eos/sys/jao-sleep.el b/eos/sys/jao-sleep.el
new file mode 100644
index 0000000..93da0e7
--- /dev/null
+++ b/eos/sys/jao-sleep.el
@@ -0,0 +1,58 @@
+;;; jao-sleep.el --- Actions upon sleep/awake -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2020 jao
+
+;; Author: jao <mail@jao.io>
+;; Keywords: hardware
+
+;; 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/>.
+
+;;; Code:
+
+(require 'dbus)
+
+(defvar jao-sleep-sleep-functions nil)
+(defvar jao-sleep-awake-functions nil)
+
+(defvar jao-sleep--dbus-registration-object nil)
+
+(defun jao-sleep--dbus-sleep-handler (sleep-start)
+ (condition-case nil
+ (if sleep-start
+ (progn (message "Running on sleep functions")
+ (run-hooks 'jao-sleep-sleep-functions))
+ (message "Running on awake functions")
+ (run-hooks 'jao-sleep-awake-functions))
+ (error (message "There was an error running %s" sleep-start))))
+
+;;;###autoload
+(defun jao-sleep-dbus-register (&optional session-dbus)
+ "Register actions to take on sleep and on awake, using the system D-BUS."
+ (when (featurep 'dbusbind)
+ (setq jao-sleep--dbus-sleep-registration-object
+ (dbus-register-signal (if session-dbus :session :system)
+ "org.freedesktop.login1"
+ "/org/freedesktop/login1"
+ "org.freedesktop.login1.Manager"
+ "PrepareForSleep"
+ #'jao-sleep--dbus-sleep-handler))))
+
+;;;###autoload
+(defun jao-sleep-dbus-unregister ()
+ (condition-case nil
+ (dbus-unregister-object jao-sleep--dbus-sleep-registration-object)
+ (wrong-type-argument nil)))
+
+(provide 'jao-sleep)
+;;; jao-sleep.el ends here