aboutsummaryrefslogtreecommitdiffstats
path: root/oni-circe.el
diff options
context:
space:
mode:
authorGravatar Tom Willemse2022-08-26 22:05:51 -0700
committerGravatar Tom Willemse2022-08-26 22:05:51 -0700
commit375120e2dd61061b5abcb4912512a9543668ee39 (patch)
treef5dd00d7917850a1300e96280d1c66c610a9bc23 /oni-circe.el
parentc7e5178a36c6424a9535e775fd0e43a9de4abc21 (diff)
downloademacs-config-375120e2dd61061b5abcb4912512a9543668ee39.tar.gz
emacs-config-375120e2dd61061b5abcb4912512a9543668ee39.zip
[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.
Diffstat (limited to 'oni-circe.el')
-rw-r--r--oni-circe.el91
1 files changed, 46 insertions, 45 deletions
diff --git a/oni-circe.el b/oni-circe.el
index d3cfbf5..0a674de 100644
--- a/oni-circe.el
+++ b/oni-circe.el
@@ -95,51 +95,52 @@ which may be encrypted."
(enable-circe-color-nicks)
(enable-circe-serenity)
-;; (require 'mowedline)
-
-;; (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 "")))
-
-;; (setq mowedline-update-function 'mowedline-update/dbus)
-
-;; (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:clear-irc-mowedline-widget ()
-;; (mowedline-clear 'irc))
-
-;; (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)
-
-;;(advice-add 'tracking-status :around #'jjf-external-tracking-advice)
-;;(add-hook 'kill-emacs-hook 'oni:clear-irc-mowedline-widget)
+;;; 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.
+
+(defvar oni-circe-tracking-buffers nil)
+(defvar oni-circe-tracking-timer nil)
+
+(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 "")))
+
+(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-circe-polybar-tracking (orig-fun &rest args)
+ "Update my external status bar when tracking computes a new status line.
+
+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 #'oni-circe-polybar-tracking)
(add-hook 'circe-channel-mode-hook 'olivetti-mode)