-
Notifications
You must be signed in to change notification settings - Fork 102
/
alchemist-phoenix.el
145 lines (113 loc) · 4.9 KB
/
alchemist-phoenix.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
;;; alchemist-phoenix.el --- Minor mode for the Phoenix web framework
;; Copyright © 2014-2017 Samuel Tonini
;; Author: Samuel Tonini <[email protected]
;; This file is not part of GNU Emacs.
;; 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:
;; Minor mode for the Phoenix web framework
;;; Code:
(require 'alchemist-key)
(require 'alchemist-project)
(defgroup alchemist-phoenix nil
"Minor mode for the Phoenix web framework."
:prefix "alchemist-phoenix-"
:group 'alchemist)
;;;###autoload
(defun alchemist-phoenix-project-p ()
"Return non-nil if `default-directory' is inside a Phoenix project."
(and (alchemist-project-p)
(file-directory-p (concat (alchemist-project-root) "web"))))
(defun alchemist-phoenix-find-dir (directory)
(unless (alchemist-phoenix-project-p)
(error "Could not find a Phoenix Mix project root."))
(alchemist-file-find-files (alchemist-project-root) directory))
(defun alchemist-phoenix-find-web ()
(interactive)
(alchemist-phoenix-find-dir "web"))
(defun alchemist-phoenix-find-views ()
(interactive)
(alchemist-phoenix-find-dir "web/views"))
(defun alchemist-phoenix-find-controllers ()
(interactive)
(alchemist-phoenix-find-dir "web/controllers"))
(defun alchemist-phoenix-find-channels ()
(interactive)
(alchemist-phoenix-find-dir "web/channels"))
(defun alchemist-phoenix-find-templates ()
(interactive)
(alchemist-phoenix-find-dir "web/templates"))
(defun alchemist-phoenix-find-models ()
(interactive)
(alchemist-phoenix-find-dir "web/models"))
(defun alchemist-phoenix-find-static ()
(interactive)
(alchemist-phoenix-find-dir "web/static"))
(defun alchemist-phoenix-routes (&optional prefix)
(interactive)
"Run the Mix task 'phoenix.routes' and list all available Phoenix routes."
(alchemist-mix-execute '("phoenix.routes") prefix))
(defun alchemist-phoenix-router ()
"Open the 'router.ex' file from 'web' directory."
(interactive)
(unless (alchemist-phoenix-project-p)
(error "Could not find an Phoenix Mix project root."))
(find-file (concat (alchemist-project-root) "web/router.ex")))
(defvar alchemist-phoenix-command-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "n w") #'alchemist-phoenix-find-web)
(define-key map (kbd "n v") #'alchemist-phoenix-find-views)
(define-key map (kbd "n c") #'alchemist-phoenix-find-controllers)
(define-key map (kbd "n l") #'alchemist-phoenix-find-channels)
(define-key map (kbd "n t") #'alchemist-phoenix-find-templates)
(define-key map (kbd "n m") #'alchemist-phoenix-find-models)
(define-key map (kbd "n s") #'alchemist-phoenix-find-static)
(define-key map (kbd "n r") #'alchemist-phoenix-router)
(define-key map (kbd "n R") #'alchemist-phoenix-routes)
map)
"Keymap for Alchemist Phoenix commands after `alchemist-key-command-prefix'.")
(fset 'alchemist-phoenix-command-map alchemist-phoenix-command-map)
(defvar alchemist-phoenix-mode-map
(let ((map (make-sparse-keymap)))
(define-key map alchemist-key-command-prefix 'alchemist-phoenix-command-map)
map)
"Keymap for Alchemist Phoenix minor mode.")
(easy-menu-define alchemist-mode-menu alchemist-phoenix-mode-map
"Menu for Alchemist-Phoenix mode."
'("Phoenix"
("Directory lookup"
["Lookup 'web' " alchemist-phoenix-find-web]
["Lookup 'web/views' " alchemist-phoenix-find-views]
["Lookup 'web/controllers' " alchemist-phoenix-find-controllers]
["Lookup 'web/channels' " alchemist-phoenix-find-channels]
["Lookup 'web/templates' " alchemist-phoenix-find-templates]
["Lookup 'web/models' " alchemist-phoenix-find-models]
["Lookup 'web/static'" alchemist-phoenix-find-static])
("Mix tasks"
["Run 'phoenix.routes'" alchemist-phoenix-routes])
["Open the 'router.ex' file" alchemist-phoenix-router]))
;;;###autoload
(define-minor-mode alchemist-phoenix-mode
"Minor mode for Elixir Phoenix web framework projects.
The following commands are available:
\\{alchemist-phoenix-mode-map}"
:lighter " alchemist-phoenix"
:keymap alchemist-phoenix-mode-map
:group 'alchemist)
;;;###autoload
(defun alchemist-phoenix-enable-mode ()
(when (alchemist-phoenix-project-p)
(alchemist-phoenix-mode)))
;;;###autoload
(dolist (hook '(alchemist-mode-hook))
(add-hook hook 'alchemist-phoenix-enable-mode))
(provide 'alchemist-phoenix)
;;; alchemist-phoenix.el ends here