mirror of
https://github.com/zyedidia/micro.git
synced 2025-06-19 07:15:34 -04:00
Lua prompt support and plugin improvements
This commit is contained in:
parent
3b306c1d3b
commit
94ff79e7b2
@ -68,6 +68,10 @@ func BufMapKey(k Event, action string) {
|
|||||||
} else if strings.HasPrefix(a, "lua:") {
|
} else if strings.HasPrefix(a, "lua:") {
|
||||||
a = strings.SplitN(a, ":", 2)[1]
|
a = strings.SplitN(a, ":", 2)[1]
|
||||||
afn = LuaAction(a)
|
afn = LuaAction(a)
|
||||||
|
if afn == nil {
|
||||||
|
screen.TermMessage("Lua Error:", action, "does not exist")
|
||||||
|
continue
|
||||||
|
}
|
||||||
} else if f, ok := BufKeyActions[a]; ok {
|
} else if f, ok := BufKeyActions[a]; ok {
|
||||||
afn = f
|
afn = f
|
||||||
} else {
|
} else {
|
||||||
|
@ -89,11 +89,7 @@ func LuaFunctionCommand(fn string) func(*BufPane, []string) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return func(bp *BufPane, args []string) {
|
return func(bp *BufPane, args []string) {
|
||||||
var luaArgs []lua.LValue
|
luaArgs := []lua.LValue{luar.New(ulua.L, bp), luar.New(ulua.L, args)}
|
||||||
luaArgs = append(luaArgs, luar.New(ulua.L, bp))
|
|
||||||
for _, v := range args {
|
|
||||||
luaArgs = append(luaArgs, luar.New(ulua.L, v))
|
|
||||||
}
|
|
||||||
_, err := pl.Call(plFn, luaArgs...)
|
_, err := pl.Call(plFn, luaArgs...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
screen.TermMessage(err)
|
screen.TermMessage(err)
|
||||||
|
File diff suppressed because one or more lines are too long
@ -2,8 +2,14 @@ package info
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/zyedidia/micro/internal/buffer"
|
"github.com/zyedidia/micro/internal/buffer"
|
||||||
|
luar "layeh.com/gopher-luar"
|
||||||
|
|
||||||
|
"github.com/zyedidia/micro/internal/config"
|
||||||
|
ulua "github.com/zyedidia/micro/internal/lua"
|
||||||
|
"github.com/zyedidia/micro/internal/screen"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The InfoBuf displays messages and other info at the bottom of the screen.
|
// The InfoBuf displays messages and other info at the bottom of the screen.
|
||||||
@ -113,6 +119,8 @@ func (i *InfoBuf) Prompt(prompt string, msg string, ptype string, eventcb func(s
|
|||||||
i.Buffer.Insert(i.Buffer.Start(), msg)
|
i.Buffer.Insert(i.Buffer.Start(), msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// YNPrompt creates a yes or no prompt, and the callback returns the yes/no result and whether
|
||||||
|
// the prompt was canceled
|
||||||
func (i *InfoBuf) YNPrompt(prompt string, donecb func(bool, bool)) {
|
func (i *InfoBuf) YNPrompt(prompt string, donecb func(bool, bool)) {
|
||||||
if i.HasPrompt {
|
if i.HasPrompt {
|
||||||
i.DonePrompt(true)
|
i.DonePrompt(true)
|
||||||
@ -126,6 +134,63 @@ func (i *InfoBuf) YNPrompt(prompt string, donecb func(bool, bool)) {
|
|||||||
i.YNCallback = donecb
|
i.YNCallback = donecb
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PlugPrompt provides a plugin interface for calling "Prompt" with the appropriate Lua callbacks
|
||||||
|
func (i *InfoBuf) PlugPrompt(prompt string, msg string, ptype string, eventcb string, donecb string) {
|
||||||
|
eventLuaFn := strings.Split(eventcb, ".")
|
||||||
|
doneLuaFn := strings.Split(donecb, ".")
|
||||||
|
var luaEventcb func(string)
|
||||||
|
var luaDonecb func(string, bool)
|
||||||
|
|
||||||
|
if len(eventLuaFn) == 2 {
|
||||||
|
plName, plFn := doneLuaFn[0], doneLuaFn[1]
|
||||||
|
pl := config.FindPlugin(plName)
|
||||||
|
if pl != nil {
|
||||||
|
luaEventcb = func(resp string) {
|
||||||
|
_, err := pl.Call(plFn, luar.New(ulua.L, resp))
|
||||||
|
if err != nil && err != config.ErrNoSuchFunction {
|
||||||
|
screen.TermMessage(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(doneLuaFn) == 2 {
|
||||||
|
plName, plFn := doneLuaFn[0], doneLuaFn[1]
|
||||||
|
pl := config.FindPlugin(plName)
|
||||||
|
if pl != nil {
|
||||||
|
luaDonecb = func(resp string, canceled bool) {
|
||||||
|
_, err := pl.Call(plFn, luar.New(ulua.L, resp), luar.New(ulua.L, canceled))
|
||||||
|
if err != nil && err != config.ErrNoSuchFunction {
|
||||||
|
screen.TermMessage(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
i.Prompt(prompt, msg, ptype, luaEventcb, luaDonecb)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PlugYNPrompt provides a plugin interface for calling "YNPrompt" with the appropriate Lua callbacks
|
||||||
|
func (i *InfoBuf) PlugYNPrompt(prompt string, donecb string) {
|
||||||
|
doneLuaFn := strings.Split(donecb, ".")
|
||||||
|
var luaDonecb func(bool, bool)
|
||||||
|
|
||||||
|
if len(doneLuaFn) == 2 {
|
||||||
|
plName, plFn := doneLuaFn[0], doneLuaFn[1]
|
||||||
|
pl := config.FindPlugin(plName)
|
||||||
|
if pl != nil {
|
||||||
|
luaDonecb = func(resp bool, canceled bool) {
|
||||||
|
_, err := pl.Call(plFn, luar.New(ulua.L, resp), luar.New(ulua.L, canceled))
|
||||||
|
if err != nil && err != config.ErrNoSuchFunction {
|
||||||
|
screen.TermMessage(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
i.YNPrompt(prompt, luaDonecb)
|
||||||
|
}
|
||||||
|
|
||||||
// DonePrompt finishes the current prompt and indicates whether or not it was canceled
|
// DonePrompt finishes the current prompt and indicates whether or not it was canceled
|
||||||
func (i *InfoBuf) DonePrompt(canceled bool) {
|
func (i *InfoBuf) DonePrompt(canceled bool) {
|
||||||
hadYN := i.HasYN
|
hadYN := i.HasYN
|
||||||
|
@ -115,11 +115,7 @@ func luaFunctionJob(fn string) func(string, ...interface{}) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return func(output string, args ...interface{}) {
|
return func(output string, args ...interface{}) {
|
||||||
var luaArgs []lua.LValue
|
luaArgs := []lua.LValue{luar.New(ulua.L, output), luar.New(ulua.L, args)}
|
||||||
luaArgs = append(luaArgs, luar.New(ulua.L, output))
|
|
||||||
for _, v := range args {
|
|
||||||
luaArgs = append(luaArgs, luar.New(ulua.L, v))
|
|
||||||
}
|
|
||||||
_, err := pl.Call(plFn, luaArgs...)
|
_, err := pl.Call(plFn, luaArgs...)
|
||||||
if err != nil && err != config.ErrNoSuchFunction {
|
if err != nil && err != config.ErrNoSuchFunction {
|
||||||
screen.TermMessage(err)
|
screen.TermMessage(err)
|
||||||
|
@ -102,11 +102,7 @@ func (t *Terminal) Start(execCmd []string, getOutput bool, wait bool, callback s
|
|||||||
pl := config.FindPlugin(plName)
|
pl := config.FindPlugin(plName)
|
||||||
if pl != nil {
|
if pl != nil {
|
||||||
t.callback = func(out string) {
|
t.callback = func(out string) {
|
||||||
var luaArgs []lua.LValue
|
luaArgs := []lua.LValue{luar.New(ulua.L, out), luar.New(ulua.L, userargs)}
|
||||||
luaArgs = append(luaArgs, luar.New(ulua.L, out))
|
|
||||||
for _, v := range userargs {
|
|
||||||
luaArgs = append(luaArgs, luar.New(ulua.L, v))
|
|
||||||
}
|
|
||||||
_, err := pl.Call(plFn, luaArgs...)
|
_, err := pl.Call(plFn, luaArgs...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
screen.TermMessage(err)
|
screen.TermMessage(err)
|
||||||
|
@ -74,7 +74,7 @@ function commentSelection(bp, startLine, endLine)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function comment(bp)
|
function comment(bp, args)
|
||||||
if bp.Cursor:HasSelection() then
|
if bp.Cursor:HasSelection() then
|
||||||
if bp.Cursor.CurSelection[1]:GreaterThan(-bp.Cursor.CurSelection[2]) then
|
if bp.Cursor.CurSelection[1]:GreaterThan(-bp.Cursor.CurSelection[2]) then
|
||||||
local endLine = bp.Cursor.CurSelection[1].Y
|
local endLine = bp.Cursor.CurSelection[1].Y
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
local micro = import("micro")
|
||||||
local runtime = import("runtime")
|
local runtime = import("runtime")
|
||||||
local filepath = import("path/filepath")
|
local filepath = import("path/filepath")
|
||||||
local shell = import("micro/shell")
|
local shell = import("micro/shell")
|
||||||
@ -59,8 +60,8 @@ function init()
|
|||||||
makeLinter("gcc", "c", "gcc", {"-fsyntax-only", "-Wall", "-Wextra", "%f"}, "%f:%l:%c:.+: %m")
|
makeLinter("gcc", "c", "gcc", {"-fsyntax-only", "-Wall", "-Wextra", "%f"}, "%f:%l:%c:.+: %m")
|
||||||
makeLinter("gcc", "c++", "gcc", {"-fsyntax-only","-std=c++14", "-Wall", "-Wextra", "%f"}, "%f:%l:%c:.+: %m")
|
makeLinter("gcc", "c++", "gcc", {"-fsyntax-only","-std=c++14", "-Wall", "-Wextra", "%f"}, "%f:%l:%c:.+: %m")
|
||||||
makeLinter("dmd", "d", "dmd", {"-color=off", "-o-", "-w", "-wi", "-c", "%f"}, "%f%(%l%):.+: %m")
|
makeLinter("dmd", "d", "dmd", {"-color=off", "-o-", "-w", "-wi", "-c", "%f"}, "%f%(%l%):.+: %m")
|
||||||
makeLinter("gobuild", "go", "go", {"build", "-o", devnull}, "%f:%l: %m")
|
makeLinter("gobuild", "go", "go", {"build", "-o", devnull}, "%f:%l:%c:? %m")
|
||||||
makeLinter("golint", "go", "golint", {"%f"}, "%f:%l:%c: %m")
|
-- makeLinter("golint", "go", "golint", {"%f"}, "%f:%l:%c: %m")
|
||||||
makeLinter("javac", "java", "javac", {"-d", "%d", "%f"}, "%f:%l: error: %m")
|
makeLinter("javac", "java", "javac", {"-d", "%d", "%f"}, "%f:%l: error: %m")
|
||||||
makeLinter("jshint", "javascript", "jshint", {"%f"}, "%f: line %l,.+, %m")
|
makeLinter("jshint", "javascript", "jshint", {"%f"}, "%f: line %l,.+, %m")
|
||||||
makeLinter("literate", "literate", "lit", {"-c", "%f"}, "%f:%l:%m", {}, false, true)
|
makeLinter("literate", "literate", "lit", {"-c", "%f"}, "%f:%l:%m", {}, false, true)
|
||||||
@ -78,7 +79,7 @@ function init()
|
|||||||
config.MakeCommand("lint", "linter.lintCmd", config.NoComplete)
|
config.MakeCommand("lint", "linter.lintCmd", config.NoComplete)
|
||||||
end
|
end
|
||||||
|
|
||||||
function lintCmd(bp)
|
function lintCmd(bp, args)
|
||||||
bp:Save()
|
bp:Save()
|
||||||
runLinter(bp.Buf)
|
runLinter(bp.Buf)
|
||||||
end
|
end
|
||||||
@ -128,12 +129,13 @@ function onSave(bp)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function lint(buf, linter, cmd, args, errorformat, loff, coff)
|
function lint(buf, linter, cmd, args, errorformat, loff, coff)
|
||||||
buf:ClearMessages("linter")
|
buf:ClearMessages(linter)
|
||||||
|
|
||||||
shell.JobSpawn(cmd, args, "", "", "linter.onExit", buf, linter, errorformat, loff, coff)
|
shell.JobSpawn(cmd, args, "", "", "linter.onExit", buf, linter, errorformat, loff, coff)
|
||||||
end
|
end
|
||||||
|
|
||||||
function onExit(output, buf, linter, errorformat, loff, coff)
|
function onExit(output, args)
|
||||||
|
local buf, linter, errorformat, loff, coff = args[1], args[2], args[3], args[4], args[5]
|
||||||
local lines = split(output, "\n")
|
local lines = split(output, "\n")
|
||||||
|
|
||||||
local regex = errorformat:gsub("%%f", "(..-)"):gsub("%%l", "(%d+)"):gsub("%%c", "(%d+)"):gsub("%%m", "(.+)")
|
local regex = errorformat:gsub("%%f", "(..-)"):gsub("%%l", "(%d+)"):gsub("%%c", "(%d+)"):gsub("%%m", "(.+)")
|
||||||
@ -146,15 +148,18 @@ function onExit(output, buf, linter, errorformat, loff, coff)
|
|||||||
if not string.find(errorformat, "%%c") then
|
if not string.find(errorformat, "%%c") then
|
||||||
hascol = false
|
hascol = false
|
||||||
msg = col
|
msg = col
|
||||||
|
elseif col == nil then
|
||||||
|
hascol = false
|
||||||
end
|
end
|
||||||
|
micro.Log(basename(buf.Path), basename(file))
|
||||||
if basename(buf.Path) == basename(file) then
|
if basename(buf.Path) == basename(file) then
|
||||||
local bmsg = nil
|
local bmsg = nil
|
||||||
if hascol then
|
if hascol then
|
||||||
local mstart = buffer.Loc(tonumber(col-1+coff), tonumber(line-1+loff))
|
local mstart = buffer.Loc(tonumber(col-1+coff), tonumber(line-1+loff))
|
||||||
local mend = buffer.Loc(tonumber(col+coff), tonumber(line-1+loff))
|
local mend = buffer.Loc(tonumber(col+coff), tonumber(line-1+loff))
|
||||||
bmsg = buffer.NewMessage("linter", msg, mstart, mend, buffer.MTError)
|
bmsg = buffer.NewMessage(linter, msg, mstart, mend, buffer.MTError)
|
||||||
else
|
else
|
||||||
bmsg = buffer.NewMessageAtLine("linter", msg, tonumber(line+loff), buffer.MTError)
|
bmsg = buffer.NewMessageAtLine(linter, msg, tonumber(line+loff), buffer.MTError)
|
||||||
end
|
end
|
||||||
buf:AddMessage(bmsg)
|
buf:AddMessage(bmsg)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user