summaryrefslogtreecommitdiffhomepage
path: root/lib/eos
diff options
context:
space:
mode:
Diffstat (limited to 'lib/eos')
-rw-r--r--lib/eos/jao-afio.el315
-rw-r--r--lib/eos/jao-dirmon.el42
-rw-r--r--lib/eos/jao-ednc.el16
-rw-r--r--lib/eos/jao-eshell-here.el6
-rw-r--r--lib/eos/jao-minibuffer.el93
-rw-r--r--lib/eos/jao-mode-line.el64
-rw-r--r--lib/eos/jao-notify.el33
-rw-r--r--lib/eos/jao-r2e.el228
-rw-r--r--lib/eos/jao-shell.el31
-rw-r--r--lib/eos/jao-sleep.el12
-rw-r--r--lib/eos/jao-tracking.el113
-rw-r--r--lib/eos/jao-wayland.el181
12 files changed, 859 insertions, 275 deletions
diff --git a/lib/eos/jao-afio.el b/lib/eos/jao-afio.el
index 306a1d5..162a1b7 100644
--- a/lib/eos/jao-afio.el
+++ b/lib/eos/jao-afio.el
@@ -1,6 +1,6 @@
;;; jao-afio.el --- workspaces in just one frame -*- lexical-binding: t; -*-
-;; Copyright (C) 2020, 2021, 2022 jao
+;; Copyright (C) 2020, 2021, 2022, 2024, 2025 jao
;; Author: jao <mail@jao.io>
;; Keywords: frames
@@ -18,112 +18,113 @@
;; 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:
-
+;;; initialisation
(require 'cl-lib)
+(require 'jao-doc-session)
+
+(defvar jao-afio-use-frames (not window-system))
(defvar jao-open-doc-fun 'find-file)
(defvar jao-afio-mail-function 'gnus)
(defvar jao-afio-use-w3m nil)
-(defvar jao-afio-notmuch-in-web nil)
+(defvar jao-afio-auto-toggle nil)
(defvar jao-afio-switch-hook nil)
-(defvar jao-afio--configs '(?c ?w ?g ?p ?s))
-(defvar jao-afio--current-config (car jao-afio--configs))
-(defvar jao-afio--locker nil)
-(defvar jao-afio-fallback-fun nil)
+(defvar jao-afio--configs '(?c ?w ?g ?p ?s ?t))
+(defvar jao-afio--previous-config (car jao-afio--configs))
-(defun jao-afio--check-frame-p ()
- (assoc 'afio (frame-parameters)))
+(defun jao-afio--current-config (&optional c f)
+ (when c (modify-frame-parameters f `((afio . ,c))))
+ (frame-parameter f 'afio))
(defun jao-afio--init (&optional f)
(interactive)
- (when (and (frame-live-p jao-afio--locker)
- (not (eql f jao-afio--locker)))
- (if jao-afio-fallback-fun
- (funcall jao-afio-fallback-fun)
- (error "Another frame is using afio")))
- (setq jao-afio--locker f)
- (modify-frame-parameters f '((afio . t)))
- (setq jao-afio--current-config ?c)
- (mapc (lambda (r) (set-register r nil)) jao-afio--configs)
- (window-configuration-to-register ?c))
-
-(defun jao-afio--steal ()
- (interactive)
- (setq jao-afio--locker nil)
- (jao-afio--init (window-frame (get-buffer-window (current-buffer)))))
+ (jao-afio--current-config ?c)
+ (if jao-afio-use-frames
+ (set-frame-name (jao-afio-frame-name ?c))
+ (window-configuration-to-register ?c)))
(defun jao-afio--check-frame ()
- (unless (jao-afio--check-frame-p)
- (or ;; (when jao-afio-fallback-fun
- ;; (funcall jao-afio-fallback-fun)
- ;; t)
- (when (y-or-n-p "Another frame is using afio. Steal? ")
- (jao-afio--steal)
- t)
- (error "Aborted"))))
-
-(defun jao-afio--next-frame ()
- (interactive)
- (jao-afio--check-frame)
- (let* ((cur (member jao-afio--current-config jao-afio--configs))
- (next (or (cadr cur) (car jao-afio--configs))))
- (jao-afio--goto-frame next)))
+ (unless (jao-afio--current-config)
+ (jao-afio--init (window-frame (get-buffer-window (current-buffer))))))
+;;; utilities
+(defun jao-afio-trisect (&optional force)
+ (interactive)
+ (let ((fw (frame-width))
+ (display-buffer-alist nil))
+ (cond ((or force (>= fw 240))
+ (let ((b (current-buffer)))
+ (delete-other-windows)
+ (switch-to-buffer (other-buffer b))
+ (split-window-horizontally)
+ (switch-to-buffer (other-buffer b))
+ (split-window-horizontally)
+ (switch-to-buffer b)
+ (balance-windows)))
+ ((> fw 162)
+ (delete-other-windows)
+ (split-window-horizontally)
+ (switch-to-buffer (other-buffer))))))
+
+;;; session openers
;;;###autoload
-(defun jao-afio-open-pdf-session ()
+(defun jao-afio-open-pdf-session (&optional docs)
(interactive)
- (let ((jao-doc-view-inhibit-session-save t))
- (dolist (doc (jao-doc-view-session))
- (when (and (file-exists-p doc) (y-or-n-p (format "Open %s? " doc)))
- (jao-open-doc doc)
- (other-window 1)))
- (other-window 1)))
+ (dolist (doc (or docs (jao-doc-session)))
+ (when (and doc (file-exists-p doc))
+ (if (jao-pdf-is-pdf-file doc) (jao-open-doc doc) (find-file doc))
+ (other-window 1)))
+ (other-window 1))
(defun jao-afio-open-doc ()
(interactive)
(delete-other-windows)
(split-window-right)
- (let ((docs (cl-remove-if-not (lambda (b)
- (with-current-buffer b (jao-doc-view--is-doc)))
- (buffer-list))))
+ (let ((docs (cl-remove-if-not 'jao-doc-session-is-doc (buffer-list))))
(if (car docs)
(progn (switch-to-buffer (car docs))
(switch-to-buffer-other-window (or (cadr docs) (car docs))))
- (when (and (jao-doc-view-session) (y-or-n-p "Load saved session? "))
- (jao-afio-open-pdf-session)))))
+ (when-let (docs (jao-doc-session))
+ (when (y-or-n-p (format "Load saved session? (%d docs)" (length docs)))
+ (jao-afio-open-pdf-session docs))))))
+
+(declare-function w3m "w3m")
+(declare-function notmuch "notmuch")
+(declare-function jao-eww-session-eww-buffers "jao-eww-session")
+(declare-function jao-eww-session-load "jao-eww-session")
-(declare w3m "w3m")
-(declare w3m-alive-p "w3m")
-(declare w3m-previous-buffer "w3m")
-(declare notmuch "notmuch")
+(defun jao-afio--open-eww-session ()
+ (if-let (b (jao-eww-session-eww-buffers))
+ (switch-to-buffer (car b))
+ (jao-eww-session-load)))
;;;###autoload
(defun jao-afio-open-www ()
(interactive)
(require 'jao-eww-session)
(if (< (frame-width) 160)
- (if jao-afio-use-w3m (w3m) (jao-eww-session-load))
- (delete-other-windows)
- (split-window-right)
+ (if jao-afio-use-w3m (w3m) (jao-afio--open-eww-session))
(if jao-afio-use-w3m
- (w3m)
- (jao-eww-session-load)
+ (progn (delete-other-windows)
+ (split-window-right)
+ (w3m))
+ (jao-afio-trisect)
+ (jao-afio--open-eww-session)
(let ((b (current-buffer)))
(other-window 1)
- (if jao-afio-notmuch-in-web
- (notmuch)
- (switch-to-buffer (car (jao-eww-session--list-buffers b))))
+ (switch-to-buffer (car (jao-eww-session-eww-buffers b)))
+ (other-window 1)
+ (switch-to-buffer (car (jao-eww-session-eww-buffers b)))
(other-window 1)))))
;;;###autoload
(defun jao-afio-open-gnus ()
(interactive)
- (delete-other-windows)
- (org-agenda-list)
+ (jao-org-agenda)
(calendar)
(find-file (expand-file-name "inbox.org" org-directory))
+ (delete-other-windows)
(gnus)
(jao-gnus--set-summary-line))
@@ -131,136 +132,130 @@
(other-window 1)
(delete-other-windows-vertically)
(find-file (expand-file-name "inbox.org" org-directory))
+ (set-window-dedicated-p nil t)
(split-window-below (/ (window-height) 3))
(other-window 1)
- (org-agenda-list)
- (split-window-below -9)
+ (jao-org-agenda)
+ (set-window-dedicated-p nil t)
+ (split-window-below -8)
(other-window 1)
(switch-to-buffer "*Calendar*")
+ (set-window-dedicated-p nil t)
(other-window 1))
-;;;###autoload
-(defun jao-afio-open-notmuch ()
- (interactive)
+(defun jao-afio--open-mail (fun)
+ (unless (get-buffer "*Calendar*") (calendar))
(delete-other-windows)
(split-window-horizontally -80)
- (notmuch)
- (jao-afio--mail-sidebar))
-
-(defun jao-afio-open-mail-function ()
- (interactive)
- (jao-trisect)
- (other-window 2)
- (delete-window)
- (other-window 1)
- (funcall jao-afio-mail-function)
+ (funcall fun)
+ ;; (set-window-dedicated-p nil t)
(jao-afio--mail-sidebar))
;;;###autoload
(defun jao-afio-open-mail ()
(interactive)
- (unless (get-buffer "*Calendar*") (calendar))
(cond ((eq 'gnus jao-afio-mail-function) (jao-afio-open-gnus))
- ((eq 'notmuch jao-afio-mail-function) (jao-afio-open-notmuch))
- (jao-afio-open-mail-function (jao-afio-open-mail-function))))
+ ((eq 'notmuch jao-afio-mail-function) (jao-afio--open-mail 'notmuch))
+ (t (jao-afio-trisect))))
+
+;;;###autoload
+(defun jao-afio-reset ()
+ (interactive)
+ (delete-other-windows)
+ (cl-case (jao-afio--current-config)
+ (?w (jao-afio-open-www))
+ (?g (jao-afio-open-mail))
+ (?p (jao-afio-open-doc))
+ (t (jao-afio-trisect))))
+
+;;; go to frame
+(defsubst jao-afio--find-frame (c)
+ (seq-find (lambda (f) (eq (jao-afio--current-config nil f) c)) (frame-list)))
+
+(defun jao-afio-frame-name (&optional c)
+ (alist-get (or c (jao-afio--current-config))
+ '((?c . "main") (?s . "scratch") (?g . "mail")
+ (?p . "docs") (?w . "web") (?t . "chats"))))
+
+(defun jao-afio-frame-no (&optional c)
+ (alist-get (or c (jao-afio--current-config))
+ '((?s . 0) (?c . 1) (?g . 2) (?w . 3) (?p . 4) (?t . 5))))
(defun jao-afio--goto-frame (next &optional reset)
- (when (or reset (not (eq next jao-afio--current-config)))
- (let ((next-cfg (when (not reset) (get-register next))))
- (window-configuration-to-register jao-afio--current-config)
- (setq jao-afio--current-config next)
- (if next-cfg
- (jump-to-register next)
- (delete-other-windows)
- (cl-case next
- (?w (jao-afio-open-www))
- (?g (jao-afio-open-mail))
- (?p (jao-afio-open-doc))
- (?s (delete-other-windows))))
- (run-hooks 'jao-afio-switch-hook))))
-
-(defun jao-afio--goto-main (&optional reset)
- (interactive "P")
(jao-afio--check-frame)
- (jao-afio--goto-frame ?c reset))
-
-(defun jao-afio--goto-scratch (&optional reset)
+ (let ((current (jao-afio--current-config)))
+ (if (and jao-afio-auto-toggle
+ (eq next current)
+ (not reset)
+ (not (eq current jao-afio--previous-config)))
+ (jao-afio--goto-frame jao-afio--previous-config)
+ (when (or reset (not (eq next current)))
+ (if jao-afio-use-frames
+ (let ((f (jao-afio--find-frame next)))
+ (select-frame-set-input-focus (or f (make-frame)))
+ (when (setq reset (or reset (not f)))
+ (set-frame-name
+ (format "%s" (or (jao-afio-frame-name next) next)))))
+ (window-configuration-to-register (jao-afio--current-config))
+ (when (and (not reset) (get-register next))
+ (ignore-errors (jump-to-register next)))
+ (setq reset (or reset (not (get-register next)))))
+ (jao-afio--current-config next)
+ (unless (eq current next) (setq jao-afio--previous-config current))
+ (when reset (jao-afio-reset))
+ (run-hooks 'jao-afio-switch-hook)))))
+
+(defun jao-afio-goto-main (&optional reset)
(interactive "P")
- (jao-afio--check-frame)
- (jao-afio--goto-frame ?s reset))
+ (jao-afio--goto-frame ?c reset))
-(defun jao-afio--goto-mail (&optional reset)
+(defun jao-afio-goto-mail (&optional reset)
(interactive "P")
- (jao-afio--check-frame)
(jao-afio--goto-frame ?g reset))
-(defun jao-afio--goto-docs (&optional reset)
+(defun jao-afio-goto-docs (&optional reset)
(interactive "P")
- (jao-afio--check-frame)
(jao-afio--goto-frame ?p reset))
-(defun jao-afio--goto-www (&optional reset)
+(defun jao-afio-goto-www (&optional reset)
(interactive "P")
- (if (jao-afio--check-frame-p)
- (jao-afio--goto-frame ?w reset)
- (when (and jao-afio-use-w3m (w3m-alive-p))
- (pop-to-buffer (w3m-alive-p)))))
-
-(defun jao-afio--try-init (&optional f)
- (ignore-errors (jao-afio--init f))
- t)
-
-(defun jao-afio--goto-www-buffer (buf &rest _)
- (jao-afio--goto-www)
- (jao-first-window)
- (switch-to-buffer buf nil t))
-
-(defun jao-afio--goto-pdf-buffer (buf &rest _)
- (if (jao-afio--check-frame-p)
- (progn (jao-afio--goto-docs)
- (jao-first-window)
- (switch-to-buffer buf nil t))
- (pop-to-buffer buf)))
+ (jao-afio--goto-frame ?w reset))
+
+(defun jao-afio-toggle ()
+ (interactive)
+ (jao-afio--goto-frame jao-afio--previous-config))
(defun jao-afio-goto-scratch (&optional one-win)
- (jao-afio--goto-scratch)
+ (interactive "P")
+ (jao-afio--goto-frame ?s one-win)
(when one-win (delete-other-windows)))
-(defun jao-afio-current-frame ()
- (cl-case jao-afio--current-config
- (?c "Main")
- (?s "Scratch")
- (?g "Mail")
- (?p "Docs")
- (?w "Web")))
-
-(defun jao-afio-current-no ()
- (cl-case jao-afio--current-config
- (?c "1")
- (?s "0")
- (?g "2")
- (?p "4")
- (?w "3")))
+(defun jao-afio-goto-chats (&optional reset)
+ (interactive "P")
+ (jao-afio--goto-frame ?t reset))
;;;###autoload
(defun jao-afio-goto-nth (n)
(cl-case n
- ((1) (jao-afio--goto-main))
- ((2) (jao-afio--goto-mail))
- ((3) (jao-afio--goto-www))
- ((4) (jao-afio--goto-docs))
- ((5) (jao-afio--goto-scratch-1))
- ((0) (jao-afio--goto-scratch))))
+ ((-1) (jao-afio-goto-scratch t))
+ ((0) (jao-afio-goto-scratch))
+ ((1) (jao-afio-goto-main))
+ ((2) (jao-afio-goto-mail))
+ ((3) (jao-afio-goto-www))
+ ((4) (jao-afio-goto-docs))
+ ((5) (jao-afio-goto-chats))))
+
+;;;###autoload
+(defun jao-afio-pop-to-buffer (n buff)
+ (interactive "NFrame number: \nBBuffer: ")
+ (jao-afio-goto-nth n)
+ (pop-to-buffer buff))
+;;; setup
;;;###autoload
-(defun jao-afio-setup (&optional fallback-fun init-p)
- (global-set-key "\C-cf" 'jao-afio--goto-main)
- (global-set-key "\C-cg" 'jao-afio--goto-mail)
- (global-set-key "\C-cw" 'jao-afio--goto-www)
- (global-set-key "\C-cz" 'jao-afio--goto-docs)
- (setq jao-afio-fallback-fun fallback-fun)
- (add-hook (if init-p 'after-init-hook 'after-make-frame-functions)
- 'jao-afio--try-init))
+(defun jao-afio-setup (&optional use-frames)
+ (setq jao-afio-use-frames use-frames)
+ (jao-afio--init))
(provide 'jao-afio)
;;; jao-afio.el ends here
diff --git a/lib/eos/jao-dirmon.el b/lib/eos/jao-dirmon.el
index 4fb8609..6a897d3 100644
--- a/lib/eos/jao-dirmon.el
+++ b/lib/eos/jao-dirmon.el
@@ -1,6 +1,6 @@
;;; jao-dirmon.el --- little utility to monitor disk usage -*- lexical-binding: t; -*-
-;; Copyright (C) 2022 jao
+;; Copyright (C) 2022, 2024, 2025 jao
;; Author: jao <mail@jao.io>
;; Keywords: tools
@@ -25,21 +25,47 @@
;;; Code:
(require 'multisession)
+(require 'view)
(require 'jao-shell)
(define-multisession-variable jao-dirmon-last '())
+(defvar jao-dirmon-roots '("/var/local" "~"))
+
(defun jao-dirmon-dirs ()
- (jao-shell-cmd-lines "find ~ -mindepth 2 -maxdepth 3 -type d"))
+ (mapcan (lambda (d)
+ (jao-shell-cmd-lines
+ (format "find %s -mindepth 2 -maxdepth 3 -type d" d)))
+ jao-dirmon-roots))
(defun jao-dirmon-sizes ()
(mapcar (lambda (f)
- (let ((x (split-string (jao-shell-string "du -s" f))))
+ (let ((x (split-string (jao-shell-string "du -BM -s" f))))
(cons (cadr x) (string-to-number (car x)))))
(jao-dirmon-dirs)))
-(defvar jao-dirmon-threshold 100000)
+(defvar jao-dirmon-threshold 100)
(defvar jao-dirmon-last-delta nil)
+(defvar jao-dirmon-buffer "*jao-dirmon")
+
+(defun jao-dirmon--show-deltas (old current deltas)
+ (with-current-buffer (get-buffer-create jao-dirmon-buffer)
+ (view-mode-disable)
+ (delete-region (point-min) (point-max))
+ (insert "High deltas since " (car old) "\n\n")
+ (dolist (d (seq-sort-by #'cdr #'> deltas))
+ (insert (format "- %s: %s Mb\n" (car d) (cdr d))))
+ (insert "\n\nSizeable dirs\n\n")
+ (let ((threshold (* 10 jao-dirmon-threshold)))
+ (dolist (c (seq-take-while (lambda (x) (> (cdr x) threshold))
+ (seq-sort-by #'cdr #'> current)))
+ (insert (format "- %s: %s Mb\n" (car c) (cdr c)))))
+ (beginning-of-buffer)
+ (view-mode-enable)
+ (pop-to-buffer (current-buffer) nil t)
+ (when (y-or-n-p "Save current state?")
+ (setf (multisession-value jao-dirmon-last)
+ (cons (current-time-string) current)))))
;;;###autoload
(defun jao-dirmon-report ()
@@ -49,12 +75,10 @@
(high ()))
(dolist (c current)
(let ((d (- (cdr c) (alist-get (car c) old 0 nil #'string=))))
- (when (> d jao-dirmon-threshold)
- (push c high))))
+ (when (> (abs d) jao-dirmon-threshold)
+ (push (cons (car c) d) high))))
(setq jao-dirmon-last-delta high)
- (let ((prompt (format"High deltas: %s. Save state?" high)))
- (when (y-or-n-p prompt)
- (setf (multisession-value jao-dirmon-last) current)))
+ (jao-dirmon--show-deltas old current jao-dirmon-last-delta)
jao-dirmon-last-delta))
(provide 'jao-dirmon)
diff --git a/lib/eos/jao-ednc.el b/lib/eos/jao-ednc.el
index 5750ea7..92ee21f 100644
--- a/lib/eos/jao-ednc.el
+++ b/lib/eos/jao-ednc.el
@@ -1,6 +1,6 @@
;;; jao-ednc.el --- Minibuffer notifications using EDNC -*- lexical-binding: t; -*-
-;; Copyright (C) 2020, 2021 jao
+;; Copyright (C) 2020, 2021, 2024 jao
;; Author: jao <mail@jao.io>
;; Keywords: tools, abbrev
@@ -91,9 +91,8 @@
(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)
+ (setq jao-notify-use-messages t)
(with-eval-after-load "tracking"
(when jao-ednc-use-tracking
(add-to-list 'tracking-faces-priorities 'jao-ednc-tracking)
@@ -104,19 +103,16 @@
(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)
@@ -124,7 +120,6 @@
(message "No active notifications"))
(jao-ednc--clean))
-;;;###autoload
(defun jao-ednc-dismiss ()
(interactive)
(when (jao-ednc--last-notification)
@@ -133,7 +128,12 @@
(ednc-dismiss-notification (jao-ednc--last-notification)))))
(jao-ednc--clean))
-;;;###autoload
+(defun jao-ednc-dismiss-and-show ()
+ (interactive)
+ (let ((m (jao-ednc--format-last)))
+ (jao-ednc-dismiss)
+ (when m (message m))))
+
(defun jao-ednc-dismiss-all ()
(interactive)
(while (jao-ednc--last-notification)
diff --git a/lib/eos/jao-eshell-here.el b/lib/eos/jao-eshell-here.el
index cf29e31..54d58f0 100644
--- a/lib/eos/jao-eshell-here.el
+++ b/lib/eos/jao-eshell-here.el
@@ -1,6 +1,6 @@
;;; jao-eshell-here.el --- Easy opening of eshell buffers -*- lexical-binding: t; -*-
-;; Copyright (C) 2021 jao
+;; Copyright (C) 2021, 2023 jao
;; Author: jao <mail@jao.io>
;; Keywords: eshell
@@ -64,7 +64,7 @@ C-u) open in the current's buffer default dir."
(jao-with-attached-buffer "^\\*eshell" 0.5
(if (buffer-live-p b)
(progn (pop-to-buffer b nil t)
- (eshell-save-some-history)
+ ;; (eshell-save-some-history)
(when dir (jao-eshell--cd-here dir)))
(let ((default-directory (or dir default-directory)))
(eshell (when force-new 4)))
@@ -75,7 +75,7 @@ C-u) open in the current's buffer default dir."
(when (derived-mode-p 'eshell-mode)
(when (fboundp 'eshell-autojump-save)
(eshell-autojump-save))
- (eshell-save-some-history)
+ ;; (eshell-save-some-history)
(if (> (frame-height) (window-height))
(delete-window)
(bury-buffer))))
diff --git a/lib/eos/jao-minibuffer.el b/lib/eos/jao-minibuffer.el
index bdafa74..05750ca 100644
--- a/lib/eos/jao-minibuffer.el
+++ b/lib/eos/jao-minibuffer.el
@@ -1,6 +1,6 @@
;;; jao-minibuffer.el --- using the minibuffer to report status -*- lexical-binding: t; -*-
-;; Copyright (C) 2020, 2021, 2022 jao
+;; Copyright (C) 2020, 2021, 2022, 2024, 2025 jao
;; Author: jao <mail@jao.io>
;; Keywords: extensions
@@ -27,18 +27,20 @@
(defvar jao-minibuffer-info ())
(defvar jao-minibuffer-msg-info '(""))
(defvar jao-minibuffer-align-right t)
-(defvar jao-minibuffer-right-margin (if window-system 0 2))
+(defvar jao-minibuffer-adaptive-alignment t)
+(defvar jao-minibuffer-right-margin (if window-system 0 1))
(defvar jao-minibuffer-maximized-frames-p t)
(defvar jao-minibuffer-frame-width nil)
(defvar jao-minibuffer-active-buffer-line-color "azure4")
(defvar jao-minibuffer-inactive-buffer-line-color "grey25")
+(defvar jao-minibuffer-inhibit nil)
(defconst jao-minibuffer--name " *Minibuf-0*")
(defun jao-minibuffer--trim (s w)
(if (< (string-width (or s "")) w)
(format (format "%%%ds" (if jao-minibuffer-align-right w (- w))) s)
- (substring s 0 w)))
+ (substring s 0 (min w (string-width s)))))
(defun jao-minibuffer--width ()
(cond ((numberp jao-minibuffer-frame-width) jao-minibuffer-frame-width)
@@ -57,19 +59,17 @@
(msg (cond (jao-minibuffer-align-right (string-trim msg))
(t (string-trim-left msg)))))
(unless (string-empty-p msg)
- (let ((msg (propertize msg :minibuffer-message t))
+ (let ((msg (propertize msg 'minibuffer-message t))
(w (- (jao-minibuffer--width) w jao-minibuffer-right-margin)))
(if (> w 0) (jao-minibuffer--trim msg w) "")))))
(defun jao-minibuffer--insert (msg)
- (let ((hack (derived-mode-p 'pdf-view-mode 'doc-view-mode)))
- (with-current-buffer jao-minibuffer--name
- (delete-region (point-min) (point-max))
- (insert msg)
- (when hack (other-window 1) (other-window -1)))))
+ (with-current-buffer jao-minibuffer--name
+ (delete-region (point-min) (point-max))
+ (insert msg)))
(defun jao-minibuffer--strip-prev (msg)
- (if-let ((n (text-property-any 0 (length msg) :minibuffer-message t msg)))
+ (if-let ((n (text-property-any 0 (length msg) 'minibuffer-message t msg)))
(string-trim (substring msg 0 n))
msg))
@@ -78,16 +78,39 @@
(unless (string-blank-p p) (concat p "\n"))))
(defun jao-minibuffer--format-msg (msg)
- (let* ((msgs (mapcar #'jao-minibuffer--strip-prev (split-string msg "\n")))
+ (let* ((msgs (mapcar #'jao-minibuffer--strip-prev (split-string msg "\n" t)))
+ (msgs (cl-remove-if (lambda (s) (get-text-property 0 'invisible s)) msgs))
(prefix (jao-minibuffer--prefix msgs))
- (msg (car (last msgs)))
+ (msg (or (car (last msgs)) ""))
(w (string-width msg)))
(if jao-minibuffer-align-right
(concat prefix msg (jao-minibuffer--aligned w))
(concat prefix (jao-minibuffer--aligned (+ 3 w)) " " msg))))
(defun jao-minibuffer--set-message (msg)
- (when jao-minibuffer-mode (jao-minibuffer--format-msg (or msg ""))))
+ (when jao-minibuffer-mode
+ (or (and (string= jao-minibuffer--name (or (buffer-name) "")) msg)
+ jao-minibuffer-inhibit
+ (let* ((info (and jao-minibuffer-msg-info
+ (jao-minibuffer--format-info
+ jao-minibuffer-msg-info)))
+ (info (or (and info msg (propertize info 'face 'jao-themes-dimm))
+ info))
+ (sep (if (string-empty-p info) "" " - "))
+ (pref (when info
+ (let ((len (+ (string-width info) (string-width sep))))
+ (format (format "\n%%%ds" len) ""))))
+ (msg (if (and msg pref)
+ (replace-regexp-in-string "\n" pref msg)
+ msg))
+ (left (if jao-minibuffer-align-right info (or msg "")))
+ (right (if jao-minibuffer-align-right (or msg "") info))
+ (msg (or (if info (format "%s%s%s" left sep right) msg) "")))
+ (if cursor-in-echo-area msg (jao-minibuffer--format-msg msg))))))
+
+(defun jao-minibuffer--clear-message ()
+ (let ((jao-minibuffer-inhibit nil))
+ (or (jao-minibuffer--insert (jao-minibuffer--set-message nil)) t)))
(setq set-message-function #'jao-minibuffer--set-message)
@@ -96,35 +119,38 @@
(set list-name (remove v (symbol-value list-name)))
(add-to-ordered-list list-name v order)))
-;;;###autoload
+(defun jao-minibuffer--adjust-alignment (&rest _)
+ (when jao-minibuffer-adaptive-alignment
+ (setq jao-minibuffer-align-right
+ (< (or (car (window-absolute-pixel-edges)) 0)
+ (/ (or (cadr (assoc 'outer-size (frame-geometry))) 0) 2))))
+ (jao-minibuffer-refresh))
+
(defun jao-minibuffer-add-variable (variable-name &optional order)
(jao-minibuffer--add-variable 'jao-minibuffer-info variable-name order))
-;;;###autoload
(defun jao-minibuffer-add-msg-variable (variable-name &optional order)
(jao-minibuffer--add-variable 'jao-minibuffer-msg-info variable-name order))
-;;;###autoload
(defun jao-minibuffer-remove-variable (variable-name)
(let ((v `(:eval ,variable-name)))
(setq jao-minibuffer-info (remove v jao-minibuffer-info))
- (setq jao-minibuffer-msg-info (remove v jao-minibuffer-info))))
+ (setq jao-minibuffer-msg-info (remove v jao-minibuffer-msg-info))))
-;;;###autoload
(define-minor-mode jao-minibuffer-mode
"Show minibuffer status"
:global t :lighter "" :group 'jao
(if jao-minibuffer-mode
- (progn (advice-add 'select-window :after #'jao-minibuffer-refresh)
+ (progn ;; (advice-add 'select-window :after #'jao-minibuffer-refresh)
+ (advice-add 'select-window :after #'jao-minibuffer--adjust-alignment)
(advice-add 'force-mode-line-update :after #'jao-minibuffer-refresh)
- (setq clear-message-function #'jao-minibuffer-refresh)
+ (setq clear-message-function #'jao-minibuffer--clear-message)
(jao-minibuffer-refresh))
(advice-remove 'select-window #'jao-minibuffer-refresh)
(advice-remove 'force-mode-line-update #'jao-minibuffer-refresh)
(setq clear-message-function nil)
(jao-minibuffer--insert "")))
-;;;###autoload
(defun jao-minibuffer-refresh (&rest _ignore)
(interactive)
(when jao-minibuffer-mode
@@ -133,5 +159,30 @@
(jao-minibuffer--format-info jao-minibuffer-msg-info))))
(jao-minibuffer--insert (jao-minibuffer--format-msg (or msg ""))))))
+(defun jao-minibuffer-toggle-adaptive-alignment ()
+ (interactive)
+ (setq jao-minibuffer-adaptive-alignment
+ (not jao-minibuffer-adaptive-alignment))
+ (jao-minibuffer-refresh))
+
+(define-minor-mode jao-minibuffer-mode-line-mode
+ "Show info in mode line instead of minibuffer"
+ :global t :lighter "" :group 'jao
+ (let ((e '(" " (:eval jao-minibuffer-info))))
+ (if jao-minibuffer-mode-line-mode
+ (add-to-list 'global-mode-string e)
+ (setq global-mode-string (delete e global-mode-string)))))
+
+(defvar jao-minibuffer--title-format nil)
+
+(define-minor-mode jao-minibuffer-frame-title-mode
+ "Show info in frame title instead of minibuffer"
+ :global t :lighter "" :group 'jao
+ (when (not jao-minibuffer--title-format)
+ (setq jao-minibuffer--title-format frame-title-format))
+ (if jao-minibuffer-frame-title-mode
+ (setq frame-title-format '("emacs - " (:eval jao-minibuffer-info)))
+ (setq frame-title-format jao-minibuffer--title-format)))
+
(provide 'jao-minibuffer)
;;; jao-minibuffer.el ends here
diff --git a/lib/eos/jao-mode-line.el b/lib/eos/jao-mode-line.el
index 0fd5a2e..0dd1abd 100644
--- a/lib/eos/jao-mode-line.el
+++ b/lib/eos/jao-mode-line.el
@@ -1,6 +1,6 @@
;;; jao-mode-line.el --- mode-line info -*- lexical-binding: t; -*-
-;; Copyright (C) 2022 jao
+;; Copyright (C) 2022, 2025 jao
;; Author: jao <mail@jao.io>
;; Keywords: convenience
@@ -41,17 +41,24 @@
;;;###autoload
(defun jao-mode-line-toggle (&optional all)
(interactive "P")
- (jao-mode-line--face-height 'mode-line all))
+ (jao-mode-line--face-height 'mode-line-active all))
;;;###autoload
(defun jao-mode-line-toggle-inactive (&optional all)
(interactive "P")
(jao-mode-line--face-height 'mode-line-inactive all))
+(defun jao-mode-line--old-str ()
+ (thread-first (format-mode-line jao-mode-line--old-format)
+ (substring-no-properties)
+ (string-trim)))
+
;;;###autoload
(defun jao-mode-line-echo ()
(interactive)
- (message "%s" (format-mode-line mode-line-format)))
+ (message "%s" (jao-mode-line--old-str))
+ (setq-local header-line-format
+ (if header-line-format nil jao-mode-line--old-format)))
;;;###autoload
(defun jao-mode-line-hide-inactive (frame)
@@ -78,8 +85,8 @@
'gnus-article-mode
'gnus-summary-mode)
mode-line-buffer-identification)
- ((derived-mode-p 'circe-channel-mode)
- (format "%s [%d]" (buffer-name) (length (circe-channel-nicks))))
+ ;; ((derived-mode-p 'circe-channel-mode)
+ ;; (format "%s [%d]" (buffer-name) (length (circe-channel-nicks))))
((not (null eww-data))
(or (plist-get eww-data :title) "No title"))
(t "%b"))))
@@ -101,7 +108,7 @@
;;;; mode line in minibuffer
-(defvar jao-mode-line--old-format nil)
+(defvar jao-mode-line--old-format mode-line-format)
(defvar jao-mode-line--face nil)
(defvar jao-mode-line--inactive-face nil)
(defvar jao-mode-line--props
@@ -120,32 +127,52 @@
(if inactive jao-mode-line--inactive-face jao-mode-line--face)))
(defun jao-mode-line-adjust-faces ()
- (let ((bg (frame-parameter nil 'background-color)))
+ (interactive)
+ (let ((bg (and (display-graphic-p)
+ (frame-parameter nil 'background-color)))
+ (ol (and (display-graphic-p) jao-minibuffer-active-buffer-line-color))
+ (ul (and (display-graphic-p)
+ jao-minibuffer-inactive-buffer-line-color)))
(jao-mode-line--extract-face nil)
(jao-mode-line--extract-face t)
(set-face-attribute 'mode-line nil :box nil :height 1
:background bg :foreground bg
- :overline jao-minibuffer-active-buffer-line-color
- :underline jao-minibuffer-inactive-buffer-line-color
- :extend t)
+ :overline ol :underline ul :extend t)
(set-face-attribute 'mode-line-inactive nil :box nil :height 1
:background bg :foreground bg
;; :overline bg
- :underline jao-minibuffer-inactive-buffer-line-color
- :extend t)))
+ :underline ul :extend t)))
-;;;###autoload
-(defun jao-mode-line-add-to-minibuffer (&optional order)
+(defun jao-mode-line--maybe-refresh ()
+ (when (mode-line-window-selected-p) (jao-minibuffer-refresh)))
+
+(defconst jao-mode-line--hidden-format
+ '("" (:eval (jao-mode-line--maybe-refresh))))
+
+(defun jao-mode-line--add-to-minibuffer (order msg-p)
(interactive)
(setq jao-mode-line--old-format mode-line-format)
- (setq-default mode-line-format '(" "))
+ (setq-default mode-line-format jao-mode-line--hidden-format)
(setq-default mode-line-position jao-mode-line--position)
(dolist (b (buffer-list))
- (with-current-buffer b (setq-local mode-line-format '(" "))))
- (jao-minibuffer-add-variable 'jao-mode-line--format (or order 90))
+ (with-current-buffer b
+ (setq-local mode-line-format jao-mode-line--hidden-format)))
+ (if msg-p
+ (jao-minibuffer-add-msg-variable '(jao-mode-line--old-str) (or order 90))
+ (jao-minibuffer-add-variable 'jao-mode-line--format (or order 90)))
(jao-mode-line-adjust-faces))
;;;###autoload
+(defun jao-mode-line-add-to-minibuffer-right (&optional order)
+ (interactive)
+ (jao-mode-line--add-to-minibuffer order nil))
+
+;;;###autoload
+(defun jao-mode-line-add-to-minibuffer-left (&optional order)
+ (interactive)
+ (jao-mode-line--add-to-minibuffer order t))
+
+;;;###autoload
(defun jao-mode-line-remove-from-minibuffer ()
(interactive)
(jao-mode-line--revert-face nil)
@@ -154,7 +181,8 @@
(dolist (b (buffer-list))
(with-current-buffer b
(setq-local mode-line-format jao-mode-line--old-format)))
- (jao-minibuffer-remove-variable 'jao-mode-line--format))
+ (jao-minibuffer-remove-variable 'jao-mode-line--format)
+ (jao-minibuffer-remove-variable '(jao-mode-line--old-str)))
(provide 'jao-mode-line)
diff --git a/lib/eos/jao-notify.el b/lib/eos/jao-notify.el
index a3ea474..8389b3a 100644
--- a/lib/eos/jao-notify.el
+++ b/lib/eos/jao-notify.el
@@ -1,6 +1,6 @@
;; jao-notify.el -- Interacting with notification daemon
-;; Copyright (c) 2017, 2019, 2020, 2021 Jose Antonio Ortega Ruiz
+;; Copyright (c) 2017, 2019, 2020, 2021, 2024, 2025 Jose Antonio Ortega Ruiz
;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
;; Start date: Sun Jan 08, 2017 20:24
@@ -12,26 +12,35 @@
;;; Code:
-(defvar jao-notify-use-messages-p nil)
+(defvar jao-notify-use-messages nil)
(defvar jao-notify-timeout 5000)
(defvar jao-notify-audio-icon (jao-data-file "music-player-icon.png"))
(declare-function notifications-notify "notifications")
+(declare-function alert "alert")
+(declare-function jao-mac-notify "jao-mac")
;; "/usr/share/icons/Papirus/64x64/mimetypes/audio-x-generic.svg"
;; "/usr/share/icons/Tango/scalable/mimetypes/audio-x-generic.svg"
-(defun jao-notify (msg &optional title icon)
+(defun jao-notify (msg &optional title icon subtitle)
(let ((title (when (and title (not (string-blank-p title))) title)))
- (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)))))
+ (cond ((eq jao-notify-use-messages t)
+ (message "%s%s%s" (or title "") (if title ": " "") (or msg "")))
+ ((eq jao-notify-use-messages 'notification)
+ (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)))
+ ((eq jao-notify-use-messages 'alert)
+ (alert msg :title title :icon icon :never-persist t))
+ ((eq jao-notify-use-messages 'mac)
+ (jao-mac-notify title subtitle msg)))))
(provide 'jao-notify)
diff --git a/lib/eos/jao-r2e.el b/lib/eos/jao-r2e.el
new file mode 100644
index 0000000..09b4504
--- /dev/null
+++ b/lib/eos/jao-r2e.el
@@ -0,0 +1,228 @@
+;;; jao-r2e.el --- List of rss2email subscriptions -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2025 Jose Antonio Ortega Ruiz
+
+;; Author: Jose Antonio Ortega Ruiz <mail@jao.io>
+;; Keywords: news
+
+;; 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/>.
+
+(require 'jao-url)
+
+(autoload 'View-quit "view")
+(autoload 'eww-view-source "eww")
+(autoload 'jao-notmuch-subtags "jao-notmuch")
+
+(defvar jao-r2e-confirm-toggle nil)
+
+(defconst jao-r2e--buffer "*r2e*")
+(defun jao-r2e--buffer ()
+ (with-current-buffer (get-buffer-create jao-r2e--buffer)
+ (unless (derived-mode-p 'jao-r2e-mode)
+ (jao-r2e-mode))
+ (current-buffer)))
+
+(defvar jao-r2e-mode-map
+ (let ((map (make-keymap)))
+ (suppress-keymap map)
+ (define-key map [?q] 'bury-buffer)
+ (define-key map [?n] 'next-line)
+ (define-key map [?p] 'previous-line)
+ (define-key map [?N] 'jao-r2e-next)
+ (define-key map [?P] 'jao-r2e-prev)
+ (define-key map [?g] 'jao-r2e-list)
+ (define-key map [?s] 'jao-r2e-subscribe)
+ (define-key map [?t] 'jao-r2e-toggle)
+ (define-key map [?D] 'jao-r2e-delete)
+ (define-key map [?u] 'jao-r2e-recover)
+ (define-key map [?y] 'jao-r2e-kill-url)
+ (define-key map [?x] 'jao-r2e-list-subscribed)
+ map))
+
+;;;###autoload
+(defun jao-r2e-mode ()
+ "A very simple mode to show the output of r2e commands."
+ (interactive)
+ (kill-all-local-variables)
+ (buffer-disable-undo)
+ (use-local-map jao-r2e-mode-map)
+ ;; (setq-local font-lock-defaults '(jao-r2e-font-lock-keywords))
+ (setq-local truncate-lines t)
+ (setq-local next-line-add-newlines nil)
+ (setq major-mode 'jao-r2e-mode)
+ (setq mode-name "r2e")
+ (read-only-mode 1))
+
+(defun jao-r2e--do (things &optional buffer)
+ "Execute a r2e command THINGS in the given BUFFER."
+ (let ((b (or buffer (pop-to-buffer (jao-r2e--buffer)))))
+ (let ((inhibit-read-only t)
+ (cmd (format "r2e %s" things)))
+ (unless buffer
+ (with-current-buffer b (delete-region (point-min) (point-max))))
+ (with-temp-message (format "Running: %s ...." cmd)
+ (shell-command cmd b))
+ (unless buffer (read-only-mode 1)))))
+
+(defconst jao-r2e--feed-rx
+ "^\\([0-9]+\\): \\[\\( \\|\\*\\)\\] \\([^ ]+\\) (\\(.+\\) -> \\(.+\\))")
+
+(defun jao-r2e--feed-at-point ()
+ (beginning-of-line)
+ (when-let* ((m (looking-at jao-r2e--feed-rx)))
+ (list (match-string 1)
+ (match-string 3)
+ (string= "*" (match-string 2))
+ (match-string 4)
+ (match-string 5))))
+
+(defun jao-r2e ()
+ (interactive)
+ (pop-to-buffer (jao-r2e--buffer))
+ (when (looking-at-p "^$")
+ (jao-r2e-list)))
+
+(defun jao-r2e-list ()
+ (interactive)
+ (jao-r2e--do "list"))
+
+(defun jao-r2e-list-subscribed (arg)
+ "Show only subscribed (unsubscribed with arg) feeds."
+ (interactive "P")
+ (jao-r2e-list)
+ (let ((inhibit-read-only t))
+ (flush-lines (if arg ".*\\[\\*\\].*" ".*\\[ \\].*"))))
+
+(defun jao-r2e--srx (opp)
+ (when-let* ((f (jao-r2e--feed-at-point)))
+ (let ((a (if opp (not (caddr f)) (caddr f))))
+ (format "^[0-9]+: \\[%s\\] " (if a "\\*" " ")))))
+
+(defun jao-r2e-next (opp)
+ "Next feed with the same (or opposite) status."
+ (interactive "P")
+ (when-let* ((rx (jao-r2e--srx opp)))
+ (next-line)
+ (when (re-search-forward rx nil t)
+ (beginning-of-line))))
+
+(defun jao-r2e-prev (opp)
+ "Previous feed with the same (or opposite) status."
+ (interactive "P")
+ (when-let* ((rx (jao-r2e--srx opp)))
+ (when (re-search-backward rx nil t)
+ (beginning-of-line))))
+
+(defun jao-r2e-kill-url ()
+ "Copy as kill the URL of the feed at point."
+ (interactive)
+ (let ((url (cadddr (jao-r2e--feed-at-point))))
+ (if (not url)
+ (error "No feed at point")
+ (kill-new url)
+ (message "%s" url))))
+
+(defun jao-r2e-toggle ()
+ (interactive)
+ (let ((f (jao-r2e--feed-at-point)))
+ (unless f (error "No feed at point"))
+ (let ((p (point))
+ (no (car f))
+ (name (cadr f))
+ (act (if (caddr f) "pause" "unpause")))
+ (when (or (not jao-r2e-confirm-toggle)
+ (yes-or-no-p (format "%s '%s'? " act name)))
+ (with-temp-buffer
+ (jao-r2e--do (format "%s %s" act no) (current-buffer)))
+ (jao-r2e-list)
+ (goto-char p)))))
+
+(define-multisession-variable jao-r2e-deleted-feeds '()
+ "List of rss2email feeds deleted at some point.")
+
+(defun jao-r2e--deleted () (multisession-value jao-r2e-deleted-feeds))
+
+(defun jao-r2e-delete ()
+ "Delete feed at point. Use `jao-r2e-recover' to undelete."
+ (interactive)
+ (let ((f (jao-r2e--feed-at-point)))
+ (unless f (error "No feed at point"))
+ (let ((p (point))
+ (no (car f))
+ (entry (cdr f)))
+ (when (yes-or-no-p (format "Delete feed '%s'" (car entry)))
+ (setf (multisession-value jao-r2e-deleted-feeds)
+ (cons entry (remove entry (jao-r2e--deleted))))
+ (with-temp-buffer
+ (jao-r2e--do (format "delete %s" no) (current-buffer)))
+ (jao-r2e-list)
+ (goto-char p)))))
+
+(defun jao-r2e-recover ()
+ (interactive)
+ (when (seq-empty-p (jao-r2e--deleted))
+ (error "No feeds recoverable at this point."))
+ (let* ((entries (jao-r2e--deleted))
+ (feed (completing-read "Recover feed: " entries)))
+ (when-let* ((ps (assoc feed entries))
+ (url (caddr ps))
+ (mail (car (last ps)))
+ (cat (when (string-match "feeds\\.\\(.+\\)@localhost" mail)
+ (match-string 1 mail))))
+ (jao-r2e-subscribe (list url feed) cat t)
+ (setf (multisession-value jao-r2e-deleted-feeds) (remove ps entries)))))
+
+(defun jao-r2e--find-url ()
+ (save-excursion
+ (when (derived-mode-p 'w3m-mode 'eww-mode)
+ (if (fboundp 'w3m-view-source) (w3m-view-source) (eww-view-source)))
+ (goto-char (point-min))
+ (when (re-search-forward
+ "type=\"application/\\(?:atom\\|rss\\)\\+xml\" +" nil t)
+ (let ((url (save-excursion
+ (when (re-search-forward
+ "href=\"\\([^\n\"]+\\)\"" nil t)
+ (match-string-no-properties 1))))
+ (title (when (re-search-forward
+ "\\(?:title=\"\\([^\n\"]+\\)\" +\\)" nil t)
+ (match-string-no-properties 1))))
+ (cond ((derived-mode-p 'w3m-view-mode) (w3m-view-source))
+ ((string-match-p ".*\\*eww-source\\b.*" (buffer-name))
+ (View-quit)))
+ (when url (cons url (or title "")))))))
+
+(defun jao-r2e-subscribe (url &optional cat relist)
+ "Subscribe to a given RSS URL. If URL not given, look for it."
+ (interactive (list (or (jao-url-around-point)
+ (jao-r2e--find-url)
+ (read-string "Feed URL: "))))
+ (let* ((url+title (ensure-list url))
+ (url (car url+title))
+ (title (cdr url+title)))
+ (unless url (error "No feeds found"))
+ (let ((url (if (string-match "^feed:" url) (substring url 5) url)))
+ (when (y-or-n-p (format "Subscribe to <%s>? " url))
+ (let* ((name (read-string "Feed name: " title))
+ (cats (cons "prog" (jao-notmuch-subtags "feeds")))
+ (cat (completing-read "Category: " cats nil t cat))
+ (subs (format "r2e add %s '%s' feeds.%s@localhost"
+ name url cat)))
+ (with-temp-message "Subscribing..."
+ (shell-command-to-string subs))
+ (with-temp-message "Retrieving feed..."
+ (shell-command (format "r2e run %s" name)))
+ (when relist (jao-r2e-list)))))))
+
+(provide 'jao-r2e)
+;;; jao-r2e.el ends here
diff --git a/lib/eos/jao-shell.el b/lib/eos/jao-shell.el
index ff1c160..86bf46b 100644
--- a/lib/eos/jao-shell.el
+++ b/lib/eos/jao-shell.el
@@ -24,25 +24,29 @@
;;; Code:
-(defun jao-shell--quote (x) (shell-quote-argument (format "%s" x)))
-
-;;;###autoload
(defun jao-shell-cmd-lines (cmd &rest args)
- (let ((cmd (concat cmd " " (mapconcat #'jao-shell--quote args " "))))
+ (let ((cmd (concat cmd " " (combine-and-quote-strings args))))
(split-string (shell-command-to-string cmd) "\n" t)))
-;;;###autoload
(defun jao-shell-string (cmd &rest args)
(string-trim (or (car (apply #'jao-shell-cmd-lines cmd args)) "")))
-;;;###autoload
-(defun jao-shell-exec (command)
+(defun jao-shell-exec (command &optional wait)
(interactive
(list (read-shell-command "$ "
(if current-prefix-arg
(cons (concat " " (buffer-file-name)) 0)
""))))
- (start-process-shell-command command nil command))
+ (if wait
+ (call-process-shell-command command)
+ (start-process-shell-command command nil command)))
+
+(defun jao-shell-exec* (command-or-wait &rest args)
+ (let ((wait (and (not (stringp command-or-wait)) command-or-wait))
+ (args (if (stringp command-or-wait) (cons command-or-wait args) args)))
+ (jao-shell-exec (combine-and-quote-strings args) wait)))
+
+(defun jao-shell-exec-p (command) (eq 0 (jao-shell-exec command t)))
(defmacro jao-shell-def-exec (name &rest args)
`(defun ,name (&rest other-args)
@@ -52,9 +56,14 @@
"*jao-exec - console*"
(string-join (append (list ,@args) other-args) " "))))
-;;;###autoload
-(defun jao-shell-running-p (pr)
- (not (string-blank-p (shell-command-to-string (concat "pidof " pr)))))
+(defun jao-shell-output (cmd handler)
+ (with-temp-buffer
+ (call-process-shell-command cmd nil (current-buffer))
+ (beginning-of-buffer)
+ (funcall handler)))
+
+(defun jao-shell-running-p (pr) (eq 0 (jao-shell-exec* t "pidof" pr)))
+(defun jao-shell-kill-p (pr) (eq 0 (jao-shell-exec* t "killall" pr)))
(provide 'jao-shell)
;;; jao-shell.el ends here
diff --git a/lib/eos/jao-sleep.el b/lib/eos/jao-sleep.el
index 93da0e7..b047373 100644
--- a/lib/eos/jao-sleep.el
+++ b/lib/eos/jao-sleep.el
@@ -41,12 +41,12 @@
"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))))
+ (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 ()
diff --git a/lib/eos/jao-tracking.el b/lib/eos/jao-tracking.el
index 520116d..2af868c 100644
--- a/lib/eos/jao-tracking.el
+++ b/lib/eos/jao-tracking.el
@@ -1,6 +1,6 @@
-;;; jao-minibuffer-tracking.el --- Tracking notifications in minibuffer -*- lexical-binding: t; -*-
+;; jao-minibuffer-tracking.el --- Tracking notifications -*- lexical-binding: t; -*-
-;; Copyright (C) 2021 jao
+;; Copyright (C) 2021, 2022, 2024 jao
;; Author: jao <mail@jao.io>
;; Keywords: convenience
@@ -18,33 +18,33 @@
;; 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
(require 'tracking)
(require 'shorten)
(require 'jao-minibuffer)
+(require 'jao-afio)
-
-;; shorten
+;;; shorten
+;;;###autoload
(defun jao-shorten-modes (&rest modes)
(dolist (m modes) (add-to-list 'tracking-shorten-modes m)))
-(defun jao-tracking--clean-slack (s)
- (let* ((s (replace-regexp-in-string
- "^\\*Slack - .*? : \\(mpdm-\\)?\\([^ ]+\\)\\( \\(T\\)\\)?.*"
- "#\\2\\4"
- s))
- (s (replace-regexp-in-string "logstash-\\([^-]+\\)-\\(.+\\)"
- "\\2-\\1"
- s)))
- (replace-regexp-in-string "^[^a-zA-Z#]+" "#" s)))
+(defvar jao-tracking-cleaners '(("^[^a-zA-Z#@]+" . "#")))
+
+;;;###autoload
+(defun jao-tracking-cleaner (rx subst)
+ (add-to-list 'jao-tracking-cleaners (cons rx subst)))
(defun jao-tracking-shorten-aggressively (lst tail-count)
- (let* ((s (shorten-join-sans-tail lst tail-count)))
+ (let ((s (shorten-join-sans-tail lst tail-count)))
(if (string-match-p "^#" s) (substring s 1 nil) s)))
(defun jao-tracking-split-clean (s)
- (shorten-split (jao-tracking--clean-slack s)))
+ (dolist (cln jao-tracking-cleaners)
+ (when (string-match (car cln) s)
+ (setq s (replace-match (cdr cln) nil nil s))))
+ (shorten-split s))
(defun jao-tracking-shorten (old-func &rest args)
(let ((shorten-join-function #'jao-tracking-shorten-aggressively)
@@ -53,14 +53,15 @@
(advice-add #'tracking-shorten :around #'jao-tracking-shorten)
-
-;; additional highlighting
+;;; additional highlighting
(defvar jao-tracking-highlight-rx "$^")
+;;;###autoload
(defun jao-tracking-faces (&rest faces)
(dolist (face faces)
(add-to-list 'tracking-faces-priorities face)))
+;;;###autoload
(defun jao-tracking-add-buffer (old-func &rest args)
(let* ((buffer (car args))
(faces (if (and buffer
@@ -73,8 +74,7 @@
(advice-add 'tracking-add-buffer :around #'jao-tracking-add-buffer)
(jao-tracking-faces 'lui-highlight-face)
-
-;; minibuffer
+;;; minibuffer
(defvar jao-tracking-string "")
(defvar jao-tracking-bkg "grey93")
@@ -84,11 +84,21 @@
`((t :foreground ,jao-tracking-bkg :background ,jao-tracking-bkg)) ""
:group 'faces)
+(defvar jao-tracking--pipe
+ (let ((name "/tmp/emacs.status"))
+ (unless (file-exists-p name)
+ (shell-command (format "mkfifo %s" name name)))
+ name))
+
(defun jao-tracking-set-log (v)
(when (member window-system '(x))
- (x-change-window-property "_EMACS_LOG" v nil nil nil nil 0)))
-
-(jao-tracking-set-log "")
+ (x-change-window-property "_EMACS_LOG" v nil nil nil nil 0))
+ (if jao-wayland-enabled
+ (let ((inhibit-message t))
+ (shell-command (format "echo \"%s\" > %s" v jao-tracking--pipe)))
+ (let* ((action (if (string-blank-p v) "remove" "add"))
+ (cmd (format "wmctrl -r emacs -b %s,demands_attention" action)))
+ (shell-command-to-string cmd))))
(defun jao-tracking--buffer-str (s)
(if (listp s)
@@ -114,10 +124,59 @@
(setq jao-tracking-string (jao-tracking-build-str new-val))
(jao-minibuffer-refresh))
-(jao-minibuffer-add-variable 'jao-tracking-string -10)
-(add-variable-watcher 'tracking-mode-line-buffers #'jao-tracking-echo)
-;; since we're using the minibuffer, forget the mode line
-(advice-add #'tracking-mode :override (lambda (&optional _) (interactive)))
+(defvar jao-tracking-use-scratch 5)
+(defvar jao-tracking--start-frame nil)
+
+(defun jao-tracking--remove-visible-buffers ()
+ (unless (and jao-afio-use-frames jao-tracking-use-scratch)
+ (tracking-remove-visible-buffers)))
+
+;;; package setup
+;;;###autoload
+(defun jao-tracking-go-to-chats ()
+ (interactive)
+ (when jao-tracking-use-scratch
+ (jao-afio-goto-nth jao-tracking-use-scratch)))
+
+;;;###autoload
+(defun jao-tracking-next-buffer ()
+ (interactive)
+ (if jao-tracking-use-scratch
+ (let ((k (if (numberp jao-tracking-use-scratch) jao-tracking-use-scratch 0))
+ (n (jao-afio-frame-no)))
+ (unless (eq k n) (setq jao-tracking--start-frame n))
+ (cond (tracking-buffers
+ (let ((bs tracking-buffers))
+ (if (eq k n)
+ (tracking-next-buffer)
+ (jao-afio-goto-nth k)
+ (when (and (car bs) (not (memq (current-buffer) bs)))
+ (pop-to-buffer (car bs)))
+ (tracking-remove-visible-buffers))))
+ (jao-tracking--start-frame
+ (jao-afio-goto-nth jao-tracking--start-frame)
+ (setq jao-tracking--start-frame nil))))
+ (tracking-next-buffer))
+ (jao-tracking-update-minibuffer))
+
+(defun jao-tracking-add-to-minibuffer ()
+ (interactive)
+ (jao-minibuffer-add-variable 'jao-tracking-string -10)
+ (add-variable-watcher 'tracking-mode-line-buffers #'jao-tracking-echo)
+ (advice-add #'tracking-mode :override (lambda (&optional _) (interactive))))
+
+(defun jao-tracking-remove-from-minibuffer ()
+ (interactive)
+ (jao-minibuffer-remove-variable 'jao-tracking-string)
+ (remove-variable-watcher 'tracking-mode-line-buffers #'jao-tracking-echo)
+ (advice-remove #'tracking-mode (lambda (&optional _) (interactive))))
+
+;;;###autoload
+(defun jao-tracking-setup (&optional minibuffer)
+ (when minibuffer (jao-tracking-add-to-minibuffer))
+ (add-hook 'jao-afio-switch-hook #'jao-tracking--remove-visible-buffers)
+ (global-set-key (kbd "C-c C-SPC") #'jao-tracking-next-buffer)
+ (define-key tracking-mode-map (kbd "C-c C-SPC") #'jao-tracking-next-buffer))
(provide 'jao-tracking)
;;; jao-minibuffer-tracking.el ends here
diff --git a/lib/eos/jao-wayland.el b/lib/eos/jao-wayland.el
new file mode 100644
index 0000000..9458ccb
--- /dev/null
+++ b/lib/eos/jao-wayland.el
@@ -0,0 +1,181 @@
+;;; jao-wayland.el --- interacting with wayland compositors -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2022, 2023 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/>.
+
+(require 'jao-shell)
+(require 'jao-pdf)
+(require 'jao-tracking)
+
+;;; wayland
+(defvar jao-wayland-enabled
+ (string= "wayland" (or (getenv "XDG_SESSION_TYPE") "")))
+
+(defsubst jao-wayland-type (&rest args)
+ (apply #'jao-shell-exec* t "wtype" args))
+
+;;; river
+(defvar jao-river-enabled (jao-shell-running-p "river"))
+(defun jao-river-enabled-p () jao-river-enabled)
+
+(defsubst jao-river-to-ws (n)
+ (jao-wayland-type "-M" "win" (format "%s" n)))
+
+(defsubst jao-river-window-list ()
+ (alist-get 'toplevels
+ (jao-shell-output "lswt -j"
+ (lambda ()
+ (let ((json-false nil)) (json-read))))))
+
+(defun jao-river-focused ()
+ (seq-some (lambda (w) (and (alist-get 'activated w) w))
+ (jao-river-window-list)))
+
+(defsubst jao-river-get-focused-title ()
+ (alist-get 'title (jao-river-focused)))
+
+(defsubst jao-river-get-focused-app-id ()
+ (alist-get 'app-id (jao-river-focused)))
+
+(defun jao-river-focus-window (title &optional rx)
+ (let* ((ws (jao-river-window-list))
+ (fltr (if rx #'string-match-p #'string=))
+ (w (seq-find (lambda (w)
+ (or (funcall fltr title (alist-get 'app_id w ""))
+ (funcall fltr title (alist-get 'title w ""))))
+ ws)))
+ (or (alist-get 'activated w)
+ (seq-some (lambda (_ignored)
+ (jao-shell-exec "riverctl focus-view next" t)
+ (or (funcall fltr title (jao-river-get-focused-app-id))
+ (funcall fltr title (jao-river-get-focused-title))))
+ (and w ws)))))
+
+(defun jao-river-zathura-to-org ()
+ (let ((title (jao-river-get-focused-title)))
+ (jao-river-to-ws 1)
+ (jao-org-open-from-zathura title t)))
+
+(defun jao-river-zathura-kill-link ()
+ (when-let* ((title (jao-river-get-focused-title))
+ (lnk (jao-pdf-zathura-org-link title)))
+ (jao-river-to-ws 1)
+ (kill-new lnk)
+ (message "Link to %s killed" title)))
+
+(defun jao-river-find-zathura-window (file)
+ (let ((frx (regexp-quote (file-name-nondirectory file))))
+ (seq-some (lambda (w)
+ (and (string-suffix-p ".zathura" (alist-get 'app_id w ""))
+ (string-match-p frx (alist-get 'title w ""))
+ w))
+ (jao-river-window-list))))
+
+(defun jao-river-open-with-zathura (file page)
+ (let ((wd (jao-river-find-zathura-window file)))
+ (jao-river-to-ws 3)
+ (or (and wd (jao-river-focus-window (alist-get 'title wd)))
+ (jao-shell-exec* "riverctl" "spawn" (jao-pdf-zathura-open-cmd file page)))
+ (when page (sit-for 0.2) (jao-wayland-type (format "%dg" page)))))
+
+(defun jao-river-set-wallpaper (f)
+ (jao-shell-kill-p "swaybg")
+ (jao-shell-exec* "riverctl" "spawn" (concat "swaybg -m fill -i " f)))
+
+(defun jao-river-restart-i3bar ()
+ (interactive)
+ (jao-shell-kill-p "i3bar-river")
+ (jao-shell-exec "riverctl spawn i3bar-river")
+ (sit-for 0.2)
+ (jao-tracking-set-log ""))
+
+(defun jao-river-toggle-emacs ()
+ (let ((erx "^p?emacs\\(client\\)?\\|\\(.* - emacs\\)"))
+ (if (or (string-match-p erx (jao-river-get-focused-title))
+ (string-match-p erx (jao-river-get-focused-app-id)))
+ (jao-shell-exec "riverctl focus-previous-tags")
+ (jao-river-to-ws 1)
+ (unless (jao-river-focus-window erx t)
+ (jao-shell-exec* "riverctl" "spawn" "efoot")))))
+
+(defun jao-river-toggle-firefox ()
+ (if (string-match-p "Firefox" (or (jao-river-get-focused-app-id) ""))
+ (jao-river-to-ws 1)
+ (jao-river-to-ws 2)
+ (unless (jao-river-focus-window "Firefox")
+ (jao-shell-exec* "riverctl" "spawn" "firefox"))))
+
+;;; sway
+(defun jao-sway-msg (msg)
+ (shell-command (format "swaymsg '%s' >/dev/null" msg)))
+
+(defmacro jao-def-swaymsg (name msg)
+ `(defun ,(intern (format "jao-sway-%s" name)) ()
+ (interactive)
+ (jao-sway-msg ,msg)))
+
+(jao-def-swaymsg firefox "[app_id=Firefox] focus")
+(jao-def-swaymsg pemacs "[app_id=pemacs] focus")
+
+(defvar jao-sway-enabled (jao-shell-running-p "sway"))
+
+(defconst jao-sway-get-active-title
+ "swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true).name'")
+
+(defconst jao-sway-get-active-app
+ "swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true).app_id'")
+
+(defun jao-sway-get-active-title ()
+ (let ((tl (jao-shell-string jao-sway-get-active-title)))
+ (and (string-match "\"\\(.+\\)\"" tl) (match-string 1 tl))))
+
+(defun jao-sway-get-active-app ()
+ (let ((tl (jao-shell-string jao-sway-get-active-app)))
+ (and (string-match "\"\\(.+\\)\"" tl) (match-string 1 tl))))
+
+(defun jao-sway-zathura-org ()
+ (jao-org-open-from-zathura (jao-sway-get-active-title) t))
+
+(defun jao-sway-open-with-zathura (file page)
+ (let* ((n (file-name-nondirectory file))
+ (m (format "[title=\"%s\" app_id=\".*zathura\"] focus" n)))
+ (jao-sway-msg "workspace number 3")
+ (unless (= 0 (jao-sway-msg m))
+ (jao-shell-exec (jao-pdf-zathura-open-cmd file page)))
+ (when page (sit-for 0.2) (jao-wayland-type (format "%dg" page)))))
+
+(defun jao-sway-set-wallpaper (f)
+ (jao-sway-msg (format "output * bg %s fill" f)))
+
+(defun jao-sway-run-or-focus (cmd &optional ws)
+ (if (jao-shell-running-p "firefox")
+ (jao-sway-msg (format "[app_id=%s] focus" cmd))
+ (jao-sway-msg (format "workspace %s" (or ws 2)))
+ (start-process-shell-command cmd nil cmd)))
+
+(defun jao-sway-run-or-focus-firefox ()
+ (interactive)
+ (jao-sway-run-or-focus "firefox"))
+
+(defun jao-sway-toggle-emacs ()
+ (if (string-match-p "p?emacs" (jao-sway-get-active-app))
+ (jao-sway-firefox)
+ (jao-sway-pemacs)))
+
+(provide 'jao-wayland)
+;;; jao-wayland.el ends here