diff --git a/rc/filetype/fidl.kak b/rc/filetype/fidl.kak new file mode 100644 index 00000000..4164d838 --- /dev/null +++ b/rc/filetype/fidl.kak @@ -0,0 +1,79 @@ +# Detection +hook global BufCreate .*\.fidl %{ + set-option buffer filetype fidl +} + +hook global WinSetOption filetype=fidl %< + require-module fidl + hook window ModeChange pop:insert:.* -group fidl-trim-indent fidl-trim-indent + hook window InsertChar \n -group fidl-indent fidl-indent-on-new-line + hook window InsertChar [)}] -group fidl-indent fidl-indent-on-closing + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window fidl-.+ } +> + +hook -group fidl-highlight global WinSetOption filetype=fidl %{ + add-highlighter window/fidl ref fidl + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/fidl } +} + +provide-module fidl %§ + +# Highlighters + +add-highlighter shared/fidl regions +add-highlighter shared/fidl/code default-region group + +add-highlighter shared/fidl/string region \" (? s \h+$ d } +} + +define-command -hidden fidl-indent-on-new-line %~ + evaluate-commands -draft -itersel %@ + try %{ # line comment + # copy the commenting prefix + execute-keys -draft k s ^\h*/{2,}\h* yjghP + } catch %` + # preserve previous line indent + try %{ execute-keys -draft K } + # align to opening ( or { if possible + try %+ + execute-keys -draft [)}] m 1 + + catch %+ + # indent after lines ending with ( or { + try %! execute-keys -draft k [({]$ j ! + + + ` + # remove trailing white spaces + try %{ execute-keys -draft k : fidl-trim-indent } + @ +~ + +define-command -hidden fidl-indent-on-closing %~ + evaluate-commands -draft -itersel %@ + # align to opening ( or { when alone on a line + try %< execute-keys -draft ^\h*[)}]$ m 1 > + @ +~ + +§ diff --git a/test/indent/fidl/comments/cmd b/test/indent/fidl/comments/cmd new file mode 100644 index 00000000..e3036a40 --- /dev/null +++ b/test/indent/fidl/comments/cmd @@ -0,0 +1 @@ +c diff --git a/test/indent/fidl/comments/in b/test/indent/fidl/comments/in new file mode 100644 index 00000000..691bd5b0 --- /dev/null +++ b/test/indent/fidl/comments/in @@ -0,0 +1,19 @@ + // foo%( ) + + // foo%( )bar + + //%( ) + + // %( ) + + // foo(%( ) + + /// foo%( ) + + /// foo%( )bar + + ///%( ) + + /// %( ) + + /// foo(%( ) diff --git a/test/indent/fidl/comments/out b/test/indent/fidl/comments/out new file mode 100644 index 00000000..2678cb23 --- /dev/null +++ b/test/indent/fidl/comments/out @@ -0,0 +1,29 @@ + // foo + // + + // foo + // bar + + // + // + + // + // + + // foo( + // + + /// foo + /// + + /// foo + /// bar + + /// + /// + + /// + /// + + /// foo( + /// diff --git a/test/indent/fidl/comments/rc b/test/indent/fidl/comments/rc new file mode 100644 index 00000000..d93242fb --- /dev/null +++ b/test/indent/fidl/comments/rc @@ -0,0 +1,3 @@ +source "%val{runtime}/colors/default.kak" +source "%val{runtime}/rc/filetype/fidl.kak" +set buffer filetype fidl diff --git a/test/indent/fidl/on-closing/cmd b/test/indent/fidl/on-closing/cmd new file mode 100644 index 00000000..de4c4fba --- /dev/null +++ b/test/indent/fidl/on-closing/cmd @@ -0,0 +1 @@ +c} diff --git a/test/indent/fidl/on-closing/in b/test/indent/fidl/on-closing/in new file mode 100644 index 00000000..8fc9031f --- /dev/null +++ b/test/indent/fidl/on-closing/in @@ -0,0 +1,3 @@ + foo {%( ) + + foo {%( ); diff --git a/test/indent/fidl/on-closing/out b/test/indent/fidl/on-closing/out new file mode 100644 index 00000000..6ec01cc5 --- /dev/null +++ b/test/indent/fidl/on-closing/out @@ -0,0 +1,5 @@ + foo { + } + + foo { + }; diff --git a/test/indent/fidl/on-closing/rc b/test/indent/fidl/on-closing/rc new file mode 100644 index 00000000..d93242fb --- /dev/null +++ b/test/indent/fidl/on-closing/rc @@ -0,0 +1,3 @@ +source "%val{runtime}/colors/default.kak" +source "%val{runtime}/rc/filetype/fidl.kak" +set buffer filetype fidl diff --git a/test/indent/fidl/on-newline/cmd b/test/indent/fidl/on-newline/cmd new file mode 100644 index 00000000..e3036a40 --- /dev/null +++ b/test/indent/fidl/on-newline/cmd @@ -0,0 +1 @@ +c diff --git a/test/indent/fidl/on-newline/in b/test/indent/fidl/on-newline/in new file mode 100644 index 00000000..cda171e8 --- /dev/null +++ b/test/indent/fidl/on-newline/in @@ -0,0 +1,11 @@ + foo%( ) + + @foo(%( ) + + foo {%( ) + + @foo(%( )) { + + @foo(%( )"bar") { + + foo {%( )}; diff --git a/test/indent/fidl/on-newline/out b/test/indent/fidl/on-newline/out new file mode 100644 index 00000000..6ffa26b3 --- /dev/null +++ b/test/indent/fidl/on-newline/out @@ -0,0 +1,17 @@ + foo + + + @foo( + + + foo { + + + @foo( + ) { + + @foo( + "bar") { + + foo { + }; diff --git a/test/indent/fidl/on-newline/rc b/test/indent/fidl/on-newline/rc new file mode 100644 index 00000000..d93242fb --- /dev/null +++ b/test/indent/fidl/on-newline/rc @@ -0,0 +1,3 @@ +source "%val{runtime}/colors/default.kak" +source "%val{runtime}/rc/filetype/fidl.kak" +set buffer filetype fidl