How do you create macros then...
The easiest way to
create a macro is to just define a simple word.
#define
MACRO This is a macro
The word
"MACRO" will expand to "This is a macro". You can also have
parameters to a macro.
#define MACRO( name ) This is a
macro done by name
If you then
type "MACRO( Per )" and expand that you will get "This is a macro
done by Per". The parameter name will be replaced by the word that you have
typed in macro. If you forgot the parantheses GDexpi will try to add it anyway.
So if you write "MACRO Per" you will get the same result.
Let say that you will add more
than one word for a parameter. Type "MACRO( "Per on the computer"
)". If you select this and expand it you will get "This is a macro
done by Per on the computer". As you can se if you place the parameter
between "" you can uses spaces for the parameter.
There is also a functionlity that is called
tokenpaste. If you are going to extend a word or change one part of it you kan
use tokenpaste.
#define MACRO( phone ) 000-##phone goes
to XXX.
Type "MACRO( 12345678 )" and expand
it. You will then get "000-12345678 goes to XXX"
Description of the macro language
The rules for creating
macros is similar to create macros in C
There are
some keywords that is used to create a macro.
#define
This word marks that we are going to create a new macro.
EXAMPLE:
#define NEW_MACRO This is a new macro
We now have defined a macro that is called
"NEW_MACRO" and the text macro is replace with is "This is a new
macro".
#start
if the macro text is long or you need
to wrap lines, you can use #start (ends with #end)
EXAMPLE:
#define NEW_MACRO
#start
The macro text for the macro
NEW_MACRO is between at start and a end
keyword.
#end
Here the
macro text for NEW_MACRO is written between #start and #end key words.
#end
#end ends a macro block that start with
#start.
If you have a macro and
don't want to use the #start and #end marks you can wrap lines. This is done
with the backslash character.
EXAMPLE:
#define NEW_MACRO This text is \
going to be
replace \
when NEW_MACRO is selected.
Here the text for macro NEW_MACRO is broken to many rows. The character
that brakes each line is the backslash character.
To
write a backslach character in macro text you need to type two.
EXAMPLE:
#define NEW_MACRO A backslash \\ should
be like two backslashes in macro text.
##
Token-paste is
used when you have a parameter in a macro that is going to be merged with a
word.
EXAMPLE:
#define
NEW_MACRO( rest ) aaaaaa##restbbbbbb
If you write
"NEW_MACRO( xxxx )" and expand it you will get
"aaaaaaxxxxbbbbbb".
If a parameter is more than one word you need to put it between double
quotation marks.
EXAMPLE:
#define NEW_MACRO( rest ) aaaaaa##restbbbbbb
If
you write "NEW_MACRO( "xxxx yyyy")" and expand it you will
get "aaaaaaxxxx yyyybbbbbb".
Parameters
A macro
can have parameters. This is for making the macros more flexible.
EXAMPLE:
#define PARAM( one, two,
three ) Parameters are one two three
If you then type
PARAM( FIVE, SIX, SEVEN ) and expand that you will get "Parameters are FIVE
SIX SEVEN".
When you type
macros in editor and choose to expand them. There is some intelligence to parse
the macro. If you have a macro that is like:
#define
MACRO( one, two ) this number is one and this is two.
If
you type and select the following text you will get the same result
MACRO( ONE, TWO )
MACRO ONE, TWO
MACRO ONE TWO
GDexpi will try
to add parentheses and comma where it thinks it has been forgotten. If you don't
have selected the text and press the GDexpi command it will selext the whole
line and try to extract the macro for expansion.
If you don't know what
parameters a macro can have the type the macro with a ? before. If for example
a
macro i called "test" and i takes two parameters that are named
one and two. The macro definition is
#define test( one, two ) ......
If
you type "?test" and press the command button it will be expanded to
"test(one,two)". Use this if you have
forgotten wich parameters the
macro had.