AutoYADM commit: 2025-05-15 21:56:01
This commit is contained in:
parent
78e6028845
commit
b171583d3d
2 changed files with 42 additions and 1 deletions
|
@ -1,3 +1,4 @@
|
||||||
hook global WinSetOption filetype=go %{
|
hook global WinSetOption filetype=go %{
|
||||||
hook -group go-auto-format window BufWritePre .* lsp-formatting
|
set-option window lsp_fmt true
|
||||||
|
# hook -group go-auto-format window BufWritePre .* lsp-formatting
|
||||||
}
|
}
|
||||||
|
|
40
.config/kak/autoload/format.kak
Normal file
40
.config/kak/autoload/format.kak
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
declare-option -docstring "shell command used for the 'format-selections' and 'format-buffer' commands" \
|
||||||
|
str formatcmd
|
||||||
|
declare-option -docstring "whether the LSP should be preferred for formatting" lsp_fmt bool false
|
||||||
|
|
||||||
|
define-command format-buffer -docstring "Format the contents of the buffer" %{
|
||||||
|
evaluate-commands -draft %{
|
||||||
|
execute-keys '%'
|
||||||
|
format-selections
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
define-command format-selections -docstring "Format the selections individually" %{
|
||||||
|
evaluate-commands %sh{
|
||||||
|
if [ -z "${kak_opt_formatcmd}" ]; then
|
||||||
|
echo "fail 'The option ''formatcmd'' must be set'"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
evaluate-commands -draft -no-hooks -save-regs 'e|' %{
|
||||||
|
set-register e nop
|
||||||
|
set-register '|' %{
|
||||||
|
format_in="$(mktemp "${TMPDIR:-/tmp}"/kak-formatter.XXXXXX)"
|
||||||
|
format_out="$(mktemp "${TMPDIR:-/tmp}"/kak-formatter.XXXXXX)"
|
||||||
|
|
||||||
|
cat > "$format_in"
|
||||||
|
eval "$kak_opt_formatcmd" < "$format_in" > "$format_out"
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
cat "$format_out"
|
||||||
|
else
|
||||||
|
echo "set-register e fail formatter returned an error (exit code $?)" >"$kak_command_fifo"
|
||||||
|
cat "$format_in"
|
||||||
|
fi
|
||||||
|
rm -f "$format_in" "$format_out"
|
||||||
|
}
|
||||||
|
execute-keys '|<ret>'
|
||||||
|
%reg{e}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
alias global format format-buffer
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue