fish.kak (3566B)
1 # http://fishshell.com 2 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ 3 4 # Detection 5 # ‾‾‾‾‾‾‾‾‾ 6 7 hook global BufCreate .*[.](fish) %{ 8 set-option buffer filetype fish 9 } 10 11 # Initialization 12 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ 13 14 hook global WinSetOption filetype=fish %{ 15 require-module fish 16 17 hook window ModeChange pop:insert:.* -group fish-trim-indent fish-trim-indent 18 hook window InsertChar .* -group fish-indent fish-indent-on-char 19 hook window InsertChar \n -group fish-insert fish-insert-on-new-line 20 hook window InsertChar \n -group fish-indent fish-indent-on-new-line 21 22 hook -once -always window WinSetOption filetype=.* %{ remove-hooks window fish-.+ } 23 } 24 25 hook -group fish-highlight global WinSetOption filetype=fish %{ 26 add-highlighter window/fish ref fish 27 hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/fish } 28 } 29 30 31 provide-module fish %{ 32 33 # Highlighters 34 # ‾‾‾‾‾‾‾‾‾‾‾‾ 35 36 add-highlighter shared/fish regions 37 add-highlighter shared/fish/code default-region group 38 add-highlighter shared/fish/double_string region (?<!\\)(?:\\\\)*\K" (?<!\\)(\\\\)*" group 39 add-highlighter shared/fish/single_string region (?<!\\)(?:\\\\)*\K' (?<!\\)(\\\\)*' fill string 40 add-highlighter shared/fish/comment region (?<!\\)(?:\\\\)*(?:^|\h)\K# '$' fill comment 41 42 add-highlighter shared/fish/double_string/ fill string 43 add-highlighter shared/fish/double_string/ regex ((?<!\\)(?:\\\\)*\K\$\w+)|(\{\$\w+\}) 0:variable 44 45 add-highlighter shared/fish/code/ regex (?<!\\)(?:\\\\)*\K(\$\w+)|(\{\$\w+\}) 0:variable 46 47 # Command names are collected using `builtin --names`. 48 add-highlighter shared/fish/code/ regex \b(?<![$-])(and|argparse|begin|bg|bind|block|break|breakpoint|builtin|case|cd|command|commandline|complete|contains|continue|count|disown|echo|else|emit|end|eval|exec|exit|false|fg|for|function|functions|history|if|jobs|math|not|or|printf|pwd|random|read|realpath|return|set|set_color|source|status|string|switch|test|time|true|ulimit|wait|while)\b(?!-) 0:keyword 49 50 # Commands 51 # ‾‾‾‾‾‾‾‾ 52 53 define-command -hidden fish-trim-indent %{ 54 evaluate-commands -no-hooks -draft -itersel %{ 55 # remove trailing white spaces 56 try %{ execute-keys -draft x 1s^(\h+)$<ret> d } 57 } 58 } 59 60 define-command -hidden fish-indent-on-char %{ 61 evaluate-commands -no-hooks -draft -itersel %{ 62 # align middle and end structures to start and indent when necessary 63 try %{ execute-keys -draft x<a-k>^\h*(else)$<ret><a-semicolon><a-?>^\h*(if)<ret>s\A|.\z<ret>1<a-&> } 64 try %{ execute-keys -draft x<a-k>^\h*(end)$<ret><a-semicolon><a-?>^\h*(begin|for|function|if|switch|while)<ret>s\A|.\z<ret>1<a-&> } 65 try %{ execute-keys -draft x<a-k>^\h*(case)$<ret><a-semicolon><a-?>^\h*(switch)<ret>s\A|.\z<ret>1<a-&> } 66 } 67 } 68 69 define-command -hidden fish-insert-on-new-line %{ 70 evaluate-commands -no-hooks -draft -itersel %{ 71 # copy '#' comment prefix and following white spaces 72 try %{ execute-keys -draft k x s ^\h*#\h* <ret> y jgh P } 73 } 74 } 75 76 define-command -hidden fish-indent-on-new-line %{ 77 evaluate-commands -no-hooks -draft -itersel %{ 78 # preserve previous line indent 79 try %{ execute-keys -draft <semicolon> K <a-&> } 80 # cleanup trailing whitespaces from previous line 81 try %{ execute-keys -draft k x s \h+$ <ret> d } 82 # indent after start structure 83 try %{ execute-keys -draft kx<a-k>^\h*(begin|case|else|for|function|if|while)\b<ret>j<a-gt> } 84 } 85 } 86 87 }