-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnameframe-projectile.el
76 lines (61 loc) · 3.06 KB
/
nameframe-projectile.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
;;; nameframe-projectile.el --- Nameframe integration with Projectile
;; Author: John Del Rosario <[email protected]>
;; URL: https://github.com/john2x/nameframe
;; Version: 0.5.0-beta
;; Package-Requires: ((nameframe "0.5.0-beta") (projectile "0.13.0"))
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This package defines a function to replace Projectile's
;; `projectile-switch-project' which will create/switch to a named frame
;; of the target project.
;; To use this library, put this file in your Emacs load path,
;; and call (nameframe-projectile-mode t).
;;; Code:
(require 'nameframe)
(require 'projectile)
;;;###autoload
(define-minor-mode nameframe-projectile-mode
"Global minor mode that creates/switches to a frame when switching projects."
:init-value nil
:lighter nil
:global t
:group 'nameframe
:require 'nameframe-projectile
(cond
(nameframe-projectile-mode
(nameframe-projectile--add-advice-around-switch-project-by-name)
(add-hook 'projectile-before-switch-project-hook #'nameframe-projectile--before-switch-project-hook))
(t
(remove-hook 'projectile-before-switch-project-hook #'nameframe-projectile--before-switch-project-hook))))
(defun nameframe-projectile--before-switch-project-hook ()
"Hook to create/switch to a project's frame."
(let* ((project-to-switch nameframe-projectile--project-to-switch) ;; set by advise
(name (file-name-nondirectory (directory-file-name project-to-switch)))
(curr-frame (selected-frame))
(frame-alist (nameframe-frame-alist))
(frame (nameframe-get-frame name frame-alist)))
(cond
;; project frame already exists
((and frame (not (equal frame curr-frame)))
(select-frame-set-input-focus frame))
((not frame)
(nameframe-make-frame name)))))
(defun nameframe-projectile-switch-project-by-name (projectile-switch-project-by-name &rest args)
"Workaround for https://github.com/bbatsov/projectile/issues/1056
Set the variable nameframe-projectile--project-to-switch to the target project so our hooks can use it."
(let* ((nameframe-projectile--project-to-switch (car args)))
(apply projectile-switch-project-by-name args)))
(defun nameframe-projectile--add-advice-around-switch-project-by-name ()
"Workaround for https://github.com/bbatsov/projectile/issues/1056"
(advice-add #'projectile-switch-project-by-name :around #'nameframe-projectile-switch-project-by-name))
(provide 'nameframe-projectile)
;;; nameframe-projectile.el ends here