doomemacs/modules/ui/treemacs/autoload.el
James Ravn e05e452528
Enable treemacs workspace/persp support
With https://github.com/Alexander-Miller/treemacs/issues/592 merged,
treemacs now fully supports perspective mode. That is, each treemacs
buffer is scoped to a perspective and initializes itself using projectile.

This change re-enables treemacs-persp, enables the `Perspectives` scope,
and adjusts the doom treemacs init behavior to support the new
treemacs-persp behavior.

I haven't been able to reproduce the prior errors with melpa so I think
this is safe to re-enable now. In my testing it seems to work
flawlessly, both with and without persp-mode enabled.

Only one issue is that users might need to remove their treemacs persist
file (`~/.emacs.d/.local/cache/treemacs-persist`) after this change if
using persp-mode. I'm not sure if it is necessary since I blew away my
own before testing.
2020-04-02 21:05:49 +01:00

42 lines
1.5 KiB
EmacsLisp

;;; 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))
(unless (bound-and-true-p persp-mode)
(dolist (project (treemacs-workspace->projects (treemacs-current-workspace)))
(treemacs-do-remove-project-from-workspace project)))
(with-current-buffer origin-buffer
(let ((project-root (or (doom-project-root) default-directory)))
(treemacs-do-add-project-to-workspace
(treemacs--canonical-path project-root)
(doom-project-name project-root)))
(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.
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)))
(+treemacs--init)
(with-current-buffer origin-buffer
(treemacs-find-file arg))))