haml.kak (2634B)
1 # http://haml.info 2 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ 3 4 # Detection 5 # ‾‾‾‾‾‾‾‾‾ 6 7 hook global BufCreate .*[.](haml) %{ 8 set-option buffer filetype haml 9 } 10 11 # Initialization 12 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ 13 14 hook global WinSetOption filetype=haml %{ 15 require-module haml 16 17 hook window ModeChange pop:insert:.* -group haml-trim-indent haml-trim-indent 18 hook window InsertChar \n -group haml-insert haml-insert-on-new-line 19 hook window InsertChar \n -group haml-indent haml-indent-on-new-line 20 21 hook -once -always window WinSetOption filetype=.* %{ remove-hooks window haml-.+ } 22 } 23 24 hook -group haml-highlight global WinSetOption filetype=haml %{ 25 add-highlighter window/haml ref haml 26 hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/haml } 27 } 28 29 30 provide-module haml %[ 31 require-module ruby 32 require-module coffee 33 require-module sass 34 35 # Highlighters 36 # ‾‾‾‾‾‾‾‾‾‾‾‾ 37 38 add-highlighter shared/haml regions 39 add-highlighter shared/haml/code default-region group 40 add-highlighter shared/haml/comment region ^\h*/ $ fill comment 41 42 # Filters 43 # http://haml.info/docs/yardoc/file.REFERENCE.html#filters 44 add-highlighter shared/haml/eval1 region -recurse \{ ^\h*%([A-Za-z][A-Za-z0-9_-]*)([#.][A-Za-z][A-Za-z0-9_-]*)?\{\K|#\{\K (?=\}) ref ruby 45 add-highlighter shared/haml/eval2 region ^\h*[=-]\K (?<!\|)(?=\n) ref ruby 46 add-highlighter shared/haml/coffee region ^\h*:coffee\K ^\h*[%=-]\K ref coffee 47 add-highlighter shared/haml/sass region ^\h*:sass\K ^\h*[%=-]\K ref sass 48 49 add-highlighter shared/haml/code/ regex ^\h*(:[a-z]+|-|=)|^(!!!)$ 0:meta 50 add-highlighter shared/haml/code/ regex ^\h*%([A-Za-z][A-Za-z0-9_-]*)([#.][A-Za-z][A-Za-z0-9_-]*)? 1:keyword 2:variable 51 52 # Commands 53 # ‾‾‾‾‾‾‾‾ 54 55 define-command -hidden haml-trim-indent %{ 56 # remove trailing white spaces 57 try %{ execute-keys -draft -itersel x s \h+$ <ret> d } 58 } 59 60 define-command -hidden haml-insert-on-new-line %{ 61 evaluate-commands -draft -itersel %{ 62 # copy '/' comment prefix and following white spaces 63 try %{ execute-keys -draft k x s ^\h*\K/\h* <ret> y gh j P } 64 } 65 } 66 67 define-command -hidden haml-indent-on-new-line %{ 68 evaluate-commands -draft -itersel %{ 69 # preserve previous line indent 70 try %{ execute-keys -draft <semicolon> K <a-&> } 71 # filter previous line 72 try %{ execute-keys -draft k : haml-trim-indent <ret> } 73 # indent after lines beginning with : or - 74 try %{ execute-keys -draft k x <a-k> ^\h*[:-] <ret> j <a-gt> } 75 } 76 } 77 78 ]