diff --git a/modules/config/default/+bindings.el b/modules/config/default/+bindings.el index 0f62a49d6..889fe8442 100644 --- a/modules/config/default/+bindings.el +++ b/modules/config/default/+bindings.el @@ -703,7 +703,7 @@ :desc "Find file in project sidebar" :n "P" #'+neotree/find-this-file) (:when (featurep! :ui treemacs) :desc "Project sidebar" :n "p" #'+treemacs/toggle - :desc "Find file in project sidebar" :n "P" #'treemacs-find-file) + :desc "Find file in project sidebar" :n "P" #'+treemacs/find-file) :desc "Imenu sidebar" :nv "i" #'imenu-list-smart-toggle :desc "Terminal" :n "t" #'+term/open :desc "Terminal in popup" :n "T" #'+term/open-popup-in-project diff --git a/modules/ui/treemacs/autoload.el b/modules/ui/treemacs/autoload.el index d477128cf..b34f34d19 100644 --- a/modules/ui/treemacs/autoload.el +++ b/modules/ui/treemacs/autoload.el @@ -1,27 +1,39 @@ ;;; ui/treemacs/autoload.el -*- lexical-binding: t; -*- +(defun +treemacs--init () + (require 'treemacs) + (let ((origin-buffer (current-buffer))) + (cl-letf (((symbol-function 'treemacs-workspace->is-empty?) + (symbol-function 'ignore))) + (treemacs--init)) + (dolist (project (treemacs-workspace->projects (treemacs-current-workspace))) + (treemacs-do-remove-project-from-workspace project)) + (with-current-buffer origin-buffer + (treemacs-do-add-project-to-workspace + (treemacs--canonical-path (doom-project-root 'nocache)) + (doom-project-name 'nocache)) + (setq treemacs--ready-to-follow t) + (when (or treemacs-follow-after-init treemacs-follow-mode) + (treemacs--follow))))) + ;;;###autoload (defun +treemacs/toggle () "Initialize or toggle treemacs. Ensures that only the current project is present and all other projects have -been removed." +been removed. + +Use `treemacs' command for old functionality." (interactive) - (require 'treemacs) + (pcase (treemacs-current-visibility) + (`visible (delete-window (treemacs-get-local-window))) + (_ (+treemacs--init)))) + +;;;###autoload +(defun +treemacs/find-file (arg) + "Open treemacs (if necessary) and find current file." + (interactive "P") (let ((origin-buffer (current-buffer))) - (cl-letf (((symbol-function 'treemacs-workspace->is-empty?) - (symbol-function 'ignore))) - (treemacs--init)) - ;; - (dolist (project (treemacs-workspace->projects (treemacs-current-workspace))) - (treemacs-do-remove-project-from-workspace project)) - ;; + (+treemacs--init) (with-current-buffer origin-buffer - (treemacs-do-add-project-to-workspace - (treemacs--canonical-path (doom-project-root 'nocache)) - (doom-project-name 'nocache))) - ;; - (setq treemacs--ready-to-follow t) - (when (or treemacs-follow-after-init treemacs-follow-mode) - (with-current-buffer origin-buffer - (treemacs--follow))))) + (treemacs-find-file arg))))