When an action is defined, you can use macro arguments to pass to your shell or external commands. Macro arguments are special parameters that are transformed every time the command is executed. The following macro arguments are provided.
The equivalent python command is given for all tests. These commands are useful when you are writing a full python script, and want to test for yourself whether the context is properly defined.
%a
%builder
gnatmake
if your project contains only Ada code,
or gprbuild
for non Ada or multi-language projects, or gprmake
if you have set the multi language builder preference accordingly.
Note: this macro is only available in the commands defined in the Build
Manager and the Build Launcher dialogs.
%c
GPS.current_context().column()
%d
GPS.current_context().directory()
%dk
%e
GPS.current_context().entity().name()
%E
%ek
%e
, except long names are shorted as in %fk
.
%eL
-eL
, depending on whether the
Fast Project Loading
preference if set or not.
-eL
is used by GNAT tools to specify whether symbolink links
should be followed or not when parsing projects.
Note: this macro is only available in the commands defined in the Build
Manager and the Build Launcher dialogs.
%external
%f
import os.path os.path.basename (GPS.current_context().file().name())
%F
GPS.current_context().file().name()
%fk
%fp
%gnatmake
%gprbuild
%gprclean
gnat clean
, or gprclean
.
Note: this macro is only available in the commands defined in the Build
Manager and the Build Launcher dialogs.
%i
%l
GPS.current_context().line()
%o
%O
%p
GPS.current_context().project().name()
%P
GPS.Project.root().name()
%Pb
%Pl
%pp
GPS.current_context().project().file().name()
%PP
GPS.Project.root().file().name()
%pps
%pp
, except it returns the project name prepended
with -P
, or an empty string if there is no project file selected and the
current source file doesn't belong to any project. This is mostly for use with
the GNAT command line tools. The project name is quoted if it contains spaces.
Python equivalent:
if GPS.current_context().project(): return "-P" & GPS.current_context().project().file().name()
%PPs
%PP
, except it returns the project name prepended
with -P
, or an empty string if the root project is the default project.
This is mostly for use with the GNAT command line tools.
%(p|P)[r](d|s)[f]
P
p
r
d
Python equivalent:
GPS.current_context().project().source_dirs()
s
Python equivalent:
GPS.current_context().project().sources()
f
%s
%S
%switches(tool)
IDE'Default_Switches (tool)
, in other words, if you
have a tool whose switches are defined via an xml file in GPS, they
are stored as Default_Switches (xxx)
in the IDE
package
and can be retrieved using this macro. The value returned is a list of
switches, or an empty list if not set.
Note: This macro is only available in the commands defined in the Build
Manager and Build Launcher dialogs.
%T
%TT
%TT
, but returns the full path to main sources rather than
the base filename.
%attr(Package'Name[,default])
Package'Name
, in other words, the
attribute Name
from the package Package
. Package'
is
optional if Name
is a top level attribute (e.g. Object_Dir
).
If the attribute is not defined in the project, an optional default
value is returned, or an empty string if not.
Note: This macro is only available in the commands defined in the Build
Manager and Build Launcher dialogs, and only supports single string attributes,
not lists.
%dirattr(Package'Name[,default])
%attr
above.
%baseattr(Package'Name[,default])
%attr
above.
%vars
<variable>=<value>
, where
<variable> is the name of a scenario variable and <value> its current
value, as configured in the Scenario View. All the scenario variables
defined in the current project tree will be listed.
Alternatively, you can also use %vars(-D)
to generate a list of
switches of the form -D<variable>=<value>
.
Note: this macro is only available in the commands defined in the Build
Manager and the Build Launcher dialogs.
%X
-X<variable>=<value>
, where
<variable> is the name of a scenario variable and <value> its current
value, as configured in the Scenario View. All the scenario variables
defined in the current project tree will be listed.
Note: this macro is only available in the commands defined in the Build
Manager and the Build Launcher dialogs.
%%
%Ps
%prs
%prdf
Another type of macros are expanded before commands are executed: These
all start with the $
character, and represent parameters passed to
the action by its caller. Depending on the context, GPS will give zero, one
or more arguments to the action. This is in particular used when you define
your own VCS system. See also the shell function execute_action
, which
you can use yourself to execute an action and pass it some arguments.
These arguments are the following
$1, $2, ... $n
$1-, $2-, ... $n-
$*
$repeat
"Repeat Next"
, which allows automatic
repetition of an action.
By default, when the action "Repeat Next" is invoked by the user, it will repeat the following action as many times as the user specified. However, in some cases, either for efficiency reasons or simply for technical reasons, you might want to handle yourself the repear. This can be done with the following action declaration:
<action name="my_action"> <shell lang="python">if $repeat==1: my_function($remaining + 1)</shell> </action> def my_function (count): """Perform an action count times""" ...
Basically, the technics here is to only perform something the first time the
action is called (hence the if statement), but pass your shell function the
number of times that it should repeat (hence the $remaining
parameter).
$remaining