summaryrefslogtreecommitdiff
path: root/rc/filetype/python.kak
diff options
context:
space:
mode:
authorJustin Frank <justinpfrank@protonmail.com>2019-04-09 20:54:19 -0700
committerJustin Frank <justinpfrank@protonmail.com>2019-04-09 20:54:19 -0700
commit80ac46e09de0a30c0bf590fd50b6cbf9bfd1c41b (patch)
treed4abde4c341a026d56512d74f79608d6a45ec85a /rc/filetype/python.kak
parent887a5223ac8e71ca6d7f0cd9c764d68ce3d90dbe (diff)
Fixed many of the filetype support modules to not use `BufSetOption` to load
Diffstat (limited to 'rc/filetype/python.kak')
-rw-r--r--rc/filetype/python.kak152
1 files changed, 76 insertions, 76 deletions
diff --git a/rc/filetype/python.kak b/rc/filetype/python.kak
index 82fe9971..7c4472a3 100644
--- a/rc/filetype/python.kak
+++ b/rc/filetype/python.kak
@@ -8,8 +8,23 @@ hook global BufCreate .*[.](py) %{
set-option buffer filetype python
}
-hook -once global BufSetOption filetype=python %{
+# Initialization
+# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
+
+hook global WinSetOption filetype=python %{
require-module python
+
+ set-option window static_words %opt{python_static_words}
+
+ hook window InsertChar \n -group python-indent python-indent-on-new-line
+ # cleanup trailing whitespaces on current line insert end
+ hook window ModeChange insert:.* -group python-trim-indent %{ try %{ execute-keys -draft \; <a-x> s ^\h+$ <ret> d } }
+ hook -once -always window WinSetOption filetype=.* %{ remove-hooks window python-.+ }
+}
+
+hook -group python-highlight global WinSetOption filetype=python %{
+ add-highlighter window/python ref python
+ hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/python }
}
provide-module python %{
@@ -42,79 +57,79 @@ add-highlighter shared/python/docstring/ region '\.\.\. \K' '\z' ref python
evaluate-commands %sh{
# Grammar
- values="True|False|None|self|inf"
- meta="import|from"
+ values="True False None self inf"
+ meta="import from"
# attributes and methods list based on https://docs.python.org/3/reference/datamodel.html
- attributes="__annotations__|__closure__|__code__|__defaults__|__dict__|__doc__"
- attributes="${attributes}|__globals__|__kwdefaults__|__module__|__name__|__qualname__"
- methods="__abs__|__add__|__aenter__|__aexit__|__aiter__|__and__|__anext__"
- methods="${methods}|__await__|__bool__|__bytes__|__call__|__complex__|__contains__"
- methods="${methods}|__del__|__delattr__|__delete__|__delitem__|__dir__|__divmod__"
- methods="${methods}|__enter__|__eq__|__exit__|__float__|__floordiv__|__format__"
- methods="${methods}|__ge__|__get__|__getattr__|__getattribute__|__getitem__"
- methods="${methods}|__gt__|__hash__|__iadd__|__iand__|__ifloordiv__|__ilshift__"
- methods="${methods}|__imatmul__|__imod__|__imul__|__index__|__init__"
- methods="${methods}|__init_subclass__|__int__|__invert__|__ior__|__ipow__"
- methods="${methods}|__irshift__|__isub__|__iter__|__itruediv__|__ixor__|__le__"
- methods="${methods}|__len__|__length_hint__|__lshift__|__lt__|__matmul__"
- methods="${methods}|__missing__|__mod__|__mul__|__ne__|__neg__|__new__|__or__"
- methods="${methods}|__pos__|__pow__|__radd__|__rand__|__rdivmod__|__repr__"
- methods="${methods}|__reversed__|__rfloordiv__|__rlshift__|__rmatmul__|__rmod__"
- methods="${methods}|__rmul__|__ror__|__round__|__rpow__|__rrshift__|__rshift__"
- methods="${methods}|__rsub__|__rtruediv__|__rxor__|__set__|__setattr__"
- methods="${methods}|__setitem__|__set_name__|__slots__|__str__|__sub__"
- methods="${methods}|__truediv__|__xor__"
+ attributes="__annotations__ __closure__ __code__ __defaults__ __dict__ __doc__
+ __globals__ __kwdefaults__ __module__ __name__ __qualname__"
+ methods="__abs__ __add__ __aenter__ __aexit__ __aiter__ __and__ __anext__
+ __await__ __bool__ __bytes__ __call__ __complex__ __contains__
+ __del__ __delattr__ __delete__ __delitem__ __dir__ __divmod__
+ __enter__ __eq__ __exit__ __float__ __floordiv__ __format__
+ __ge__ __get__ __getattr__ __getattribute__ __getitem__
+ __gt__ __hash__ __iadd__ __iand__ __ifloordiv__ __ilshift__
+ __imatmul__ __imod__ __imul__ __index__ __init__
+ __init_subclass__ __int__ __invert__ __ior__ __ipow__
+ __irshift__ __isub__ __iter__ __itruediv__ __ixor__ __le__
+ __len__ __length_hint__ __lshift__ __lt__ __matmul__
+ __missing__ __mod__ __mul__ __ne__ __neg__ __new__ __or__
+ __pos__ __pow__ __radd__ __rand__ __rdivmod__ __repr__
+ __reversed__ __rfloordiv__ __rlshift__ __rmatmul__ __rmod__
+ __rmul__ __ror__ __round__ __rpow__ __rrshift__ __rshift__
+ __rsub__ __rtruediv__ __rxor__ __set__ __setattr__
+ __setitem__ __set_name__ __slots__ __str__ __sub__
+ __truediv__ __xor__"
# built-in exceptions https://docs.python.org/3/library/exceptions.html
- exceptions="ArithmeticError|AssertionError|AttributeError|BaseException|BlockingIOError"
- exceptions="${exceptions}|BrokenPipeError|BufferError|BytesWarning|ChildProcessError"
- exceptions="${exceptions}|ConnectionAbortedError|ConnectionError|ConnectionRefusedError"
- exceptions="${exceptions}|ConnectionResetError|DeprecationWarning|EOFError|Exception"
- exceptions="${exceptions}|FileExistsError|FileNotFoundError|FloatingPointError|FutureWarning"
- exceptions="${exceptions}|GeneratorExit|ImportError|ImportWarning|IndentationError"
- exceptions="${exceptions}|IndexError|InterruptedError|IsADirectoryError|KeyboardInterrupt"
- exceptions="${exceptions}|KeyError|LookupError|MemoryError|ModuleNotFoundError|NameError"
- exceptions="${exceptions}|NotADirectoryError|NotImplementedError|OSError|OverflowError"
- exceptions="${exceptions}|PendingDeprecationWarning|PermissionError|ProcessLookupError"
- exceptions="${exceptions}|RecursionError|ReferenceError|ResourceWarning|RuntimeError"
- exceptions="${exceptions}|RuntimeWarning|StopAsyncIteration|StopIteration|SyntaxError"
- exceptions="${exceptions}|SyntaxWarning|SystemError|SystemExit|TabError|TimeoutError|TypeError"
- exceptions="${exceptions}|UnboundLocalError|UnicodeDecodeError|UnicodeEncodeError|UnicodeError"
- exceptions="${exceptions}|UnicodeTranslateError|UnicodeWarning|UserWarning|ValueError|Warning"
- exceptions="${exceptions}|ZeroDivisionError"
+ exceptions="ArithmeticError AssertionError AttributeError BaseException BlockingIOError
+ BrokenPipeError BufferError BytesWarning ChildProcessError
+ ConnectionAbortedError ConnectionError ConnectionRefusedError
+ ConnectionResetError DeprecationWarning EOFError Exception
+ FileExistsError FileNotFoundError FloatingPointError FutureWarning
+ GeneratorExit ImportError ImportWarning IndentationError
+ IndexError InterruptedError IsADirectoryError KeyboardInterrupt
+ KeyError LookupError MemoryError ModuleNotFoundError NameError
+ NotADirectoryError NotImplementedError OSError OverflowError
+ PendingDeprecationWarning PermissionError ProcessLookupError
+ RecursionError ReferenceError ResourceWarning RuntimeError
+ RuntimeWarning StopAsyncIteration StopIteration SyntaxError
+ SyntaxWarning SystemError SystemExit TabError TimeoutError TypeError
+ UnboundLocalError UnicodeDecodeError UnicodeEncodeError UnicodeError
+ UnicodeTranslateError UnicodeWarning UserWarning ValueError Warning
+ ZeroDivisionError"
# Keyword list is collected using `keyword.kwlist` from `keyword`
- keywords="and|as|assert|async|await|break|class|continue|def|del|elif|else|except|exec"
- keywords="${keywords}|finally|for|global|if|in|is|lambda|nonlocal|not|or|pass|print"
- keywords="${keywords}|raise|return|try|while|with|yield"
+ keywords="and as assert async await break class continue def del elif else except exec
+ finally for global if in is lambda nonlocal not or pass print
+ raise return try while with yield"
+
+ types="bool buffer bytearray bytes complex dict file float frozenset int
+ list long memoryview object set str tuple unicode xrange"
- 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 breakpoint callable chr classmethod compile complex
+ delattr dict dir divmod enumerate eval exec filter
+ format frozenset getattr globals hasattr hash help
+ hex id __import__ input isinstance issubclass iter
+ len locals map max memoryview min next oct open ord
+ pow print property range repr reversed round
+ setattr slice sorted staticmethod sum super type vars zip"
- functions="abs|all|any|ascii|bin|breakpoint|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"
+ join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*"; }
# Add the language's grammar to the static completion list
- printf %s\\n "hook global WinSetOption filetype=python %{
- set-option window static_words ${values} ${meta} ${attributes} ${methods} ${exceptions} ${keywords} ${types} ${functions}
- }" | tr '|' ' '
+ printf %s\\n "declare-option str-list python_static_words $(join "${values} ${meta} ${attributes} ${methods} ${exceptions} ${keywords} ${types} ${functions}" ' ')"
# Highlight keywords
printf %s "
- add-highlighter shared/python/code/ regex '\b(${values})\b' 0:value
- add-highlighter shared/python/code/ regex '\b(${meta})\b' 0:meta
- add-highlighter shared/python/code/ regex '\b(${attribute})\b' 0:attribute
- add-highlighter shared/python/code/ regex '\bdef\s+(${methods})\b' 1:function
- add-highlighter shared/python/code/ regex '\b(${exceptions})\b' 0:function
- add-highlighter shared/python/code/ regex '\b(${keywords})\b' 0:keyword
- add-highlighter shared/python/code/ regex '\b(${functions})\b\(' 1:builtin
- add-highlighter shared/python/code/ regex '\b(${types})\b' 0:type
+ add-highlighter shared/python/code/ regex '\b($(join "${values}" '|'))\b' 0:value
+ add-highlighter shared/python/code/ regex '\b($(join "${meta}" '|'))\b' 0:meta
+ add-highlighter shared/python/code/ regex '\b($(join "${attribute}" '|'))\b' 0:attribute
+ add-highlighter shared/python/code/ regex '\bdef\s+($(join "${methods}" '|'))\b' 1:function
+ add-highlighter shared/python/code/ regex '\b($(join "${exceptions}" '|'))\b' 0:function
+ add-highlighter shared/python/code/ regex '\b($(join "${keywords}" '|'))\b' 0:keyword
+ add-highlighter shared/python/code/ regex '\b($(join "${functions}" '|'))\b\(' 1:builtin
+ add-highlighter shared/python/code/ regex '\b($(join "${types}" '|'))\b' 0:type
add-highlighter shared/python/code/ regex '@[\w_]+\b' 0:attribute
"
}
@@ -138,19 +153,4 @@ define-command -hidden python-indent-on-new-line %{
}
}
-# Initialization
-# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
-
-hook -group python-highlight global WinSetOption filetype=python %{
- add-highlighter window/python ref python
- hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/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 ModeChange insert:.* -group python-trim-indent %{ try %{ execute-keys -draft \; <a-x> s ^\h+$ <ret> d } }
- hook -once -always window WinSetOption filetype=.* %{ remove-hooks window python-.+ }
-}
-
}