Skip to content

Instantly share code, notes, and snippets.

@shegeley
Created October 28, 2024 08:05
Show Gist options
  • Save shegeley/cadcb16137fffd911f34ed6aaf673f54 to your computer and use it in GitHub Desktop.
Save shegeley/cadcb16137fffd911f34ed6aaf673f54 to your computer and use it in GitHub Desktop.
Emacs Treemacs auto-toggling in text and prog-modes. Author: @ichernyshovvv
(defun treemacs-toggle-maybe ()
(require 'treemacs)
(if (eq last-command 'treemacs)
(set-frame-parameter (selected-frame) 'treemacs-forced-p
(not (frame-parameter (selected-frame) 'treemacs-forced-p)))
(unless (frame-parameter (selected-frame) 'treemacs-forced-p)
(if (seq-find
(lambda (x)
(with-current-buffer (window-buffer x)
(derived-mode-p 'text-mode 'prog-mode)))
(window-list))
(unless (eq (treemacs-current-visibility) 'visible)
(save-selected-window (treemacs)))
(and (eq (treemacs-current-visibility) 'visible)
(not (minibufferp))
(delete-window (treemacs-get-local-window)))))))
(add-hook 'window-configuration-change-hook 'treemacs-toggle-maybe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment