From 452bb7c21d05a5d35220ddedc5c2e311364bfe51 Mon Sep 17 00:00:00 2001 From: Mike Vink Date: Fri, 31 Oct 2025 11:41:01 +0100 Subject: add some stuff for python and debugging --- .config/kak/autoload/connect/commands/:fifo | 2 +- .config/kak/kakrc | 31 ++++++++++++++++++++--------- .config/kak/snippets.python.kak | 11 ++++++++++ .pdbrc | 7 +++++++ 4 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 .config/kak/snippets.python.kak create mode 100644 .pdbrc diff --git a/.config/kak/autoload/connect/commands/:fifo b/.config/kak/autoload/connect/commands/:fifo index ea2ede0..4c31940 100755 --- a/.config/kak/autoload/connect/commands/:fifo +++ b/.config/kak/autoload/connect/commands/:fifo @@ -3,7 +3,7 @@ # Edit fifo buffer in a client mkfifo buffer.fifo trap 'rm buffer.fifo' EXIT -:send edit! -fifo "$PWD/buffer.fifo" '*fifo*' +:send evaluate-commands -try-client tools %{edit! -fifo "$PWD/buffer.fifo" '*fifo*'} # Send to fifo buffer the output of the given command, # or read from stdin if available. diff --git a/.config/kak/kakrc b/.config/kak/kakrc index e4157ba..ee1b76e 100644 --- a/.config/kak/kakrc +++ b/.config/kak/kakrc @@ -43,17 +43,19 @@ hook -once global KakBegin .* %{ } # Added bracketed paste support. - define-command -override dtach-send-text -params 0..1 -docstring %{ + define-command -override dtach-send-bracketed-text -params 0..1 -docstring %{ dtach-send-text [text]: Send text to the REPL. If no text is passed, then the selection is used } %{ nop %sh{ - printf "\033[200~%s\033[201~\n" "${@:-$kak_selection}" | dtach -p "$kak_opt_dtach_repl_id" + { printf '\033[200~'; printf '%s' "${@:-$kak_selection}"; printf '\033[201~'; } | dtach -p "$kak_opt_dtach_repl_id" + { printf '\n'; } | dtach -p "$kak_opt_dtach_repl_id" } } alias global repl-new dtach-repl - alias global repl-send-text dtach-send-text + alias global repl-send-text dtach-send-bracketed-text + alias global / dtach-send-bracketed-text } # Ide / connect @@ -107,7 +109,7 @@ define-command -override relative-cd %{ } } map global user c ":relative-cd" -map global user f ":> yazi" +map global user f ":evaluate-commands -try-client main %{ > yazi }" define-command find -params 1 %{ edit %arg{1} } complete-command -menu find shell-script-candidates %{ fd --type=f --hidden --exclude='.git**' } @@ -151,22 +153,33 @@ hook global WinSetOption filetype=latex %{ } } -hook -group kakrc-python-flat-lint global WinSetOption filetype=python %{ +hook -group kakrc-python-lint global WinSetOption filetype=python %{ set-option buffer lintcmd %{parallel "mypy --show-column-numbers {}" :::} } define-command -override python-package-lint-file -params 1..2 %{ + remove-hooks global kakrc-python-lint + set-option buffer lintcmd "parallel 'mypy --show-column-numbers %arg{1} | grep %reg{percent}; :' :::" evaluate-commands %sh{ - printf '%s\n' "set-option buffer lintcmd %{parallel 'mypy --show-column-numbers ${1:?} | grep ${2:-$kak_reg_percent}; :' :::}" +cat <:repl-send-text "b %val{buffile}:%val{cursor_line} ;; continue ;; clear -1 ;; f self.kind()"| + set-option buffer formatcmd 'ruff format -' hook buffer -group format BufWritePost .* format-but-write + map buffer user r %|:repl-send-text "b %val{cursor_line} ;; continue ;; clear -1"| + try %{ source ~/.config/kak/snippets.python.kak } + hook global BufWritePost snippets.python.kak %{ + echo "snippets written" + try %{ source ~/.config/kak/snippets.python.kak } + } } hook global WinSetOption filetype=terraform %{ diff --git a/.config/kak/snippets.python.kak b/.config/kak/snippets.python.kak new file mode 100644 index 0000000..5db5ecc --- /dev/null +++ b/.config/kak/snippets.python.kak @@ -0,0 +1,11 @@ +echo "sourced snippets" + +set buffer snippets_auto_expand 'true' +map buffer normal ": phantom-selection-iterate-next" +map buffer normal ": phantom-selection-iterate-prev" +map buffer insert ": try phantom-selection-iterate-nexti" +map buffer insert ": try phantom-selection-iterate-previ" + +set buffer snippets 'breakpoint' ';b' %{ + snippets-insert %@breakpoint()${}@ +} diff --git a/.pdbrc b/.pdbrc new file mode 100644 index 0000000..29f017d --- /dev/null +++ b/.pdbrc @@ -0,0 +1,7 @@ +alias edit import os; os.system(f"$EDITOR {$_frame.f_code.co_filename} +{$_frame.f_lineno}") +alias e edit +alias s step ;; edit +alias n next ;; edit +alias r return ;; edit +alias c continue ;; edit +alias f import subprocess as sub; import json; sub.run("jq | :f", shell=True, input=json.dumps(%1).encode()) -- cgit v1.2.3