emacselispprojectile

Emacs - How to automate adding new projects in BOTH - projectile and treemacs?


My workflow of using Emacs involve checking of many different projects. They are added and removed pretty frequently. This is very annoying and time consuming at the moment:

  1. projectile-add-known-project and set a path to a new project
  2. helm-projectile-switch-project and select a new project
  3. treemacs-add-and-display-current-project
  4. now you're ready to finally start working on it.

Is there a way to automate/simplify/speed it up? Perhaps by using some kind of elisp function? If so, what it may look like?

I have some prior experience of using LISP but I haven't written elisp code before.


Solution

  • Well, you can just simply put what you normally do by hand inside one command. You might wanna change a bit to match your needs perfectly.

    (defun add-or-switch-project-dwim (dir)
      "Let elisp do a few chores & set my hands free!"
      (interactive (list (read-directory-name "Add to known projects: ")))
      (projectile-add-known-project dir)
      (find-file dir)
      (treemacs-add-and-display-current-project))