summaryrefslogtreecommitdiff
path: root/rc/filetype/javascript.kak
diff options
context:
space:
mode:
Diffstat (limited to 'rc/filetype/javascript.kak')
-rw-r--r--rc/filetype/javascript.kak47
1 files changed, 30 insertions, 17 deletions
diff --git a/rc/filetype/javascript.kak b/rc/filetype/javascript.kak
index c02c6aab..6f60a4ec 100644
--- a/rc/filetype/javascript.kak
+++ b/rc/filetype/javascript.kak
@@ -9,6 +9,34 @@ hook global BufCreate .*[.](ts)x? %{
set-option buffer filetype typescript
}
+# Initialization
+# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
+
+hook global WinSetOption filetype=(javascript|typescript) %{
+ require-module javascript
+
+ hook window ModeChange insert:.* -group "%val{hook_param_capture_1}-trim-indent" javascript-trim-indent
+ hook window InsertChar .* -group "%val{hook_param_capture_1}-indent" javascript-indent-on-char
+ hook window InsertChar \n -group "%val{hook_param_capture_1}-indent" javascript-indent-on-new-line
+
+ hook -once -always window WinSetOption filetype=.* "
+ remove-hooks window %val{hook_param_capture_1}-.+
+ "
+}
+
+hook -group javascript-highlight global WinSetOption filetype=javascript %{
+ add-highlighter window/javascript ref javascript
+ hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/javascript }
+}
+
+hook -group typescript-highlight global WinSetOption filetype=typescript %{
+ add-highlighter window/typescript ref typescript
+ hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/typescript }
+}
+
+
+provide-module javascript %§
+
# Commands
# ‾‾‾‾‾‾‾‾
@@ -89,23 +117,6 @@ define-command -hidden init-javascript-filetype -params 1 %~
# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get
# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set
add-highlighter "shared/%arg{1}/code/" regex \b(async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|export|extends|finally|for|function|get|if|import|in|instanceof|let|new|of|return|set|static|super|switch|throw|try|typeof|var|void|while|with|yield)\b 0:keyword
-
- # Initialization
- # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
-
- hook -group "%arg{1}-highlight" global WinSetOption "filetype=%arg{1}" "
- add-highlighter window/%arg{1} ref %arg{1}
-
- hook -once -always window WinSetOption filetype=.* %%{ remove-highlighter window/%arg{1} }
- "
-
- hook global WinSetOption "filetype=%arg{1}" "
- hook window ModeChange insert:.* -group %arg{1}-trim-indent javascript-trim-indent
- hook window InsertChar .* -group %arg{1}-indent javascript-indent-on-char
- hook window InsertChar \n -group %arg{1}-indent javascript-indent-on-new-line
-
- hook -once -always window WinSetOption filetype=.* %%{ remove-hooks window %arg{1}-.+ }
- "
~
init-javascript-filetype javascript
@@ -117,3 +128,5 @@ add-highlighter shared/typescript/code/ regex \b(array|boolean|date|number|objec
# Keywords grabbed from https://github.com/Microsoft/TypeScript/issues/2536
add-highlighter shared/typescript/code/ regex \b(as|constructor|declare|enum|from|implements|interface|module|namespace|package|private|protected|public|readonly|static|type)\b 0:keyword
+