2014-07-05 14:32:37 +02:00
|
|
|
# http://json.org
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufCreate .*[.](json) %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer filetype json
|
2014-07-05 14:32:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-07-01 11:53:35 +02:00
|
|
|
add-highlighter shared/json regions
|
|
|
|
add-highlighter shared/json/code default-region group
|
2018-07-02 12:59:12 +02:00
|
|
|
add-highlighter shared/json/string region '"' (?<!\\)(\\\\)*" fill string
|
2014-07-05 14:32:37 +02:00
|
|
|
|
2018-07-01 11:53:35 +02:00
|
|
|
add-highlighter shared/json/code/ regex \b(true|false|null|\d+(?:\.\d+)?(?:[eE][+-]?\d*)?)\b 0:value
|
2014-07-05 14:32:37 +02:00
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -hidden json-filter-around-selections %{
|
2015-11-04 10:48:47 +01:00
|
|
|
# remove trailing white spaces
|
2017-11-03 09:09:45 +01:00
|
|
|
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
|
2014-07-05 14:32:37 +02:00
|
|
|
}
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -hidden json-indent-on-char %<
|
2017-11-03 09:09:45 +01:00
|
|
|
evaluate-commands -draft -itersel %<
|
2014-07-16 13:56:40 +02:00
|
|
|
# align closer token to its opener when alone on a line
|
2017-11-03 09:09:45 +01:00
|
|
|
try %< execute-keys -draft <a-h> <a-k> ^\h+[]}]$ <ret> m s \A|.\z <ret> 1<a-&> >
|
2015-11-10 14:36:16 +01:00
|
|
|
>
|
|
|
|
>
|
2014-07-05 14:32:37 +02:00
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -hidden json-indent-on-new-line %<
|
2017-11-03 09:09:45 +01:00
|
|
|
evaluate-commands -draft -itersel %<
|
2014-07-05 14:32:37 +02:00
|
|
|
# preserve previous line indent
|
2017-11-03 09:09:45 +01:00
|
|
|
try %{ execute-keys -draft \; K <a-&> }
|
2014-07-05 14:32:37 +02:00
|
|
|
# filter previous line
|
2017-11-03 09:09:45 +01:00
|
|
|
try %{ execute-keys -draft k : json-filter-around-selections <ret> }
|
2014-07-05 14:32:37 +02:00
|
|
|
# indent after lines beginning with opener token
|
2017-11-03 09:09:45 +01:00
|
|
|
try %< execute-keys -draft k <a-x> <a-k> ^\h*[[{] <ret> j <a-gt> >
|
2015-11-10 14:36:16 +01:00
|
|
|
>
|
|
|
|
>
|
2014-07-05 14:32:37 +02:00
|
|
|
|
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-11-28 10:39:15 +01:00
|
|
|
hook -group json-highlight global WinSetOption filetype=json %{
|
|
|
|
add-highlighter window/json ref json
|
2018-12-11 00:11:35 +01:00
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/json }
|
2018-11-28 10:39:15 +01:00
|
|
|
}
|
2014-07-05 14:32:37 +02:00
|
|
|
|
2016-09-25 15:15:07 +02:00
|
|
|
hook global WinSetOption filetype=json %{
|
2018-01-21 00:35:05 +01:00
|
|
|
hook window ModeChange insert:.* -group json-hooks json-filter-around-selections
|
2017-01-13 01:56:30 +01:00
|
|
|
hook window InsertChar .* -group json-indent json-indent-on-char
|
|
|
|
hook window InsertChar \n -group json-indent json-indent-on-new-line
|
2016-09-28 08:45:01 +02:00
|
|
|
|
2018-12-11 00:11:35 +01:00
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window json-.+ }
|
2014-07-05 14:32:37 +02:00
|
|
|
}
|