2014-07-07 17:48:09 +04:00
|
|
|
# http://python.org
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufCreate .*[.](py) %{
|
|
|
|
set buffer filetype python
|
|
|
|
}
|
|
|
|
|
2016-03-14 15:08:51 +03:00
|
|
|
# Highlighters & Completion
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
2014-07-07 17:48:09 +04:00
|
|
|
|
2017-01-04 03:07:45 +03:00
|
|
|
add-highlighter -group / regions -default code python \
|
2014-07-15 00:42:19 +04:00
|
|
|
double_string '"""' '"""' '' \
|
|
|
|
single_string "'''" "'''" '' \
|
|
|
|
double_string '"' (?<!\\)(\\\\)*" '' \
|
2014-11-06 00:02:06 +03:00
|
|
|
single_string "'" (?<!\\)(\\\\)*' '' \
|
2014-07-15 00:42:19 +04:00
|
|
|
comment '#' '$' ''
|
2014-07-07 17:48:09 +04:00
|
|
|
|
2017-01-04 03:07:45 +03:00
|
|
|
add-highlighter -group /python/double_string fill string
|
|
|
|
add-highlighter -group /python/single_string fill string
|
|
|
|
add-highlighter -group /python/comment fill comment
|
2014-07-07 17:48:09 +04:00
|
|
|
|
2016-03-14 15:08:51 +03:00
|
|
|
%sh{
|
|
|
|
# Grammar
|
2016-03-14 19:29:11 +03:00
|
|
|
values="True|False|None"
|
|
|
|
meta="import|from"
|
2016-03-14 15:08:51 +03:00
|
|
|
# Keyword list is collected using `keyword.kwlist` from `keyword`
|
2016-11-11 16:07:45 +03:00
|
|
|
keywords="and|as|assert|break|class|continue|def|del|elif|else|except|exec"
|
|
|
|
keywords="${keywords}|finally|for|global|if|in|is|lambda|not|or|pass|print"
|
|
|
|
keywords="${keywords}|raise|return|try|while|with|yield"
|
|
|
|
types="bool|buffer|bytearray|bytes|complex|dict|file|float|frozenset|int"
|
|
|
|
types="${types}|list|long|memoryview|object|set|str|tuple|unicode|xrange"
|
|
|
|
functions="abs|all|any|ascii|bin|callable|chr|classmethod|compile|complex"
|
|
|
|
functions="${functions}|delattr|dict|dir|divmod|enumerate|eval|exec|filter"
|
|
|
|
functions="${functions}|format|frozenset|getattr|globals|hasattr|hash|help"
|
|
|
|
functions="${functions}|hex|id|__import__|input|isinstance|issubclass|iter"
|
|
|
|
functions="${functions}|len|locals|map|max|memoryview|min|next|oct|open|ord"
|
|
|
|
functions="${functions}|pow|print|property|range|repr|reversed|round"
|
|
|
|
functions="${functions}|setattr|slice|sorted|staticmethod|sum|super|type|vars|zip"
|
2014-07-07 17:48:09 +04:00
|
|
|
|
2016-03-14 15:08:51 +03:00
|
|
|
# Add the language's grammar to the static completion list
|
2016-04-23 08:47:01 +03:00
|
|
|
printf %s\\n "hook global WinSetOption filetype=python %{
|
2016-11-11 16:07:45 +03:00
|
|
|
set window static_words '${values}:${meta}:${keywords}:${types}:${functions}'
|
2016-03-17 16:30:14 +03:00
|
|
|
}" | sed 's,|,:,g'
|
2014-07-07 17:48:09 +04:00
|
|
|
|
2016-03-14 15:08:51 +03:00
|
|
|
# Highlight keywords
|
2016-03-17 16:30:14 +03:00
|
|
|
printf %s "
|
2017-01-04 03:07:45 +03:00
|
|
|
add-highlighter -group /python/code regex '\b(${values})\b' 0:value
|
|
|
|
add-highlighter -group /python/code regex '\b(${meta})\b' 0:meta
|
|
|
|
add-highlighter -group /python/code regex '\b(${keywords})\b' 0:keyword
|
|
|
|
add-highlighter -group /python/code regex '\b(${functions})\b\(' 1:builtin
|
2016-03-14 15:08:51 +03:00
|
|
|
"
|
2014-07-07 17:48:09 +04:00
|
|
|
|
2016-11-11 16:07:45 +03:00
|
|
|
# Highlight types and attributes
|
|
|
|
printf %s "
|
2017-01-04 03:07:45 +03:00
|
|
|
add-highlighter -group /python/code regex '\b(${types})\b' 0:type
|
|
|
|
add-highlighter -group /python/code regex '@[\w_]+\b' 0:attribute
|
2016-11-11 16:07:45 +03:00
|
|
|
"
|
2014-07-07 17:48:09 +04:00
|
|
|
}
|
|
|
|
|
2016-03-14 15:08:51 +03:00
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-01-02 07:20:05 +03:00
|
|
|
def -hidden python-indent-on-new-line %{
|
2014-07-07 17:48:09 +04:00
|
|
|
eval -draft -itersel %{
|
2017-01-11 16:56:48 +03:00
|
|
|
# copy '#' comment prefix and following white spaces
|
2017-01-13 03:50:03 +03:00
|
|
|
try %{ exec -draft k <a-x> s ^\h*#\h* <ret> y jgh P }
|
2014-07-07 17:48:09 +04:00
|
|
|
# preserve previous line indent
|
2017-01-13 03:50:03 +03:00
|
|
|
try %{ exec -draft \; K <a-&> }
|
2016-05-05 15:59:06 +03:00
|
|
|
# cleanup trailing whitespaces from previous line
|
2016-05-05 15:50:49 +03:00
|
|
|
try %{ exec -draft k <a-x> s \h+$ <ret> d }
|
2016-10-13 22:10:41 +03:00
|
|
|
# indent after line ending with :
|
2014-07-07 17:48:09 +04:00
|
|
|
try %{ exec -draft <space> k x <a-k> :$ <ret> j <a-gt> }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-01-04 03:07:45 +03:00
|
|
|
hook -group python-highlight global WinSetOption filetype=python %{ add-highlighter ref python }
|
2016-09-25 16:15:07 +03:00
|
|
|
|
2014-07-07 17:48:09 +04:00
|
|
|
hook global WinSetOption filetype=python %{
|
2017-01-02 07:20:05 +03:00
|
|
|
hook window InsertChar \n -group python-indent python-indent-on-new-line
|
2016-05-05 15:59:06 +03:00
|
|
|
# cleanup trailing whitespaces on current line insert end
|
|
|
|
hook window InsertEnd .* -group python-indent %{ try %{ exec -draft \; <a-x> s ^\h+$ <ret> d } }
|
2014-07-07 17:48:09 +04:00
|
|
|
}
|
|
|
|
|
2017-01-04 03:07:45 +03:00
|
|
|
hook -group python-highlight global WinSetOption filetype=(?!python).* %{ remove-highlighter python }
|
2016-09-28 09:45:01 +03:00
|
|
|
|
2014-07-07 17:48:09 +04:00
|
|
|
hook global WinSetOption filetype=(?!python).* %{
|
2017-01-04 03:07:45 +03:00
|
|
|
remove-hooks window python-indent
|
2014-07-07 17:48:09 +04:00
|
|
|
}
|