Grief is built on the concept of extensibility and programmability. Macros are so ingrained in the design of BRIEF that many of the standard editing functions are implemented in the macro language, rather than in compiled code.
By writing your own macros, you can tailor the standard editor in both small ways (such as setting start-up colors, tab settings, or window positions), and large ways (such as modifying existing commands or creating new commands of your own design).
| Macros | Grief is built on the concept of extensibility and programmability. |
| Types of Macros | A function can be called from the macro language. |
| Commands | Prompt line and keyword command macros. |
| Startup and main | Every macro source may have a main() function; where you place it is a matter of preference. |
| File Extension Macros | File extension callbacks are executed whenever GriefEdit edits a file via the edit_file primitive. |
| Registered Macros | A registered macro is one that is executed when an associated event ocurrs. |
| Replacement Macros | A replacement macros is an overloaded function, whereby an existing macro or builtin can be replaced and extended, yet allowing the replacment macro to then execute the origin |
| Special Purpose Macros | Similar to registered macros, special purpose macros act a signal handlers. |
| Built-in Functions | A built-in function is a function that was implemented in the interpreter and was not written in the Grief language. |
| Macro Resources | |
| Keyboards | Most of Grief’s keyboard input is either via the command prompt get_parm or executed through the use of keyboard resources. |
| Buffers | Buffers are the basic editing construct utilised by Grief. |
| Buffer Identifiers | Buffers can are identfied by one of two means, firstly by name and secondary its associated unique buffer handle or identifier. |
| Marked Regions | Many commands work on certain regions of text. |
| Scrap Buffer | The scrap is a special buffer used for moving or copying blocks of text. |
| BookMarks | A bookmark allows a record of the current buffer position to be saved for quick navigation to the same location at a later time. |
| Buffer List | Buffers are maintained in a circular list, refered to as the buffer list. |
| System Buffer | There are two primary categories of buffers, user and system buffers. |
| Scrap Buffers | Scrap buffers are buffers which have been assigned the job of cut and paste storage. |
| Buffer Content | The following primitives are used to manage buffer content. |
| Buffer Attributes | As buffers are the basic editing construct utilised by Grief, they also represent the primary user interface. |
| Encoding | Grief supports both explicit and auto-detection of most file encoding types including; |
| Hilite Regions | Similar to marked regions, buffers may have one or more special highlighting regions defined, allowing macros to show specific buffer content. |
| Syntax Highlighting | Syntax highlighting allow different colors and text styles to be given to dozens of different lexical sub-elements of syntax. |
| Process Buffers | An external, for example a command shell, may be attached to specific buffer providing a tty style view for the underlining process. |
| Dictionaries | A dictionary is a collections of associations. |
| Windows | Windows are used to create views into buffers. |
| Dialogs | A dialog is a small window resource that prompts the user to make a decision or enter additional information. |
| Regular Expressions | A regular expression is a pattern that the regular expression engine attempts to match in input text. |
A function can be called from the macro language. Grief has a number of different kinds of macros or functions;
The following sections describe each of the function types.
Prompt line and keyword command macros.
A command function is a macro which are assigned to a key or key sequence. As these are normally explicitly designed to be called directly by the user from the keyboard, these shall be referred to as commands.
There is no specific differences between command macros and other macros, as commands can be called also from other macros.
The _command keyword has been reserved for a possible extension to the macro language, whereby command macros must be explicity declared, hiding all not command macros from direct user usage.
Every macro source may have a main() function; where you place it is a matter of preference.
static int buffer; void main() { // initial our private working buffer buffer = create_buffer("--working-buffer--", NULL, 1); }
As such like C, some programmers place main at the beginning of the file, others at the very end. Like all macros, their location of order of function declarations contained the macro source has not effect of the execution order.
File extension callbacks are executed whenever GriefEdit edits a file via the edit_file primitive.
It is provided to allow macros to hooks buffer loads, for example to setup defaults tabs before any extension specific settings are applied.
Once executed if defined the extension specific handler shall be executed, which should be named as _ext. If not available the default extension handler _default shall be executed.
The extension case shall be preserved on case sensitive file-systems otherwise the extension is converted to lower case.
A registered macro is one that is executed when an associated event ocurrs.
Types of events which can be registered include;
These events are registered using the register_macro() primitive and can then be unregistered using the unregister_macro() primitive. One or more macros can be registered against any given event, in which case each macro shall be executed upon the event, in the same order as there were registered.
Registered macro primitive include;
A replacement macros is an overloaded function, whereby an existing macro or builtin can be replaced and extended, yet allowing the replacment macro to then execute the origin

The replacement keyword is used to explicity declare overloaded interfaces, which is a macro that supersedes (or complements) another macro of the same name.
A built-in function is a function that was implemented in the interpreter and was not written in the Grief language.
See the Library Reference for the list of built-in functions.
Most of Grief’s keyboard input is either via the command prompt get_parm or executed through the use of keyboard resources.
Keyboard resources map key strokes to actions allowing
The following primitives are used to manage keyboards.
Prompts are used to request direct user input, either indirectly then invoking a primitive or directly through the use of get_parm. The command prompt has a number of macro callbacks which are invoked during the prompt session, which may be replaced to modify and/or extend the prompt behaviour.
The following special macros _prompt_begin, _bad_key and _prompt_end:
| _prompt_begin | This callback is invoked priot to prompt display. If the macro _prompt_begin has been loaded, it is executed with a string parameter containing the value of prompt to be presented on the prompt. This macro may set the default response, use the prompt as key to load previous values or other similar functions. |
| _bad_key | This callback may be invoked one or more times during the command line edit session upon an invalid/unknown key being used during the edit. The read_char primitive retrieves the associated bad key, which can be ignored, processed or replaced. |
| _prompt_end | This callback is invoked during the prompt completion process. The primitive inq_cmd_line retrieves the value entered during the edit session. |
Buffers are the basic editing construct utilised by Grief. One buffer corresponds to one piece of text being edited. You can have several buffers open at once, but can edit only one at a time.
Each buffer may hold text only limited by the available system memory with as many buffers active at any given time in memory as desired, again only limited by system resources.
Several buffers can be visible at the same time when you’re splitting your window, see Windows.
The following primitives are used to create and delete buffers
Many commands work on certain regions of text. A region is defined by two points, the first being the anchor and the other the cursor position. Each buffer may have their own region, yet commands generally only work on the marked region within the current buffer.
The following primitives are used to manage regions
The scrap is a special buffer used for moving or copying blocks of text. A scrap buffer differs from a regular buffer because:
The following primitives are used to manage the scrap buffer.
Buffers are maintained in a circular list, refered to as the buffer list. New buffers are automaticly inserted into the list on creation. To locate a buffer that is not current, the next_buffer and previous_buffer primitives along with set_buffer can be use to manipulate the current buffer.
As buffers are the basic editing construct utilised by Grief, they also represent the primary user interface. Each buffer has many run-time attributes which effect the way content is presented to the user.
These attributes include.
The following primitives are used to manage buffer attributes.
Grief supports both explicit and auto-detection of most file encoding types including;
The following primitives are used to manage character maps and buffer encodings.
Syntax highlighting allow different colors and text styles to be given to dozens of different lexical sub-elements of syntax. These include keywords, comments, control-flow statements, variables, and other elements
There are several forms of highlighting engines.
The following primitives are used to manage syntax resources.
A dictionary is a collections of associations. Dictionaries consist of pairs of keys and their corresponding values, both arbitrary data values. Dictionaries are also known as associative arrays or hash tables.
Dictionaries require more space than lists, yet allow fast searches. Only one association in a dictionary may have a given key, that item keys must be unique.
You can iterate over a dictionary’s associations using the dict_each primitive; at each step of the statement, the loop index will contain a list [key, value] for the current association.
The following primitives are used to manage dictionary resources; see the descriptions of each function for details.
Windows are used to create views into buffers. Windows are either tiled or popup.
Tiled windows are the normal user views into buffers, allowing direct user interaction so that they may edit the buffer content.
The Grief window manager organises the screen into mutually non-overlapping frames. Tiled windows are not permitted to be overlapped with other tiled windows, as such are sized and positioned to own a specified rectangled area of the display.
The following primitives are used to create and delete tiled windows.
Unlike Tiled windows, Popup Windows when displayed overlay any tiled windows positioned behind and maybe sized and positions anywhere within the visible arena.
Usually, popup windows are utilised to display temporary information, for example the results of a command. They are generally created dynamically and managed by macros and are destroyed on completion of that macro.
In addition popup windows stack, allowing multiple popups to represent nested structures; one example being the help system which allows the user to drill down thru command relationships and then backout in reverse.
The following primitives are used to create and delete popup windows.
Like buffers each windows has a set of attributes which effect the presentation of connected buffer contentt, these are managed using the following primitives.
A dialog is a small window resource that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for modal events that require users to take an action before they can proceed.
The following primitives are used to manage dialogs.
A regular expression is a pattern that the regular expression engine attempts to match in input text. A pattern consists of one or more character literals, operators, or constructs.
The following primitives are used to utilise regular expressions.
in addition the following are Brief compatible interfaces which also support regular expressions.
$Id: macros.txt,v 1.4 2014/10/31 01:09:05 ayoung Exp $
To send feedback on this topic email: griefedit@gmail.com
Copyright © Adam Young All Rights Reserved.
Edit a file.
int edit_file( ... )
Retrieve the value of a macro parameter.
int get_parm( [int argument], declare & symbol, [string prompt], [int length = MAXPROMPT], [declare default], [int one = FALSE] )
Default extension handler.
void _default( string ext )
Register a callback procedure.
int register_macro( int type, string macro, [int local = FALSE] )
Buffer load handler.
void _extension( string ext )
Remove a registered macro.
int unregister_macro( int type, string macro, [int local = FALSE] )
Invoke registered macro callbacks.
int call_registered_macro( int type )
Startup event callback.
void _startup_complete( int mode )
Command prompt session begin callback.
void _prompt_begin( string prompt )
Command prompt session end callback.
void _prompt_end()
Command prompt unknown key callback.
string _bad_key()
Invalid key event.
void _invalid_key()
Fatal condition callback.
void _fatal_error( int signo, string desc )
Property change event.
void _chg_properties()
Assign command to key or key sequence.
int assign_to_key( [string key], [string macro] )
Copy a keyboard.
int copy_keyboard( int kbdid, [string cmd ...] )
Get key assignment for function.
string inq_assignment( int|string val, [int tokey = FALSE] )
Peek at the keyboard.
int inq_kbd_char()
Retrieve the keyboard identifier.
int inq_keyboard()
Retrieve local keyboard identifier.
int inq_local_keyboard()
Flush the keyboard buffer.
void keyboard_flush()
Pop a keyboard from the keyboard stack.
void keyboard_pop( [int save = FALSE] )
Push a keyboard onto the keyboard stack.
void keyboard_push( [int kbdid] )
Assign self_insert to all typeable keys.
int keyboard_typeables()
Pause keystroke definition.
void pause()
Invoke a Grief engine.
void process()
Push back a character into the keyboard.
void push_back( int key, [int front], [int x], [int y] )
Read next key from the keyboard.
void read_char( [int timeout = 0], [int mode = 0] )
Start remembering keystrokes.
int remember( [string|int overwrite], [int macroid] )
Insert a character as if it was typed.
void self_insert( [int character] )
Associate a keyboard with a buffer.
int use_local_keyboard( int kbdid )
Retrieve the command line message.
string inq_cmd_line()
Create and load a buffer.
int create_buffer( string bufname, [string filename], [int sysflag = FALSE], [int editflags = 0], [string encoding = ""] )
Attach a buffer to a window.
void attach_buffer( int bufnum )
Delete a buffer.
void delete_buffer( int bufnum )
Retrieve a buffer identifier.
int inq_buffer( [string filename] )
Set the current buffer.
int set_buffer( int bufnum )
Determine the current marked region.
int inq_marked( [int &start_line], [int &start_col], [int &end_line], [int &end_col] )
Start marking a selection.
int drop_anchor( [int type = MK_NORMAL] )
Set the end of the anchor.
int end_anchor( [int line], [int column] )
Raise the last dropped mark.
int raise_anchor()
Swaps the mark with the current position.
int swap_anchor()
Deleted selected region.
int delete_block()
Cut marked area to scrap.
int cut( [int append = FALSE], [int syscopy = FALSE] )
Copy marked area to scrap.
int copy( [int append = FALSE], [int keep = FALSE] )
Insert scrap buffer at cursor location.
int paste( [int syspaste = FALSE] )
Buffer to buffer transfer.
int transfer( int bufnum, int sline, [int scolumn], int eline, [int ecolumn] )
Obtain the scrap buffer identifier.
int inq_scrap( [int &last], [int &type] )
Set the scrap buffer details.
void set_scrap_info( [int last], [int type], [int bufnum] )
Create or update a bookmark.
int drop_bookmark( [int bookid], [string yesno], [int bufnum], [int line], [int column], [int local = FALSE] )
Delete a bookmark.
void delete_bookmark( int bookid )
Seek a bookmark.
int goto_bookmark( int bookid = NULL, [int &bufnum], [int &line], [int &column] )
Retrieve existing bookmark list.
list bookmark_list()
Identifier of the next buffer.
int next_buffer( [int sysflag = 0], [int previous], [int tab] )
Identifier of the previous buffer.
int previous_buffer( [int sysflag = 0], [int tab] )
Set buffer flags.
void set_buffer_flags( [int bufnum], [string|int or_mask], [string|int and_mask], [int set = 1] )
Determine if buffer is a system buffer.
int inq_system( [int bufnum] )
Retrieve marked region content.
int get_region( [int bufnum] )
Insert string into current buffer.
int insert( string|int val, [int num = 1] )
Insert a formatted string.
int insertf( string format, ... )
Insert format text into a buffer.
int insert_buffer( int bufnum, string format, ... )
Retrieve buffer flags.
int inq_buffer_flags( [int bufnum], [string flag|int set = 1], [string ~flags] )
Set the color attributes.
int set_attribute( [int|string text], [int|string normal], [int bufnum] )
Retrieve the current attributes.
int inq_attribute( [int &normal], [int bufnum] )
Set buffer tab stops.
int tabs( [string tabs | list tabs | int tab, ...] )
Retrieves the buffer tab specification.
string|list inq_tabs( [int bufnum], [int min_count], [int aslist = FALSE] ))
Configure the buffer ruler.
int set_ruler( [int bufnum], [list|string|int ...] )
Retrieves the ruler specification.
string|list inq_ruler( [int bufnum], [int min_count], [int aslist = FALSE] )
Set the buffers default indentation.
int set_indent( [int indent], [int bufnum] )
Get current indentation settings.
int inq_indent( [int bufnum] )
Set buffer formatting margins.
int set_margins( [int bufnum], [int left = NULL], [int right = NULL], [int style = NULL], [int colorcolumn = NULL] )
Retrieve buffer formatting margins.
int inq_margins( [int bufnum], [int &left], [int &right], [int &style], [int &colorcolumn], [int global = TRUE] )
Set a buffers character encoding.
int set_encoding( [string encoding = NULL], [int bufnum = NULL] )
Retrieve a buffers character encoding.
string inq_encoding( [int bufnum] )
Create a display character-map.
int create_char_map( [int mapid|string name], [int start = 0], [list chars], [list flags], [string name] )
Set a buffers character-map.
int set_buffer_cmap( [int mapid|string name], [int bufnum] )
Retrieve the character-map.
int inq_char_map( [int winnum], [string &name] )
Set a buffers line terminator.
int set_terminator( [int bufnum], int|string term )
Retrieve a buffers line terminator.
int inq_terminator( [int bufnum], [string &term] )
Define the file type detection rules.
int set_file_magic( [string encoding], [int cost] )
Retrieve the file type detection rules.
string inq_file_magic( [int &isdefault] )
Create a hilite resource.
int hilite_create( [int bufnam], [int type], [int timeout], [int sline], [int scol], [int eline], [int ecol], [string | int attr], [int ident] )
Destroy hilite resources.
int hilite_destroy( [int bufnum], [int type] )
Attach a syntax to a buffer.
int attach_syntax( int|string syntable )
Syntax table creation.
int create_syntax( string table )
Add keywords to a syntax dictionary.
void define_keywords( [int|string] keywords, string words|list words, [int length], [int flags], [int|string syntable] )
Define a syntax token.
void syntax_token( int type, [<type1> param1], [<type2> param2], [int|string syntable] )
Detach a syntax from a buffer.
void detach_syntax()
Retrieve the specific color.
void get_color_pair( string name|int ident, [int|string fg], [int|string bg], [int|string sf] )
Build a syntax hiliting engine.
void syntax_build( [int timestamp], [string cache], [int|string syntable] )
Define a syntax hilite rule.
void syntax_rule( string pattern, string attribute, [int|string syntable] )
Retrieve the syntax identifier.
int inq_syntax( [int &flags], [int|string syntable] )
Set a specific color.
void set_color_pair( string|int ident, [int|string fg], [int|string bg], [int|string sf] )
Set syntax flags.
int set_syntax_flags( int flags, [int|string syntable] )
Column syntax coloriser.
int syntax_column_ruler( list ruler, [string attribute], [int|string syntable] )
Attach a process to a process.
int connect( int mode, string shell = NULL, string cwd = NULL )
Disconnect a buffer from a process.
int disconnect()
Send string to a attached process.
int insert_process( string|int val, [int num = 1] )
Set process insertion position.
int set_process_position( [int line], [int column] )
Get position of process buffer.
int inq_process_position( [int &line], [int &column] )
Wait for attached process to terminate.
int wait( [int &status] )
Wait for process output.
int wait_for( [int timeout], list|string pattern, [int flags = 0] )
Send signal to a process buffer.
int send_signal( int signal )
Iterator a dictionary.
int dict_each( int obj_id, [string key], [declare value] )
Create a dictionary.
int create_dictionary( string ~name, int ~tablesize, int ~tablefactor )
Destroy a dictionary.
int delete_dictionary( int obj_id )
Set a dictionary item.
int set_property( int obj_id, string key, [declare value] )
Retrieve a dictionary item.
declare get_property( int obj_id, string key )
Remove a dictionary item.
int dict_delete( int obj_id, string key )
Dictionary item existence check.
int dict_exists( int obj_id, string key )
Iterator dictionary keys.
int dict_keys( int obj_id, [string key] )
Iterator dictionary values.
int dict_values( int obj_id, [declare value] )
Retrieve dictionary items.
list dict_list( int obj_id )
Retrieve a dictionary name.
string dict_name( int obj_id )
List of created dictionaries.
list list_of_dictionaries( [bool nonempty = false], [bool named = false] )
Creates a tiled window.
int create_tiled_window( int lx, int by, int rx, int ty, [int bufnum] )
Control window display.
int display_windows( [int mode] )
Selects a new window.
void change_window( [int direction], [string message] )
Modify a window.
int move_edge( [int direction], [int amount] )
Create an edge, splitting the window.
int create_edge( [int direction] )
Delete an edge, combining a split window.
int delete_edge( [int direction] )
Retrieve window view port coordinates.
int inq_top_left( [int &top], [int &indent], [int winnum], [int &line], [int &col], [int &bufnum] )
Retrieve the current window.
int inq_window()
Retrieve the current window information.
int inq_window_info( [int &winnum], [int &bufnum], [int &lx], [int &by], [int &rx], [int &ty], [string &title = NULL], [string &message = NULL] )
Manages window view port coordinates.
int set_top_left( [int line], [int column], [int winnum], [int csrline], [int csrcolumn], [int bufnum] )
Set the active window.
int set_window( int winnum )
Obtain the next window identifier.
int next_window( int winnum )
Create a popup window.
int create_window( int lx, int by, int rx, int ty, [string message] )
Delete a window.
void delete_window( [int winum] )
Set window flags.
void set_window_flags( [int winnum], [string set|int or_mask], [string clear|int and_mask] )
Retrieve window flags.
int inq_window_flags( [int winnum], [string flags] )
Build a dialog resource.
int dialog_create( list decl )
Delete a dialog resource.
int dialog_delete( int dialog )
Exit a dialog resource.
int dialog_exit( int retval = 0, [int dialog] )
Execute a dialog resource.
int dialog_run( int dialog, [string args] )
Retrieve the current dialog resource.
int inq_dialog()
Retrieve a widget attribute.
declare widget_get( [int dialog], [int name|string name], [int attr = DLGA_VALUE], [int index = 0] )
Set a widget attribute.
declare widget_set( [int dialog], [int name|string name], declare value, [int attr = DLGA_VALUE], [int index = 0] )
Quote regexp special characters.
string quote_regexp( string text )
Compile a regular expression.
list re_comp( [int flags], string pattern, [string &error] )
Delete a compiled expression.
int re_delete( list handle )
Retrieve search captures.
int re_result( [int capture], [string &value], [int &offset], [int &length] )
Search for a string.
int re_search( [int flags], [string pattern], [declare object], [int start], [int lensym] )
Set the regular expression mode.
int re_syntax( [int re], [int case], [int capture] )
Search and replace.
int|string re_translate( [int flags], string pattern, [string replacement], [declare object] )
Set the search pattern case mode.
int search_case( [int case] )
Backwards buffer search.
int search_back( string pattern, [int re], [int case], [int block], [int length] )
Buffer search.
int search_fwd( string pattern, [int re], [int case], [int block], [int length] )
Search list contents.
int search_list( [int start], string pattern, list expr, [int re], [int case] )
Searches for a pattern in a string.
int search_string( string pattern, string text, [int &length], [int re], [int case] )
Buffer search and replace.
int translate( string pattern, string replacement, [int global], [int re], [int case], [int block], [int forward] )