1
0
Fork 0

[oni-circe] Show channel status in polybar

I don't like that this global status thing shows up everywhere on the mode line,
which is already quite full with minor modes and the like. This way it's only
ever in one place.
This commit is contained in:
Tom Willemse 2022-08-26 22:05:51 -07:00
parent c7e5178a36
commit 375120e2dd

View file

@ -95,51 +95,52 @@ which may be encrypted."
(enable-circe-color-nicks)
(enable-circe-serenity)
;; (require 'mowedline)
;;; Polybar
;; This was originally written by retroj in his own configuration and shared
;; with me from when I was using mowedline. I've adapted the code to work for
;; polybar instead and renamed all of the functions.
;; (defun mowedline-colorize-mode-line-spec (s)
;; (cond
;; ((stringp s) (string-trim s))
;; ((eq ':propertize (car s))
;; (let ((s (cadr s))
;; (face (plist-get (cddr s) 'face)))
;; (if face
;; `(color ,(face-foreground face)
;; ,(substring-no-properties s))
;; s)))
;; (t "")))
(defvar oni-circe-tracking-buffers nil)
(defvar oni-circe-tracking-timer nil)
;; (setq mowedline-update-function 'mowedline-update/dbus)
(defun oni-circe-colorize (s)
"Turn any color description of S into one that Polybar understands."
(cond
((stringp s) (string-trim s))
((eq ':propertize (car s))
(let ((s (cadr s))
(face (plist-get (cddr s) 'face)))
(if face
(format "%%{F%s}%s%%{F-}"
(face-foreground face)
(substring-no-properties s))
s)))
(t "")))
;; (defvar jjf-tracking-buffers '())
;; (defvar jjf-external-tracking-timer nil)
;; (defun jjf-external-tracking ()
;; (setq jjf-external-tracking-timer nil)
;; (mowedline-update
;; 'irc
;; (if (stringp jjf-tracking-buffers)
;; (mowedline-colorize jjf-tracking-buffers t)
;; (format "%S" (mapcar #'mowedline-colorize-mode-line-spec
;; jjf-tracking-buffers)))))
(defun oni-circe-update-polybar ()
"Send a command to Polybar to update my Circe widget."
(setq oni-circe-tracking-timer nil)
(shell-command (format "polybar-msg action circe send %s"
(shell-quote-argument
(if (stringp oni-circe-tracking-buffers)
(oni-circe-colorize oni-circe-tracking-buffers)
(mapconcat #'oni-circe-colorize oni-circe-tracking-buffers))))))
;; (defun oni:clear-irc-mowedline-widget ()
;; (mowedline-clear 'irc))
(defun oni-circe-polybar-tracking (orig-fun &rest args)
"Update my external status bar when tracking computes a new status line.
;; (defun jjf-external-tracking-advice (orig-fun &rest args)
;; "Update my external status bar when tracking computes a new
;; status line, and suppress tracking in the mode-line. Since
;; tracking-status may be called many times in quick succession, for
;; example on a make-frame-visible event, we use a short timer to
;; only call the updater once within a minimum duration."
;; (setq jjf-tracking-buffers (apply orig-fun args))
;; (when jjf-external-tracking-timer
;; (cancel-timer jjf-external-tracking-timer))
;; (setq jjf-external-tracking-timer
;; (run-at-time 0.2 nil 'jjf-external-tracking))
;; nil)
Also suppress tracking in the mode-line. Since tracking-status
may be called many times in quick succession, for example on a
make-frame-visible event, we use a short timer to only call the
updater once within a minimum duration."
(setq oni-circe-tracking-buffers (apply orig-fun args))
(when oni-circe-tracking-timer
(cancel-timer oni-circe-tracking-timer))
(setq oni-circe-tracking-timer
(run-at-time 0.2 nil #'oni-circe-update-polybar))
nil)
;;(advice-add 'tracking-status :around #'jjf-external-tracking-advice)
;;(add-hook 'kill-emacs-hook 'oni:clear-irc-mowedline-widget)
(advice-add 'tracking-status :around #'oni-circe-polybar-tracking)
(add-hook 'circe-channel-mode-hook 'olivetti-mode)