-
Notifications
You must be signed in to change notification settings - Fork 11
/
grails-mode.el
182 lines (152 loc) · 5.46 KB
/
grails-mode.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
;;; grails-mode.el --- minor-mode that adds some Grails project management to a grails project
;; Copyright (C) 2010 Jim Morris
;; Author: Jim Morris <[email protected]>
;; Version: 0.1
;; URL: http://blog.wolfman.com
;; This file is not currently 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 2, 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 ; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;
;;; depends on
;; groovy-mode
;; find-cmd
;; anything
;; anything-config
;;
;;; Commentary:
;;
;; A minor mode that adds some useful commands for navigating around
;; a grails project
;;
;; In the root of the grails project (where the grails-app directory is)
;; add this to your .dir-locals.el file (v23+)
;; (groovy-mode . ((grails-mode . 1)))
;; (java-mode . ((grails-mode . 1)))
;; (html-mode . ((grails-mode . 1)))
;;
;; This will turn on grails minor mode whenever a groovy, java or gsp file is opened,
;; this presumes you have gsp files et to use html-mode adjust to whatever mode gsp files use
;;
;; or just add this to have grails mode with any file in that directory structure
;;
;; ((nil . ((grails-mode . 1))))
;;
;; The main addition is a view in anything that shows all the grails project files
;;
(require 'find-cmd)
(eval-when-compile
(defvar anything-project-root))
;; TODO
(defun grails-jump-to-model ()
"Jump to the domain model for the given context."
(interactive)
(let (var1)
(setq var1 'some)
(message "jump to model at point")
)
)
;; TODO
(defun grails-jump-to-controller ()
"thisandthat."
(interactive)
(let (var1)
(setq var1 'some)
(message "jump to controller at point")
)
)
;; TODO
(defun grails-jump-to-view ()
"Jumps the view for the controller action we are in"
(interactive)
(let (var1)
(setq var1 'some)
(message "jump to view for given action")
)
)
;;
;; Handle anything integration with grails project view
;;
(defvar grails-root-extra-find-args
(find-to-string '(prune (name ".svn" ".git")))
"Extra find args that will be AND'd to the defaults (which are
in `grails-root-file-find-process')")
(defun grails-make-displayable-name (path)
"makes path into a displayable name. eg view(post): file, domain: file, controller: name"
(let ((dir (file-name-directory path))
(name (file-name-nondirectory path)))
(let
((type (cond
((string-match "/grails-app/views/\\([a-zA-Z0-9_]+\\)/" dir)
(concat "view(" (match-string 1 dir) ")"))
((string-match "/grails-app/controllers/.*/\\([a-zA-Z0-9_]+\\)Controller" dir) "controller")
((string-match "/grails-app/domain/" dir) "domain")
((string-match "/grails-app/conf/" dir) "configuration")
((string-match "/grails-app/i18n/" dir) "i18n")
((string-match "/grails-app/services/" dir) "services")
((string-match "/grails-app/taglib/" dir) "taglib")
((string-match "/grails-app/utils/" dir) "utils")
((string-match "/grails-app/\\([a-zA-Z0-9_]+\\)/" dir) (match-string 1 dir))
(t "misc file"))))
(concat type ": " (file-name-sans-extension name)))))
(defun grails-list-project-files ()
"Returns a list of all files found under the grails project."
;; find root of project
;; TODO should also check for grails-app directory
(setq grails-project-root
(locate-dominating-file default-directory "build.xml"))
;; get a list of all the relevant files
(setq grails-project-files-list
(split-string
(shell-command-to-string (concat "find " grails-project-root "grails-app "
(find-to-string
`(or (name "*.groovy")
(name "*.gsp")))))))
;; convert the list into cons pair of (display . filepath) where
;; display is a friendly name
(setq grails-project-files-list-display
(mapcar
(lambda (f)
(cons (grails-make-displayable-name f) f)) grails-project-files-list)))
;; anything source for showing all grails project files
(defvar anything-grails-project-files
'((name . "Files in Grails Project")
(candidates . grails-project-files-list-display)
(match anything-c-match-on-file-name)
;(candidate-transformer nil)
(type . file)))
(defun grails-show-project-files ()
"Uses Anything to show all the project files"
(interactive)
(grails-list-project-files)
(anything '(anything-grails-project-files)))
;;;###autoload
(define-minor-mode grails-mode
"Grails Minor Mode.
With no argument, this command toggles the mode.
Non-null prefix argument turns on the mode.
Null prefix argument turns off the mode.
When Grails mode is enabled, several keys are enabled that
will allow navigation around a typical grails project."
;; The initial value.
:init-value nil
;; The indicator for the mode line.
:lighter " Grails"
;; The minor mode bindings.
:keymap
'(("\C-c/m" . grails-jump-to-model)
("\C-c/c" . grails-jump-to-controller)
("\C-c/v" . grails-jump-to-view)
("\C-ca" . grails-show-project-files)
)
:group 'grails)
(provide 'grails-mode)