Created
October 28, 2024 08:05
-
-
Save shegeley/cadcb16137fffd911f34ed6aaf673f54 to your computer and use it in GitHub Desktop.
Emacs Treemacs auto-toggling in text and prog-modes. Author: @ichernyshovvv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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