Mini-buffer -> Polybar

Not sure how I am going to do this… Trying to get the mode line more or less into polybar. It seemed like an easy task at first, but man the mode-line-format variable is cryptic, a ton is going on there and I am slowly piece mealing this together.

I already have the exwm-workspace number in the top right from the polybar video and have added the name of the buffer myself. I’d like to get pointer location in next, which should be easy. What will be challenging is completion information, as well as emms scroll info. I will use this post as a way to post and keep up with my progress. Feel free to add tips or ideas!

1 Like

Okay! here to report back!

With the great help of BigEatie, I have completed this project. The following changes make this happen.

First I have added to ~/.config/polybar/config :

modules-left = exwm-workspace mode-line

and

[module/mode-line]
type = custom/ipc
hook-0 = emacsclient -e “(mode-line-string)” | sed -e ‘s/^"//’ -e ‘s/"$//’
initial = 1
format-underline = ${colors.underline-1}
format-padding = 1

[module/exwm-workspace]
type = custom/ipc
hook-0 = emacsclient -e “exwm-workspace-current-index” | sed -e ‘s/^"//’ -e ‘s/"$//’
initial = 1
format-underline = ${colors.underline-1}
format-padding = 1

As for my emacs config:

(defun efs/send-polybar-exwm-workspace ()
(efs/send-polybar-hook “exwm-workspace” 1))

;; the code inside the function below is courtesy of BigEatie.
(defun mode-line-string ()
(let* ((mode-line-string (format-mode-line mode-line-format))
(start 0)
(end (length mode-line-string)))
(set-text-properties start end nil mode-line-string)
mode-line-string))

(defun efs/send-polybar-mode-line ()
(efs/send-polybar-hook “mode-line” 1))

;; setting the below to ‘.01 .01’ is much more responsive, but significantly kicks
;; up my computers resources.

(run-with-timer .1 .1 (lambda () (efs/send-polybar-mode-line)))

All that is left is to:

(use-package hide-mode-line
:ensure t
:config
(global-hide-mode-line-mode t))

And that does it! mode-line-format is now in polybar and I am free of multiple mode lines for each window buffer.

Thanks again to BigEatie, and hopefully others use this and find ways to optimize.

Cheers!

edit: One change that could be made is using the post-command-hook instead of a timer to relieve the machine of constantly updating the mode-line-string function.

I love projects like this that try to “spread out” Emacs into the rest of the desktop environment. EXWM is great, but it is only the window manager. Showing the mode line in the panel or polybar is another good step in that direction!

For me, the ultimate Emacs extension would be something that could display the minibuffer in the Panel (the “panel” widget seen in DEs like Xfce, MATE, and Cinnamon) so I could have the Emacs minibuffer share screen space with all the other widgets in the pannel. I would also love it if my web browser would display the URL bar in the panel. (I’ll bet one could probably program the Nyxt browser to put its URL bar in a panel.)

I looked around and apparently at one point there was an Xfce Panel widget that used a GtkPlug widget, and you could program Emacs to create a new frame every time the minibuffer was needed while re-parenting the frame in the Panel widget. But this Xfce panel widget has bit-rotted, and now that everything is moving to Wayland I am not sure if it would be worth the effort to try to revive it.

The next best thing would be to create a new frame every time the minibuffer pops-up and program the window manager to only show that frame at the bottom of the screen in a space reserved for the panel. Maybe another possiblity for Gtk-based panels would be to have a “GtkBuilder” widget in the panel that rendered arbitrary XML sent to it from Emacs over DBus.