blob: 577ce40657b3e27e9a27eb3148d21ed03fddbe88 (
plain) (
blame)
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
|
;; adapted from http://www.emacswiki.org/emacs/FlymakeJavaScript
;;
;; Installation:
;;
;; (add-to-list 'load-path "~/lib/jshint-mode")
;; (require 'flymake-jshint)
;; (add-hook 'javascript-mode-hook
;; (lambda () (flymake-mode t)))
;;
;; run M-x flymake-mode to turn flymake on and off
;;
(require 'flymake)
(defcustom jshint-mode-mode "jshint"
"Can use either jshint or jslint"
:type 'string
:group 'flymake-jshint)
(defcustom jshint-mode-node-program "node"
"The program name to invoke node.js."
:type 'string
:group 'flymake-jshint)
(defcustom jshint-mode-location (file-name-directory load-file-name)
"The directory jshint-mode.js may be found in."
:type 'string
:group 'flymake-jshint)
(defcustom jshint-mode-port 3003
"The port the jshint-mode server runs on."
:type 'integer
:group 'flymake-jshint)
(defcustom jshint-mode-host "127.0.0.1"
"The host the jshint-mode server runs on."
:type 'string
:group 'flymake-jshint)
(setq jshint-process "jshint-mode-server")
(setq jshint-buffer "*jshint-mode*")
(defun jshint-mode-init ()
"Start the jshint-mode server."
(interactive)
(if (eq (process-status jshint-process) 'run)
'started
(start-process
jshint-process
jshint-buffer
jshint-mode-node-program
(expand-file-name (concat jshint-mode-location "/jshint-mode.js"))
"--host" jshint-mode-host
"--port" (number-to-string jshint-mode-port))
(set-process-query-on-exit-flag (get-process jshint-process) nil)
(message
(concat "jshint server has started on " jshint-mode-host
(number-to-string jshint-mode-port)))
'starting
))
(defun jshint-mode-stop ()
"Stop the jshint-mode server."
(interactive)
(delete-process jshint-process))
(defun flymake-jshint-init ()
(if (eq (jshint-mode-init) 'started)
(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)))
(jshint-url (format "http://%s:%d/check" jshint-mode-host jshint-mode-port)))
(list "curl" (list "--form" (format "source=<%s" local-file)
"--form" (format "filename=%s" local-file)
"--form" (format "mode=%s" jshint-mode-mode)
jshint-url)))))
(setq flymake-allowed-file-name-masks
(cons '(".+\\.js$"
flymake-jshint-init
flymake-simple-cleanup
flymake-get-real-file-name)
flymake-allowed-file-name-masks))
(setq flymake-err-line-patterns
(cons '("^Lint at line \\([[:digit:]]+\\) character \\([[:digit:]]+\\): \\(.+\\)$"
nil 1 2 3)
flymake-err-line-patterns))
(provide 'flymake-jshint)
|