I have been trying to automatically resize the undo-tree-visualizer window whenever it opens up in emacs. To fix this I have made a hook, the hook does resize the window however once the hook is ran the cursor ends up on the *undo-tree*
window, to solve this I have to use the (save-selected-window)
command however it did not work. I then decided to try and force emacs to go back to the previous window by using the (evil-window-left)
function (I am using evil mode) however it only results in giving me this error:
Error:
Debugger entered--Lisp error: (wrong-number-of-arguments (1 . 1) 0)
evil-window-left()
(if (not (get-buffer-window " *undo-tree*")) nil (select-window (get-buffer-window " *undo-tree*")) (evil-window-set-width 45) (evil-window-left))
undo-tree-hook()
run-hooks(change-major-mode-after-body-hook special-mode-hook undo-tree-visualizer-mode-hook)
apply(run-hooks (change-major-mode-after-body-hook special-mode-hook undo-tree-visualizer-mode-hook))
run-mode-hooks(undo-tree-visualizer-mode-hook)
undo-tree-visualizer-mode()
Code:
(defun undo-tree-hook ()
"Hook to make the undo-tree-visualizer window to automatically resize to become smaller"
(interactive)
(unless (not (get-buffer-window undo-tree-visualizer-buffer-name))
(select-window (get-buffer-window undo-tree-visualizer-buffer-name))
(evil-window-set-width 45)
(evil-window-left)))
(add-hook 'undo-tree-visualizer-mode-hook 'undo-tree-hook)
As Drew said, I needed to pass a parameter to the evil-window-left
function and I also used save-excursion
to save the point where I was on in the current buffer before I executed to the commands to switch to and resize the *undo-tree*
buffer.
(defun undo-tree-hook ()
"Hook to make the undo-tree-visualizer window to automatically resize to become smaller"
(interactive)
(unless (not (get-buffer-window " *undo-tree*"))
(save-excursion
(select-window (get-buffer-window " *undo-tree*"))
(evil-window-set-width 45)
(evil-window-left 1))))
(add-hook 'undo-tree-visualizer-mode-hook 'undo-tree-hook)