Move linter and go plugins to their own repos

The linter and go plugins are no longer 'default'. Their installation
should be handled by the plugin manager: `> plugin install go` and
`> plugin install linter`.

The autoclose plugin will remain a default plugin because it provides
a more essential feature.

Closes #397
This commit is contained in:
Zachary Yedidia
2016-10-06 17:18:53 -04:00
parent c410b7b2ce
commit aa624d86e6
5 changed files with 5 additions and 199 deletions

File diff suppressed because one or more lines are too long

View File

@@ -117,23 +117,10 @@ Here are the options that you can set:
Default plugin options:
* `linter`: lint languages on save (supported languages are C, D, Go, Java,
Javascript, Lua). Provided by the `linter` plugin.
default value: `on`
* `autoclose`: Automatically close `{}` `()` `[]` `""` `''`. Provided by the `autoclose` plugin
default value: `on`
* `goimports`: Run goimports on save. Provided by the `go` plugin.
default value: `off`
* `gofmt`: Run gofmt on save. Provided by the `go` plugin.
default value: `on`
Any option you set in the editor will be saved to the file
~/.config/micro/settings.json so, in effect, your configuration file will be
created for you. If you'd like to take your configuration with you to another

View File

@@ -162,8 +162,8 @@ MakeCommand("foo", "example.foo", MakeCompletion("example.complete"))
# Default plugins
For examples of plugins, see the default plugins `linter`, `go`, and `autoclose`.
They are stored in Micro's GitHub repository [here](https://github.com/zyedidia/micro/tree/master/runtime/plugins).
For examples of plugins, see the default `autoclose` plugin (stored in the normal micro core repo under `runtime/plugins/autoclose`) as well as
any plugins that are stored in the official channel [here](https://github.com/micro-editor/plugin-channel).
# Plugin Manager
@@ -201,4 +201,4 @@ metadata for your plugin. Here is an example:
Then open a pull request at github.com/micro-editor/plugin-channel adding a link to the
raw `repo.json` that is in your plugin repository.
To make updating the plugin work, the first line of your plugins lua code should contain the version of the plugin. (Like this: `VERSION = "1.0.0"`)
Please make sure to use [semver](http://semver.org/) for versioning.
Please make sure to use [semver](http://semver.org/) for versioning.

View File

@@ -1,52 +0,0 @@
if GetOption("goimports") == nil then
AddOption("goimports", false)
end
if GetOption("gofmt") == nil then
AddOption("gofmt", true)
end
MakeCommand("goimports", "go.goimports", 0)
MakeCommand("gofmt", "go.gofmt", 0)
function onViewOpen(view)
if view.Buf:FileType() == "go" then
SetLocalOption("tabstospaces", "off", view)
end
end
function onSave(view)
if CurView().Buf:FileType() == "go" then
if GetOption("goimports") then
goimports()
elseif GetOption("gofmt") then
gofmt()
end
end
end
function gofmt()
CurView():Save(false)
local handle = io.popen("gofmt -w " .. CurView().Buf.Path)
local result = handle:read("*a")
handle:close()
CurView():ReOpen()
end
function goimports()
CurView():Save(false)
local handle = io.popen("goimports -w " .. CurView().Buf.Path)
local result = split(handle:read("*a"), ":")
handle:close()
CurView():ReOpen()
end
function split(str, sep)
local result = {}
local regex = ("([^%s]+)"):format(sep)
for each in str:gmatch(regex) do
table.insert(result, each)
end
return result
end

View File

@@ -1,79 +0,0 @@
if GetOption("linter") == nil then
AddOption("linter", true)
end
MakeCommand("lint", "linter.lintCommand", 0)
function lintCommand()
CurView():Save(false)
runLinter()
end
function runLinter()
local ft = CurView().Buf:FileType()
local file = CurView().Buf.Path
local devnull = "/dev/null"
if OS == "windows" then
devnull = "NUL"
end
if ft == "go" then
lint("gobuild", "go build -o " .. devnull, "%f:%l: %m")
lint("golint", "golint " .. CurView().Buf.Path, "%f:%l:%d+: %m")
elseif ft == "lua" then
lint("luacheck", "luacheck --no-color " .. file, "%f:%l:%d+: %m")
elseif ft == "python" then
lint("pyflakes", "pyflakes " .. file, "%f:%l:.-:? %m")
elseif ft == "c" then
lint("gcc", "gcc -fsyntax-only -Wall -Wextra " .. file, "%f:%l:%d+:.+: %m")
elseif ft == "d" then
lint("dmd", "dmd -color=off -o- -w -wi -c " .. file, "%f%(%l%):.+: %m")
elseif ft == "java" then
lint("javac", "javac " .. file, "%f:%l: error: %m")
elseif ft == "javascript" then
lint("jshint", "jshint " .. file, "%f: line %l,.+, %m")
end
end
function onSave(view)
if GetOption("linter") then
runLinter()
else
CurView():ClearAllGutterMessages()
end
end
function lint(linter, cmd, errorformat)
CurView():ClearGutterMessages(linter)
JobStart(cmd, "", "", "linter.onExit", linter, errorformat)
end
function onExit(output, linter, errorformat)
local lines = split(output, "\n")
local regex = errorformat:gsub("%%f", "(..-)"):gsub("%%l", "(%d+)"):gsub("%%m", "(.+)")
for _,line in ipairs(lines) do
-- Trim whitespace
line = line:match("^%s*(.+)%s*$")
if string.find(line, regex) then
local file, line, msg = string.match(line, regex)
if basename(CurView().Buf.Path) == basename(file) then
CurView():GutterMessage(linter, tonumber(line), msg, 2)
end
end
end
end
function split(str, sep)
local result = {}
local regex = ("([^%s]+)"):format(sep)
for each in str:gmatch(regex) do
table.insert(result, each)
end
return result
end
function basename(file)
local name = string.gsub(file, "(.*/)(.*)", "%2")
return name
end