cabal.kak (3159B)
1 # http://haskell.org/cabal 2 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ 3 4 # Detection 5 # ‾‾‾‾‾‾‾‾‾ 6 7 hook global BufCreate .*[.](cabal) %{ 8 set-option buffer filetype cabal 9 } 10 11 # Initialization 12 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ 13 14 hook global WinSetOption filetype=cabal %[ 15 require-module cabal 16 17 hook window ModeChange pop:insert:.* -group cabal-trim-indent cabal-trim-indent 18 hook window InsertChar \n -group cabal-insert cabal-insert-on-new-line 19 hook window InsertChar \n -group cabal-indent cabal-indent-on-new-line 20 hook window InsertChar \{ -group cabal-indent cabal-indent-on-opening-curly-brace 21 hook window InsertChar \} -group cabal-indent cabal-indent-on-closing-curly-brace 22 23 hook -once -always window WinSetOption filetype=.* %{ remove-hooks window cabal-.+ } 24 ] 25 26 hook -group cabal-highlight global WinSetOption filetype=cabal %{ 27 add-highlighter window/cabal ref cabal 28 hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/cabal } 29 } 30 31 32 provide-module cabal %[ 33 34 # Highlighters 35 # ‾‾‾‾‾‾‾‾‾‾‾‾ 36 37 add-highlighter shared/cabal regions 38 add-highlighter shared/cabal/code default-region group 39 add-highlighter shared/cabal/line_comment region (--) $ fill comment 40 add-highlighter shared/cabal/comment region -recurse \{- \{- -\} fill comment 41 42 add-highlighter shared/cabal/code/ regex \b(true|false)\b|(([<>]?=?)?\d+(\.\d+)+) 0:value 43 add-highlighter shared/cabal/code/ regex \b(if|else)\b 0:keyword 44 add-highlighter shared/cabal/code/ regex ^\h*([A-Za-z][A-Za-z0-9_-]*)\h*: 1:variable 45 46 # Commands 47 # ‾‾‾‾‾‾‾‾ 48 49 define-command -hidden cabal-trim-indent %{ 50 # remove trailing white spaces 51 try %{ execute-keys -draft -itersel x s \h+$ <ret> d } 52 } 53 54 define-command -hidden cabal-insert-on-new-line %[ 55 evaluate-commands -draft -itersel %[ 56 # copy '--' comment prefix and following white spaces 57 try %[ execute-keys -draft k x s ^\h*\K--\h* <ret> y gh j P ] 58 ] 59 ] 60 61 define-command -hidden cabal-indent-on-new-line %[ 62 evaluate-commands -draft -itersel %[ 63 # preserve previous line indent 64 try %[ execute-keys -draft <semicolon> K <a-&> ] 65 # filter previous line 66 try %[ execute-keys -draft k : cabal-trim-indent <ret> ] 67 # indent after lines ending with { or : 68 try %[ execute-keys -draft , k x <a-k> [:{]$ <ret> j <a-gt> ] 69 # deindent closing brace when after cursor 70 try %[ execute-keys -draft x <a-k> \h*\} <ret> gh / \} <ret> m <a-S> 1<a-&> ] 71 ] 72 ] 73 74 define-command -hidden cabal-indent-on-opening-curly-brace %[ 75 evaluate-commands -draft -itersel %[ 76 # align indent with opening paren when { is entered on a new line after the closing paren 77 try %[ execute-keys -draft h <a-F> ) M <a-k> \A\(.*\)\h*\n\h*\{\z <ret> s \A|.\z <ret> 1<a-&> ] 78 ] 79 ] 80 81 define-command -hidden cabal-indent-on-closing-curly-brace %[ 82 evaluate-commands -draft -itersel %[ 83 # align to opening curly brace when alone on a line 84 try %[ execute-keys -draft <a-h> <a-k> ^\h+\}$ <ret> h m s \A|.\z<ret> 1<a-&> ] 85 ] 86 ] 87 88 ]