-
Notifications
You must be signed in to change notification settings - Fork 2
/
vue.kak
92 lines (73 loc) · 3.18 KB
/
vue.kak
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
# Vue file
# ‾‾‾‾‾‾‾‾
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufCreate .*\.vue %{
set-option buffer filetype vue
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook -group vue-highlight global WinSetOption filetype=vue %{ add-highlighter window/vue ref vue }
hook global WinSetOption filetype=vue %{
require-module vue
hook window ModeChange insert:.* -group vue-hooks vue-filter-around-selections
hook window InsertChar '>' -group vue-indent vue-indent-on-greater-than
hook window InsertChar \n -group vue-indent vue-indent-on-new-line
set window comment_line '//'
set window comment_block_begin '<!--'
set window comment_block_end '-->'
}
hook -group vue-highlight global WinSetOption filetype=(?!vue).* %{ remove-highlighter window/vue }
hook global WinSetOption filetype=(?!vue).* %{
remove-hooks window vue-indent
remove-hooks window vue-hooks
}
provide-module vue %[
try %{
require-module html
require-module css
require-module javascript
require-module pug
require-module scss
require-module less
}
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
add-highlighter shared/vue regions
add-highlighter shared/vue/tag region < > regions
add-highlighter shared/vue/pug region <template\b.*?lang="pug".*?>\K (?=</template>) ref pug
add-highlighter shared/vue/html region <template\b.*?>\K (?=</template>) ref html
add-highlighter shared/vue/scss region <style\b.*?lang="scss".*?>\K (?=</style>) ref scss
add-highlighter shared/vue/sass region <style\b.*?lang="sass".*?>\K (?=</style>) ref sass
add-highlighter shared/vue/less region <style\b.*?lang="less".*?>\K (?=</style>) ref less
add-highlighter shared/vue/css region <style\b.*?>\K (?=</style>) ref css
add-highlighter shared/vue/ts region <script\b.*?lang="ts".*?>\K (?=</script>) ref typescript
add-highlighter shared/vue/js region <script\b.*?>\K (?=</script>) ref javascript
add-highlighter shared/vue/tag/base default-region group
add-highlighter shared/vue/tag/ region '"' (?<!\\)(\\\\)*" fill string
add-highlighter shared/vue/tag/ region "'" "'" fill string
add-highlighter shared/vue/tag/base/ regex \b([a-zA-Z0-9_-]+)=? 1:attribute
add-highlighter shared/vue/tag/base/ regex </?(\w+) 1:keyword
# Commands
# ‾‾‾‾‾‾‾‾
define-command -hidden vue-filter-around-selections %{
# remove trailing white spaces
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
}
define-command -hidden vue-indent-on-greater-than %[
evaluate-commands -draft -itersel %[
# align closing tag to opening when alone on a line
try %[ execute-keys -draft <space> <a-h> s ^\h+<lt>/(\w+)<gt>$ <ret> {c<lt><c-r>1,<lt>/<c-r>1<gt> <ret> s \A|.\z <ret> 1<a-&> ]
]
]
define-command -hidden vue-indent-on-new-line %{
evaluate-commands -draft -itersel %{
# preserve previous line indent
try %{ execute-keys -draft \; K <a-&> }
# filter previous line
try %{ execute-keys -draft k : vue-filter-around-selections <ret> }
# indent after lines ending with opening tag
try %{ execute-keys -draft k <a-x> <a-k> <[^/][^>]+>$ <ret> j <a-gt> }
}
}
]