From 68ef15d382d0b6f10c6ad30a7370db57ed8318e9 Mon Sep 17 00:00:00 2001
From: Sergey Matveev <stargrave@stargrave.org>
Date: Thu, 30 Jun 2022 23:00:40 +0300
Subject: [PATCH] Simpler and less disturbing :Fmt

---
 vim/.vim/autoload/fmt.vim    |  7 ++++
 vim/.vim/ftplugin/c/fmt.vim  |  2 +-
 vim/.vim/ftplugin/go/fmt.vim | 69 ++----------------------------------
 3 files changed, 10 insertions(+), 68 deletions(-)
 create mode 100644 vim/.vim/autoload/fmt.vim

diff --git a/vim/.vim/autoload/fmt.vim b/vim/.vim/autoload/fmt.vim
new file mode 100644
index 0000000..5e7a001
--- /dev/null
+++ b/vim/.vim/autoload/fmt.vim
@@ -0,0 +1,7 @@
+vim9script
+
+export def Do()
+    var view = winsaveview()
+    normal gg=G
+    winrestview(view)
+enddef
diff --git a/vim/.vim/ftplugin/c/fmt.vim b/vim/.vim/ftplugin/c/fmt.vim
index 0c50d99..2deba28 100644
--- a/vim/.vim/ftplugin/c/fmt.vim
+++ b/vim/.vim/ftplugin/c/fmt.vim
@@ -1,2 +1,2 @@
 set equalprg=cfmt.sh
-command! -buffer Fmt normal mtgg=G'tz.
+command! -buffer Fmt call fmt#Do()
diff --git a/vim/.vim/ftplugin/go/fmt.vim b/vim/.vim/ftplugin/go/fmt.vim
index 9ed68ad..feebf10 100644
--- a/vim/.vim/ftplugin/go/fmt.vim
+++ b/vim/.vim/ftplugin/go/fmt.vim
@@ -1,67 +1,2 @@
-" Copyright 2011 The Go Authors. All rights reserved.
-" Use of this source code is governed by a BSD-style
-" license that can be found in the LICENSE file.
-"
-" fmt.vim: Vim command to format Go files with gofmt.
-"
-" This filetype plugin add a new commands for go buffers:
-"
-"   :Fmt
-"
-"       Filter the current Go buffer through gofmt.
-"       It tries to preserve cursor position and avoids
-"       replacing the buffer with stderr output.
-"
-" Options:
-"
-"   g:go_fmt_commands [default=1]
-"
-"       Flag to indicate whether to enable the commands listed above.
-"
-"   g:gofmt_command [default="gofmt"]
-"
-"       Flag naming the gofmt executable to use.
-"
-if exists("b:did_ftplugin_go_fmt")
-    finish
-endif
-
-if !exists("g:go_fmt_commands")
-    let g:go_fmt_commands = 1
-endif
-
-let g:gofmt_command = get(g:, "gofmt_command", "goimports")
-
-if g:go_fmt_commands
-    command! -buffer Fmt call s:GoFormat()
-endif
-
-function! s:GoFormat()
-    let view = winsaveview()
-    silent execute "%!" . g:gofmt_command
-    if v:shell_error
-        let errors = []
-        for line in getline(1, line('$'))
-            let tokens = matchlist(line, '^\(.\{-}\):\(\d\+\):\(\d\+\)\s*\(.*\)')
-            if !empty(tokens)
-                call add(errors, {"filename": @%,
-                                 \"lnum":     tokens[2],
-                                 \"col":      tokens[3],
-                                 \"text":     tokens[4]})
-            endif
-        endfor
-        if empty(errors)
-            % | " Couldn't detect gofmt error format, output errors
-        endif
-        undo
-        if !empty(errors)
-            call setqflist(errors, 'r')
-        endif
-        echohl Error | echomsg "Gofmt returned error" | echohl None
-    endif
-    call winrestview(view)
-endfunction
-
-let b:did_ftplugin_go_fmt = 1
-
-" vim:ts=4:sw=4:et
+set equalprg=goimports
+command! -buffer Fmt call fmt#Do()
-- 
2.51.0