Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions cmd/micro/runtime.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions runtime/plugins/formatter/formatter.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
if GetOption("formatter") == nil then
AddOption("formatter", false)
end

MakeCommand("format", "formatter.runFormatter", 0)

function runFormatter()
CurView():Save(false)

local ft = CurView().Buf:FileType()
local handle
if ft == "fish" then
handle = io.popen("fish_indent -w " .. CurView().Buf.Path)
elseif ft == "go" then
handle = io.popen("gofmt -s -w " .. CurView().Buf.Path)
elseif ft == "shell" then
handle = io.popen("shfmt -s -w " .. CurView().Buf.Path)
else
return
end
local result = handle:read("*a")
handle:close()

CurView():ReOpen()
end

function onSave(view)
if GetOption("formatter") then
runFormatter()
end
end