From d91dfe6c7766b4b82e886183fc8e50ed9e4cb0bf Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Wed, 25 Jun 2014 19:25:25 +0100 Subject: 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. --- tag-emacs/emacs.d/init.el | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tag-emacs/emacs.d/init.el b/tag-emacs/emacs.d/init.el index 3e24147..00d595f 100644 --- a/tag-emacs/emacs.d/init.el +++ b/tag-emacs/emacs.d/init.el @@ -32,6 +32,9 @@ (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 @@ :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))) -- cgit 1.4.1