mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-20 07:47:15 +09:00
Pass the view into plugin callbacks
This commit is contained in:
@@ -9,12 +9,11 @@ end
|
||||
local autoclosePairs = {"\"\"", "''", "()", "{}", "[]"}
|
||||
local autoNewlinePairs = {"()", "{}", "[]"}
|
||||
|
||||
function onRune(r)
|
||||
function onRune(r, v)
|
||||
if not GetOption("autoclose") then
|
||||
return
|
||||
end
|
||||
|
||||
local v = CurView()
|
||||
for i = 1, #autoclosePairs do
|
||||
if r == charAt(autoclosePairs[i], 2) then
|
||||
local curLine = v.Buf:Line(v.Cursor.Y)
|
||||
@@ -43,12 +42,11 @@ function onRune(r)
|
||||
end
|
||||
end
|
||||
|
||||
function preInsertNewline()
|
||||
function preInsertNewline(v)
|
||||
if not GetOption("autoclose") then
|
||||
return
|
||||
end
|
||||
|
||||
local v = CurView()
|
||||
local curLine = v.Buf:Line(v.Cursor.Y)
|
||||
local curRune = charAt(curLine, v.Cursor.X)
|
||||
local nextRune = charAt(curLine, v.Cursor.X+1)
|
||||
@@ -68,13 +66,11 @@ function preInsertNewline()
|
||||
return true
|
||||
end
|
||||
|
||||
function preBackspace()
|
||||
function preBackspace(v)
|
||||
if not GetOption("autoclose") then
|
||||
return
|
||||
end
|
||||
|
||||
local v = CurView()
|
||||
|
||||
for i = 1, #autoclosePairs do
|
||||
local curLine = v.Buf:Line(v.Cursor.Y)
|
||||
if charAt(curLine, v.Cursor.X+1) == charAt(autoclosePairs[i], 2) and charAt(curLine, v.Cursor.X) == charAt(autoclosePairs[i], 1) then
|
||||
|
||||
@@ -9,13 +9,12 @@ MakeCommand("goimports", "go.goimports", 0)
|
||||
MakeCommand("gofmt", "go.gofmt", 0)
|
||||
|
||||
function onViewOpen(view)
|
||||
-- messenger:Message("HI")
|
||||
if view.Buf:FileType() == "go" then
|
||||
SetLocalOption("tabstospaces", "off", view)
|
||||
end
|
||||
end
|
||||
|
||||
function onSave()
|
||||
function onSave(view)
|
||||
if CurView().Buf:FileType() == "go" then
|
||||
if GetOption("goimports") then
|
||||
goimports()
|
||||
|
||||
@@ -30,7 +30,7 @@ function runLinter()
|
||||
end
|
||||
end
|
||||
|
||||
function onSave()
|
||||
function onSave(view)
|
||||
if GetOption("linter") then
|
||||
runLinter()
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user