diff options
| author | Jacob McDonnell <jacob@simplelittledream.com> | 2022-07-16 18:13:16 -0400 |
|---|---|---|
| committer | Jacob McDonnell <jacob@simplelittledream.com> | 2022-07-16 18:13:16 -0400 |
| commit | 8fad9a5ecddc88d57a531e4b0084544984f23d25 (patch) | |
| tree | 84954bc8219942aa56bc899330ccd0007bbe0ef0 /.config/micro/plug/go | |
| parent | 2887af7fcfb4d618dd13cf66ec2fbdbd84c7527c (diff) | |
Added profile and other missing configs
Diffstat (limited to '.config/micro/plug/go')
| -rw-r--r-- | .config/micro/plug/go/README.md | 10 | ||||
| -rw-r--r-- | .config/micro/plug/go/go.lua | 84 | ||||
| -rw-r--r-- | .config/micro/plug/go/help/go-plugin.md | 42 | ||||
| -rw-r--r-- | .config/micro/plug/go/repo.json | 37 |
4 files changed, 173 insertions, 0 deletions
diff --git a/.config/micro/plug/go/README.md b/.config/micro/plug/go/README.md new file mode 100644 index 0000000..8002e0e --- /dev/null +++ b/.config/micro/plug/go/README.md @@ -0,0 +1,10 @@ +# Go Plugin for Micro + +This repository holds the Go plugin for micro. This plugin +has been updated for use with micro 2.0. + +Install by cloning this into your plug directory: + +``` +git clone https://github.com/micro-editor/go-plugin ~/.config/micro/plug/go-plugin +``` diff --git a/.config/micro/plug/go/go.lua b/.config/micro/plug/go/go.lua new file mode 100644 index 0000000..d030316 --- /dev/null +++ b/.config/micro/plug/go/go.lua @@ -0,0 +1,84 @@ +VERSION = "2.0.2" + +local micro = import("micro") +local config = import("micro/config") +local shell = import("micro/shell") +local buffer = import("micro/buffer") + +-- outside init because we want these options to take effect before +-- buffers are initialized +config.RegisterCommonOption("go", "goimports", false) +config.RegisterCommonOption("go", "gofmt", true) + +function init() + config.MakeCommand("goimports", goimports, config.NoComplete) + config.MakeCommand("gofmt", gofmt, config.NoComplete) + config.MakeCommand("gorename", gorenameCmd, config.NoComplete) + + config.AddRuntimeFile("go", config.RTHelp, "help/go-plugin.md") + config.TryBindKey("F6", "command-edit:gorename ", false) +end + +function onSave(bp) + if bp.Buf:FileType() == "go" then + if bp.Buf.Settings["go.goimports"] then + goimports(bp) + elseif bp.Buf.Settings["go.gofmt"] then + gofmt(bp) + end + end + return true +end + +function gofmt(bp) + bp:Save() + local _, err = shell.RunCommand("gofmt -w " .. bp.Buf.Path) + if err ~= nil then + micro.InfoBar():Error(err) + return + end + + bp.Buf:ReOpen() +end + +function gorenameCmd(bp, args) + micro.Log(args) + if #args == 0 then + micro.InfoBar():Message("Not enough arguments") + else + bp:Save() + local buf = bp.Buf + if #args == 1 then + local c = bp.Cursor + local loc = buffer.Loc(c.X, c.Y) + local offset = buffer.ByteOffset(loc, buf) + local cmdargs = {"--offset", buf.Path .. ":#" .. tostring(offset), "--to", args[1]} + shell.JobSpawn("gorename", cmdargs, nil, renameStderr, renameExit, bp) + else + local cmdargs = {"--from", args[1], "--to", args[2]} + shell.JobSpawn("gorename", cmdargs, nil, renameStderr, renameExit, bp) + end + micro.InfoBar():Message("Renaming...") + end +end + +function renameStderr(err) + micro.Log(err) + micro.InfoBar():Message(err) +end + +function renameExit(output, args) + local bp = args[1] + bp.Buf:ReOpen() +end + +function goimports(bp) + bp:Save() + local _, err = shell.RunCommand("goimports -w " .. bp.Buf.Path) + if err ~= nil then + micro.InfoBar():Error(err) + return + end + + bp.Buf:ReOpen() +end diff --git a/.config/micro/plug/go/help/go-plugin.md b/.config/micro/plug/go/help/go-plugin.md new file mode 100644 index 0000000..a4cdb33 --- /dev/null +++ b/.config/micro/plug/go/help/go-plugin.md @@ -0,0 +1,42 @@ +# Go Plugin + +The go plugin provides some extra niceties for using micro with +the Go programming language. The main thing this plugin does is +run `gofmt` and `goimports` for you automatically. If you would also +like automatically error linting, check out the `linter` plugin. +The plugin also provides `gorename` functionality. + +You can run + +``` +> gofmt +``` + +or + +``` +> goimports +``` + +To automatically run these when you save the file, use the following +options: + +* `gofmt`: run gofmt on file saved. Default value: `on` +* `goimports`: run goimports on file saved. Default value: `off` + +To use `gorename`, place your cursor over the variable you would like +to rename and enter the command `> gorename newName`. + +You also press F6 (the default binding) to open a prompt to rename. You +can rebind this in your `bindings.json` file with the action `go.gorename`. + +The go plugin also provides an interface for using `gorename` if you have +it installed. The gorename command behaves in two ways: + +* With one argument: `> gorename newname` will rename the identifier + under the cursor with the new name `newname`. + +* With two arguments: `> gorename oldname newname` will rename the old + identifier with the new one. This uses gorename's syntax for specifying + the old identifier, so please see `gorename --help` for the details + for how to specify the variable. diff --git a/.config/micro/plug/go/repo.json b/.config/micro/plug/go/repo.json new file mode 100644 index 0000000..f4e914c --- /dev/null +++ b/.config/micro/plug/go/repo.json @@ -0,0 +1,37 @@ +[{ + "Name": "go", + "Description": "Go language support (gofmt and goimports)", + "Tags": ["go", "golang"], + "Website": "https://github.com/micro-editor/go-plugin", + "Versions": [ + { + "Version": "2.0.2", + "Url": "https://github.com/micro-editor/go-plugin/archive/v2.0.2.zip", + "Require": { + "micro": ">=2.0.0" + } + }, + { + "Version": "2.0.1", + "Url": "https://github.com/micro-editor/go-plugin/archive/v2.0.1.zip", + "Require": { + "micro": ">=2.0.0-1" + } + }, + { + "Version": "2.0.0", + "Url": "https://github.com/micro-editor/go-plugin/archive/v2.0.0.zip", + "Require": { + "micro": ">=2.0.0-1" + } + }, + { + "Version": "1.0.1", + "Url": "https://github.com/micro-editor/go-plugin/archive/v1.0.1.zip", + "Require": { + "micro": ">=1.0.3 <2.0.0-1" + } + } + ] +}] + |
