From 3aaee810becfbda80b761923ca1bcac14191feb5 Mon Sep 17 00:00:00 2001 From: Cormac Stephenson Date: Thu, 9 Jun 2022 02:18:00 +0100 Subject: [PATCH 1/6] rc: add hare language module --- rc/filetype/hare.kak | 122 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 rc/filetype/hare.kak diff --git a/rc/filetype/hare.kak b/rc/filetype/hare.kak new file mode 100644 index 00000000..c61f175c --- /dev/null +++ b/rc/filetype/hare.kak @@ -0,0 +1,122 @@ +# detection +hook global BufCreate .*[.]ha %{ + set-option buffer filetype hare +} + +# initialisation +hook global WinSetOption filetype=hare %{ + require-module hare + hook window ModeChange pop:insert:.* -group hare-trim-indent hare-trim-indent + hook window InsertChar \n -group hare-indent hare-indent-on-new-line + hook window InsertChar \n -group hare-insert hare-insert-on-new-line +} + +hook -group hare-highlight global WinSetOption filetype=hare %{ + add-highlighter window/hare ref hare + hook -once -always window WinSetOption filetype=*. %{ remove-highlighter window/hare } +} + +# highlighters +provide-module hare %{ + add-highlighter shared/hare regions + add-highlighter shared/hare/code default-region group + add-highlighter shared/hare/comment region // $ fill comment + + add-highlighter shared/hare/rawstring region ` ` group + add-highlighter shared/hare/rawstring/ fill string + + add-highlighter shared/hare/string region '"' (? K } + # remove trailing whitespace on the above line + execute-keys -draft k :hare-trim-indent + } } + + define-command -hidden hare-insert-on-new-line %{ evaluate-commands -draft -itersel %{ + try %{ evaluate-commands -draft -save-regs '/"' %{ + # copy the comment prefix + execute-keys -save-regs '' k s ^\h*\K//\h* y + try %{ + # paste the comment prefix + execute-keys j s ^\h* P + } + } } + try %{ + # remove trailing whitespace on the above line + execute-keys -draft k :hare-trim-indent + } + } } + + define-command -hidden hare-trim-indent %{ evaluate-commands -draft -itersel %{ + # remove trailing whitespace + try %{ execute-keys -draft s \h+$ d } + } } + + # TODO + # const/null/void/size are ambiguous + # indentation (copy c-family.kak) +} From 1898528421ea38448baf1e9ba6ce39565f6d6ae3 Mon Sep 17 00:00:00 2001 From: Jon Eskin Date: Thu, 9 Jun 2022 04:29:32 -0400 Subject: [PATCH 2/6] Add hare comments and indentation --- rc/filetype/hare.kak | 24 ++++++++++++++++++++++-- rc/tools/comment.kak | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/rc/filetype/hare.kak b/rc/filetype/hare.kak index c61f175c..31007067 100644 --- a/rc/filetype/hare.kak +++ b/rc/filetype/hare.kak @@ -9,6 +9,8 @@ hook global WinSetOption filetype=hare %{ hook window ModeChange pop:insert:.* -group hare-trim-indent hare-trim-indent hook window InsertChar \n -group hare-indent hare-indent-on-new-line hook window InsertChar \n -group hare-insert hare-insert-on-new-line + hook window InsertChar \{ -group hare-indent hare-indent-on-opening-curly-brace + hook window InsertChar \} -group hare-indent hare-indent-on-closing-curly-brace } hook -group hare-highlight global WinSetOption filetype=hare %{ @@ -17,7 +19,7 @@ hook -group hare-highlight global WinSetOption filetype=hare %{ } # highlighters -provide-module hare %{ +provide-module hare %§ add-highlighter shared/hare regions add-highlighter shared/hare/code default-region group add-highlighter shared/hare/comment region // $ fill comment @@ -92,6 +94,14 @@ provide-module hare %{ define-command -hidden hare-indent-on-new-line %{ evaluate-commands -draft -itersel %{ # preserve indentation on new lines try %{ execute-keys -draft K } + # indent after lines ending with { or ( + try %[ execute-keys -draft k [{(]\h*$ j i ] + # cleanup trailing white spaces on the previous line + try %{ execute-keys -draft k s \h+$ d } + # indent after a switch's case/default statements + try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] + # deindent closing brace(s) when after cursor + try %[ execute-keys -draft ^\h*[})] gh / [})] m 1 ] # remove trailing whitespace on the above line execute-keys -draft k :hare-trim-indent } } @@ -111,6 +121,16 @@ provide-module hare %{ } } } + define-command -hidden hare-indent-on-opening-curly-brace %[ + # align indent with opening paren when { is entered on a new line after the closing paren + try %[ execute-keys -draft -itersel h)M \A\(.*\)\h*\n\h*\{\z s \A|.\z 1 ] + ] + + define-command -hidden hare-indent-on-closing-curly-brace %[ + # align to opening curly brace when alone on a line + try %[ execute-keys -itersel -draft ^\h+\}$hms\A|.\z1 ] + ] + define-command -hidden hare-trim-indent %{ evaluate-commands -draft -itersel %{ # remove trailing whitespace try %{ execute-keys -draft s \h+$ d } @@ -119,4 +139,4 @@ provide-module hare %{ # TODO # const/null/void/size are ambiguous # indentation (copy c-family.kak) -} + § diff --git a/rc/tools/comment.kak b/rc/tools/comment.kak index 1094fbba..803a96fe 100644 --- a/rc/tools/comment.kak +++ b/rc/tools/comment.kak @@ -118,7 +118,7 @@ hook global BufSetOption filetype=perl %{ set-option buffer comment_block_end ']' } -hook global BufSetOption filetype=(pug|zig|cue) %{ +hook global BufSetOption filetype=(pug|zig|cue|hare) %{ set-option buffer comment_line '//' } From 318fb02bb9d62d45a95993d34d7dd7d59eddd67b Mon Sep 17 00:00:00 2001 From: Jon Eskin Date: Thu, 9 Jun 2022 04:38:10 -0400 Subject: [PATCH 3/6] remove redundant whitespace trim --- rc/filetype/hare.kak | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rc/filetype/hare.kak b/rc/filetype/hare.kak index 31007067..9b97532e 100644 --- a/rc/filetype/hare.kak +++ b/rc/filetype/hare.kak @@ -97,13 +97,11 @@ provide-module hare %§ # indent after lines ending with { or ( try %[ execute-keys -draft k [{(]\h*$ j i ] # cleanup trailing white spaces on the previous line - try %{ execute-keys -draft k s \h+$ d } + execute-keys -draft k :hare-trim-indent # indent after a switch's case/default statements try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] # deindent closing brace(s) when after cursor try %[ execute-keys -draft ^\h*[})] gh / [})] m 1 ] - # remove trailing whitespace on the above line - execute-keys -draft k :hare-trim-indent } } define-command -hidden hare-insert-on-new-line %{ evaluate-commands -draft -itersel %{ From 2b051dd25aa138c71d59e75255b862aef6b7f6a7 Mon Sep 17 00:00:00 2001 From: Jon Eskin Date: Thu, 9 Jun 2022 04:54:50 -0400 Subject: [PATCH 4/6] fix case statement regex --- rc/filetype/hare.kak | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rc/filetype/hare.kak b/rc/filetype/hare.kak index 9b97532e..4b9b299c 100644 --- a/rc/filetype/hare.kak +++ b/rc/filetype/hare.kak @@ -98,8 +98,8 @@ provide-module hare %§ try %[ execute-keys -draft k [{(]\h*$ j i ] # cleanup trailing white spaces on the previous line execute-keys -draft k :hare-trim-indent - # indent after a switch's case/default statements - try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] + # indent after match/switch's case statements + try %[ execute-keys -draft k case\h.*=>\h*$ j ] # deindent closing brace(s) when after cursor try %[ execute-keys -draft ^\h*[})] gh / [})] m 1 ] } } From db856ba2884fe568599feab03c8b9f3c856a446e Mon Sep 17 00:00:00 2001 From: Cormac Stephenson Date: Thu, 9 Jun 2022 13:11:14 +0100 Subject: [PATCH 5/6] hare.kak: remove TODO list --- rc/filetype/hare.kak | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/rc/filetype/hare.kak b/rc/filetype/hare.kak index 4b9b299c..7e536476 100644 --- a/rc/filetype/hare.kak +++ b/rc/filetype/hare.kak @@ -133,8 +133,4 @@ provide-module hare %§ # remove trailing whitespace try %{ execute-keys -draft s \h+$ d } } } - - # TODO - # const/null/void/size are ambiguous - # indentation (copy c-family.kak) - § +§ From 971b52c94e25794b493baf1e761cd1a0dc84c252 Mon Sep 17 00:00:00 2001 From: Cormac Stephenson Date: Sat, 11 Jun 2022 05:55:24 +0100 Subject: [PATCH 6/6] hare.kak: highlight module imports as "module" --- rc/filetype/hare.kak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc/filetype/hare.kak b/rc/filetype/hare.kak index 7e536476..47d0da41 100644 --- a/rc/filetype/hare.kak +++ b/rc/filetype/hare.kak @@ -44,8 +44,8 @@ provide-module hare %§ add-highlighter shared/hare/rune/ regex "(\\U[0-9a-fA-F]{8})" 0:meta # imports + add-highlighter shared/hare/code/ regex "\buse\s.*?(?=;)" 0:module add-highlighter shared/hare/code/ regex "\buse\b" 0:meta - add-highlighter shared/hare/code/ regex "\buse\s.*?;" 0:meta # attributes add-highlighter shared/hare/code/ regex "@(offset|init|fini|test|noreturn|symbol)\b" 0:attribute