Emacs: Add commands to open a work or home project Given that the projects are folders under (work|home)-project-directory which match projectile's own predicates, switch to them with projectile, even if they're not 'known' to it.
Alan Pearce alan@alanpearce.co.uk
Wed, 25 Jun 2014 19:25:25 +0100
1 files changed, 31 insertions(+), 0 deletions(-)
jump to
M tag-emacs/emacs.d/init.el → tag-emacs/emacs.d/init.el
@@ -32,6 +32,9 @@ (expand-file-name "init.el" (file-name-directory (file-truename init-file)))) "Where the emacs init file really is, passing through symlinks.") +(defvar work-project-directory "~/work") +(defvar home-project-directory "~/projects") + ;;;; Package Management (add-to-list 'load-path (expand-file-name "elisp/" user-emacs-directory)) @@ -657,6 +660,34 @@ ("s-G" . projectile-vc)) :init (projectile-global-mode) :diminish projectile-mode :config (progn + (defun ap/subfolder-projects (dir) + (--map (file-relative-name it dir) + (-filter (lambda (subdir) + (--reduce-from (or acc (funcall it subdir)) nil + projectile-project-root-files-functions)) + (-filter #'file-directory-p (directory-files dir t "\\<"))))) + + (defun ap/-add-known-subfolder-projects (dir) + (-map #'projectile-add-known-project (ap/subfolder-projects dir))) + + (defun ap/add-known-subfolder-projects () + (interactive) + (ap/-add-known-subfolder-projects (ido-read-directory-name "Add projects under: "))) + + (defun ap/open-subfolder-project (from-dir &optional arg) + (let ((project-dir (projectile-completing-read "Open project: " + (ap/subfolder-projects from-dir)))) + (projectile-switch-project-by-name (expand-file-name project-dir from-dir) arg))) + + (defun ap/open-work-project (&optional arg) + (interactive "P") + (ap/open-subfolder-project work-project-directory arg)) + + (defun ap/open-home-project (&optional arg) + (interactive "P") + (ap/open-subfolder-project home-project-directory arg)) + + (setq projectile-switch-project-action #'projectile-dired projectile-remember-window-configs t)))