<commit_before>// Copyright 2015 <NAME>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package commands

import (
	"bytes"
	"go/scanner"

	"nvim-go/gb"
	"nvim-go/nvim"

	"github.com/garyburd/neovim-go/vim"
	"github.com/garyburd/neovim-go/vim/plugin"
	"golang.org/x/tools/imports"
)

var options = imports.Options{
	AllErrors: true,
	Comments:  true,
	TabIndent: true,
	TabWidth:  8,
}

func init() {
	plugin.HandleCommand("Gofmt", &plugin.CommandOptions{Range: "%", Eval: "expand('%:p:h')"}, Fmt)
	plugin.HandleAutocmd("BufWritePre", &plugin.AutocmdOptions{Pattern: "*.go", Eval: "expand('%:p:h')"}, onBufWritePre)
}

func onBufWritePre(v *vim.Vim, dir string) {
	go Fmt(v, [2]int{0, 0}, dir)
}

func Fmt(v *vim.Vim, r [2]int, dir string) error {<commit_msg>Add async fmt flag variable<commit_after>// Copyright 2015 <NAME>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package commands

import (
	"bytes"
	"go/scanner"

	"nvim-go/gb"
	"nvim-go/nvim"

	"github.com/garyburd/neovim-go/vim"
	"github.com/garyburd/neovim-go/vim/plugin"
	"golang.org/x/tools/imports"
)

var (
	fmtAsync  = "go#fmt#async"
	vFmtAsync interface{}
)

var options = imports.Options{
	AllErrors: true,
	Comments:  true,
	TabIndent: true,
	TabWidth:  8,
}

func init() {
	plugin.HandleCommand("Gofmt", &plugin.CommandOptions{Range: "%", Eval: "expand('%:p:h')"}, Fmt)
	plugin.HandleAutocmd("BufWritePre", &plugin.AutocmdOptions{Pattern: "*.go", Eval: "expand('%:p:h')"}, onBufWritePre)
}

func onBufWritePre(v *vim.Vim, dir string) {
	v.Var(fmtAsync, &vFmtAsync)
	if vFmtAsync.(int64) == int64(1) {
		go Fmt(v, [2]int{0, 0}, dir)
	} else {
		Fmt(v, [2]int{0, 0}, dir)
	}
}

func Fmt(v *vim.Vim, r [2]int, dir string) error {
{'fraction_non_alphanumeric': 0.17447495961227788, 'fraction_numerical': 0.014001077005923533, 'mean_word_length': 4.4169096209912535, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '93633', 'n_tokens_mistral': 798, 'n_tokens_neox': 760, 'n_words': 175}