2014-07-07 15:48:09 +02:00
|
|
|
# http://python.org
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufSetOption mimetype=text/x-python %{
|
|
|
|
set buffer filetype python
|
|
|
|
}
|
|
|
|
|
|
|
|
hook global BufCreate .*[.](py) %{
|
|
|
|
set buffer filetype python
|
|
|
|
}
|
|
|
|
|
2016-03-14 13:08:51 +01:00
|
|
|
# Highlighters & Completion
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
2014-07-07 15:48:09 +02:00
|
|
|
|
2014-07-14 22:42:19 +02:00
|
|
|
addhl -group / regions -default code python \
|
|
|
|
double_string '"""' '"""' '' \
|
|
|
|
single_string "'''" "'''" '' \
|
|
|
|
double_string '"' (?<!\\)(\\\\)*" '' \
|
2014-11-05 22:02:06 +01:00
|
|
|
single_string "'" (?<!\\)(\\\\)*' '' \
|
2014-07-14 22:42:19 +02:00
|
|
|
comment '#' '$' ''
|
2014-07-07 15:48:09 +02:00
|
|
|
|
|
|
|
addhl -group /python/double_string fill string
|
|
|
|
addhl -group /python/single_string fill string
|
|
|
|
addhl -group /python/comment fill comment
|
|
|
|
|
2016-03-14 13:08:51 +01:00
|
|
|
%sh{
|
|
|
|
# Grammar
|
2016-03-14 17:29:11 +01:00
|
|
|
values="True|False|None"
|
|
|
|
meta="import|from"
|
2016-03-14 13:08:51 +01:00
|
|
|
# Keyword list is collected using `keyword.kwlist` from `keyword`
|
2016-03-14 17:29:11 +01:00
|
|
|
keywords="and|as|assert|break|class|continue|def|del|elif|else|except|exec|finally|for|global|if|in|is|lambda|not|or|pass|print|raise|return|try|while|with|yield"
|
|
|
|
types="bool|buffer|bytearray|complex|dict|file|float|frozenset|int|list|long|memoryview|object|set|str|tuple|unicode|xrange"
|
2014-07-07 15:48:09 +02:00
|
|
|
|
2016-03-14 13:08:51 +01:00
|
|
|
# Add the language's grammar to the static completion list
|
2016-04-23 07:47:01 +02:00
|
|
|
printf %s\\n "hook global WinSetOption filetype=python %{
|
2016-04-09 11:20:13 +02:00
|
|
|
set window static_words '${values}:${meta}:${keywords}:${types}'
|
2016-03-17 14:30:14 +01:00
|
|
|
}" | sed 's,|,:,g'
|
2014-07-07 15:48:09 +02:00
|
|
|
|
2016-03-14 13:08:51 +01:00
|
|
|
# Highlight keywords
|
2016-03-17 14:30:14 +01:00
|
|
|
printf %s "
|
2016-04-21 21:43:17 +02:00
|
|
|
addhl -group /python/code regex '\b(${values})\b' 0:value
|
|
|
|
addhl -group /python/code regex '\b(${meta})\b' 0:meta
|
|
|
|
addhl -group /python/code regex '\b(${keywords})\b' 0:keyword
|
2016-03-14 13:08:51 +01:00
|
|
|
"
|
2014-07-07 15:48:09 +02:00
|
|
|
|
2016-03-14 13:08:51 +01:00
|
|
|
# Highlight types, when they are not used as constructors
|
2016-04-21 21:43:17 +02:00
|
|
|
printf %s "addhl -group /python/code regex '\b(${types})\b[^(]' 1:type"
|
2014-07-07 15:48:09 +02:00
|
|
|
}
|
|
|
|
|
2016-03-14 13:08:51 +01:00
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2014-07-07 15:48:09 +02:00
|
|
|
def -hidden _python_indent_on_new_line %{
|
|
|
|
eval -draft -itersel %{
|
|
|
|
# preserve previous line indent
|
|
|
|
try %{ exec -draft <space> K <a-&> }
|
2016-05-05 14:59:06 +02:00
|
|
|
# cleanup trailing whitespaces from previous line
|
2016-05-05 14:50:49 +02:00
|
|
|
try %{ exec -draft k <a-x> s \h+$ <ret> d }
|
2014-07-07 15:48:09 +02:00
|
|
|
# copy '#' comment prefix and following white spaces
|
|
|
|
try %{ exec -draft k x s ^\h*\K#\h* <ret> y j p }
|
|
|
|
# indent after :
|
|
|
|
try %{ exec -draft <space> k x <a-k> :$ <ret> j <a-gt> }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2016-09-25 15:15:07 +02:00
|
|
|
hook -group python-highlight global WinSetOption filetype=python %{ addhl ref python }
|
|
|
|
|
2014-07-07 15:48:09 +02:00
|
|
|
hook global WinSetOption filetype=python %{
|
|
|
|
hook window InsertChar \n -group python-indent _python_indent_on_new_line
|
2016-05-05 14:59:06 +02:00
|
|
|
# cleanup trailing whitespaces on current line insert end
|
|
|
|
hook window InsertEnd .* -group python-indent %{ try %{ exec -draft \; <a-x> s ^\h+$ <ret> d } }
|
2016-03-14 13:08:51 +01:00
|
|
|
|
|
|
|
set window formatcmd "autopep8 -"
|
2014-07-07 15:48:09 +02:00
|
|
|
}
|
|
|
|
|
2016-10-01 15:09:59 +02:00
|
|
|
hook -group python-highlight global WinSetOption filetype=(?!python).* %{ rmhl python }
|
2016-09-28 08:45:01 +02:00
|
|
|
|
2014-07-07 15:48:09 +02:00
|
|
|
hook global WinSetOption filetype=(?!python).* %{
|
|
|
|
rmhooks window python-indent
|
|
|
|
}
|