yaml.kak (2425B)
1 # http://yaml.org 2 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ 3 4 # Detection 5 # ‾‾‾‾‾‾‾‾‾ 6 7 hook global BufCreate .*[.](ya?ml) %{ 8 set-option buffer filetype yaml 9 } 10 11 # Initialization 12 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ 13 14 hook global WinSetOption filetype=yaml %{ 15 require-module yaml 16 17 hook window ModeChange pop:insert:.* -group yaml-trim-indent yaml-trim-indent 18 hook window InsertChar \n -group yaml-insert yaml-insert-on-new-line 19 hook window InsertChar \n -group yaml-indent yaml-indent-on-new-line 20 hook -once -always window WinSetOption filetype=.* %{ remove-hooks window yaml-.+ } 21 } 22 23 hook -group yaml-highlight global WinSetOption filetype=yaml %{ 24 add-highlighter window/yaml ref yaml 25 hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/yaml } 26 } 27 28 29 provide-module yaml %{ 30 31 # Highlighters 32 # ‾‾‾‾‾‾‾‾‾‾‾‾ 33 34 add-highlighter shared/yaml regions 35 add-highlighter shared/yaml/code default-region group 36 add-highlighter shared/yaml/double_string region '"' (?<!\\)(\\\\)*" fill string 37 add-highlighter shared/yaml/single_string region "'" "'" fill string 38 add-highlighter shared/yaml/comment region '(?:^| )#' $ fill comment 39 40 add-highlighter shared/yaml/code/ regex ^(---|\.\.\.)$ 0:meta 41 add-highlighter shared/yaml/code/ regex ^(\h*:\w*) 0:keyword 42 add-highlighter shared/yaml/code/ regex \b(true|false|null)\b 0:value 43 add-highlighter shared/yaml/code/ regex ^\h*-?\h*(\S+): 1:attribute 44 45 # Commands 46 # ‾‾‾‾‾‾‾‾ 47 48 define-command -hidden yaml-trim-indent %{ 49 # remove trailing white spaces 50 try %{ execute-keys -draft -itersel x s \h+$ <ret> d } 51 } 52 53 define-command -hidden yaml-insert-on-new-line %{ 54 evaluate-commands -draft -itersel %{ 55 # copy '#' comment prefix and following white spaces 56 try %{ execute-keys -draft k x s ^\h*\K#\h* <ret> y gh j P } 57 } 58 } 59 60 define-command -hidden yaml-indent-on-new-line %{ 61 evaluate-commands -draft -itersel %{ 62 # preserve previous line indent 63 try %{ execute-keys -draft <semicolon> K <a-&> } 64 # filter previous line 65 try %{ execute-keys -draft k : yaml-trim-indent <ret> } 66 # indent after : 67 try %{ execute-keys -draft , k x <a-k> :$ <ret> j <a-gt> } 68 # indent after - 69 try %{ execute-keys -draft , k x <a-k> ^\h*- <ret> j <a-gt> } 70 } 71 } 72 73 }