-- http://forum.ru-board.com/topic.cgi?forum=5&topic=31718&start=7620#7 -- v1.2 local F = far.Flags local function GetFileName(l) return regex.match(l,'^(?:\\[\\d+?\\] )?([A-Z]:.+?)(?::|$)') end local function GInfo() local ei=editor.GetInfo(-1) local y,x,p = ei.CurLine,ei.CurPos,ei.LeftPos local l,i,f = editor.GetString(-1,y).StringText,y local n,s = l:match('^(%d-)[-:](.+)$') repeat i,f = i-1,GetFileName(editor.GetString(-1,i).StringText) until f or i==-1 return f,l,y,x,p,n,s 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('\\%w-%.tmp$') end; action=function() local f,l,y,x,p,n,s = GInfo() if n then editor.SetPosition(-1,y,x,_,_,p) if f then editor.Editor(f,_,_,_,_,_,bit64.bor(F.EF_NONMODAL,F.EF_IMMEDIATERETURN,F.EF_OPENMODE_USEEXISTING),tonumber(n),x-#n-1) editor.SetPosition(-1,_,_,_,_,p-#n) end end end; } Macro { area="Editor"; key="AltG"; flags=""; description="RESearch: 2. Grep Save line"; condition=function() return editor.GetInfo(-1).FileName:match('\\%w-%.tmp$') end; action=function() local f,l,y,x,p,n,s = GInfo() if n then editor.SetPosition(-1,y,x,_,_,p) if f then editor.Editor(f,_,_,_,_,_,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?",f) else editor.Quit(-1) end end end end; } Macro { area="Editor"; key="AltG"; flags=""; description="RESearch: 3. Grep Save All"; condition=function() return editor.GetInfo(-1).FileName:match('\\%w-%.tmp$') end; action=function() 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=GetFileName(l) if f then if #t>1 then FileSave(t) t={} end t[1]={f,nil} end end end if #t>1 then FileSave(t) end end; } |