From 98594cf6df600eefe4fc5913685f6a43aeb76055 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Mon, 14 Mar 2016 14:08:51 +0200 Subject: Add static completion suggestions to several languages, set `autopep8` as default python formatter --- rc/core/python.kak | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) (limited to 'rc/core/python.kak') diff --git a/rc/core/python.kak b/rc/core/python.kak index 4891f200..8f482f4d 100644 --- a/rc/core/python.kak +++ b/rc/core/python.kak @@ -12,8 +12,8 @@ hook global BufCreate .*[.](py) %{ set buffer filetype python } -# Highlighters -# ‾‾‾‾‾‾‾‾‾‾‾‾ +# Highlighters & Completion +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ addhl -group / regions -default code python \ double_string '"""' '"""' '' \ @@ -26,22 +26,36 @@ addhl -group /python/double_string fill string addhl -group /python/single_string fill string addhl -group /python/comment fill comment -addhl -group /python/code regex \<(True|False|None)\> 0:value -addhl -group /python/code regex \<(import|from)\> 0:meta +%sh{ + # Grammar + values="True:False:None" + meta="import:from" + # Keyword list is collected using `keyword.kwlist` from `keyword` + 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" -# Keyword list is collected using `keyword.kwlist` from `keyword` -addhl -group /python/code regex \<(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)\> 0:keyword -# Highlight types, when they are not used as constructors -addhl -group /python/code regex \<(bool|buffer|bytearray|complex|dict|file|float|frozenset|int|list|long|memoryview|object|set|str|tuple|unicode|xrange)\>[^(] 1:type + # Add the language's grammar to the static completion list + echo "hook global WinSetOption filetype=python %{ + set window static_words '${values}' + set -add window static_words '${meta}' + set -add window static_words '${keywords}' + set -add window static_words '${types}' + }" -# Commands -# ‾‾‾‾‾‾‾‾ + # Highlight keywords + echo " + addhl -group /python/code regex '\<(${values//:/|})\>' 0:value + addhl -group /python/code regex '\<(${meta//:/|})\>' 0:meta + addhl -group /python/code regex '\<(${keywords//:/|})\>' 0:keyword + " -def -hidden _python_filter_around_selections %{ - # remove trailing white spaces - try %{ exec -draft -itersel s \h+$ d } + # Highlight types, when they are not used as constructors + echo "addhl -group /python/code regex '\<(${types//:/|})\>[^(]' 1:type" } +# Commands +# ‾‾‾‾‾‾‾‾ + def -hidden _python_indent_on_new_line %{ eval -draft -itersel %{ # preserve previous line indent @@ -60,13 +74,12 @@ def -hidden _python_indent_on_new_line %{ hook global WinSetOption filetype=python %{ addhl ref python - - hook window InsertEnd .* -group python-hooks _python_filter_around_selections hook window InsertChar \n -group python-indent _python_indent_on_new_line + + set window formatcmd "autopep8 -" } hook global WinSetOption filetype=(?!python).* %{ rmhl python rmhooks window python-indent - rmhooks window python-hooks } -- cgit v1.2.3 From 3079d2a7e328309e3d2b298d573020c6bf5b0aca Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Mon, 14 Mar 2016 18:29:11 +0200 Subject: Replace non-POSIX inline character replacement in shell scripts --- rc/core/python.kak | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'rc/core/python.kak') diff --git a/rc/core/python.kak b/rc/core/python.kak index 8f482f4d..380c43c4 100644 --- a/rc/core/python.kak +++ b/rc/core/python.kak @@ -28,14 +28,14 @@ addhl -group /python/comment fill comment %sh{ # Grammar - values="True:False:None" - meta="import:from" + values="True|False|None" + meta="import|from" # Keyword list is collected using `keyword.kwlist` from `keyword` - 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" + 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" # Add the language's grammar to the static completion list - echo "hook global WinSetOption filetype=python %{ + sed 's,|,:,g' <<< "hook global WinSetOption filetype=python %{ set window static_words '${values}' set -add window static_words '${meta}' set -add window static_words '${keywords}' @@ -44,13 +44,13 @@ addhl -group /python/comment fill comment # Highlight keywords echo " - addhl -group /python/code regex '\<(${values//:/|})\>' 0:value - addhl -group /python/code regex '\<(${meta//:/|})\>' 0:meta - addhl -group /python/code regex '\<(${keywords//:/|})\>' 0:keyword + addhl -group /python/code regex '\<(${values})\>' 0:value + addhl -group /python/code regex '\<(${meta})\>' 0:meta + addhl -group /python/code regex '\<(${keywords})\>' 0:keyword " # Highlight types, when they are not used as constructors - echo "addhl -group /python/code regex '\<(${types//:/|})\>[^(]' 1:type" + echo "addhl -group /python/code regex '\<(${types})\>[^(]' 1:type" } # Commands -- cgit v1.2.3 From 4bb5658206778b68110d7d00bba6703e3b838e52 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Thu, 17 Mar 2016 15:30:14 +0200 Subject: Replace non-POSIX here-strings and calls to `echo` --- rc/core/python.kak | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'rc/core/python.kak') diff --git a/rc/core/python.kak b/rc/core/python.kak index 380c43c4..f378d7a6 100644 --- a/rc/core/python.kak +++ b/rc/core/python.kak @@ -35,22 +35,22 @@ addhl -group /python/comment fill comment types="bool|buffer|bytearray|complex|dict|file|float|frozenset|int|list|long|memoryview|object|set|str|tuple|unicode|xrange" # Add the language's grammar to the static completion list - sed 's,|,:,g' <<< "hook global WinSetOption filetype=python %{ + printf %s "hook global WinSetOption filetype=python %{ set window static_words '${values}' set -add window static_words '${meta}' set -add window static_words '${keywords}' set -add window static_words '${types}' - }" + }" | sed 's,|,:,g' # Highlight keywords - echo " + printf %s " addhl -group /python/code regex '\<(${values})\>' 0:value addhl -group /python/code regex '\<(${meta})\>' 0:meta addhl -group /python/code regex '\<(${keywords})\>' 0:keyword " # Highlight types, when they are not used as constructors - echo "addhl -group /python/code regex '\<(${types})\>[^(]' 1:type" + printf %s "addhl -group /python/code regex '\<(${types})\>[^(]' 1:type" } # Commands -- cgit v1.2.3