reddit / emacs

undo-tree changed Treemacs layout when move history cursor

madahadamahu · 2022-04-20 01:07
When I use Spacemacs with the Treemacs feature inside it, like the picture, I opened it by Alt Shift m + p + t https://preview.redd.it/z9xajaup1lu81.png?width=1917&format=png&auto=webp&s=82c9ddb9a184d72601757cc2c796f0404d8e51a6 Then use Ctrl x + u to open undo-tree https://preview.redd.it/qbu570t32lu81.png?width=1917&format=png&auto=webp&s=a554d541a9898632059a69c806767d94933cf5a7 When I move the cursor on the undo-tree by Ctrl + p, the layout had been resized https://preview.redd.it/8wcqsv7b2lu81.png?width=1915&format=png&auto=webp&s=4c0ebe2fa18ff8fc2fb06b2eb7c2a4529d652e2a Even I close the undo-tree window, the layout didn't back to the first picture. https://preview.redd.it/evwx8q403lu81.png?width=1916&format=png&auto=webp&s=1d5577306e3cb2cfac95bfc961b3572e75a8a139 Why it happened? How to avoid it?
DasEwigeLicht · 2022-04-20 20:14
It happened because that's what Emacs does when your windows get rearranged, it balances their size. That is why by default the width of the treemacs window is locked, and can only be changed by dedicated commands (`w` & `tw`). Spacemacs or your own config must have disabled that. The initial width setting is controlled by `treemacs-width-is-initially-locked`.
madahadamahu · 2022-04-21 02:52
Thank you for comment. How to edit `treemacs-width-is-initially-locked`? I didn't find it in the `~/.spacemacs` file. On Treemacs' [github repository](https://github.com/Alexander-Miller/treemacs), there is a description: > Indicates whether the treemacs windows starts with a locked width or not. The default value it `t`. I think it's true. So it already enabled on starting. But how to make it permanent.
lawlist · 2022-04-21 04:48
As indicated in the comments of the duplicate post to the emacs.stackexchange.com thread https://emacs.stackexchange.com/q/71436/2287 , changing the calls of `undo-tree-visualize-undo` and `undo-tree-visualize-redo` to use `with-current-buffer` instead of `switch-to-buffer-other-window` should resolve the issue. An exception can also be made within the hook function of treemacs responsible for making the change when the window configuration changes (likewise discussed in the comments of the duplicate thread).