Closed IceAsteroid closed 1 month ago
The treemacs configuration:
(defun my-setup/treemacs ()
(with-eval-after-load 'treemacs
(treemacs-load-all-the-icons-with-workaround-font "Hermit")
(setq treemacs-display-in-side-window t
treemacs-is-never-other-window t
treemacs-position 'left
treemacs-width 30
treemacs-width-increment 1
treemacs-width-is-initially-locked t
treemacs-wide-toggle-width 40
treemacs-is-never-other-window nil
treemacs-no-delete-other-windows t
treemacs-show-hidden-files t
treemacs-missing-project-action 'ask
treemacs-follow-after-init t
treemacs-expand-after-init t
treemacs-eldoc-display 'simple
treemacs-project-follow-cleanup t
)
(add-hook 'treemacs-mode-hook
;; Unbind dangerous commands
(lambda ()
;;unbind treemacs-delete-file
(local-unset-key (kbd "d"))
;;unbind treemacs-move-file
(local-unset-key (kbd "m"))
;;unbind treemacs-rename-file
(local-unset-key (kbd "R"))))
(keymap-global-set "C-x t t" 'treemacs) ;original command was other-tab-prefix
))
(my-setup/treemacs)
Tested also in Emacs with no configuration with emacs -q
, treemacs behaves the same
It looks like the state-swap feature is just not compatible with side-windows in general. Luckily you can get around that by setting treemacs-display-in-side-window
to nil.
Sorry, I was wanting treemacs to stay where it is, which means prohibit windmove-states-swap-*
commands to move treemacs.
That would be better, which means the treemacs-display-in-side-window
is still set to t
and just like split-window-*
commands cannot do things on treemacs.
Try this:
(with-eval-after-load 'windmove
(defun treemacs--windmove-swap-state-advice (original-fn &rest args)
(unless (and treemacs-display-in-side-window
(treemacs-is-treemacs-window-selected?))
(apply original-fn args)))
(with-no-warnings
(advice-add 'windmove-swap-states-in-direction
:around #'treemacs--windmove-swap-state-advice)))
It works fine with the above code, thank you!
And besides this, use windmove-states-swap-*
for example to left or right for a window in swap of treemacs, things will still go wrong. But this time it can swap back by using the opposite direction one of windmove-states-swap-*
.
It's good already, just here to post to show it.
If there's two window opened horizontally, with treemacs opened as a side window, when a window is swap with treemacs, it becomes like in the following picture.
I've added my compatibility code to treemacs now, so you won't need to keep it in your config.
For the other issues you mention, unless you have set windmove-allow-all-windows
to non-nil you can make treemacs invisible to windmove's commands by setting treemacs-is-never-other-window
to t. Specifically it'll make treemacs invisible to all commands that target something like the "next windows".
Okay, thank you!
After the swap by
windmove-states-swap-right
, in the treemacs window, the window layout becomes like follows, and none of the windows can be deleted bydelete-window
nordelete-other-windows
.Is there a way to prohibit such a swap action when in the treemacs window?
I know that commands like
split-window-*
work fine and treemacs would just stay fixed in the side window, but commands that swap states break this.