You can use the following functions in the macro sequence:
| Mathematical functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Function | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=abs(N) | Returns the absolute value of a numeric argument N. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=max(N1,N2) | Returns the maximal value of two numeric arguments N1 and N2. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=min(N1,N2) | Returns the minimal value of two numeric arguments N1 and N2. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=mod(N1,N2) | Division of N1 by the modulus N2. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=int(V) | Evaluates the V argument to a number. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Function | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=index(S1,S2) | Returns the position of the first occurrence of the substring S2 within string S1, -1 otherwise. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=rindex(S1,S2) | Returns the position of the last occurrence of the substring S2 within string S1, -1 otherwise. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Result=replace(Str,Find,Replace[,Cnt]) | Replace substing Find in Str with Replace, Cnt times
(set Cnt to 0 or omit this parameter to replace all occurrences). Returns the resulting string. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=asc(S) | Returns the code of character S. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| S=chr(N) | Returns the character for the code N. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| S=itoa(N[,Radix]) | Converts numeric value N to a string. Radix parameter defines the radix of the numerical representation for the number conversion. The valid Radix values are from 2 to 36. If Radix is omitted, base 10 is implied. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=atoi(S[,Radix]) | Converts string representation of a number N into a number.
Radix parameter defines a radix to use during conversion of a string S.
The valid Radix values are from 2 to 36. If Radix is omitted, function tries to determine the correct value automatically. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=len(V) | Returns the length of the expression V. This function evaluates the value of V to a string and then returns the length of the string. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| S=string(V) | Converts the value of the expression V to a string. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| S=substr(V,N1[,N2]) | Returns the substring of the expression V
beginning from position N1 with the length of N2. If N2 parameter is omitted or equal to -1, function returns the substring from position N1 to the end of the string. If N2 parameter is equal to 0, function returns empty string. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| S=trim(V[,N]) | Removes whitespace (spaces, tabs, line feeds, and carriage returns) from a string V: leading and trailing (N=0 or omitted), only leading (N=1), or only trailing (N=2). | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| S=lcase(S) | Transforms the string S to lower-case. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| S=ucase(S) | Transforms the string S to upper-case. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| S=date(format) | Returns the current date/time according to the format format
(See the $Date for the format description). This function is similar to $Date macro-command but can also be used in expressions. The format argument is mandatory. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| S=xlat(S) | Returns the transliterated string. This function is similar to $XLat macro command but can be used in expressions. Argument S is mandatory. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| File functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Function | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| S=fsplit(path,N) | Splits the path path into the components and
returns theirs combination depending on the flag combination N:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=fexist(S) | Checks if the file or folder S exists and returns
1 if true or 0 otherwise. Usage of the '*' and '?' mask symbols is allowed in the S argument. In that case the function checks only the first occurrence of the file or folder. This function does not work with the panels. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=fattr(S) | Returns the file system attributes of the file or folder S
Usage of the '*' and '?' mask symbols is allowed in the S argument. In that case the function checks only the first occurrence of the file or folder. This function does not work with the panels. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Panel | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Function | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=panel.fexist(panelType,S) | Checks if the file or folder S exists in the active (panelType=0) or the passive (panelType=1) panel (returns 1 if true or 0 otherwise). Usage of the '*' and '?' mask symbols is allowed in the S argument. In that case the function checks only the first occurrence of the file or folder. This function works only with the panels. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=panel.fattr(panelType,S) | Returns the file system attributes of the file or folder S from the active (panelType=0) or the passive (panelType=1) panel.
Usage of the '*' and '?' mask symbols is allowed in the S argument. In that case the function checks only the first occurrence of the file or folder. This function works only with the panels. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| V=panelitem(panelType,itemIndex,propIndex) | Queries the information for the panel element itemIndex from the
active (panelType=0) or passive (panelType=1) panel. propIndex can be one
of the following values:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=panel.setpos(panelType,fileName) | Positions the cursor on the element with name fileName on the active
(panelType=0) or passive (panelType=1) panel. Returns the position of the element or 0 if there is no such element. For example, the following macro creates a directory named after the current date in YYYYMMDD format or positions the cursor on this directory if it already exists. %dt=date("%Y%m0%d");
$If (fexist(%dt))
panel.SetPos(0,%dt)
$Else
F7 $Text %dt Enter
$End
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=panel.setpath(panelType,pathName[,fileName]) | На активной (panelType=0) или пассивной (panelType=1) панели выставляет каталог pathName и
позиционирует курсор на элемент с именем fileName (если указан параметр fileName). Возвращает 1 в случае успешной установки каталога и 0, если каталог не существует. Например, на активной панели выставить каталог "C:\WINDOWS", на пассивной - "C:\Program Files", активную панель сделать слева и установить курсор на каталог "FAR": $if(APanel.Left) CtrlU $End panel.SetPath(1,"C:\\WINDOWS") panel.SetPath(0,"C:\\Program Files","FAR") |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=panel.setposidx(panelType,indexItem) | Positions the cursor on the element with index indexItem on the active (panelType=0) or the passive (panelType=1) panel. Returns element position or 0 if such element does not exist. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Control functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Function | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| V=iif(Cond,True,False) | Conditional function. If condition Cond is true then True-expression is returned, False-expression otherwise. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Execution environment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Function | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| V=akey(N) | Returns the name or code of the key combination that was used to call this macro.
N = 0 - key code is returned, N = 1 - key name is returned. See example in the full description $AKey |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| S=env(V) | Returns the value of an environment variable V, for instance:$if (Env("FARLANG") == "English") ...do something... $end |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| B=msave(S) | Stores the value of a global variable with the name S
to the Vars area.
Returns 0 in case of failure. Example: %%GlobalVars="Foo Bar"; %a=msave("%%GlobalVars");
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| V=clip(Cmd[,S]) | Allows to perform miscellaneous manipulations on the Clipboard in accordance with the
Cmd command:
Clip(1,"Name;Size\r\n")
Home
$While(!APanel.Eof)
$If(!APanel.Folder && PanelItem(0,0,8))
Clip(2,PanelItem(0,0,0)+";"+PanelItem(0,0,6)+"\r\n")
$End
Down
$End
See $IClip, IClip.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| V=flock(Nkey,NState) | Toggles Lock keys state (NumLock, CapsLock, and ScrollLock). Key Nkey:
Функция капризная (возможно зависание компьютера), поэтому пользоваться ей надо осторожно. Например, макрос, повешенный на CtrlCapsLock (переключение между окнами) должен иметь некую обвязку: CtrlShiftTab %a=flock(1,-1)&1; $while((flock(1,-1)&1)==%a) sleep(50) flock(1,2) $end |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=sleep(N) | Pause macro execution for N milliseconds.
Negative sleep time is considered to be an error and the function returns 0. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| V=waitkey([N, [T]]) | Ожидает любую клавишу и возвращает ее название (T=0) или значение (T=1).
Если время ожидания N (миллисекунды) истекло, функция возвращает пустую строку (T=0) или 0 (T=1).
Если параметр N не указан или равен 0, то функция будет бесконечно ждать нажатия клавиши.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| S=key(V) | Преобразует параметр V в строковый эквивалент названия клавиши. Если V строка, то проверяется правильность написания клавиши и она же возвращается, если V число, то происходит попытка преобразовать значение в текстовый эквивалент названия клавиши. В случае ошибок - возвращается пустая строка. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=eval(S[,T]) | "Проиграть" (T=0) или проверить (T=1) макропоследовательность заданную строкой S.
If S contains syntax errors, the sequence will not be played.
FAR компилирует последовательность S. Для режима исполнения (T=0): если нет ошибок, то состояние текущего макроса сохраняется и начинает выполняться последовательность S. После исполнения S прерванный макрос продолжает работать. Функция возвращает 0 в случае успешной компиляции последовательности S или код ошибки:
Local variables are common for both the current macro and the macro executed by eval. For example, we want by pressing F10 to open an Explorer window with the current folder on the active panel, command line contents should be saved.
%%CmdSave=$If (!CmdLine.Empty) %Flg_Cmd=1;
%CmdCurPos=CmdLine.ItemCount-CmdLine.CurPos+1;
%CmdVal=CmdLine.Value; Esc $End
%%CmdRestore=$If (%Flg_Cmd==1) $Text %CmdVal
%Flg_Cmd=0; %Num=%CmdCurPos;
$While (%Num!=0) %Num=%Num-1; CtrlS $End $End
then we set the following macro to F10:
$If (APanel.Visible && (!APanel.Plugin || (!APanel.Bof &&(APanel.OPIFlags & 0x20))))
Eval(%%CmdSave)
$If (APanel.Current == "..")
.
ShiftEnter
$Else
"%SystemRoot%\\explorer.exe /select,"
$If (Apanel.LFN)
CtrlN
$End
CtrlEnter
$If (!Apanel.LFN)
CtrlN
$End
Enter
$End
Eval(%%CmdRestore)
$End
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| User interaction | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Function | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=msgbox([Title[,Text[,Flags]]]) | Shows up the message box with the Text and the Title.
Lines in the Text argument should be delimited by '\n'. Flags can be a combination of the following values:
The return value is the number of the button the user selected (1 for the first, 2 for the second, etc.), if user canceled the message the result will be 0. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| S=prompt("Title"[,"Prompt"[,flags[, "Src"[, "History"]]]]) | Функция позволяет ввести одну строку текста. Параметры: Title - заголовок диалога, Prompt - приглашения для ввода, Src - начальное значение строки ввода, History - имя истории ввода Flags может быть набором следующих значений (аналогичным константам FIB_*):
Например, запросить пароль и вывести его %s=prompt("Password","Input password:",0x02); $Text %s
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Control elements | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Function | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=checkhotkey(S) | Returns 1 if there is a hot key S in a menu
and the current 'object' is a menu, otherwise returns 0.
For example there's a hotkey '7' assigned to 'S&R' plugin in the plugins menu (F11). The following macro command sequence for the internal file editor should call 'S&R' plugin if there is a hot key assigned and the standard search dialog if not: F11 $if (checkhotkey("7")) 7 1 $else Esc AltF7 $end
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| S=gethotkey(N) | Returns the hotkey S for item N, if the item has a hotkey
and the current "object" is a menu. Otherwise 0 is returned. N - item position beginning with 1 (0 - current item). |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=Menu.Select(S[,N]) | В меню позиционирует курсор на первый пункт, содержащий подстроку S.
Поиск подстроки ведется в зависимости от указанного режима N:
Возвращает: -1=ошибка - функция вызвана не для меню, 0=ошибка при позиционировании (нет пункта или пункт задисаблен), иначе - позицию пункта меню. F11 $if(Menu.Select("Advanced compare",0) > 0) Enter $end
Если параметр N не указан, подразумевается полное совпадение.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| V=Dlg.GetValue(ID,Type) | Get misc. values of the current dialog. ID - dialog element number (elements are numbered starting with 1; 0 - is the dialog windows itself). Type - type of the value to get, depending on the type of the element. For the dialog windows itself (ID=0) the following values are allowed:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| V=Editor.Set(Idx,Var) | Change settings of the current editor instance.
Returns the previous value of the option or -1 if wrong arguments are given. For example, a macro that moves the selected block one line down: $IClip CtrlX %a=Editor.Set(2,1); Down CtrlV %a=Editor.Set(2,%a); |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| V=Editor.Sel(Action[,Opt]) | Функция позволяет производить некоторые операции с блоками в тексте (в редакторе, в строках ввода в диалогах, в командной строке).
Например, повторим некоторые сочетания клавиш из Turbo-сред (макрос на сочетание Ctrl-K): %k=waitkey(0,1);
$if(%k==B || %k==b || %k==CtrlB)
editor.sel(2,0)
$else
$if(%k==K || %k==k || %k==CtrlK)
editor.sel(2,1)
$else
$if((%k==C || %k==c || %k==CtrlC) && Selected)
CtrlC
$else
$if((%k==Y || %k==y || %k==CtrlY) && Selected)
CtrlD
$else
eval("F1")
$end
$end
$end
$end
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Bookmarks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Function | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=BM.Add() | Добавить текущие параметры закладки и обрезать хвост | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=BM.Clear() | Clear all bookmarks | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=BM.Del([Idx]) | Удалить закладку с указанным индексом Idx (нумерация начинается с 1). Если параметр Idx не указан или равен 0 - удаляется текущая закладка. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=BM.Get(Idx,M) | Получить параметры закладки с индексом Idx (нумерация начинается с 1), Idx=0 - текущая закладка. M parameter can have these values:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=BM.Next() | Jump to the next bookmark | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=BM.Prev() | Jump to the previous bookmark | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| N=BM.Stat([M]) | Get bookmark information. M parameter can have these values:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Bookmark handling example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||