mina86/auto-dim-other-buffers.el

Dimming doesn't update after a window selection inside `with-selected-window`

Closed this issue · 5 comments

I've managed to stumble into some edge case which bypasses/confuses auto-dim-other-buffers' detection of window selection. Minimal repro:

  1. Emacs frame with two windows, left and right.

  2. Left window selected.

  3. [Causes bug] M-: (with-selected-window (selected-window) (other-window 1)) RET.

  4. [Bug manifests] Select right window (for example with other-window or windmove-right) - dimming doesn't update on this window switch.

mina86 commented

I actually can’t reproduce it. After the command is done, the window on the left remains selected and undimmed while the one on the left is dimmed. What Emacs version are you on? M-x emacs-version RET. Maybe it’s something

Hmm, okay. Another piece of my config must be contributing.

I see this on both Emacs 29.1 and an older version (can't remember/check which r.n.). 100% repro rate for me.

I'll try to circle back soon-ish to isolate it more.

Minimal repro from emacs -Q on Emacs 29.1. I paste this in the scratch buffer, and separately manually do C-x C-e (eval-last-sexp) on the progn and then on the last line.

(progn
    (require 'package)
    (setq package-load-list '((auto-dim-other-buffers t)))
    (package-initialize)
    (auto-dim-other-buffers-mode 1)
    (split-window-below))
(with-selected-window (selected-window) (other-window 1))

That leads to this, with the active cursor in the dimmed blue window:

image

It doesn't reproduce if I evaluate the last line at the same time (with eval-region or by moving it into the progn).

mina86 commented

Thanks. I’m actually running 30 so this could be something that got fixed on master. I’ll try to reproduce on stable when I find a moment.

Closing because I no longer think this is a bug in this package.

Whenever this bug happens, it means some lisp code did a non-"recorded" window switch and failed to run the relevant hooks. (See norecord argument of selected-window.)

With that understanding, we can actually simplify minimal repro from (with-selected-window (selected-window) (other-window 1)) to a mere (select-window (cadr (window-list nil nil (selected-window))) t).

In other words, auto-dim-other-buffers is arguably doing the correct thing here, in response to a window switch which says "ignore me".