forked from vjohansen/emacs-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tempo-javascript.el
85 lines (66 loc) · 2.77 KB
/
tempo-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
(require 'tempo)
(defvar javascript-tempo-tags nil)
(add-hook 'javascript-mode-hook 'javascript-tempo)
(defun javascript-tempo ()
"Set up javascript mode to use tempo.el"
(local-set-key "\C-c\C-e" 'tempo-complete-tag)
(local-set-key "\C-c\C-f" 'tempo-forward-mark)
(tempo-use-tag-list 'javascript-tempo-tags))
(tempo-define-template
"javascript-for"
(list "for (" '(p "initial: ") "; " '(p "condition: ") "; " '(p "increment: ") ") {" 'n> 'p 'n "}" '>)
"for" "insert a for loop" 'javascript-tempo-tags)
;;; You can use 'P' to force interactive query.
;;; This is useful here because "var" is used more than once.
(tempo-define-template "javascript-for-i"
'(> "for (var " (P "variable: " var) " = 0; " (s var)
" < "(p "upper bound: " ub)"; " (s var) "++)" > n>
"{" > n> r n
"}" > n>
)
"fori" "Insert a indexed for loop" 'javascript-tempo-tags)
(tempo-define-template
"javascript-for-in"
(list "for (" '(p "variable: ") " in " '(p "object: ") ") {" '> 'n> 'p 'n "}" '>)
"infor" "insert a for loop" 'javascript-tempo-tags)
(tempo-define-template
"javascript-if"
(list "if (" '(p "condition: ") ") {" 'n> 'p 'n "}" '>)
"if" "insert an if statement" 'javascript-tempo-tags)
(tempo-define-template
"javascript-while"
(list "while (" '(p "condition: ") ") {" 'n> 'p 'n "}" '>)
"while" "insert a while statement" 'javascript-tempo-tags)
(tempo-define-template
"javascript-do"
(list "do {" '> 'n> 'p 'n "} while(" '(p "condition: ") ");" '>)
"do" "insert a do-while statement" 'javascript-tempo-tags)
(tempo-define-template
"javascript-with"
(list "with (" '(p "with what? ") ") {" 'n> 'p 'n "}" '>)
"with" "insert a with statement" 'javascript-tempo-tags)
(tempo-define-template
"javascript-defun"
(list "function " '(p "function name: ") "(" '(p "arguments: ") ") {" 'n> 'p 'n "}" '>)
"function" "insert a function definition" 'javascript-tempo-tags)
(tempo-define-template
"javascript-switch"
(list "switch (" '(p "variable: ") ") {" '> 'n> "case '" 'p "' :" '> 'n> "break;" '> 'n> "default :" '> 'n> "}" '>)
"switch" "insert a switch statement" 'javascript-tempo-tags)
(tempo-define-template
"javascript-case"
(list "case '" 'p "' :" '> 'n> "break;" '>)
"case" "insert a case" 'javascript-tempo-tags)
(defun vj-js-proto-name ()
""
(save-excursion
(if (re-search-backward "^function \\([A-Za-z_][A-Za-z0-9_]*\\)" nil t)
(match-string-no-properties 1) (file-name-sans-extension (buffer-name)))))
(tempo-define-template
"javascript-prototype"
'((vj-js-proto-name) ".prototype." 'p " = function(" 'p "){" '> 'n> 'p '> 'n> "}" '> )
"prototype" "insert a method" 'javascript-tempo-tags)
(tempo-define-template
"javascript-log"
(list "console.log(\"" 'p "\");")
"console.log" "insert a log" 'javascript-tempo-tags)