buffer-init - Initialize a buffer language template.
buffer-init-hooks - Initialize the buffer language template hooks.
buffer-init-fhook - Initialize the buffer file hooks.
n buffer-init name [etf]
buffer-init-hooks
buffer-init-fhook name
The buff-init commands prepare the operating modes of a buffer for a language template. These commands operate with variables defined in the template and automatically configure MicroEmacs to use the template.
The commands are used in the hook files (hkXXX.emf - see File Hooks) and simply the setting up of File Language Templates by automating common actions and integrating the configuration settings made via buffer-setup(3).
The hook file is declared from me.emf or the user start up file binding a file extension or magic string association with the hook file. i.e.
-1 add-file-hook "-[*!]-[ \t]*XXX.*-[*!]-" fhook-XXX 1 add-file-hook "^#!/.*XXX" fhook-XXX
On loading a file which matches the add-file-hook(2) definition then the hkXXX.emf file is executed and the template is applied to the file.
A basic template framework to be used with the buff-init commands may be defined as follows for a language template called XXX:-
; File hook - initialize buffer on loading the file. define-macro fhook-XXX set-variable $buffer-mask "luh1" @# buffer-init "XXX" buffer-init-hooks !emacro ; buffer-init variables set-variable .fhook-XXX.name "XXX Macro" set-variable .fhook-XXX.setup ® "/history/fhook/XXX" "bdfghnopx" set-variable .fhook-XXX.setup-mask "abdefghikmnoptux" ; Commenting configuration -- omit if not defined. set-variable .fhook-XXX.comment "|#||#|# | #||" ; Additional commands -- omit if not defined. set-variable .fhook-XXX.command-flag "||" set-variable .fhook-XXX.command-name "||" set-variable .fhook-XXX.command-nbind "||" set-variable .fhook-XXX.command-kbind "||" set-variable .fhook-XXX.command-desc "||" ; OR define the commands one per line uniquely numbered from 0. set-variable .fhook-XXX.command-0 "|bo||xxx-para|esc o||" set-variable .fhook-XXX.command-1 "|bo||xxx-para|esc q||" ; Define additional buffer setup menu items -- omit if not defined set-variable .fhook-c.setup-flags "|c|l|" set-variable .fhook-c.setup-labels "|Option 1|Option 2|" ; Set up collapse or folding for XXX -- omit if not defined set-variable .fhook-XXX.collapse-open "^{" set-variable .fhook-XXX.collapse-close "^}" set-variable .fhook-XXX.collapse-mopen "-1" set-variable .fhook-XXX.collapse-mclose "1" set-variable .fhook-XXX.collapse-mnext "-1" ; setup XXX item-list -- omit if not defined set-variable .fhook-XXX.item-list-s1 "^[ \t]*func\\(\\w+\\)" set-variable .fhook-XXX.item-list-r1 "^[ \t]*end" ; Set up hilighting !if &and &sin "h" .fhook-XXX.setup &band .hilight.flags 0x02 ; Hi-light XXX Mode !if ¬ &exi .hilight.XXX set-variable .hilight.XXX &pinc .hilight.next 1 !endif 0 hilight .hilight.XXX 2 50 hilight .hilight.XXX 0 "#.*" .scheme.comment hilight .hilight.XXX 1 "end" .scheme.keyword hilight .hilight.XXX 1 "^[ \t]*func" .scheme.function ; ... more ... ; Hilight numbers. !if &band .hilight.flags 0x08 ; hilight constants, e.g. numbers hilight .hilight.XXX 1 "[[:digit:]]+" .scheme.constant hilight .hilight.XXX 1 "-[[:digit:]]+" .scheme.constant hilight .hilight.XXX 1 "0[xX][[:xdigit:]]+" .scheme.constant hilight .hilight.XXX 1 "[[:digit:]]+\.[[:digit:]]+" .scheme.constant hilight .hilight.XXX 1 "-[[:digit:]]+\.[[:digit:]]+" .scheme.constant hilight .hilight.XXX 1 "[[:digit:]]+\.[[:digit:]]+f" .scheme.constant hilight .hilight.XXX 1 "-[[:digit:]]+\.[[:digit:]]+f" .scheme.constant !endif !endif ; End the initialisation - call user extensions i.e. myXXX.emf buffer-init-fhook "XXX"
buffer-init is invoked from the buffer file hook fhook and is invoked with the numerical argument passed to the fhook macro (specified as $#). The call takes two arguments, the first is the name of the template or hook, in the example this is XXX. The second argument is the etf template name (see etf(8)). The command initializes the buffer, using the .fhook-XXX variable information defined in the file.
buffer-init-hooks is invoked from the buffer file hook fhook typically following the buffer-init call this macro invokes any user defined file hooks of the form my-fhook-XXX. User defined my-bhook-XXX and my-ehook-XXX are configured into the buffer space ready for execution.
buffer-init-hooks must be placed in all fhook-XXX macros to correctly initialize the file hooks. If this is not added then the "my-*hook-always" macros may not be called correctly for buffers where the fhook-XXX has not been configured correctly.
buffer-init-fhook is placed at the end of the hook file definition and retrieves additional configuration information from the registry and the user settings, it will also locate and load any user additions to the template by loading the file myXXX.emf.
A set of global default file hooks may be defined of the form my-fhook-always, my-bhook-always, my-ehook-always and my-dhook-always. These file hooks are global and invoked after the
It is important to understand the execution sequence of the buffer hook files. On identifying a new file hook then the hkXXX.emf file is fetched from the file system and executed. Execution causes all of the variables to be defined and finally, when all definitions have been made, buffer-init-fhook is executed to load in any user defined extensions. At this point then the macro fhook-XXX has ONLY been defined it has NOT been executed. This load operation is performed once only and is on demand.
The fhook-XXX macro must be defined BEFORE any of the variables associated with the hook as all subsequent variables are command variables and are defined in the context of the macro definition. See Variables(4) for more information on macro variables.
fhook-XXX is invoked to apply hilighting, buffer key bindings, indentation etc. to a new buffer which has just been created.
ehook-XXX is invoked when a buffer is swapped out. This may be used to save global variables that have been modified in the context of the buffer.
bhook-XXX is invoked when a buffer is swapped in. This may be used to restore variables that are specific to a buffer to global variables.
dhook-XXX is invoked before a buffer is deleted. This may be used to clean up a buffer before it is destroyed.
Extended file hooks
The buffer hooks [fbed]hook-XXX may be extended by user specific configuration in the form my-[fbed]hook-any, these are invoked after the primary hook as been invoked and operate on all buffers rather than a specific buffer type. The my-*hook-always mechanism is provided by the buffer-init macros of buffinit.emf rather than from the base command set of MicroEmacs.
Buffer initialization is controlled by the settings of the variables .fhook-XXX.setup and fhook-XXX.setup-mask:-
set-variable .fhook-XXX.setup ® "/history/fhook/XXX" "bdfghnopx" set-variable .fhook-XXX.setup-mask "abdefghikmnoptux"
The variables use an ASCII configuration string that identifies the modes of operation that are required. Upper and lower case alternatives are presented, an uppercase flag disables the mode, lower case enables. Where the flag is not specified then the mode is not changed.
a - Auto mode
b - Abbreviation mode
c - View / Author mode
d - Auto indentation operation.
Where indent(2m) mode is required then omit the d flag and use flag i instead.
e - Exact or case sensitivity operation
f - Folding/Collapsing operation
g - Fence matching operation
h - Hilighting
i - Automatic indentation
j - Justify
k - Backup mode
m - Magic mode
n - New buffer header
o - Tool menu
p - Help page
s - Auto spell
t - Tab mode
u - Undo
w - Wrap
x - Time stamping
1 - Reformatting hilighting
# - Commenting
.fhook-XXX.setup is the current set-up, this is normally defined to take settings from the registry providing a default when not defined. This is the only mask that is allowed to include the uppercase flags. All values defined in .fhook-XXX.setup are explicitly enabled or disabled by default. The setup set should contain the configuration flags that are required to make the template operate correctly, but should not include modes that the user may set up i.e. exact or magic etc.
.fhook-XXX.setup-mask defines the set of flags that are allowed with the template. The configuration defined in buffer-setup(3) is tested against the mask, if the mask allows it then the mode is enabled. .fhook-XXX.setup is generally a subset of .fhook-XXX.setup-mask.
buffer-setup(3) operates with the values defined by .fhook-XXX.setup and .fhook-XXX.setup-mask. The initialization of .fhook-XXX.setup is performed using the registry as follows:-
set-variable .fhook-XXX.setup ® "/history/fhook/XXX" "bdfghnopx"
This allows the user to configure over-ridding modes via buffer-setup(3). The user configuration is saved to the Registry and restored using ®(4), when the variable is defined. The flags that are defined by buffer-setup(3) include a, b, c, d, e, f, g, h, i, j, k, m, n, o, p, s, t, u, w, and x.
The buffer setup may be configured to add a tags generator to the language template, this is added to the menu. The tags generation is declared in the template by assigning the variable .fhook-XXX.tags with a command line to run tags utility. The command line string should commence with a ! character to tell MicroEmacs to execute an external command, for example to use the GNU ctags(2) utility is defined as:-
set-variable .fhook-c.tags "!ctags *.c *.h"
When the value starts with a '!' then rest of the line is spawned as a process, no additional interface is provided to the command.
Some language templates include a macro tags facility to generate a tags file (See emftags(3f) - emftags.emf, ctags(3f) - ctags.emf, ntags(3f) - ntags.emf). .fhook-XXX.tags may be defined to use an internal macro based tags generator rather than an external command. Without the '!' character the command line is assumed to be an MicroEmacs macro based and runs the command
me @<.tags-var-value> -v%tag-options=<options>
A macros based command line for the 'C' Programming Language is defined as:-
set-variable .fhook-c.tags "ctags"
The presence of a tags generator is not flagged in the setup flags, declaration of the .fhook-XXX.tags variable is sufficient to declare that a tags generator exists.
The .fhook-XXX.setup may be extended to include local configuration items that are private to a specific buffer. The extensions are added to the buffer-setup(3) menu and provide an on/off check-box control to enable and disable specific buffer features. Feature examples include: Enable or disable Doxygen highlighting in a buffer, control hidden file names in a directory listing etc.
The configuration extensions are defined using two additional hook variables, these variables are normally omitted and only defined if the extensions are required.
.fhook-XXX.setup-flags
.fhook-XXX.setup-labels
To add a new feature switch then the the character flags to hold the state are are defined with the .fhook-XXX.setup-flags and .fhook-XXX.setup-labels. The characters defined with the setup-flags should be added to .fhook-XXX.setup-mask. If the option is to be enabled by default then the enabling character is added to .fhook-XXX.setup.
To enable/disable the features then buffer-setup(3) when invoked modifies the state of the variable .fhook-XXX.setup and then executes the buffer hook again causing the new state to be processed and applied. The modified .fhook-XXX.setup value is stored in the user registry and is applied thereafter when the specified buffer type is loaded.
Within the template definition then the additional flags are checked by testing the state of the .fhook-XXX.setup variable. An example is shown below.
; Add the extra variable to the buffer-init variables ; Option 1 is disabled and Option 2 is enabled by default here. set-variable .fhook-XXX.setup ® "/history/fhook/XXX" "bdfghnopxl" set-variable .fhook-XXX.setup-mask "abdefghikmnoptuxcl" ; Define the additional options. set-variable .fhook-XXX.setup-flags "|c|l|" set-variable .fhook-XXX.setup-labels "|Option 1|Option 2|" ; Test for the Option 1 being enabled. !if &sin "c" .fhook-XXX.setup ; Do Option 1 configuration. !endif ; Test for the Option 2 being enabled. !if &sin "l" .fhook-XXX.setup ; Do Option 2 configuration. !endif
The templates hkc.emf, hkcpp.emf and hkjava.emf include private extensions which may be used as examples.
The format of comments may be defined in the template using the .fhook-XXX.comment variable. Definition of the comment form allows the comment formatting to be automatically set up. Where the comment format is defined then the following key bindings are automatically added to the template:-
C-c C-s comment-start - start a new comment.
C-c C-c comment-line - comment out the current line.
C-c C-d uncomment-line - remove commenting from current line.
C-c C-e comment-to-end-of-line - comment to end of line.
C-c C-r comment-restyle - format/re-style comment.
Help information is automatically added to the buffer to describe the key bindings if help information is enabled.
The default comment format is defined with the variable .fhook-XXX.comment with an argument string in the form "| <comment-start> | <comment-end> | <comment-pad> | <mid-box-left> | <mid-box-right> | <comment-flags> |". Where a language supports multiple comment types, or styles, then additional comment styles may be specified with a comment definition of the form .fhook-XXX.comment-N where N is an integer from 1 to n. Each definition defines an different comment style. Additional comment definitions should be ordered such that the longest or most definitive comment definition appears before other comment definitions which have less definitive features. The comment matching searches each of the comment definitions in the order 1 to n to determine the comment style, as soon as a positive match is located then the comment is used without searching the remaining comments.
The fields of the comment definition are defined as follows:-
<comment-start>
<comment-end>
<comment-pad>
<mid-box-left>
<mid-box-right>
<comment-flags>
b
f
F
h
H
j
r
Examples of the comments format are shown below.
'C' Programming language
set-variable .fhook-c.comment "|/*| */|*| * | * |f|"
The comment output is defined as:-
/*************************************************************** * This is a box comment * ***************************************************************/ /* Comment to end of line **************************************/
C++ Programming language
set-variable .fhook-cpp.comment "|//||/|// | //||"
The comment output is defined as:-
///////////////////////////////////////////////////////////////// // This is a box comment // ///////////////////////////////////////////////////////////////// // Comment to end of line ///////////////////////////////////////
C++ supports both C and C++ comment styles, both styles may be defined in the language template. For C++ then // is assumed to be the default style.
set-variable .fhook-cpp.comment "|//||/|// | //||" set-variable .fhook-cpp.comment-1 "|/*| */|*| * | * |f|"
MicroEmacs macro language
set-variable .fhook-emf.comment "|;||;|; | ;||"
The comment output is defined as:-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Box Comment ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Comment to end of line ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Shell script
set-variable .fhook-shell.comment "|#||#|# | #||"
The comment output is defined as:-
################################################################# # Box Comment # ################################################################# # Comment to end of line ########################################
MS-DOS Batch file
set-variable .fhook-dos.comment "|rem |||rem |||"
The comment output is defined as:-
rem rem Box Comment rem rem Comment to end of line
Local buffer commands and key bindings for over-riding key definitions used within the buffer are defined with the fhook-XXX.command-* variables. These are defined as MicroEmacs list variables (see &lfind(4), &lget(4), etc. for the full syntax definition) and define a list of keys, commands and bindings. Each command is typically separated by the '|' character. The field order in all of the fhook-XXX.command-* variables MUST be consistent, so if a command is defined in field 5, then all definitions associated with that command MUST be defined in field 5 for all variables.
To make the command definitions easier then the syntax fhook-XXX.command-n may be used where n is an integer from 0..n-1. The fhook-XXX.command-n statements are used to construct the fhook-XXX.command-* lists, the advantage being that the command and key bindings etc. are defined together. Once the command-n variables are processed then they are deleted from the environment. The general syntax of the command-n variable is defined as a list:
|command-flag|command-nbind|command-name|command-kbind|command-desc|
The command variables are defined as follows:-
.fhook-c.command-flag
t - Toolbar
h - Help Screen
b - Key binding
o - Forced key binding
i - Emulated key binding
H - Hilighting key binding
.fhook-XXX.command-name
.fhook-XXX.command-nbind
.fhook-XXX.command-kbind
.fhook-c.command-desc
As an example, two new commands or bindings may be defined for a template, the first field is bound to key A-q which executes macro XXX-comp with a numerical argument of 2. The second field binds a new key to comment-restyle(3).
..... set-variable .fhook-XXX.command-flag "|th|bo|" set-variable .fhook-XXX.command-name "|XXX-comp|comment-restyle|" set-variable .fhook-XXX.command-nbind "|2||" set-variable .fhook-XXX.command-kbind "|A-q|esc o|" set-variable .fhook-XXX.command-desc "|Complete command||" ..... ; Local macro definition to perform command completion define-macro XXX-comp set-variable #l1 @# ..... !emacro
The alternative form of definition using the command-n syntax is defined as:-
..... set-variable .fhook-XXX.command-0 "|th|2|XXX-comp|A-q|Complete command|" set-variable .fhook-XXX.command-1 "|bo||comment-restyle|esc o||" ..... ; Local macro definition to perform command completion define-macro XXX-comp set-variable #l1 @# ..... !emacro
The key bindings sometimes need to be protected where they have been redefined to perform some other operation for example when emulation modes are used (i.e. nedit, me3.8). The buffer initialisation uses the command buffer-bind-create and the variables .buffer-bind-create.map-from and .buffer-bind-create.map-to which define replacement keys for bindings. As an example the nedit emulation mode uses key binding C-c C-c and provides a buffer binding mapping to translate any key buffer binding to a different key. i.e.
; reconfigure the buffer bindings set-variable .buffer-bind-key.map-from "|C-c C-c|C-c C-d|" set-variable .buffer-bind-key.map-to "|C-b|C-u|"
MicroEmacs '06 provides a generic, albeit coarse, folding mechanism which is applied to some of the well known file modes. The folding mechanism allows parts of the buffer to be scrolled up and hidden, leaving a residue hilighting marker within the buffer indicating a folded region. A folded buffer typically allows a summary of the buffer contents to be viewed within several windows, hiding the detail of the buffer.
Note: collapse was called fold in earlier releases but the name was changed when real fold editing support was added, see fold.emf for more information.
The folding mechanism uses well defined start and end markers which form part of the syntax of the well known file mode. i.e. in 'C' this is the open and closed braces that appear on the left-hand margin ({ .. }). The intention is that the natural syntax of the text is used to determine the fold positions, requiring no additional text formating or special text tags to be inserted by the user.
The language template defines the syntax of blocks of information that may be collapsed and hidden with narrow. In order to utilize the collapse-current(3) and collapse-all(3) commands within a buffer, the start and end markers have to be initialized for the syntactical contents of the buffer. The buffer specific variables are defined as follows, where XXX is the file hook base name. The .fhook-XXX.collapse-* variables define the regular expression search pattern and line positioning.
.fhook-XXX-collapse-open
.fhook-XXX-collapse-close
.fhook-XXX-collapse-mopen
.fhook-XXX-collapse-mclose
.fhook-XXX-collapse-mnext
The following examples show how the collapse variables are set up in each of the buffer modes.
C and C++
set-variable .fhook-c.collapse-open "^{" set-variable .fhook-c.collapse-close "^}" set-variable .fhook-c.collapse-mopen "-1" set-variable .fhook-c.collapse-mclose "1" set-variable .fhook-c.collapse-mnext "-1"
Given a 'C' function definition:-
static void myfunc (int a, int b) { /* Function body */ }
the folded version appears as follows:-
static void myfunc (int a, int b) ... }
emf
set-variable .fhook-emf.collapse-open "^0? ?define-macro[ \t]" set-variable .fhook-emf.collapse-close "^!emacro" set-variable .fhook-emf.collapse-mclose "1" set-variable .fhook-emf.collapse-mnext "-1"
Given a macro definition:-
0 define-macro mymacro ; This is the body of the macro ; ... and some more ... !emacro
the collapsed version of the macro is defined as:-
0 define-macro mymacro ... !emacro
nroff
set-variable .fhook-nroff.collapse-open "^\.S[SH]" set-variable .fhook-nroff.collapse-close "^\.S[SH]\|\'" set-variable .fhook-nroff.collapse-mnext "-1"
Given an nroff block of text defined as:-
.SH SYNOPSIS .\" Some text .\" Some more text .SH DESCRIPTION
Then the collapsed version appears as:
.SH SYNOPSIS .SH DESCRIPTION
tcl/tk
set-variable .fhook-tcl.collapse-open "^proc " set-variable .fhook-tcl.collapse-close "^}" set-variable .fhook-tcl.collapse-mclose "1" set-variable .fhook-tcl.collapse-mnext "-1"
Given a tcl procedure definition:-
proc tixControl:InitWidgetRec {w} { upvar #0 $w data tixChainMethod $w InitWidgetRec set data(varInited) 0 set data(serial) 0 }
The collapsed version of the same section appears as:-
proc tixControl:InitWidgetRec {w} { ... }
Where folding is required using fold-open(3) then the collapse methods above are not enacted when folding is enabled. Folding may be enabled as defined by the File Hooks, alternatively the folding may be explicitly defined using the variable .fhook-XXX.fold. The .fhook-XXX.fold variable argument is defined as "| <literal-open> | <literal-close> | <comment-termination> | <regex-find-open> | <regex-find-close> |. Where the fields are defined as follows:-
<literal-open>
<literal-close>
<comment-termination>
<regex-find-open>
<regex-find-close>
As an example, a language may have the following syntax for defining folds:-
/* {{{ This is an example fold. */ This is the body of the fold /* }}} */
The fold is defined as follows:-
set-variable fhook-XXX.fold "|/\\* {{{|/\\* }}}|\\*/|/\\*[ \t]*{{{|/\\*[ \t]*}}}|"
Item Lists perform a regular expression search of a buffer, presenting a list of the located text and associated types in a separate window which is presented to the left of the buffer window or more typically in the toolbar. The command item-list(3) is a generic command that interacts with the buffer environment variables to present abbreviated buffer information to the user.
The regular expression search strings are predefined in the language templates, using the variables .fhook-XXX-item-list-sY and .fhook-XXX-item-list-rY and are described more fully in item-list(3).
Buffer hilighting is defined by the hilight(2) command. Within the context of buffer-init then the standard definitions and name space conventions should be adhered to:-
!if ¬ &exist .hilight.XXX set-variable .hilight.XXX &pinc .hilight.next 1 !endif !if &and &sin "h" .fhook-XXX.setup &band .hilight.flags 0x02 ; High-light XXX Mode 0 hilight .hilight.XXX 0 $global-scheme ..... ; Variable hilighting !if &band .hilight.flags 0x08 ; hilight constants, e.g. numbers hilight .hilight.XXX 1 "[[:digit:]]+" .scheme.constant ...... !endif !endif
Buffer indentation is defined by the indent(2) command. Within the context of buffer-init then the standard definitions and name space conventions should be adhered to. The buffer indentation scheme uses the hilighting variable, if hilighting is not defined then the variable allocation of .hilight.XXX should be performed as defined in the previous Hilighting section.
!if &sin "d" .fhook-XXX.setup 0 indent .hilight.XXX 0 10 indent .hilight.XXX n "{" 4 indent .hilight.XXX o "}" -4 ..... !endif
The January 2005 version of MicroEmacs introduced the following changes:
$buffer-hilight(5),
$buffer-indent(5),
add-file-hook(2),
buffer-abbrev-file(2),
buffer-setup(3),
collapse-all(3),
collapse-current(3),
ctags(3f),
eaf(8),
emftags(3f),
etf(8),
etfinsrt(3),
execute-buffer(2),
expand-abbrev(2),
global-abbrev-file(2),
hilight(2),
indent(2),
indent(2m),
item-list(3),
narrow-buffer(2),
ntags(3f),
restyle-buffer(3),
restyle-region(3),
scheme-editor(3),
time(2m),
File Hooks,
File Language Templates.
Copyright (c) 1998-2006 JASSPA
Last Modified: 2006/07/28
Generated On: 2006/10/07