Приложен редакторный макрос, который выводит диалог, подобный выводимому при записи макросов. При нажатии ОК вставляется шаблон нового макроса в редактор.
P.S. Макрос поправлен для Far 3 build 3290+.
Вставка шаблона макроса
-
- Posts: 6836
- Joined: Thu 23 Mar, 2006 21:36
- Location: Israel
- Has thanked: 41 times
- Been thanked: 530 times
Вставка шаблона макроса
- Attachments
-
- InsertMacro.lua.7z
- (1.33 KiB) Downloaded 747 times
Last edited by Shmuel on Sun 31 Mar, 2013 21:58, edited 2 times in total.
- Aidar
- Posts: 541
- Joined: Mon 09 Mar, 2009 22:43
- Location: Kazan
- Has thanked: 8 times
- Been thanked: 7 times
- Contact:
Re: Вставка шаблона макроса
Можно ещё добавить установку курсора в конец строки
, чтобы можно было сразу ввести код макроса после вставки шаблона.
Code: Select all
action=function()
- John Doe
- Бюрократ
- Posts: 13855
- Joined: Wed 27 Apr, 2005 20:42
- Has thanked: 73 times
- Been thanked: 428 times
- Contact:
Re: Вставка шаблона макроса
Весьма поучительно!
Можете пояснить эту конструкцию: (" flags=%q;"):format(table.concat(tFlags," "))
Кинулся мануалы читать, но не знаю даже что искать.
А в частности интересует как получить это %q без кавычек.
Можете пояснить эту конструкцию: (" flags=%q;"):format(table.concat(tFlags," "))
Кинулся мануалы читать, но не знаю даже что искать.
А в частности интересует как получить это %q без кавычек.
-
- Posts: 6836
- Joined: Thu 23 Mar, 2006 21:36
- Location: Israel
- Has thanked: 41 times
- Been thanked: 530 times
Re: Вставка шаблона макроса
table.concat() склеивает строки, находящиеся в таблице-массиве (первый аргумент), опционально вставляя между склеиваемыми строками строку-второй аргумент.
Смотрите также в мануале описание string.format.
Чтобы было без кавычек, нужно вместо %q указать %s.
Смотрите также в мануале описание string.format.
Чтобы было без кавычек, нужно вместо %q указать %s.
- John Doe
- Бюрократ
- Posts: 13855
- Joined: Wed 27 Apr, 2005 20:42
- Has thanked: 73 times
- Been thanked: 428 times
- Contact:
Re: Вставка шаблона макроса
Спасибо!
Попробую модифицировать макрос, чтобы флаги вставлялись в condition (в форме макросвойств).
Попробую модифицировать макрос, чтобы флаги вставлялись в condition (в форме макросвойств).
- John Doe
- Бюрократ
- Posts: 13855
- Joined: Wed 27 Apr, 2005 20:42
- Has thanked: 73 times
- Been thanked: 428 times
- Contact:
Re: Вставка шаблона макроса
Вот первое приближение:
Если флаги не выбраны, то надо бы комментировать блок условия...
P.S.
Ещё добавил ограничение, чтобы макрос вызывался только на *.lua
Code: Select all
local function InsertMacro()
local F=far.Flags
local Items =
{
--[[00]] {F.DI_DOUBLEBOX,3,1,69,18,0,0,0,0,"Macro settings"},
--[[01]] {F.DI_TEXT,5,2,0,2,0,0,0,0,"Description:"},
--[[02]] {F.DI_EDIT,5,3,67,3,0,"MacroDescription",0,F.DIF_HISTORY,""},
--[[03]] {F.DI_TEXT,-1,4,0,4,0,0,0,F.DIF_SEPARATOR,""},
--[[04]] {F.DI_CHECKBOX,5,5,0,5,0,0,0,0,"Allo&w screen output while executing macro"},
--[[05]] {F.DI_CHECKBOX,5,6,0,6,0,0,0,0,"Execute after FAR &start"},
--[[06]] {F.DI_CHECKBOX,5,7,0,7,0,0,0,0,"Do not send &keys to plugins"},
--[[07]] {F.DI_TEXT,-1,8,0,8,0,0,0,F.DIF_SEPARATOR,""},
--[[08]] {F.DI_CHECKBOX,5,9,0,9,0,0,0,0,"&ActivePanel"},
--[[09]] {F.DI_CHECKBOX,7,10,0,10,2,0,0,{DIF_3STATE=1,DIF_DISABLE=1},"P&luginPanel"},
--[[10]] {F.DI_CHECKBOX,7,11,0,11,2,0,0,{DIF_3STATE=1,DIF_DISABLE=1},"Execute for &folders"},
--[[11]] {F.DI_CHECKBOX,7,12,0,12,2,0,0,{DIF_3STATE=1,DIF_DISABLE=1},"Se&lection present"},
--[[12]] {F.DI_CHECKBOX,37,9,0,9,0,0,0,0,"&PassivePanel"},
--[[13]] {F.DI_CHECKBOX,39,10,0,10,2,0,0,{DIF_3STATE=1,DIF_DISABLE=1},"P&luginPanel"},
--[[14]] {F.DI_CHECKBOX,39,11,0,11,2,0,0,{DIF_3STATE=1,DIF_DISABLE=1},"Execute for &folders"},
--[[15]] {F.DI_CHECKBOX,39,12,0,12,2,0,0,{DIF_3STATE=1,DIF_DISABLE=1},"Se&lection present"},
--[[16]] {F.DI_TEXT,-1,13,0,13,0,0,0,F.DIF_SEPARATOR,""},
--[[17]] {F.DI_CHECKBOX,5,14,0,14,2,0,0,F.DIF_3STATE,"Empty &command line"},
--[[18]] {F.DI_CHECKBOX,5,15,0,15,2,0,0,F.DIF_3STATE,"Selection &block present"},
--[[19]] {F.DI_TEXT,-1,16,0,16,0,0,0,F.DIF_SEPARATOR,""},
--[[20]] {F.DI_BUTTON,0,17,0,17,0,0,0,{DIF_DEFAULTBUTTON=1,DIF_CENTERGROUP=1},"OK"},
--[[21]] {F.DI_BUTTON,0,17,0,17,0,0,0,F.DIF_CENTERGROUP,"Cancel"},
}
local function DlgProc (hDlg,Msg,Param1,Param2)
if Msg == F.DN_BTNCLICK then
if Param1==8 or Param1==12 then
local enable = far.SendDlgMessage(hDlg,"DM_GETCHECK",Param1)
far.SendDlgMessage(hDlg,"DM_ENABLE",Param1+1,enable)
far.SendDlgMessage(hDlg,"DM_ENABLE",Param1+2,enable)
far.SendDlgMessage(hDlg,"DM_ENABLE",Param1+3,enable)
end
end
end
local guid = win.Uuid("7feed31e-ce59-4f94-9dd9-7da619b4ef00")
if far.Dialog (guid,-1,-1,73,20,nil,Items,nil,DlgProc) ~= 20 then return end
local tFlags = {}
if Items[5][6]==0 then tFlags[#tFlags+1]="DisableOutput" end
if Items[6][6]==1 then tFlags[#tFlags+1]="RunAfterFARStart" end
if Items[7][6]==1 then tFlags[#tFlags+1]="NoSendKeysToPlugins" end
local tCondition = {}
if Items[9][6]==1 then
if Items[10][6]==0 then tCondition[#tCondition+1]="not APanel.Plugin"
elseif Items[10][6]==1 then tCondition[#tCondition+1]="APanel.Plugin"
end
if Items[11][6]==0 then tCondition[#tCondition+1]="not APanel.Folder"
elseif Items[11][6]==1 then tCondition[#tCondition+1]="APanel.Folder"
end
if Items[12][6]==0 then tCondition[#tCondition+1]="not APanel.Selected"
elseif Items[12][6]==1 then tCondition[#tCondition+1]="APanel.Selected"
end
end
if Items[13][6]==1 then
if Items[14][6]==0 then tCondition[#tCondition+1]="not PPanel.Plugin"
elseif Items[14][6]==1 then tCondition[#tCondition+1]="PPanel.Plugin"
end
if Items[15][6]==0 then tCondition[#tCondition+1]="not PPanel.Folder"
elseif Items[15][6]==1 then tCondition[#tCondition+1]="PPanel.Folder"
end
if Items[16][6]==0 then tCondition[#tCondition+1]="not PPanel.Selected"
elseif Items[16][6]==1 then tCondition[#tCondition+1]="PPanel.Selected"
end
end
if Items[18][6]==0 then tCondition[#tCondition+1]="not CmdLine.Empty"
elseif Items[18][6]==1 then tCondition[#tCondition+1]="CmdLine.Empty"
end
if Items[19][6]==0 then tCondition[#tCondition+1]="not Selected"
elseif Items[19][6]==1 then tCondition[#tCondition+1]="Selected"
end
local tResult = {}
tResult[#tResult+1] = "Macro {"
tResult[#tResult+1] = (" description=%q;"):format(Items[3][10])
tResult[#tResult+1] = " area=\"\";"
tResult[#tResult+1] = " key=\"\";"
tResult[#tResult+1] = (" flags=%q;"):format(table.concat(tFlags," "))
tResult[#tResult+1] = " --priority=50;"
tResult[#tResult+1] = " condition=function()"
tResult[#tResult+1] = (" return %s"):format(table.concat(tCondition," and "))
tResult[#tResult+1] = " end;"
tResult[#tResult+1] = " action=function()"
tResult[#tResult+1] = " end;"
tResult[#tResult+1] = "}"
tResult[#tResult+1] = ""
print(table.concat(tResult,"\r\n"))
end
Macro {
description="Insert macro template";
area="Editor";
key="CtrlF12";
flags="DisableOutput";
condition=function()
return mf.fmatch(Editor.FileName,"*.lua")==1
end;
action=InsertMacro;
}
P.S.
Ещё добавил ограничение, чтобы макрос вызывался только на *.lua
Code: Select all
condition=function()
return mf.fmatch(Editor.FileName,"*.lua")==1
end;