Formula Editor

The new AFL Formula Editor features:

These features greatly simplify formula writing and provide instant help, so the time needed to write formulas decreases significantly.

Menu

Formula Editor menu options are described in detail in Menus: Formula Editor chapter of the guide.

Toolbar

The Formula Editor toolbar provides the following buttons:

Usage

Typical use of Formula Editor is as follows:

AFL Code Assistant

Version 7.00 brings a new AI-based code assistant that can write code for you from a single sentence, fix errors for you, and explain code written by others. Detailed explanation of AFL Code Assistant functionality is given here.

Syntax highlighting

AmiBroker's AFL editor features user-definable syntax highlighting that automatically applies user-defined colors and styles to different language elements like functions and reserved variable names, strings, numbers, comments, etc. This feature greatly simplifies code writing. You can modify the coloring scheme in Preferences window.

Enhanced error reporting

When you make an error in your formula, AmiBroker's enhanced error reporting will help you to locate and fix it by highlighting the place where the error occurred and displaying an extended error description with examples of common mistakes and advice on how to fix them. In version 5.80, descriptions of errors are displayed in-line with the code.

A message bar displays the total number of errors and/or warnings. If you press "Go to error" button, the editor will move the caret to the relevant line containing the error; if you press it again, it will move to the next error and so on. If you close the message bar with the "X" button, all error messages will be cleared (hidden) from the view. You can use Edit->Clear Error Message menu (Ctrl+E) to clear an individual error message (in the current line).

Context  help

You can quickly display the relevant AFL function reference page if you press F1 key or choose "Function reference" from the context menu while the caret is inside or right after a function name, as shown in the picture below:

Automatic statement completion

 
The automatic completion feature (available when you press CTRL+SPACE key combination) finishes typing your functions and reserved variables for you, or displays a list of candidates if what you've typed has more than one possible match. You can select the item from the list using up/down arrow keys or your mouse. To accept the selection, press RETURN (ENTER). You can also immediately type a space (for variables) or an opening brace (for a function), and AmiBroker will auto-complete the currently selected word and close the list. To dismiss the list, press the ESC key.
 
 
 
Parameter Information
 
When you are typing a function, you can display a Tool Tip containing the complete function prototype, including parameters.  The Parameter Info Tool Tip is also displayed for nested functions.

With your insertion point next to a function, type an open parenthesis as you normally would to enclose the parameter list.

AmiBroker displays the complete declaration for the function in a pop-up window just under the insertion point.

Typing the closing parenthesis dismisses the parameter list.

You can also dismiss the list if you press an arrow up/down key, click with the mouse, or press RETURN.

Editor configuration

The settings of the AFL editor can be changed using Tools->Preferences, Editor page:

Window control

The AFL Editor window, as a separate frame, can be brought to the top or to the back as any other application window using the Windows Taskbar. In addition to that, there is a Window->Toggle Frame menu (and Ctrl+` shortcut (` is the tilde key just above the TAB key on most keyboards) that allows to quickly toggle between the AmiBroker main frame and the AFL editor frame.

The user may also turn on the Window->Keep On Top feature that keeps the editor window on top of the AmiBroker main frame.

Margins

The Line Numbers margin, Selection margin, and Fold margin can be switched on/off using the View menu. In this menu, there are also options to fold/unfold all code.

Code snippets

A code snippet is a small piece of AFL code. It can be inserted by:

For more information about code snippets, see Tutorial: Using Code Snippets

Bookmarks

A bookmark is a marker that allows you to quickly jump to a marked line within the formula.

To set/remove the bookmark, use Edit->Bookmark->Insert /Remove menu option or the Ctrl+F2 key. When you set the bookmark, a light blue marker will be shown in the left-hand margin. Now, with a couple of bookmarks set, you can quickly navigate (jump) between them using the F2 key (goes to the next bookmark), or the Shift+F2 key (goes to the previous bookmark). You can clear all bookmarks using Edit->Bookmark->Clear All. Please note that bookmarks are saved along with debug information (breakpoints/watches) in a separate file with a .dbg extension.

Find in Files

Find in Files functionality is available from the Edit->Find in Files menu and allows you to search all files in selected folders for specified text. The search results are presented in the Output window (the Window->Output menu) like this:

Filepath\Filename.afl(line_number): Line contents

Now, if you double-click on that output line, AmiBroker would automatically open the given file in the new editor tab.

Block comment/uncomment

The AFL editor now provides a tool to automatically comment out blocks of selected lines. The tool adds a // (double slash) comment to every line within the selected area. To use this tool, select some lines using the mouse or the cursor + SHIFT key, then use the Edit->Line Comment option. All lines within the selected range will be commented out with // (double slash). To uncomment, select the range again and choose the Edit->Line Comment option once again.

Clickable links in comments

The AFL Editor now supports clickable JavaDoc/Doxygen-style links in doc comments. To use links in comments, you have to put an @link command followed by the path to a file or URL inside a JavaDoc/Doxygen-style comment:

Now, when you hover the mouse over an @link command, you will see an underline that indicates it is clickable. It reacts to a double-click (not a single click). When you double-click it, the linked document will open.

An @link command can open web pages, local files (both relative and absolute paths are supported) with a Windows-registered program to open the given file type. So if you use:

/// @link something.doc

then MS Word would be used.

/// @link test.xls

would open test.xls in Excel.

Relative paths refer to the AmiBroker working directory. HTML files are opened with the default browser; TXT files are usually opened with Notepad (or whatever application you use). If a file does not exist, then you will get an error message.