From 2f0668439dfa246b2807497f2824ec7c7fbbeb49 Mon Sep 17 00:00:00 2001 From: Alexander Miller Date: Mon, 28 Oct 2024 22:21:48 +0100 Subject: [PATCH] [Compatibility] Prevent windmove-swap-state commands from running in treemacs. Fixes #1126 --- src/elisp/treemacs-compatibility.el | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/elisp/treemacs-compatibility.el b/src/elisp/treemacs-compatibility.el index 049bd575..ea0e0bd7 100644 --- a/src/elisp/treemacs-compatibility.el +++ b/src/elisp/treemacs-compatibility.el @@ -65,6 +65,22 @@ (add-hook 'eyebrowse-post-window-switch-hook #'treemacs--follow-after-eyebrowse-switch)) +(with-eval-after-load 'windmove + (defun treemacs--windmove-swap-state-advice (original-fn &rest args) + "Advice for windmove-swap-state-* functions to ignore treemacs. +These commands do not seem to be compatible with side windows (and thus treemacs +in its default configuration), so this advice changes them to do nothing when +the `selected-window' is treemacs. + +For all other cases ORIGINAL-FN is called with original 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))) + (with-eval-after-load 'winum (when (boundp 'winum-ignored-buffers-regexp) (add-to-list 'winum-ignored-buffers-regexp (regexp-quote (format "%sScoped-Buffer-" treemacs--buffer-name-prefix)))))