Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 142 lines (122 sloc) 4.914 kb
c017b74 Dmitry Galinsky ??
dima-exe authored
1 ;;; rails-compile.el --- run compilation process for rails application.
2
3 ;; Copyright (C) 2006 Dmitry Galinsky <dima dot exe at gmail dot com>
4
5 ;; Authors: Dmitry Galinsky <dima dot exe at gmail dot com>,
6 ;; Rezikov Peter <crazypit13 (at) gmail.com>
7
8 ;;; License
9
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License
12 ;; as published by the Free Software Foundation; either version 2
13 ;; of the License, or (at your option) any later version.
14
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program; if not, write to the Free Software
22 ;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24 ;;; Code:
25
df3b256 Dmitry Galinsky Updated rails-compile to support a new resource schema.
dima-exe authored
26 (require 'rails-resources)
27
c017b74 Dmitry Galinsky ??
dima-exe authored
28 (defvar rails/compile/single-file-list '())
29 (defvar rails/compile/current-method-list '())
30
382a1a0 Dmitry Galinsky Added ansi color filter to all runner process.
dima-exe authored
31 (defvar rails/compile/font-lock-keywords
32 '(("\\([[:digit:]]+ tests\\), \\([[:digit:]]+ assertions\\), \\([[:digit:]]+ failures\\), \\([[:digit:]]+ errors\\)"
33 (1 compilation-info-face)
34 (2 compilation-info-face)
35 (3 compilation-error-face)
36 (4 compilation-error-face))
37 ("^\s+\\([0-9]+)\s+\\(Error\\|Failure\\):\\)"
38 1 compilation-error-face)
39 ("^[.EF]+$" . compilation-info-face)
40 ("^\\([a-z0-9_]+\\)(\\(.*\\))\\(:$\\|\n\s+\\[\\|\s+\\[\\)"
41 (1 font-lock-function-name-face)
42 (2 font-lock-type-face))
43 ("^<\\(.*\\)> \\(expected but was\\)\n<\\(.*\\)>.$"
44 (1 font-lock-constant-face)
45 (2 font-lock-string-face)
46 (3 font-lock-constant-face))
47 ("`\\(.+\\)'"
48 (1 font-lock-function-name-face))))
49
cf91454 fixed parsing in compilation mode.
Aleksei Gusev authored
50 (defun rails/compile/match-error ()
f7adccd Aleksei Gusev reindenting.
authored
51 (let ((file (match-string 1))
52 (root (rails/root default-directory)))
53 (when root
54 (unless (file-name-absolute-p file)
55 (setq file (concat root file)))
56 (setq file (expand-file-name file))
57 (if (and (file-exists-p file)
58 (not (files-ext/file-in-directory-p (concat root "vendor/") file)))
59 (list file)
60 nil))))
c017b74 Dmitry Galinsky ??
dima-exe authored
61
62 (defun rails/compile/error-regexp-alist ()
63 (list
cf91454 fixed parsing in compilation mode.
Aleksei Gusev authored
64 (list 'rails/compile/error
da843dc Aleksei Gusev added some rspec bundles, reindenting.
authored
65 (concat "\\(?:\\[\\|^\\|\\s+\\|(\\)?"
66 ;; rails framefork files should be a 'info'
67 "\\(\\([^ :\n\]+vendor/rails[^ :\n\]+\\)\\|"
68 ;; all files from vendor/ (plugins and etc) should be
69 ;; a 'warning'
70 "\\([^ :\n\]+vendor/[^ :\n\]+\\)\\|"
71 ;; all other is 'error'
72 "[^ :\n\]+\\)"
73 ":\\([0-9]+\\)+\\b")
74 1 4 nil '(3 . 2) 1)))
c017b74 Dmitry Galinsky ??
dima-exe authored
75
76
4b21a07 Aleksei Gusev fixed ROutput.
authored
77 (define-derived-mode rails/compilation-mode comint-mode "RCompile"
c017b74 Dmitry Galinsky ??
dima-exe authored
78 "Major mode for RoR tests."
79 (set (make-local-variable 'font-lock-keywords-only) t)
80 (set (make-local-variable 'font-lock-keywords) nil)
4b21a07 Aleksei Gusev fixed ROutput.
authored
81 ;; (set (make-local-variable 'font-lock-defaults) nil) ; to enable fontify by ansi-color
cf91454 fixed parsing in compilation mode.
Aleksei Gusev authored
82 ;; (set (make-local-variable 'font-lock-defaults)
83 ;; '(rails/compile/font-lock-keywords t))
382a1a0 Dmitry Galinsky Added ansi color filter to all runner process.
dima-exe authored
84 (set (make-local-variable 'compilation-mode-font-lock-keywords)
85 rails/compile/font-lock-keywords)
c017b74 Dmitry Galinsky ??
dima-exe authored
86 (set (make-local-variable 'compilation-error-regexp-alist-alist)
87 (rails/compile/error-regexp-alist))
88 (set (make-local-variable 'compilation-error-regexp-alist)
89 '(rails/compile/error)))
90
91 (defun rails/compile/run (root command args)
92 (rails/runner/run root command args :mode 'rails/compilation-mode)
93 (setq rails/runner/after-stop-func-list
f7adccd Aleksei Gusev reindenting.
authored
94 '(rails/runner/popup-buffer-if-failed)))
c017b74 Dmitry Galinsky ??
dima-exe authored
95
df3b256 Dmitry Galinsky Updated rails-compile to support a new resource schema.
dima-exe authored
96 (defun rails/compile/run-file (root rails-buffer command args-pattern &optional file-pattern)
39bca94 Dmitry Galinsky Fixed the rspec run command.
dima-exe authored
97 (let* ((item
f7adccd Aleksei Gusev reindenting.
authored
98 (when rails-buffer
99 (rails/resources/get-associated-test-item-for-buffer
100 root
101 rails-buffer)))
102 (match (when file-pattern
103 (string-ext/string=~ file-pattern
104 (or
105 (when item (rails/resource-item-file item))
106 (rails/resource-buffer-file rails-buffer))
107 t)))
108 file)
7044cb3 Dmitry Galinsky Removed action "run current file as spec" in rspec bundle, added this fu...
dima-exe authored
109 (cond
39bca94 Dmitry Galinsky Fixed the rspec run command.
dima-exe authored
110 ((and item (if file-pattern match t))
df3b256 Dmitry Galinsky Updated rails-compile to support a new resource schema.
dima-exe authored
111 (setq file (rails/resource-item-file item))
112 (rails/compile/run root
f7adccd Aleksei Gusev reindenting.
authored
113 command
114 (format args-pattern
115 file)))
df3b256 Dmitry Galinsky Updated rails-compile to support a new resource schema.
dima-exe authored
116 ((and file-pattern
f7adccd Aleksei Gusev reindenting.
authored
117 match)
7044cb3 Dmitry Galinsky Removed action "run current file as spec" in rspec bundle, added this fu...
dima-exe authored
118 (rails/compile/run root
f7adccd Aleksei Gusev reindenting.
authored
119 command
120 (format args-pattern
121 (rails/cut-root (buffer-file-name)))))
df3b256 Dmitry Galinsky Updated rails-compile to support a new resource schema.
dima-exe authored
122 (t
123 (rails/notify "Can't run current file as a test." :error)))))
c017b74 Dmitry Galinsky ??
dima-exe authored
124
125 (defun rails/compile/single-file ()
126 (interactive)
7044cb3 Dmitry Galinsky Removed action "run current file as spec" in rspec bundle, added this fu...
dima-exe authored
127 (when-bind (root (rails/root))
f7adccd Aleksei Gusev reindenting.
authored
128 (loop for func in rails/compile/single-file-list
129 for res = (funcall func root rails/current-buffer)
130 when res
131 do (return res))))
c017b74 Dmitry Galinsky ??
dima-exe authored
132
133 (defun rails/compile/current-method ()
134 (interactive)
7044cb3 Dmitry Galinsky Removed action "run current file as spec" in rspec bundle, added this fu...
dima-exe authored
135 (when-bind (root (rails/root))
f7adccd Aleksei Gusev reindenting.
authored
136 (loop for func in rails/compile/current-method-list
137 for res = (funcall func root rails/current-buffer)
138 when res
139 do (return res))))
c017b74 Dmitry Galinsky ??
dima-exe authored
140
141 (provide 'rails-compile)
Something went wrong with that request. Please try again.