# http://python.org # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*[.](py) %{ set buffer filetype python } # Highlighters & Completion # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter shared/ regions -default code python \ double_string '"""' '"""' '' \ single_string "'''" "'''" '' \ double_string '"' (? s ^\h*#\h* y jgh P } # preserve previous line indent try %{ exec -draft \; K } # cleanup trailing whitespaces from previous line try %{ exec -draft k s \h+$ d } # indent after line ending with : try %{ exec -draft k x :$ j } } } # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook -group python-highlight global WinSetOption filetype=python %{ add-highlighter window ref python } hook global WinSetOption filetype=python %{ hook window InsertChar \n -group python-indent python-indent-on-new-line # cleanup trailing whitespaces on current line insert end hook window InsertEnd .* -group python-indent %{ try %{ exec -draft \; s ^\h+$ d } } } hook -group python-highlight global WinSetOption filetype=(?!python).* %{ remove-highlighter window/python } hook global WinSetOption filetype=(?!python).* %{ remove-hooks window python-indent }