jyp / boon

Ergonomic Command Mode for Emacs
GNU General Public License v3.0
323 stars 34 forks source link

Re-setting the boon state when switching windows #121

Closed antifuchs closed 1 year ago

antifuchs commented 2 years ago

I love boon & have been extremely happy with it for the past, oh, 3 years now! One thing that has always confused me though, was that when I switch buffers via some non-boon means (I have a set of super key bindings that switch windows directionally), the buffer state would be left in whatever it was when I left that buffer. That was somewhat manageable on buffers where insert state was reasonable... and special state adds a whole layer of complexity to that; I added the indicator to the mode line, but on a large monitor, that's far away and it is easy to lose my place when checking that indicator.

So, here's my next-best solution, which I hope might be useful to others: Re-set the state in the previous buffer when the selected window changes.

(add-hook 'window-selection-change-functions
          (defun asf-boon-reset-state-for-switchw (window)
            "Re-sets the boon state to default when switching windows."
            (let* ((old (old-selected-window))
                   (prev-buf (window-buffer old)))
              (with-current-buffer prev-buf
                (if (boon-special-mode-p)
                    (boon-set-special-state)
                  (boon-set-command-state))))))

You'll notice that the code here changes the state back to "special" when we're in a special-state buffer (e.g. magit). I would much prefer to set the state to the "default" that the buffer came up with - is there a function to retrieve that state somewhere?