exwm triple monitor winum mode-line window numbers need to update better

Table of Contents

The problem

An posted on reddit.1

I have my window numbers in my modelines of every window so that I can easily navigate to them with my exwm three-monitor setup. About 90% of the time they are accurate, but they get out of sync sometimes when big window operations (or closing a window) occur. As soon as I do something to invoke a mini-buffer (any C-x command), they get updated correctly, but sometimes when I try to work quickly I find they don’t match up. Before I dig in to which functions to put on which hooks to make these better stay in sync, does anyone have suggestions for keeping them in sync?

Note that these are NOT workspace or screen numbers, as System Crafters have demonstrated before. I tend to ignore the concept of workspaces as such. These are emacs window numbers, which I use for rapid keyboard navigation across my screens.

The invocation that sticks these into my telephone2 line is this: (eval (cadr winum--mode-line-segment))

Solution: force-mode-line-update on the window-state-change-hook

I found the function I needed while reading the code to another function. Note that I needed a lambda and not just the name force-mode-line-update because, as per the documentation for the function, I need to pass a non-nil variable to make it apply to ALL modelines, not just the current buffer.

The following does the trick beautifully:

(add-hook 'window-state-change-hook (lambda () (interactive) (force-mode-line-update t)))

Footnotes

1 possibly removed by the reddit bots, but I was allowed to post a response despite their removal notice. https://www.reddit.com/r/emacs/comments/vwvut3/winum_modeline_window_numbers_need_to_update/

2 Telephone Line is a nice-looking and highly customizable modeline solution. https://github.com/dbordak/telephone-line

Tory Anderson avatar
Tory Anderson
Full-time Web App Engineer, Digital Humanist, Researcher, Computer Psychologist