ttl.kak (3226B)
1 # Terse RDF Triple Language (Turtle) 2 # of the W3C's Resource Description Framework (RDF): 3 # https://www.w3.org/TR/turtle/ 4 5 # Detection 6 # ‾‾‾‾‾‾‾‾‾ 7 8 hook global BufCreate .*\.(ttl) %{ 9 set-option buffer filetype ttl 10 } 11 12 # Initialization 13 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ 14 15 hook global WinSetOption filetype=ttl %{ 16 require-module ttl 17 18 hook window ModeChange pop:insert:.* -group ttl-trim-indent ttl-trim-indent 19 hook window InsertChar \n -group ttl-insert ttl-insert-on-new-line 20 hook window InsertChar \n -group ttl-indent ttl-indent-on-new-line 21 22 hook -once -always window WinSetOption filetype=.* %{ remove-hooks window ttl-.+ } 23 } 24 25 hook -group ttl-highlight global WinSetOption filetype=ttl %{ 26 add-highlighter window/ttl ref ttl 27 hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/ttl } 28 } 29 30 31 provide-module ttl %{ 32 33 # Highlighters 34 # ‾‾‾‾‾‾‾‾‾‾‾‾ 35 36 add-highlighter shared/ttl regions 37 add-highlighter shared/ttl/code default-region group 38 39 add-highlighter shared/ttl/comment region '#+\h' $ fill comment 40 add-highlighter shared/ttl/string1 region '"""' (?<!\\)(\\\\)*"""(?!") fill string 41 add-highlighter shared/ttl/string2 region "'''" "'''(?!')" fill string 42 add-highlighter shared/ttl/string3 region '"' (?<!\\)(\\\\)*" fill string 43 add-highlighter shared/ttl/string4 region "'" "'" fill string 44 45 add-highlighter shared/ttl/code/comment2 regex '^\h*(#+)$' 1:comment 46 add-highlighter shared/ttl/code/colon regex (:) 1:operator 47 add-highlighter shared/ttl/code/separator regex ([\;\.,<>\[\]\(\)]) 1:delimiter 48 add-highlighter shared/ttl/code/term regex :(w+)\b 1:variable 49 add-highlighter shared/ttl/code/prefix regex \b([-.\w]+): 1:module 50 add-highlighter shared/ttl/code/def regex (@\w+)\b 1:attribute 51 add-highlighter shared/ttl/code/cdef regex \b(BASE|PREFIX)\b 1:attribute 52 add-highlighter shared/ttl/code/type regex (\^\^) 1:type 53 add-highlighter shared/ttl/code/bool regex \b(true|false)\b 1:value 54 add-highlighter shared/ttl/code/num regex \b([+-]?[0-9]+\.*[0-9]*)\b 1:value 55 add-highlighter shared/ttl/code/keyword regex \b(_|a)\b 1:keyword 56 # Last position, to override single characters. 57 add-highlighter shared/ttl/code/IRI regex <(\H*)> 1:identifier 58 59 60 # Commands 61 # ‾‾‾‾‾‾‾‾ 62 63 define-command -hidden ttl-trim-indent %{ 64 # remove trailing white spaces 65 try %{ execute-keys -draft -itersel x s \h+$ <ret> d } 66 } 67 68 define-command -hidden ttl-insert-on-new-line %{ 69 evaluate-commands -draft -itersel %{ 70 # copy # comments prefix and following white spaces 71 try %{ execute-keys -draft k x s ^\h*\K#\h* <ret> y gh j P } 72 } 73 } 74 75 define-command -hidden ttl-indent-on-new-line %{ 76 evaluate-commands -draft -itersel %{ 77 # preserve previous line indent 78 try %{ execute-keys -draft <semicolon> K <a-&> } 79 # filter previous line 80 try %{ execute-keys -draft k : ttl-trim-indent <ret> } 81 } 82 } 83 84 }