diff --git a/rc/cabal.kak b/rc/cabal.kak new file mode 100644 index 00000000..c280e4e8 --- /dev/null +++ b/rc/cabal.kak @@ -0,0 +1,82 @@ +# http://haskell.org/cabal +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufSetOption mimetype=text/x-cabal %{ + set buffer filetype cabal +} + +hook global BufCreate .*[.](cabal) %{ + set buffer filetype cabal +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +addhl -group / regions -default code cabal \ + comment (--) $ '' \ + comment \{- -\} \{- + +addhl -group /cabal/comment fill comment + +addhl -group /cabal/code regex \<(true|false)\>|(([<>]?=?)?\d+(\.\d+)+) 0:value +addhl -group /cabal/code regex \<(if|else)\> 0:keyword +addhl -group /cabal/code regex ^\h*([A-Za-z][A-Za-z0-9_-]*)\h*: 1:identifier + +# Commands +# ‾‾‾‾‾‾‾‾ + +def -hidden _cabal_filter_around_selections %{ + eval -draft -itersel %{ + exec + # remove trailing white spaces + try %{ exec -draft s \h+$ d } + } +} + +def -hidden _cabal_indent_on_new_line %[ + eval -draft -itersel %[ + # preserve previous line indent + try %[ exec -draft K ] + # filter previous line + try %[ exec -draft k : _cabal_filter_around_selections ] + # copy '#' comment prefix and following white spaces + try %[ exec -draft k x s ^\h*\K#\h* y j p ] + # indent after lines ending with { or : + try %[ exec -draft k x [:{]$ j ] + ] +] + +def -hidden _cabal_indent_on_opening_curly_brace %[ + eval -draft -itersel %[ + # align indent with opening paren when { is entered on a new line after the closing paren + try %[ exec -draft h ) M \`\(.*\)\h*\n\h*\{\' s \`|.\' 1 ] + ] +] + +def -hidden _cabal_indent_on_closing_curly_brace %[ + eval -draft -itersel %[ + # align to opening curly brace when alone on a line + try %[ exec -draft ^\h+\}$ h m s \`|.\' 1 ] + ] +] + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=cabal %[ + addhl ref cabal + + hook window InsertEnd .* -group cabal-hooks _cabal_filter_around_selections + hook window InsertChar \n -group cabal-indent _cabal_indent_on_new_line + hook window InsertChar \{ -group cabal-indent _cabal_indent_on_opening_curly_brace + hook window InsertChar \} -group cabal-indent _cabal_indent_on_closing_curly_brace +] + +hook global WinSetOption filetype=(?!cabal).* %{ + rmhl cabal + rmhooks window cabal-indent + rmhooks window cabal-hooks +} diff --git a/rc/clojure.kak b/rc/clojure.kak new file mode 100644 index 00000000..fd4afb3c --- /dev/null +++ b/rc/clojure.kak @@ -0,0 +1,46 @@ +# http://clojure.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# require lisp.kak + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufSetOption mimetype=text/x-clojure %{ + set buffer filetype clojure +} + +hook global BufCreate .*[.](clj) %{ + set buffer filetype clojure +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +addhl -group / group clojure + +addhl -group /clojure ref lisp + +addhl -group /clojure regex \<(clojure.core/['/\w]+)\> 0:keyword + +# Commands +# ‾‾‾‾‾‾‾‾ + +def -hidden _clojure_filter_around_selections _lisp_filter_around_selections +def -hidden _clojure_indent_on_new_line _lisp_indent_on_new_line + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=clojure %[ + addhl ref clojure + + hook window InsertEnd .* -group clojure-hooks _clojure_filter_around_selections + hook window InsertChar \n -group clojure-indent _clojure_indent_on_new_line +] + +hook global WinSetOption filetype=(?!clojure).* %{ + rmhl clojure + rmhooks window clojure-indent + rmhooks window clojure-hooks +} diff --git a/rc/css.kak b/rc/css.kak new file mode 100644 index 00000000..a68ee5cd --- /dev/null +++ b/rc/css.kak @@ -0,0 +1,84 @@ +# http://w3.org/Style/CSS +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufSetOption mimetype=text/x-css %{ + set buffer filetype css +} + +hook global BufCreate .*[.](css) %{ + set buffer filetype css +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +addhl -group / regions -default selector css \ + declaration [{] [}] '' \ + comment /[*] [*]/ '' + +addhl -group /css/comment fill comment + +addhl -group /css/declaration regions content \ + string '"' (? + # remove trailing white spaces + try %{ exec -draft s \h+$ d } + } +} + +def -hidden _css_indent_on_new_line %[ + eval -draft -itersel %[ + # preserve previous line indent + try %[ exec -draft K ] + # filter previous line + try %[ exec -draft k : _css_filter_around_selections ] + # indent after lines ending with with { + try %[ exec -draft k x \{$ j ] + ] +] + +def -hidden _css_indent_on_closing_curly_brace %[ + eval -draft -itersel %[ + # align to opening curly brace when alone on a line + try %[ exec -draft ^\h+\}$ m s \`|.\' 1 ] + ] +] + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=css %[ + addhl ref css + + hook window InsertEnd .* -group css-hooks _css_filter_around_selections + hook window InsertChar \n -group css-indent _css_indent_on_new_line + hook window InsertChar \} -group css-indent _css_indent_on_closing_curly_brace +] + +hook global WinSetOption filetype=(?!css).* %{ + rmhl css + rmhooks window css-indent + rmhooks window css-hooks +} diff --git a/rc/haskell.kak b/rc/haskell.kak new file mode 100644 index 00000000..1a59927e --- /dev/null +++ b/rc/haskell.kak @@ -0,0 +1,75 @@ +# http://haskell.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufSetOption mimetype=text/x-haskell %{ + set buffer filetype haskell +} + +hook global BufCreate .*[.](hs) %{ + set buffer filetype haskell +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +addhl -group / regions -default code haskell \ + string '"' (? 0:meta +addhl -group /haskell/code regex \<(True|False)\> 0:value +addhl -group /haskell/code regex \<(as|case|class|data|default|deriving|do|else|hiding|if|in|infix|infixl|infixr|instance|let|module|newtype|of|qualified|then|type|where)\> 0:keyword +addhl -group /haskell/code regex \<(Int|Integer|Char|Bool|Float|Double|IO|Void|Addr|Array|String)\> 0:type + +# Commands +# ‾‾‾‾‾‾‾‾ + +# http://en.wikibooks.org/wiki/Haskell/Indentation + +def -hidden _haskell_filter_around_selections %{ + eval -draft -itersel %{ + exec + # remove trailing white spaces + try %{ exec -draft s \h+$ d } + } +} + +def -hidden _haskell_indent_on_new_line %{ + eval -draft -itersel %{ + # preserve previous line indent + try %{ exec -draft K } + # align to first clause + try %{ exec -draft k x X s ^\h*(if|then|else)?\h*(([\w']+\h+)+=)?\h*(case\h+[\w']+\h+of|do|let|where)\h+\K.* s \`|.\' & } + # filter previous line + try %{ exec -draft k : _haskell_filter_around_selections } + # copy -- comments prefix and following white spaces + try %{ exec -draft k x s ^\h*\K--\h* y j p } + # indent after lines beginning with condition or ending with expression or =( + try %{ exec -draft k x ^\h*(if)|(case\h+[\w']+\h+of|do|let|where|[=(])$ j } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=haskell %{ + addhl ref haskell + + hook window InsertEnd .* -group haskell-hooks _haskell_filter_around_selections + hook window InsertChar \n -group haskell-indent _haskell_indent_on_new_line +} + +hook global WinSetOption filetype=(?!haskell).* %{ + rmhl haskell + rmhooks window haskell-indent + rmhooks window haskell-hooks +} diff --git a/rc/html.kak b/rc/html.kak new file mode 100644 index 00000000..6dd36882 --- /dev/null +++ b/rc/html.kak @@ -0,0 +1,81 @@ +# http://w3.org/html +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufSetOption mimetype=text/x-html %{ + set buffer filetype html +} + +hook global BufCreate .*[.](html) %{ + set buffer filetype html +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +addhl -group / regions html \ + comment '' \ + tag < > '' \ + style .*?>\K (?=) '' \ + script .*?>\K (?=) '' + +addhl -group /html/comment fill comment + +addhl -group /html/style ref css +addhl -group /html/script ref javascript + +addhl -group /html/tag regex + # remove trailing white spaces + try %{ exec -draft s \h+$ d } + } +} + +def -hidden _html_indent_on_char %{ + eval -draft -itersel %{ + # align closing tag to opening when alone on a line + try %{ exec -draft s ^\h+$ 1 s \`|.\' 1 } + } +} + +def -hidden _html_indent_on_new_line %{ + eval -draft -itersel %{ + # preserve previous line indent + try %{ exec -draft K } + # filter previous line + try %{ exec -draft k : _html_filter_around_selections } + # indent after lines ending with opening tag + try %{ exec -draft k x <[^/][^>]+>$ j } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=html %{ + addhl ref html + + hook window InsertEnd .* -group html-hooks _html_filter_around_selections + hook window InsertChar .* -group html-indent _html_indent_on_char + hook window InsertChar \n -group html-indent _html_indent_on_new_line +} + +hook global WinSetOption filetype=(?!html).* %{ + rmhl html + rmhooks window html-indent + rmhooks window html-hooks +} diff --git a/rc/lisp.kak b/rc/lisp.kak new file mode 100644 index 00000000..84e9e86d --- /dev/null +++ b/rc/lisp.kak @@ -0,0 +1,64 @@ +# http://common-lisp.net +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufSetOption mimetype=text/x-lisp %{ + set buffer filetype lisp +} + +hook global BufCreate .*[.](lisp) %{ + set buffer filetype lisp +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +addhl -group / regions -default code lisp \ + string '"' (? 0:value +addhl -group /lisp/code regex (((\Q***\E)|(///)|(\Q+++\E)){1,3})|(1[+-])|(<|>|<=|=|>=|) 0:operator +addhl -group /lisp/code regex \<(([':]\w+)|([*]\H+[*]))\> 0:identifier +addhl -group /lisp/code regex \<(def[a-z]+|if|do|let|lambda|catch|and|assert|while|def|do|fn|finally|let|loop|new|quote|recur|set!|throw|try|var|case|if-let|if-not|when|when-first|when-let|when-not|(cond(->|->>)?))\> 0:keyword + +# Commands +# ‾‾‾‾‾‾‾‾ + +def -hidden _lisp_filter_around_selections %{ + eval -draft -itersel %{ + exec + # remove trailing white spaces + try %{ exec -draft s \h+$ d } + } +} + +def -hidden _lisp_indent_on_new_line %{ + eval -draft -itersel %{ + # preserve previous line indent + try %{ exec -draft K } + # indent when matches opening paren + try %{ exec -draft [( \`\([^\n]+\n[^\n]*\n?\' \; } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=lisp %{ + addhl ref lisp + + hook window InsertEnd .* -group lisp-hooks _lisp_filter_around_selections + hook window InsertChar \n -group lisp-indent _lisp_indent_on_new_line +} + +hook global WinSetOption filetype=(?!lisp).* %{ + rmhl lisp + rmhooks window lisp-indent + rmhooks window lisp-hooks +} diff --git a/rc/markdown.kak b/rc/markdown.kak new file mode 100644 index 00000000..88573c50 --- /dev/null +++ b/rc/markdown.kak @@ -0,0 +1,84 @@ +# http://daringfireball.net/projects/markdown +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufSetOption mimetype=text/x-markdown %{ + set buffer filetype markdown +} + +hook global BufCreate .*[.](markdown|md) %{ + set buffer filetype markdown +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +addhl -group / regions -default content markdown \ + sh ```sh ``` '' \ + fish ```fish ``` '' \ + ruby ```ruby ``` '' \ + code ``` ``` '' \ + code `` `` '' \ + code ` ` '' + +addhl -group /markdown/code fill meta + +addhl -group /markdown/sh ref sh +addhl -group /markdown/fish ref fish +addhl -group /markdown/ruby ref ruby + +# Setext-style header +addhl -group /markdown/content regex (\A|\n\n)[^\n]+\n={2,}\h*\n\h*$ 0:blue +addhl -group /markdown/content regex (\A|\n\n)[^\n]+\n-{2,}\h*\n\h*$ 0:cyan + +# Atx-style header +addhl -group /markdown/content regex ^(#+)(\h+)([^\n]+) 1:red + +addhl -group /markdown/content regex ^\h+([-\*])\h+[^\n]*(\n\h+[^-\*]\S+[^\n]*)*$ 0:yellow 1:cyan +addhl -group /markdown/content regex ^([-=~]+)\n[^\n\h].*?\n\1$ 0:magenta +addhl -group /markdown/content regex (? 0:cyan +addhl -group /markdown/content regex ^\h*(>\h*)+ 0:comment +addhl -group /markdown/content regex \H\K\h\h$ 0:PrimarySelection + +# Commands +# ‾‾‾‾‾‾‾‾ + +def -hidden _markdown_filter_around_selections %{ + eval -draft -itersel %{ + exec + # remove trailing white spaces + try %{ exec -draft s \h+$ d } + } +} + +def -hidden _markdown_indent_on_new_line %{ + eval -draft -itersel %{ + # preserve previous line indent + try %{ exec -draft K } + # filter previous line + try %{ exec -draft k : _markdown_filter_around_selections } + # copy block quote(s), list item prefix and following white spaces + try %{ exec -draft k x s ^\h*\K((>\h*)|[*+-])+\h* y j p } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=markdown %{ + addhl ref markdown + + hook window InsertEnd .* -group markdown-hooks _markdown_filter_around_selections + hook window InsertChar \n -group markdown-indent _markdown_indent_on_new_line +} + +hook global WinSetOption filetype=(?!markdown).* %{ + rmhl markdown + rmhooks window markdown-indent + rmhooks window markdown-hooks +} diff --git a/rc/scala.kak b/rc/scala.kak new file mode 100644 index 00000000..1a55ca49 --- /dev/null +++ b/rc/scala.kak @@ -0,0 +1,84 @@ +# http://scala-lang.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufSetOption mimetype=text/x-scala %{ + set buffer filetype scala +} + +hook global BufCreate .*[.](scala) %{ + set buffer filetype scala +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +addhl -group / regions -default code scala \ + string '"' (? 0:meta +addhl -group /scala/code regex \<(this|true|false|null)\> 0:value +addhl -group /scala/code regex \<(become|case|catch|class|def|do|else|extends|final|finally|for|forSome|goto|if|initialize|macro|match|new|object|onTransition|return|startWith|stay|throw|trait|try|unbecome|using|val|var|when|while|with|yield)\> 0:keyword +addhl -group /scala/code regex \<(abstract|final|implicit|implicitly|lazy|override|private|protected|require|sealed|super)\> 0:attribute +addhl -group /scala/code regex \<(⇒|=>|<:|:>|=:=|::|&&|\|\|)\> 0:operator +addhl -group /scala/code regex "'[_A-Za-z0-9$]+" 0:identifier + +# Commands +# ‾‾‾‾‾‾‾‾ + +def -hidden _scala_filter_around_selections %{ + eval -draft -itersel %{ + exec + # remove trailing white spaces + try %{ exec -draft s \h+$ d } + } +} + +def -hidden _scala_indent_on_new_line %[ + eval -draft -itersel %[ + # preserve previous line indent + try %[ exec -draft K ] + # filter previous line + try %[ exec -draft k : _scala_filter_around_selections ] + # copy // comments prefix and following white spaces + try %[ exec -draft k x s ^\h*\K#\h* y j p ] + # indent after lines ending with { + try %[ exec -draft k x \{$ j ] + ] +] + +def -hidden _scala_indent_on_closing_curly_brace %[ + eval -draft -itersel %[ + # align to opening curly brace when alone on a line + try %[ exec -draft ^\h+\}$ m s \`|.\' 1 ] + ] +] + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=scala %[ + addhl ref scala + + hook window InsertEnd .* -group scala-hooks _scala_filter_around_selections + hook window InsertChar \n -group scala-indent _scala_indent_on_new_line + hook window InsertChar \} -group scala-indent _scala_indent_on_closing_curly_brace +] + +hook global WinSetOption filetype=(?!scala).* %{ + rmhl scala + rmhooks window scala-indent + rmhooks window scala-hooks +}