From 02106a54e38e3bab2b9d5598d441918e79c5c9b0 Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Thu, 15 May 2025 22:11:23 -0400 Subject: [PATCH] AutoYADM commit: 2025-05-15 22:11:23 --- .config/kak/autoload/filetype/go.kak | 2 +- .config/kak/autoload/format.kak | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/.config/kak/autoload/filetype/go.kak b/.config/kak/autoload/filetype/go.kak index 0b23ffe1..5968c085 100644 --- a/.config/kak/autoload/filetype/go.kak +++ b/.config/kak/autoload/filetype/go.kak @@ -1,4 +1,4 @@ hook global WinSetOption filetype=go %{ set-option window lsp_fmt true - # hook -group go-auto-format window BufWritePre .* lsp-formatting + hook -group go-auto-format window BufWritePre .* format } diff --git a/.config/kak/autoload/format.kak b/.config/kak/autoload/format.kak index 3acb8669..0dc79c4f 100644 --- a/.config/kak/autoload/format.kak +++ b/.config/kak/autoload/format.kak @@ -1,15 +1,35 @@ 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 +declare-option -docstring "whether the LSP should be preferred for formatting" bool lsp_fmt false define-command format-buffer -docstring "Format the contents of the buffer" %{ + evaluate-commands %sh{ + if [ "$kak_opt_lsp_fmt" == "false" ]; then + echo "format-buffer-pipe" + else + echo "lsp-formatting" + fi + } +} + +define-command format-selections -docstring "Format the selections individually" %{ + evaluate-commands %sh{ + if [ "${kak_opt_lsp_fmt}" == "false" ]; then + echo "format-selections-pipe" + else + echo "lsp-range-formatting" + fi + } +} + +define-command format-buffer-pipe -hidden -docstring "Format the contents of the buffer using pipe" %{ evaluate-commands -draft %{ execute-keys '%' format-selections } } -define-command format-selections -docstring "Format the selections individually" %{ +define-command format-selections-pipe -docstring "Format the selections individually using pipe" %{ evaluate-commands %sh{ if [ -z "${kak_opt_formatcmd}" ]; then echo "fail 'The option ''formatcmd'' must be set'"