1- VERSION = " 0.2.2"
1+ VERSION = " 0.2.3"
2+
3+ -- luacheck . --globals import VERSION preQuit onAnyEvent init --ignore 212 542 611 612 613 614
24
35local micro = import (" micro" )
46local buffer = import (" micro/buffer" )
57local shell = import (" micro/shell" )
68local util = import (" micro/util" )
79local strings = import (" strings" )
8- local os = import (" os" )
10+ -- local os = import("os")
911
1012local config = import (" micro/config" )
1113local fmt = import (' fmt' )
@@ -19,35 +21,9 @@ local Highlight = require("Highlight")
1921local Diff = require (" Diff" )
2022local Minimap = require (" Minimap" )
2123
22- function LuaCopy (obj , seen )
23- if type (obj ) ~= ' table' then return obj end
24- if seen and seen [obj ] then return seen [obj ] end
25- local s = seen or {}
26- local res = setmetatable ({}, getmetatable (obj ))
27- s [obj ] = res
28- for k , v in pairs (obj ) do res [copy (k , s )] = copy (v , s ) end
29- return res
30- end
31-
32- function preQuit (bp )
33- Diff .CheckAndQuitDiffView (bp )
34- Minimap .CheckAndQuitMinimap (bp )
35- return true
36- end
37-
38- function onAnyEvent ()
39- micro .Log (" onAnyEvent called" )
40- local bpToCenter = Diff .UpdateDiffView ()
41- if bpToCenter ~= nil then
42- OmniCenter (bpToCenter )
43- end
44- History .RecordCursorHistory ()
45- Minimap .UpdateMinimapView ()
46- end
47-
4824-- See issue https://github.com/zyedidia/micro/issues/3320
4925-- Modified from https://github.com/kaarrot/microgrep/blob/e1a32e8b95397a40e5dda0fb43e7f8d17469b88c/microgrep.lua#L118
50- function WriteToClipboardWorkaround (content )
26+ local function WriteToClipboardWorkaround (content )
5127 if micro .CurPane () == nil then return end
5228
5329 local curTab = micro .CurPane ():Tab ()
@@ -57,7 +33,7 @@ function WriteToClipboardWorkaround(content)
5733 -- Split pane in half and add some text
5834 micro .CurPane ():HSplitAction ()
5935
60- local buf ,err = buffer .NewBuffer (content , " " )
36+ local buf , _ = buffer .NewBuffer (content , " " )
6137 -- Workaround to copy path to clioboard
6238 micro .CurPane ():OpenBuffer (buf )
6339 micro .CurPane ():SelectAll ()
@@ -67,18 +43,17 @@ function WriteToClipboardWorkaround(content)
6743 curTab :SetActive (curPaneIndex )
6844end
6945
70- function CheckCommand (command )
46+ local function CheckCommand (command )
7147 local _ , error = shell .RunCommand (command )
7248 if error ~= nil then return false end
7349 return true
7450end
7551
76- function OmniSelect (bp , args )
52+ local function OmniSelect (bp , args )
7753 if # args < 1 then return end
7854
7955 local buf = bp .Buf
8056 local cursor = buf :GetActiveCursor ()
81- local currentLoc = cursor .Loc
8257 local targetLine = cursor .Loc .Y
8358
8459 if Common .OmniSelectType == nil or Common .OmniSelectType == " " then
11489
11590
11691
117- function OmniCopyRelativePath (bp )
92+ local function OmniCopyRelativePath (bp )
11893 if bp .Buf == nil then return end
11994
12095 -- clipboard.Write(bp.Buf.Path, clipboard.ClipboardReg)
12196 WriteToClipboardWorkaround (bp .Buf .Path )
12297 micro .InfoBar ():Message (bp .Buf .Path , " copied into clipboard" )
12398end
12499
125- function OmniCopyAbsolutePath (bp )
100+ local function OmniCopyAbsolutePath (bp )
126101 if bp .Buf == nil then return end
127102
128103 -- clipboard.Write(bp.Buf.AbsPath, clipboard.ClipboardReg)
129104 WriteToClipboardWorkaround (bp .Buf .AbsPath )
130105 micro .InfoBar ():Message (bp .Buf .AbsPath , " copied into clipboard" )
131106end
132107
133- function OmniCenter (bp )
108+ local function OmniCenter (bp )
134109 local view = bp :GetView ()
135- local oriX = bp .Cursor .Loc .X
136110 bp .Cursor :ResetSelection ()
137111 bp .Buf :ClearCursors ()
138112 local targetLineY = view .StartLine .Line + view .Height / 2
139113 bp .Cursor :GotoLoc (Common .LocBoundCheck (bp .Buf , buffer .Loc (bp .Cursor .Loc .X , targetLineY )))
140114end
141115
142116-- Testing auto complete for commands
143- function TestCompleter (buf )
117+ local function TestCompleter (buf )
144118 local activeCursor = buf :GetActiveCursor ()
145119 local input , argstart = buf :GetArg ()
146120 -- micro.Log("input:", input)
@@ -165,7 +139,7 @@ function TestCompleter(buf)
165139 -- sort.Strings(suggestions)
166140 table.sort (suggestions , function (a , b ) return a :upper () < b :upper () end )
167141 -- completions := make([]string, len(suggestions))
168- completions = {}
142+ local completions = {}
169143 for _ , suggestion in ipairs (suggestions ) do
170144 local offset = activeCursor .X - argstart
171145 table.insert (completions , string.sub (suggestion , offset + 1 , string.len (suggestion )))
@@ -174,23 +148,23 @@ function TestCompleter(buf)
174148 -- return {"test", "test2"}, {"test", "test A"}
175149end
176150
177- function OmniTest (bp , args )
151+ local function OmniTest (bp , args )
178152 -- micro.InfoBar():Prompt("Test prompt", "Test Message", "Test", TestECB, TestDoneCB)
179153 bp :CdCmd (args )
180154end
181155
182- function TestDoneCB (msg , cancelled )
156+ local function TestDoneCB (msg , cancelled )
183157 -- git diff --output=test.diff -U5 --no-color ".\DefaultUserConfig.yaml" ".\DefaultUserConfig - Copy.yaml"
184158 local output , err = shell .RunInteractiveShell (msg , false , true )
185159 if err == nil or err :Error () == " exit status 1" then
186- OmniNewTabRight (micro .CurPane ())
160+ -- OmniNewTabRight(micro.CurPane())
187161 micro .CurPane ().Buf :Insert (buffer .Loc (0 , 0 ), output )
188162 else
189163 micro .InfoBar ():Error (err )
190164 end
191165end
192166
193- function OmniTest2 (bp , args )
167+ local function OmniTest2 (bp , args )
194168 -- micro.InfoBar():Prompt("Test prompt", "Test Message", "Test", TestECB, TestDoneCB)
195169 -- local wd = os.Getwd()
196170 -- micro.InfoBar():Message("Getwd: ", wd)
@@ -202,25 +176,25 @@ function OmniTest2(bp, args)
202176 -- micro.InfoBar():Prompt("Test prompt", "Test Message", "Test", nil, OnWordJump)
203177end
204178
205- function OmniTest3 (bp , args )
179+ local function OmniTest3 (bp , args )
206180 -- micro.InfoBar():Prompt("Test prompt", "Test Message", "Test", TestECB, TestDoneCB)
207181 -- local wd = os.Getwd()
208182 -- local path = bp.buf.AbsPath
209183end
210184
211- function OmniNewTabRight (bp )
185+ local function OmniNewTabRight (bp )
212186 local currentActiveIndex = micro .Tabs ():Active ()
213187 bp :NewTabCmd ({})
214188 bp :TabMoveCmd ({tostring (currentActiveIndex + 2 )})
215189end
216190
217- function OmniNewTabLeft (bp )
191+ local function OmniNewTabLeft (bp )
218192 local currentActiveIndex = micro .Tabs ():Active ()
219193 bp :NewTabCmd ({})
220194 bp :TabMoveCmd ({tostring (currentActiveIndex + 1 )})
221195end
222196
223- function InitializeSettings ()
197+ local function InitializeSettings ()
224198 -- Convert history line diff to integer in the beginning
225199 if Common .OmniHistoryLineDiff == nil or Common .OmniHistoryLineDiff == " " then
226200 Common .OmniHistoryLineDiff = 5
@@ -327,6 +301,22 @@ function InitializeSettings()
327301 end
328302end
329303
304+ function preQuit (bp )
305+ Diff .CheckAndQuitDiffView (bp )
306+ Minimap .CheckAndQuitMinimap (bp )
307+ return true
308+ end
309+
310+ function onAnyEvent ()
311+ micro .Log (" onAnyEvent called" )
312+ local bpToCenter = Diff .UpdateDiffView ()
313+ if bpToCenter ~= nil then
314+ OmniCenter (bpToCenter )
315+ end
316+ History .RecordCursorHistory ()
317+ Minimap .UpdateMinimapView ()
318+ end
319+
330320function init ()
331321 config .MakeCommand (" OmniGlobalSearch" , Search .OmniContent , config .NoComplete )
332322 config .MakeCommand (" OmniLocalSearch" , Search .OmniLocalSearch , config .NoComplete )
0 commit comments