Regular macros
A macro is loaded by the global function Macro
that receives one argument – a table containing parameters of the macro. On successful completion the function returns true
.
Macro { area = "Shell Info Tree"; -- string key = "CtrlF11 ShiftHome"; -- string (optional field) description = "Macro example"; -- string (optional field) flags = "NoPluginPanels EmptyCommandLine"; -- string (optional field) filemask = "*.txt,*.cpp"; -- string (optional field) priority = 50; -- number (optional field) sortpriority = 50; -- number (optional field) selected = true; -- boolean (optional field) condition = function(key) return Far.Height>30 end; -- function (optional field) action = function() msgbox("","Macro example") end; -- function id = "F0109446-AA63-4873-AEC3-17AEE993AA53"; -- string (optional field) }
The field
area
should contain names of one or more areas, separated by whitespaces.The field
key
can contain names of one or more keys, separated by whitespaces.
Keys can contain modifiers:Ctrl,LCtrl,RCtrl,Alt,RAlt,LAlt,Shift
.
Ctrl
means “any ofLCtrl,RCtrl
”, the same goes forAlt
. The order of modifiers can be arbitrary.
Alternatively, the fieldkey
can be specified as a regular expression, enclosed in slashes (/
).- In this case
/Ctrl/
will not work whenRCtrl
is pressed, it should be specified explicitly/[LR]Ctrl/
etc. - Also in this case it is necessary to maintain the order in the sequence
Ctrl
,Alt
,Shift
,
e.g./[LR]Alt[LR]CtrlF1/
would never work.
- In this case
Optional field
flags
may contain a set of flags separated with spaces. Some changes in names or interpretation of flags are described here.Optional field
priority
– a number in the range 0 to 100. The default value = 50.
Macros added viaMCTL_ADDMACRO
have priority = 50.Optional field
sortpriority
– a number in the range 0 to 100. The default value = 50.
This field affects the order of macros in the macro selection menu.Optional field
selected
– a boolean.
This field assigns this macro to be initially selected in the macro selection menu.Optional field
filemask
– a string.
It is applicable only forEditor
andViewer
areas. It is processed according to the same rules that Far Manager applies for file masks when searching from panels, etc. If name of the file open in editor or viewer does not match the given mask, the macro will not execute.Optional field
condition
– a function.- It is called with one argument: the name of pressed key. For auto-started macros it is called with no arguments.
- If the function returns
false
/nil
/nothing, the macro will not execute. - If it returns a number then this number is used instead of
priority
. - In other cases of return value (e.g.,
true
)priority
is used.
Field
action
– a function.
If the macro has passed successfully all preliminary checks (area, flags, file mask, priority) then this functgion is called.More than one macro for (
key
,area
) combination is allowed. In this case a macro with highest priority is executed. If there are multiple macros having the same priority then the macro selection menu is displayed.
The auto-starting macros are executed all, one by one, independently from priorities. The order of their execution is not defined.