diff options
| author | Adrià Arrufat <adria.arrufat@outlook.com> | 2023-04-02 21:09:57 +0900 |
|---|---|---|
| committer | Adrià Arrufat <adria.arrufat@outlook.com> | 2023-04-02 21:09:57 +0900 |
| commit | cea35cf5f418a40af78514d1da53fdfd30659e54 (patch) | |
| tree | d5399a1ca250dfee6726b557c587fcb55adc50e1 /rc/filetype/python.kak | |
| parent | 019fbc5439ad884f172c324ebc928463eab9bc74 (diff) | |
Delete commenting prefix on empty lines in Python
Diffstat (limited to 'rc/filetype/python.kak')
| -rw-r--r-- | rc/filetype/python.kak | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/rc/filetype/python.kak b/rc/filetype/python.kak index 391789ba..65da1a89 100644 --- a/rc/filetype/python.kak +++ b/rc/filetype/python.kak @@ -163,12 +163,25 @@ add-highlighter shared/python/code/ regex ^\h*(?:from|import)\h+(\S+) 1:module # Commands # ‾‾‾‾‾‾‾‾ -define-command -hidden python-insert-on-new-line %{ - evaluate-commands -draft -itersel %{ - # copy '#' comment prefix and following white spaces - try %{ execute-keys -draft k x s ^\h*#\h* <ret> y jgh P } +define-command -hidden python-insert-on-new-line %{ evaluate-commands -itersel -draft %{ + execute-keys <semicolon> + try %{ + evaluate-commands -draft -save-regs '/"' %{ + # copy the commenting prefix + execute-keys -save-regs '' k x1s^\h*(#+\h*)<ret> y + try %{ + # if the previous comment isn't empty, create a new one + execute-keys x<a-K>^\h*#+\h*$<ret> jxs^\h*<ret>P + } catch %{ + # if there is no text in the previous comment, remove it completely + execute-keys d + } + } + + # trim trailing whitespace on the previous line + try %{ execute-keys -draft k x s\h+$<ret> d } } -} +} } define-command -hidden python-indent-on-new-line %< evaluate-commands -draft -itersel %< |
