-- http://forum.ru-board.com/topic.cgi?forum=5&topic=31718&start=7620#6 local F = far.Flags local GInfo=function() local ei=editor.GetInfo(-1) local y,x,p = ei.CurLine,ei.CurPos,ei.LeftPos local l=editor.GetString(-1,y).StringText return l,y,x,p end local function FileSave(t) editor.Editor(t[1][1],_,_,_,_,_,bit64.bor(F.EF_NONMODAL,F.EF_IMMEDIATERETURN,F.EF_OPENMODE_USEEXISTING)) for j=2,#t do editor.SetString(-1,t[j][1],t[j][2]) end if not editor.SaveFile(-1) then msgbox("Warning! File is not saved - blocked?",t[1][1]) else editor.Quit(-1) end end Macro { area="Editor"; key="AltG"; flags=""; description="RESearch: 1. Grep Goto line"; condition=function() return editor.GetInfo(-1).FileName:match('\\gre%w-%.tmp$') end; action=function() local fd=Far.DisableHistory(-1) local l,y,x,p = GInfo() local n,s=l:match('^(%d-):(.+)$') if n then Keys('F7') print('^[A-Z]:') Keys('AltC subtract AltW subtract AltG add AltV add Enter') l=GInfo() l=l:match('^([A-Z]:.+):') --GetFileName editor.SetPosition(-1,y,x,_,_,p) if l then editor.Editor(l,_,_,_,_,_,bit64.bor(F.EF_NONMODAL,F.EF_IMMEDIATERETURN,F.EF_OPENMODE_USEEXISTING),tonumber(n),x-#n-1) editor.SetPosition(-1,_,_,_,_,p-#n) end end Far.DisableHistory(fd) end; } Macro { area="Editor"; key="AltG"; flags=""; description="RESearch: 2. Grep Save line"; condition=function() return editor.GetInfo(-1).FileName:match('\\gre%w-%.tmp$') end; action=function() local fd=Far.DisableHistory(-1) local l,y,x,p = GInfo() local n,s=l:match('^(%d-):(.+)$') if n then Keys('F7') print('^[A-Z]:') Keys('AltC subtract AltW subtract AltG add AltV add Enter') l=GInfo() l=l:match('^([A-Z]:.+):') --GetFileName editor.SetPosition(-1,y,x,_,_,p) if l then editor.Editor(l,_,_,_,_,_,bit64.bor(F.EF_NONMODAL,F.EF_IMMEDIATERETURN,F.EF_OPENMODE_USEEXISTING),tonumber(n),x-#n-1) editor.SetString(-1,n,s) if not editor.SaveFile(-1) then msgbox("Warning! File is not saved - blocked?",l) else editor.Quit(-1) end end end Far.DisableHistory(fd) end; } Macro { area="Editor"; key="AltG"; flags=""; description="RESearch: 3. Grep Save All"; condition=function() return editor.GetInfo(-1).FileName:match('\\gre%w-%.tmp$') end; action=function() local fd=Far.DisableHistory(-1) local t={} for i=1,editor.GetInfo(-1).TotalLines do local l=editor.GetString(-1,i).StringText local y,s = l:match('^(%d-):(.+)$') if y and s and #t>=1 then table.insert(t,{y,s}) else local f,n = l:match('^([A-Z]:.+):(%d+)$') if f and #t>1 then FileSave(t) t = {} t[1]={f,n} elseif f and #t<=1 then t[1]={f,n} end end end if #t>1 then FileSave(t) end Far.DisableHistory(fd) end; } |