Skip to content

Commit

Permalink
Merge pull request #627 from vkz/persp-projectile
Browse files Browse the repository at this point in the history
Persp projectile
  • Loading branch information
bbatsov committed Feb 22, 2015
2 parents efa7720 + 519596c commit 3c41c82
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
3 changes: 2 additions & 1 deletion helm-projectile.el
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ It is there because Helm requires it."

(defun helm-projectile-switch-to-eshell (dir)
(interactive)
(let* ((helm-ff-default-directory (file-name-directory dir)))
(let* ((projectile-require-project-root nil)
(helm-ff-default-directory (file-name-directory (projectile-expand-root dir))))
(helm-ff-switch-to-eshell dir)))

(defun helm-projectile-files-in-current-dired-buffer ()
Expand Down
25 changes: 22 additions & 3 deletions persp-projectile.el
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
(require 'perspective)
(require 'projectile)

;; TODO this may be incompatible helm which let's you find stuff in new frame
(defmacro projectile-persp-bridge (func-name)
"Create advice to create a perspective before invoking function FUNC-NAME.
The advice provides bridge between perspective and projectile
Expand All @@ -70,14 +71,32 @@ that before `projectile-switch-project' invokes
Otherwise, this function calls `persp-switch' to switch to an
existing perspective of the project unless we're already in that
perspective in which case `projectile-switch-project' is called."
perspective."
(interactive (list (projectile-completing-read "Switch to project: "
(projectile-relevant-known-projects))))
(let* ((name (file-name-nondirectory (directory-file-name project-to-switch)))
(persp (gethash name perspectives-hash)))
(if (and persp (not (equal persp persp-curr)))
(cond
;; project-specific perspective already exists
((and persp (not (equal persp persp-curr)))
(persp-switch name))
;; project-specific perspective doesn't exist
((not persp)
(let ((frame (selected-frame)))
(persp-switch name)
(projectile-switch-project-by-name project-to-switch))))
(projectile-switch-project-by-name project-to-switch)
;; Clean up if we switched to a new frame. `helm' for one allows finding
;; files in new frames so this is a real possibility.
(when (not (equal frame (selected-frame)))
(with-selected-frame frame
(persp-kill name))))))))

(defadvice persp-init-frame (after projectile-persp-init-frame activate)
"Rename initial perspective to `projectile-project-name' when a
new frame is created in a known project."
(with-selected-frame frame
(when (projectile-project-p)
(persp-rename (projectile-project-name)))))

(define-key projectile-mode-map [remap projectile-switch-project] 'projectile-persp-switch-project)

Expand Down

0 comments on commit 3c41c82

Please sign in to comment.