summaryrefslogtreecommitdiffhomepage
path: root/lib/eos
diff options
context:
space:
mode:
Diffstat (limited to 'lib/eos')
-rw-r--r--lib/eos/jao-tracking.el124
1 files changed, 124 insertions, 0 deletions
diff --git a/lib/eos/jao-tracking.el b/lib/eos/jao-tracking.el
new file mode 100644
index 0000000..1397791
--- /dev/null
+++ b/lib/eos/jao-tracking.el
@@ -0,0 +1,124 @@
+;;; jao-minibuffer-tracking.el --- Tracking notifications in minibuffer -*- 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/>.
+
+;;; Code:
+
+(require 'tracking)
+(require 'shorten)
+(require 'jao-minibuffer)
+
+
+;; shorten
+(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)))
+ (replace-regexp-in-string "^[^a-zA-Z#]+" "#" s)))
+
+(defun jao-tracking-shorten-aggressively (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)))
+
+(defun jao-tracking-shorten (old-func &rest args)
+ (let ((shorten-join-function #'jao-tracking-shorten-aggressively)
+ (shorten-split-function #'jao-tracking-split-clean))
+ (apply old-func args)))
+
+(advice-add #'tracking-shorten :around #'jao-tracking-shorten)
+
+
+;; additional highlighting
+(defvar jao-tracking-highlight-rx "$^")
+
+(defun jao-tracking-faces (&rest faces)
+ (dolist (face faces)
+ (add-to-list 'tracking-faces-priorities face)))
+
+(defun jao-tracking-add-buffer (old-func &rest args)
+ (let* ((buffer (car args))
+ (faces (if (and buffer
+ (string-match-p jao-tracking-highlight-rx
+ (buffer-name buffer)))
+ (cons 'lui-highlight-face (cadr args))
+ (cadr args))))
+ (funcall old-func buffer faces)))
+
+(advice-add 'tracking-add-buffer :around #'jao-tracking-add-buffer)
+(jao-tracking-faces 'lui-highlight-face)
+
+
+;; minibuffer
+(defvar jao-tracking-string "")
+(defvar jao-tracking-bkg "grey93")
+
+(defface jao-tracking-minibuffer `((t :background ,jao-tracking-bkg)) ""
+ :group 'faces)
+(defface jao-tracking-minibuffer-sep
+ `((t :foreground ,jao-tracking-bkg :background ,jao-tracking-bkg)) ""
+ :group 'faces)
+
+(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 "")
+
+(defun jao-tracking--buffer-str (s)
+ (if (listp s)
+ `(:propertize ,(plist-get s :propertize)
+ face
+ (jao-tracking-minibuffer
+ ,@(when-let ((f (plist-get s 'face)))
+ (jao-tracking-set-log " * ")
+ (list f))))
+ `(:propertize "|" face jao-tracking-minibuffer-sep)))
+
+(defun jao-tracking-build-str (new-val)
+ (jao-tracking-set-log "")
+ (if (listp new-val)
+ (mapcar #'jao-tracking--buffer-str new-val)
+ new-val))
+
+(defun jao-tracking-update-minibuffer (&rest _)
+ (setq jao-tracking-string (jao-tracking-build-str (tracking-status)))
+ (jao-minibuffer-refresh))
+
+(advice-add 'force-mode-line-update :after #'jao-tracking-update-minibuffer)
+
+(defun jao-tracking-echo (_sym new-val _op _where)
+ (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)))
+
+(provide 'jao-tracking)
+;;; jao-minibuffer-tracking.el ends here