taskpaper.kak (2073B)
1 # https://www.taskpaper.com 2 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ 3 4 # Detection 5 # ‾‾‾‾‾‾‾‾‾ 6 7 hook global BufCreate .*\.taskpaper %{ 8 set-option buffer filetype taskpaper 9 } 10 11 # Initialization 12 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ 13 14 hook global WinSetOption filetype=taskpaper %{ 15 require-module taskpaper 16 17 hook window ModeChange pop:insert:.* -group taskpaper-trim-indent taskpaper-trim-indent 18 hook window InsertChar \n -group taskpaper-indent taskpaper-indent-on-new-line 19 hook -once -always window WinSetOption filetype=.* %{ remove-hooks window taskpaper-.+ } 20 } 21 22 hook -group taskpaper-highlight global WinSetOption filetype=taskpaper %{ 23 add-highlighter window/taskpaper ref taskpaper 24 hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/taskpaper } 25 } 26 27 28 provide-module taskpaper %{ 29 30 # Highlighters 31 # ‾‾‾‾‾‾‾‾‾‾‾‾ 32 33 add-highlighter shared/taskpaper group 34 35 add-highlighter shared/taskpaper/ regex ^\h*([^:\n]+):\h*\n 1:header 36 add-highlighter shared/taskpaper/ regex \h@\w+(?:\(([^)]*)\))? 0:variable 1:value 37 add-highlighter shared/taskpaper/ regex ^\h*([^-:\n]+)\n 1:+i 38 add-highlighter shared/taskpaper/ regex ^\h*-\h+\N*@done\N* 0:+d 39 add-highlighter shared/taskpaper/ regex \b(([a-z]+://\S+)|((mailto:)[\w+-]+@\S+)) 0:link 40 41 # Commands 42 # ‾‾‾‾‾‾‾‾ 43 44 define-command -hidden taskpaper-trim-indent %{ 45 evaluate-commands -no-hooks -draft -itersel %{ 46 execute-keys x 47 # remove trailing white spaces 48 try %{ execute-keys -draft s \h + $ <ret> d } 49 } 50 } 51 52 define-command -hidden taskpaper-indent-on-new-line %{ 53 evaluate-commands -draft -itersel %{ 54 # preserve previous line indent 55 try %{ execute-keys -draft <semicolon>K<a-&> } 56 ## If the line above is a project indent with a tab 57 try %{ execute-keys -draft Z kx <a-k>^\h*([^:\n]+):<ret> z i<tab> } 58 # cleanup trailing white spaces on previous line 59 try %{ execute-keys -draft kx s \h+$ <ret>d } 60 } 61 } 62 63 }