2

When I use Spacemacs with the Treemacs feature inside it, like the picture, I opened it by Alt Shift m + p + t enter image description here

Then use Ctrl x + u to open undo-tree enter image description here

When I move the cursor on the undo-tree by Ctrl + p, the layout had been resized enter image description here

Even I close the undo-tree window, the layout didn't back to the first picture. enter image description here

Why it happened? How to avoid it?

7
  • I am familiar with undo-tree and am unaware of any code that resizes windows. It only uses switch-to-buffer-other-window, switch-to-buffer and display-buffer. The culprit may possibly lie elsewhere.
    – lawlist
    Commented Apr 20, 2022 at 2:21
  • @lawlist Thank you. I just installed Spacemacs v.0.300.0 . I didn't set any addon configuration after install it. This issue happened on both Linux and macOS.
    – madaha
    Commented Apr 20, 2022 at 2:41
  • I am not familiar with treemacs, but did a quick git clone and grep for shrink and enlarge and came up with the function treemacs--set-width. In your debugging quest, consider copying treemacs--set-width to a *scratch* buffer and modify it by making it do nothing. e.g., comment out everything and then evaluate the modified function; e.g., the new function that could be evaluated looks like (defun treemacs--set-width (width) "Doc-string." nil) You could even just type M-x eval-expression RET (defun treemacs--set-width (width) "Doc-string." nil) RET; and, then repeat your test.
    – lawlist
    Commented Apr 20, 2022 at 2:56
  • @lawlist Thank you for your advice. Maybe there are something config conflict by default.
    – madaha
    Commented Apr 20, 2022 at 3:22
  • If something is resizing windows, then the functions that have shrink and enlarge in their names are most likely responsible (with a few unlikely exceptions, e.g., where an alist to a display-buffer family of functions is expressly set with a particular width). Once you track down the function responsible, then you can work your way backwards to where the function is called, and then devise a plan to deal with the situation. You could even just put in some messages in the function mentioned in my previous comment to see when it gets called ...
    – lawlist
    Commented Apr 20, 2022 at 3:24

1 Answer 1

1

The issue is caused by the function undo-tree-visualizer-update-diff, which contains a (balance-windows) command at the end. So the simple dirty trick is to re-define the function with that command commented out after loading undo-tree:

(with-eval-after-load 'undo-tree

  ;; [2023-10-20 Fri] modify this function from undo-tree.el to prevent
  ;; re-balancing windows ------------------------------------------------------
  (defun undo-tree-visualizer-update-diff (&optional node)
    ;; update visualizer diff display to show diff between current state and
    ;; NODE (or previous state, if NODE is null)
    (with-current-buffer undo-tree-visualizer-parent-buffer
      (undo-tree-diff node))
    (let ((win (get-buffer-window undo-tree-diff-buffer-name)))
      (when win
        ;; (balance-windows); comment this line out 
        (shrink-window-if-larger-than-buffer win))))
  )
2
  • Thanks @LI Bing that fixed the issue :D But, just so you know, you have an extra closing parenthesis at the end of that code snippet, it must be removed before someone applies that to their ~/.emacs.d/init.el. Commented Aug 28 at 18:06
  • 1
    Corrected. @theMarceloR Thank you for pointing it out!
    – LI Bing
    Commented Sep 1 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.