Code: Select all
----------------------------------------------------------------------------------------------
-- Макросы для работы с плагином LuaFAR Search (shmuel) в редакторе.
-- Использован концепт специфического применения функции condition, автор которого:
-- John Doe Tue 27 Nov 2018 12:00 https://forum.farmanager.com/viewtopic.php?p=151767#p151767
-- Концепт обеспечивает оперативное включение/выключение показа макросов с пониженным priority
-- Для переключения между вариантами меню следует нажимать Shift дважды подряд: клац-клац
----------------------------------------------------------------------------------------------
local Guid = "8E11EA75-0303-4374-AC60-D1E38F865449"
local function LFS_Editor(...) Plugin.Call(Guid, "own", "editor", ...) end
--local function LFS_Panels(...) Plugin.Call(Guid, "own", "panels", ...) end
local function LFS_Exist() return Plugin.Exist(Guid) end
--концепт:
local fullmenu
Macro {
area="Common"; key="Shift";
description="переключатель повышения до 100 и возврата до установленных величин приоритетов макросов (jd) Shift";
action=function()
fullmenu = not fullmenu
end;
}
local function isFullMenu()
return fullmenu and 100 or true
end
-- двойное нажатие: John Doe Wed 13 Jul 2016 19:50 http://forum.farmanager.com/viewtopic.php?p=139385#p139385
local maxDelay = 500 -- промежуток времени между двумя нажатиями пусковой клавиши (в миллисекундах)
local t = 0
local ID = "165AA6E3-C89B-4F82-A0C5-C309243FD21B" -- гуид меню выбора макросов
Macro {
area="Menu"; priority = 100; key="Shift";
description="ВКЛ/ВЫКЛ показ макросов с уменьшенным приоритетом (поJD) двойнойShift";
id="F484EA2A-D1F1-4601-9CD3-B758009A07EA";
condition=function()
if Menu.Id=="165AA6E3-C89B-4F82-A0C5-C309243FD21B" -- вызов макроса только из меню выбора макросов (запущенного из
-- любой макрообласти)
then
-- далее condition обеспечивает срабатывание пускового ключа ("Shift") на двойное нажатие:
local t1 = Far.UpTime
local delay = t1-t
t = t1
return Menu.Id==ID and delay<maxDelay
end
end;
action=function()
local rbnd=Object.Title:match": (.+)$"
--msgbox("Область, из которой вызвано меню,\nи ключ, которым оно вызвано:\n",rbnd,0x00010000)
local bndf=Object.Title:match"| (.+)$" --msgbox("Полный ключ, которым вызвано меню:",bndf,0x00010000)
local mrgn=mf.replace(rbnd," | "..bndf,"") --msgbox("Область, из которой вызвано меню:",mrgn,0x00010000)
Keys("F10") --msgbox("Вышли из меню?","Да",0x00010000)
eval(mrgn.."/"..bndf,2) --msgbox("Возвращались в меню?","Да",0x00010000)
end;
}
Macro {
description="LuaFAR Search: Editor &Find-поиск (shmuel) AltShiftF";
-- ключ AltShiftF занят системной (?) командой
area="Editor"; filemask="*.*|*.tmpg"; key="AltShiftS AltShiftF"; condition=LFS_Exist and isFullMenu;
action = function() LFS_Editor "search" end
}
Macro {
description="LuaFAR Search: Editor &Replace-замена (shmuel) AltShiftR";
area="Editor"; filemask="*.*|*.tmpg"; key="AltShiftS AltShiftR"; condition=LFS_Exist and isFullMenu;
action = function() LFS_Editor "replace" end
}
Macro {
description="LuaFAR Search: Editor Rep&Eat-повторить (shmuel) AltShiftE";
area="Editor"; filemask="*.*|*.tmpg"; key="AltShiftS AltShiftE"; condition=LFS_Exist and isFullMenu;
action = function() LFS_Editor "repeat" end
}
Macro {
description="LuaFAR Search: Editor Repeat re&Verse (shmuel) CtrlShiftE";
area="Editor"; filemask="*.*|*.tmpg"; key="AltShiftS CtrlShiftE"; condition=LFS_Exist and isFullMenu;
action = function() LFS_Editor "repeat_rev" end
}
Macro {
description="LuaFAR Search: Editor искать &Word-слово (shmuel) AltShiftW";
area="Editor"; filemask="*.*|*.tmpg"; key="AltShiftS AltShiftW"; condition=LFS_Exist and isFullMenu;
action = function() LFS_Editor "searchword" end
}
Macro {
description="LuaFAR Search: Editor искать w&Ord назад (shmuel) CtrlShiftW";
area="Editor"; filemask="*.*|*.tmpg"; key="AltShiftS CtrlShiftW"; condition=LFS_Exist and isFullMenu;
action = function() LFS_Editor "searchword_rev" end
}
-- Uncomment this macro if it is needed.
-- Раскомментировать этот макрос нет необходимости, поскольку макрос переключения подсветку сбрасывает
--Macro {
----description="LuaFAR Search: Reset Highlight (shmuel) CtrlShiftH";
--description="LuaFAR Search: сбросить подсветку (shmuel) CtrlShiftH";
-- area="Editor"; key="AltShiftS CtrlShiftH"; condition=LFS_Exist;
-- action = function() LFS_Editor "resethighlight" end
--}
Macro {
--description="LuaFAR Search: Toggle Highlight (shmuel) AltShiftH";
description="LuaFAR Search: вкл/выкл доп&Highlight (shmuel) AltShiftH";
area="Editor"; filemask="*.*|*.tmpg"; key="AltShiftS AltShiftH"; condition=LFS_Exist and isFullMenu;
action = function() LFS_Editor "togglehighlight" end
}
Macro {
description="LuaFAR Search: Editor Multi-&Line replace (shmuel) AltShiftL";
area="Editor"; filemask="*.*|*.tmpg"; key="AltShiftS AltShiftL"; condition=LFS_Exist and isFullMenu;
action = function() LFS_Editor "mreplace" end
}
-- This macro works best when "Show line numbers" Grep option is used.
-- When this option is off the jump occurs to the beginning of the file.
-- Этот макрос работает лучше всего, когда используется опция "Показывать номера строк" в диалоге Grep.
-- Когда эта опция выключена, переход производится к началу файла.
Macro {
--description="Jump from Grep results to file and position under cursor";
description="edi: → из итогов &Grep в файл под курсором (shmuel) AltShiftG"; --78c&
area="Editor"; filemask="*.tmp,*.tmpg"; key="AltShiftS AltShiftG"; sortpriority=3;
condition=isFullMenu;
action=function()
local lnum = editor.GetString(nil,nil,3):match("^(%d+)[:%-]")
local EI = editor.GetInfo()
for n = EI.CurLine,1,-1 do
local fname = editor.GetString(nil,n,3):match("^%[%d+%]%s+(.+)")
if fname then
editor.Editor(fname,nil,nil,nil,nil,nil,
{EF_NONMODAL=1,EF_IMMEDIATERETURN=1,EF_ENABLE_F6=1,EF_OPENMODE_USEEXISTING=1},
lnum or 1, lnum and math.max(1, EI.CurPos-lnum:len()-1) or 1)
break
end
end
end;
}
-- следующий макрос переделан из макроса, ранее взятого из сборки Victor_VG на руборде
-- http://forum.ru-board.com/topic.cgi?forum=5&topic=49572&start=0&limit=1&m=2#1
Macro {
description="LuaFAR Search: Editor МЕНЮ ПЛАГИНА AltShiftS";--77без&
area="Editor"; key="AltShiftS"; selected=true;
condition=isFullMenu;
action=function() Plugin.Menu(Guid) end;
}
-- ПОДВАЛьные макросы:
--сначала блок из двух макросов работы с результатами Грепа авторства Алексис21
--Alexyz21 16:41 09-11-2018 http://forum.ru-board.com/topic.cgi?forum=5&topic=49572&start=1200#16
Macro {
area="Editor"; --filemask="*.tmpg";
key="AltShiftS"; flags=""; sortpriority=6; priority=40;
--description="RESearch: 2. Grep Save line";
description="edi: Grep &A): сохранить изменённую строку (Alexyz21) AltShiftA"; --78c&
--condition=function() return editor.GetInfo(-1).FileName:match('\\%w-%.tmp$') end;
--комментарий sToLp: пользователь вправе сохранить результаты грепа в любой файл и поэтому ограничивать работу макроса
--только .tmp-файлами излишне
condition=isFullMenu;
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"; --filemask="*.tmpg";
key="AltShiftS"; flags=""; sortpriority=5; priority=40;
--description="RESearch: 3. Grep Save All";
description="edi: Grep &B): сохранить все изменения (Alexyz21) AltShiftB"; --78c&
--condition=function() return editor.GetInfo(-1).FileName:match('\\%w-%.tmp$') end;
--комментарий sToLp: пользователь вправе сохранить результаты грепа в любой файл и поэтому ограничивать работу макроса
--только .tmp-файлами излишне
condition=isFullMenu;
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;
}
--а теперь макрос-индикатор наличия нативной команды Far`а, назначенной на ключ, общий для всех маросов данной подборки:
Macro {
area="Editor"; key="AltShiftS"; priority=40;
description="&Native: внутренняя команда Far не назначена AltShiftS";
id="11000C83-734C-4A71-8F2D-04BA2D747541"; sortpriority=1;
flags="NoPluginPanels EmptyCommandLine";
condition=isFullMenu;
action=function()
local cmd = far.Message(
"Нативная (внутренняя) команда Far на ключ AltShiftS не назначена.\n\nДа -- продолжить. Нет -- вернуться в меню.",
"ВНИМАНИЕ !",";YesNo")
if cmd==1 then Keys("AltShiftS")
end
if cmd==2 then eval("Editor/AltShiftS",2)
end
end;
}