forked from purcell/emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-javascript.el
97 lines (77 loc) · 3.24 KB
/
init-javascript.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
(defcustom preferred-javascript-mode 'js3-mode
"Javascript mode to use for .js files"
:type 'symbol
:group 'programming
:options '(js2-mode js3-mode js-mode))
(defvar preferred-mmm-javascript-mode 'js-mode)
(defvar preferred-javascript-indent-level 2)
;; Need to first remove from list if present, since elpa adds entries too, which
;; may be in an arbitrary order
(eval-when-compile (require 'cl))
(setq auto-mode-alist (cons `("\\.js\\(\\.erb\\|on\\)?$" . ,preferred-javascript-mode)
(loop for entry in auto-mode-alist
unless (eq preferred-javascript-mode (cdr entry))
collect entry)))
;; On-the-fly syntax checking
(eval-after-load 'js
'(add-hook 'js-mode-hook 'flymake-jslint-load))
;; js2-mode
(setq js2-use-font-lock-faces t
js2-mode-must-byte-compile nil
js2-basic-offset preferred-javascript-indent-level
js2-indent-on-enter-key t
js2-auto-indent-p t
js2-bounce-indent-p t)
;; js3-mode
(setq js3-auto-indent-p t
js3-enter-indents-newline t
js3-indent-on-enter-key t
js3-indent-level preferred-javascript-indent-level)
;; js-mode
(setq js-indent-level preferred-javascript-indent-level)
;; standard javascript-mode
(setq javascript-indent-level preferred-javascript-indent-level)
;; MMM submode regions in html
(eval-after-load 'mmm-vars
`(progn
(mmm-add-group
'html-js
'((js-script-cdata
:submode ,preferred-mmm-javascript-mode
:face mmm-code-submode-face
:front "<script[^>]*>[ \t\n]*\\(//\\)?<!\\[CDATA\\[[ \t]*\n?"
:back "[ \t]*\\(//\\)?]]>[ \t\n]*</script>"
:insert ((?j js-tag nil @ "<script language=\"JavaScript\">"
@ "\n" _ "\n" @ "</script>" @)))
(js-script
:submode ,preferred-mmm-javascript-mode
:face mmm-code-submode-face
:front "<script[^>]*>[ \t]*\n?"
:back "[ \t]*</script>"
:insert ((?j js-tag nil @ "<script language=\"JavaScript\">"
@ "\n" _ "\n" @ "</script>" @)))
(js-inline
:submode ,preferred-mmm-javascript-mode
:face mmm-code-submode-face
:front "on\w+=\""
:back "\"")))
(dolist (mode (list 'html-mode 'nxml-mode))
(mmm-add-mode-ext-class mode "\\.r?html\\(\\.erb\\)?$" 'html-js))))
(add-to-list 'auto-mode-alist '("\\.coffee$" . coffee-mode))
(eval-after-load 'coffee-mode
`(setq coffee-js-mode preferred-javascript-mode
coffee-tab-width preferred-javascript-indent-level))
(add-hook 'coffee-mode-hook 'flymake-coffee-load)
;; ---------------------------------------------------------------------------
;; Run and interact with an inferior JS via js-comint.el
;; ---------------------------------------------------------------------------
(setq inferior-js-program-command "js")
(defun add-inferior-js-keys ()
(local-set-key "\C-x\C-e" 'js-send-last-sexp)
(local-set-key "\C-\M-x" 'js-send-last-sexp-and-go)
(local-set-key "\C-cb" 'js-send-buffer)
(local-set-key "\C-c\C-b" 'js-send-buffer-and-go)
(local-set-key "\C-cl" 'js-load-file-and-go))
(dolist (hook '(js2-mode-hook js3-mode-hook js-mode-hook))
(add-hook hook 'add-inferior-js-keys))
(provide 'init-javascript)