/
flymake-coffeelint.el
140 lines (123 loc) · 4.86 KB
/
flymake-coffeelint.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
;; adapted from https://raw.github.com/keturn/lintnode/master/flymake-jslint.el
;;
;; Commentary:
;;
;; Installation:
;;
;; Put this in your load-path, then add the following to your .emacs.
;;
;; (require 'flymake-coffeelint)
;; (add-hook 'coffee-mode-hook
;; (lambda () (coffeelintnode-hook)))
;;
;; Configuration
;;
;; Do M-x customize-group flymake-coffeelint to customize paths, port and autostart.
;;
;; By default, all the coffeelint variables are on, however you can turn them off by adding
;; them to the variable coffeelintnode-coffeelint-excludes -
;;
;; Usage:
;;
;; To start lintnode, either
;; * run M-x coffeelintnode-start before invoking flymake.
;; * set the customize variable coffeelintnode-autostart to t
;;
;; Code:
(require 'flymake)
(defcustom coffeelintnode-node-program "node"
"The program name to invoke node.js."
:type 'string
:group 'flymake-coffeelint)
(defcustom coffeelintnode-location (file-name-directory load-file-name)
"The directory coffeelintnode's app.js may be found in."
:type 'string
:group 'flymake-coffeelint)
(defcustom coffeelintnode-port 3004
"The port the coffeelintnode server runs on."
:type 'integer
:group 'flymake-coffeelint)
(defcustom coffeelintnode-autostart t
"Whether to start coffeelintnode automatically when we've called coffeelintnode-hook"
:type 'boolean
:group 'flymake-coffeelint)
(defvar coffeelintnode-coffeelint-excludes nil
"a list of lisp symbols corresponding to coffeelint boolean options")
(defvar coffeelintnode-coffeelint-includes nil
"a list of lisp symbols corresponding to coffeelint boolean options")
(defvar coffeelintnode-coffeelint-set ""
"a string of comma seperated jslint options; values are seperated via colon, e.g. max_line_length:80,indentation:true,no_tabs:false")
(defun coffeelintnode-start ()
"Start the coffeelintnode server.
Uses `coffeelintnode-node-program' and `coffeelintnode-location'."
(interactive)
(message "Starting coffeelintnode")
(let ((coffeelintnode-location (expand-file-name (concat coffeelintnode-location "/app.js")))
(coffeelintnode-excludes (if (not coffeelintnode-coffeelint-excludes)
""
(mapconcat 'identity
(mapcar 'symbol-name
coffeelintnode-coffeelint-excludes)
",")))
(coffeelintnode-includes (if (not coffeelintnode-coffeelint-includes)
""
(mapconcat 'identity
(mapcar 'symbol-name
coffeelintnode-coffeelint-includes)
","))))
(start-process "coffeelintnode-server" "*coffeelintnode*"
coffeelintnode-node-program
coffeelintnode-location
"--port" (number-to-string coffeelintnode-port)
"--exclude" coffeelintnode-excludes
"--include" coffeelintnode-includes
"--set" coffeelintnode-coffeelint-set)
(sit-for 1)
;; (let ((counter 5))
;; (while (and (not (get-buffer-process "*coffeelintnode*")) (> index 0))
;; (sit-for 1)
;; (setq index (1- counter))))
))
(defun coffeelintnode-stop ()
"stop the coffeelintnode server process"
(interactive)
(if (get-process "coffeelintnode-server")
(kill-process "coffeelintnode-server")))
(defun coffeelintnode-restart()
"Restart the coffeelintnode server - typically we've fiddled with the configuration"
(interactive)
(coffeelintnode-stop)
(sit-for 1)
(coffeelintnode-start))
(defun coffeelintnode-hook ()
"When we open a file in coffeescript mode, we should check to see if there is a
coffeelint process running. If there isn't we check to see if the user has set
coffeelintnode-autostart to t, then start the process and flymake-mode."
(let ((proc (get-buffer-process "*coffeelintnode*")))
(if (not proc)
(when coffeelintnode-autostart
(coffeelintnode-start))
(flymake-mode 1))))
(defun flymake-coffeelint-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name)))
(coffeelint-url (format "http://127.0.0.1:%d/coffeelint" coffeelintnode-port)))
(list "curl" (list "--form" (format "source=<%s" local-file)
"--form" (format "filename=%s" local-file)
;; FIXME: For some reason squid hates this curl invocation.
"--proxy" ""
coffeelint-url))))
(setq flymake-allowed-file-name-masks
(cons '(".+\\.coffee$"
flymake-coffeelint-init
flymake-simple-cleanup
flymake-get-real-file-name)
flymake-allowed-file-name-masks))
(setq flymake-err-line-patterns
(cons '("^Lint at line \\([[:digit:]]+\\): \\(.+\\)$"
nil 1 nil 2)
flymake-err-line-patterns))
(provide 'flymake-coffeelint)