# https://prql-lang.org/ # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*[.](prql) %{ set-option buffer filetype prql } # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook global WinSetOption filetype=prql %{ require-module prql set-option window static_words %opt{prql_static_words} hook window InsertChar \n -group prql-insert prql-insert-on-new-line hook window InsertChar \n -group prql-indent prql-indent-on-new-line # cleanup trailing whitespaces on current line insert end hook window ModeChange pop:insert:.* -group prql-trim-indent %{ try %{ execute-keys -draft x s ^\h+$ d } } hook -once -always window WinSetOption filetype=.* %{ remove-hooks window prql-.+ } } hook -group prql-highlight global WinSetOption filetype=prql %{ add-highlighter window/prql ref prql hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/prql } } provide-module prql %§ # Highlighters & Completion # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter shared/prql regions add-highlighter shared/prql/code default-region group add-highlighter shared/prql/documentation region '##' '$' fill documentation add-highlighter shared/prql/comment region '#' '$' fill comment # String interpolation add-highlighter shared/prql/f_triple_string region -match-capture f("""|''') (?=|<>?|>|!=|==|~=|\||\^|&|\+|-|\*\*?|//?|%|~) 0:operator add-highlighter shared/prql/code/ regex (?<=[\w\s\d'"_])((?!]):?=(?![=])|[+*-]=) 0:builtin add-highlighter shared/prql/code/ regex ^\h*(?:module)\h+(\S+) 1:module # Commands # ‾‾‾‾‾‾‾‾ define-command -hidden prql-insert-on-new-line %{ evaluate-commands -itersel -draft %{ execute-keys try %{ evaluate-commands -draft -save-regs '/"' %{ # Ensure previous line is a comment execute-keys -draft kxs^\h*#+\h* # now handle the comment continuation logic try %{ # try and match a regular block comment, copying the prefix execute-keys -draft -save-regs '' k x 1s^(\h*#+\h*)\S.*$ y execute-keys -draft P } catch %{ try %{ # try and match a regular block comment followed by a single # empty comment line execute-keys -draft -save-regs '' kKx 1s^(\h*#+\h*)\S+\n\h*#+\h*$ y execute-keys -draft P } catch %{ try %{ # try and match a pair of empty comment lines, and delete # them if we match execute-keys -draft kKx ^\h*#+\h*\n\h*#+\h*$ } catch %{ # finally, we need a special case for a new line inserted # into a file that consists of a single empty comment - in # that case we can't expect to copy the trailing whitespace, # so we add our own execute-keys -draft -save-regs '' k x1s^(\h*#+)\h*$ y execute-keys -draft P execute-keys -draft i } } } } # trim trailing whitespace on the previous line try %{ execute-keys -draft k x s\h+$ d } } } } define-command -hidden prql-indent-on-new-line %< evaluate-commands -draft -itersel %< # preserve previous line indent try %{ execute-keys -draft K } # cleanup trailing whitespaces from previous line try %{ execute-keys -draft k x s \h+$ d } # indent after line ending with : try %{ execute-keys -draft , k x :$ ^\h*# j } # deindent closing brace/bracket when after cursor (for arrays and dictionaries) try %< execute-keys -draft x ^\h*[}\]] gh / [}\]] m 1 > > > §