Alexander-Miller / treemacs

GNU General Public License v3.0
2.05k stars 151 forks source link

Start Treemacs with prog-mode? #1091

Open JPRuehmann opened 4 months ago

JPRuehmann commented 4 months ago

Hello I try to find a Way to open treemacs automaticaly with prog-mode. I've tried :hook (prog-mode . treemacs) and :init (add-hook 'pog-mode-hook 'treemacs. But both did not work, instead a second Window (scratch) with treemacs gets opened beside the dashboard at startup.

My Goal is to get treemacs started at opening a project with projectile. Thanks,

stale[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity (this bot only works as a reminder, it will not close issues).

Alexander-Miller commented 1 month ago

I don' think a general hook is the right approach, as that means you'd call treemacs for every new prog buffer, especially the ones you don't expect to derive from prog-mode. You'd need to add some extra config to make sure treemacs opens only once.

It might be easier to integrate treemacs with your projectile workflow - how exactly do you open your projects?

JPRuehmann commented 1 month ago

Via click on the Link in the Dashboard.

Alexander-Miller commented 1 month ago

In that case you need to find out what function this click invokes. Maybe there is already a hook for it, maybe you need to use advice. Either way you need something like this:

(defun open-treemacs-after-click ()
  (save-selected-window (treemacs-select-window)))
(add-hook 'dashboard-after-click-hook #'open-treemacs-after-click)
(advice-add #'dashboard-click :after #'open-treemacs-after-click)