| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
15.1 The Preferences Dialog 15.2 Customizing the Menu and Tool Bar 15.3 Adding Support for New Languages 15.4 Defining Text Aliases 15.5 Defining New Styles and Key Bindings 15.6 Scripting GPS
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Edit->Preferences, allows you to
modify the global preferences of GPS.
To enable the new preferences, you simply need to confirm by pressing
the OK button. To test your changes, you can use the Apply
button. Pressing the Cancel button will undo all your changes.

Each preference is composed of a label displaying the name of the preference, and an editing area to modify its value. If you leave to mouse over the label, a tool tip will be displayed giving an on-line help on the preference.
The preferences dialog is composed of eight areas, accessible through the tabs at the left of the dialog, labeled General, Editor, Debugger, Helpers, Browsers, Visual Diff, Messages and Project. Each page corresponds to a section of preferences.
The general preferences are composed of two pages available at the top of the right area: General and Windows
Emacs and Default
{}[]()
Each modified file is saved under a file called .#filename, which is
removed on the next explicit save operation.
xterm -geometry 80x50 -exec vi +%l %f |
The following substitutions are provided:
%l
%c
%f
%e
%p
%%
variable1,
variable2,
variable3 : Integer;
|
case Value is
when others =>
null;
end case;
|
If this preference is set to False, this would be indented as:
case Value is when others => null; end case; |
Note that in this mode under Windows, the Debug->Interrupt menu
will not interrupt the debugged program. Instead, you need to hit
Ctrl-C in the separate execution window to interrupt it while it is
running.
If false, no execution window will be created. The debugger assumes that the program being debugged does not require input, or that if it does, input is handled outside GPS. For example, when you attach to a running process, this process already has a separate associated terminal.
rsh -l user
rcp -l user
a2ps, available under GNU/Linux
systems. This utility can be used on most Unix systems, and can be downloaded
from http://www.inf.enst.fr/~demaille/a2ps
Under Windows systems, a possible replacement is the PrintFile freeware utility which is available from http://www.lerup.com/printfile/descr.html
-c nor -u switch).
Arguments of interest may include (this will depend on the version of diff
used):
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Then, you can simply navigate through the menus, and type the key binding you want to associate to a particular item. To remove a key binding, use the Backspace key. Your changes will be saved when GPS exits, in a file called `$HOME/.gps/custom_keys'. In particular, this means that if for some reason you need to edit the file manually, you need to do it outside of GPS, or save the file under a different name, and rename it after exiting GPS.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Here is an example for such a file:
<?xml version="1.0"?>
<Custom>
<Submenu>
<Title>custom menu</Title>
<Menu_Item>
<Title>item 1</Title>
<Action>external-command 1</Action>
</Menu_Item>
<Submenu>
<Title>other menu</Title>
<Menu_Item>
<Title> (etc..)
</Menu_Item>
<Submenu>
(...)
</Submenu>
</Submenu>
</Submenu>
</Custom>
|
The example above creates a top-level menu named custom menu.
This menu contains a menu item named item 1, which is associated to the
shell command external-command 1, a sub menu named other menu,
etc...
Note for Windows users: like under UNIX, scripts can be called
from custom menu. In order to do that, you must write your script in a
`.bat' or `.cmd' file, and call this file using cmd /c.
Thus, the Action tag would look like:
<Action>cmd /c c:\.gps\my_scripts\my_command.cmd</Action> |
As well as external commands, you can use custom menu items to invoke GPS
commands using the GPS_Action tag. The following example shows how to
create a menu to invoke the help interactive command and to open the
file `main.c'.
<Submenu>
<Title>Edit</Title>
<Menu_Item>
<Title>List GPS commands</Title>
<GPS_Action>help</GPS_Action>
</Menu_Item>
<Menu_Item>
<Title>Edit main.c</Title>
<GPS_Action>edit main.c</GPS_Action>
</Menu_Item>
</Submenu>
|
See below for more information on this GPS_Action tag.
You can define the accelerator keys for your menus, using underscores
in the titles. Thus, if you want an accelerator on the first letter in
a menu named File, set its title as _File.
You can add items or sub menus to existing menus, using titles for
menus that already exist. For example, this adds an item named
Robert to the Edit menu.
<Submenu>
<Title>Edit</Title>
<Menu_Item>
<Title>Robert</Title>
</Menu_Item>
</Submenu>
|
Use the / separator to identify the sub menu in a menu. For
example, this adds a sub menu named Olga containing an item named
Item to the Edit menu.
<Submenu>
<Title>Edit/Olga</Title>
<Menu_Item>
<Title>Item</Title>
</Menu_Item>
</Submenu>
|
Adding an item with an empty title or no title at all inserts a menu separator.
The following tags are available in a Submenu section:
Title
Submenu or Menu_Item: set title of the submenu or
menu item.
Menu_Item
Action
GPS_Action
lang. The default value for this attribute is
shell, i.e. the command is written with the GPS shell.
When programming with the GPS shell, you can execute multiple commands by separating them with semicolons. Therefore, the following example adds a menu which lists all the files used by the current file, in a project browser. Note: due to some current limitation of the parsing of the custom files, the '%' argument must be surrounded by spaces, as shown in the example.
<Menu_Item> <Title>Current file uses</Title> <GPS_Action lang="shell">File %f ; File.uses $1</GPS_Action> </Menu_Item> |
It is possible to mix both shell commands and external commands. For instance, the following command opens an xterm (on Unix systems only) in the current directory, which depends on the context.
<Menu_Item> <Title>_Xterm in current directory</Title> <GPS_Action lang="shell">cd %d</GPS_Action> <Action>xterm</Action> </Menu_Item> |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
<Toolbar_Item> tag in place of the <Submenu> tag.
Within this tag, the tag <Pixmap> can be used to indicate
the location of an image file (of the type jpeg, png, gif
or xpm) to be used as icon for the button. An empty
<Toolbar_Item> tag indicates a separator in the tool bar.
<Toolbar_Item> <Title>Custom Button</Title> <Pixmap>/my_pixmaps/button.jpg</Pixmap> <GPS_Action>my gps command</GPS_Action> </Toolbar_Item> |
The following tags are available in a Toolbar_Item section:
Title
Pixmap
Action
GPS_Action
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Action node in a menu or tool bar item,
you can use macro arguments to pass to your shell commands. Macro arguments
are special parameters that are transformed every time the command is executed.
The following macro arguments are provided:
%f
%F
%p
%pp
%PP
%(p|P)[r](d|s)[f]
P
p
r
d
s
f
%Ps
%prs
%prdf
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
You can define new languages in a custom file by using the Language
tag. Defining languages gives GPS the ability to highlight the syntax of a
file, explore a file (using e.g. the project explorer), and find files
associated with a given language.
As described previously for menu items, any file in the `customize' directory will be loaded by GPS at start up.
The following tags are available in a Language section:
Name
Spec_Suffix
Body_Suffix
Keywords
Keywords tags can be specified, and will be concatenated
into a single regular expression.
The full grammar of the regular expression can be found in the spec of the file `g-regpat.ads' in the GNAT run time.
Context
Comment_Start
Comment_End
New_Line_Comment_Start
String_Delimiter
Quote_Character
\ in C).
Constant_Character
Can_Indent
Syntax_Highlighting
Case_Sensitive
Categories
Category nodes,
each describing the characteristics of a given category, with the following
nodes:
Name
Pattern
Keywords node, multiple Pattern tags can be
specified and will be concatenated into a single regular expression.
Index
Here is an example of a language definition for the GPS project files:
<?xml version="1.0"?>
<Custom>
<Language>
<Name>Project File</Name>
<Spec_Suffix>.gpr</Spec_Suffix>
<Keywords>^(case|e(nd|xte(nds|rnal))|for|is|</Keywords>
<Keywords>limited|null|others|</Keywords>
<Keywords>p(ackage|roject)|renames|type|use|w(hen|ith))\b</Keywords>
<Context>
<New_Line_Comment_Start>--</New_Line_Comment_Start>
<String_Delimiter>"</String_Delimiter>
<Constant_Character>'</Constant_Character>
<Can_Indent>True</Can_Indent>
<Syntax_Highlighting>True</Syntax_Highlighting>
<Case_Sensitive>False</Case_Sensitive>
</Context>
<Categories>
<Category>
<Name>package</Name>
<Pattern>^[ \t]*package[ \t]+((\w|\.)+)</Pattern>
<Index>1</Index>
</Category>
<Category>
<Name>type</Name>
<Pattern>^[ \t]*type[ \t]+(\w+)</Pattern>
<Index>1</Index>
</Category>
</Categories>
</Language>
</Custom>
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GPS provides a mechanism known as aliases. These are defined
through the menu Edit->Aliases. Each alias has a name, which
is generally a short string of characters. When you type them in any
textual entry in GPS (generally a source editor, but also entry fields
for instance in the file selector), and then press the special
activation key (by default control-o, controlled by a
preference), this name is removed from the source editor, and replaced
by the text you have associated with it.

Alias names may be composed of any character, but must start with a letter. GPS will jump to the start of each word before the current cursor position, and if the characters between this word start and the cursor position is an alias name, this alias is expanded.
The alias editor is divided into three main parts: on the left side, the list of currently defined aliases is shown. Clicking on any of them will display the replacement text for this alias. If you click again the selected alias, GPS displays a text entry which you can use to rename an existing alias. Alias names must start with a letter. A check button at the bottom selects whether the read-only aliases (i.e. system-wide aliases) should be displayed.
The second part is the expansion text for the alias, at the bottom right corner. This replacement text can used multiple lines, and contain some special text that act as a special replacement. These special texts are highlighted in a different color. You can insert these special entities either by typing them, or by right-clicking in the editor, and select the entity in the contextual menu.
The following special entities are currently defined:
%_
%(name)
%D
%H
%l
%c
%f
%d
%p
%P
The indentation as set in the expansion of the alias is preserved when the alias is expanded. All the lines will be indented the same amount to the right as the alias name.
The third part of the aliases editor, at the top right corner, lists the parameters for the currently selected alias. Any time you insert a %(name) string in the expansion text, GPS automatically detects there is a new parameter reference (or an old reference has changed name or was removed); the list of parameters is automatically updated to show the current list.
Each parameters has three attributes:
When an alias that contains parameters is expanded, GPS will first display a dialog to ask for the value of the parameters. You can interactively enter this value, which replaces all the %(name) entities in the expansion text.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GPS manages multiple aliases files. One of them is editable
interactively by the user through the Edit->Aliases menu,
whereas all the others are defined system-wide, and are not editable
interactively.
The user-defined file is `$HOME/.gps/aliases'.
The system files are all the files stored in the directory `<prefix>/share/gps/aliases', where `<prefix>' is the path in which GPS was installed. The aliases defined in these files are read-only, and indicated as such in the aliases editor.
All the files have the same XML format, which can be seen in the following example. Each alias has its own <alias> tag.
<?xml version="1.0"?>
<Aliases>
<alias name="proc" >
<param name="p" >Proc1</param>
<param environment="true" name="env" />
<text>procedure %(p) is
%(env)%_
end %(p);</text>
</alias>
</Aliases>
|
The following tags are available:
alias
name, which the text to type in the source editor
before pressing control-o.
param
alias node. There is one per
parameter of the alias. They have one mandatory attribute,
name, which is the name to type between %(name) in the
alias expansion text.
They have one optional attribute, environment, which indicates
the default value must be read from the environment variables if it is
set to true.
These tags contain text, which is the default value for the parameter.
text
alias node, whose value is the
replacement text for the alias.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In addition to the preferences dialog, GPS can be configured through the Gtk+ mechanism of `RC files'. You can create a text file called `gtkrc' in the gps home directory (`~/.gps' on Unix systems), or as a global change, in the directory etc/gps in the GPS installation.
This file follows the Gtk+ resource file syntax and gives the possibility in particular to define a number of styles and key bindings and attach them to particular visual objects such as text editors, menu items, ...
For example, you can set Ctrl-v in the source editors to scroll forward one page. The following code defines this new key binding:
# Create new key bindings for text editors
binding "custom-text-key"
{
# define Ctrl-v to scroll forward one page
bind "<ctrl>v" { "move-cursor" (pages, 1, 0) }
}
# Associate the new binding created above with text editors
class "GtkTextView" binding "custom-text-key"
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
# characters delimit comments and the portion of a line after a
# is ignored when parsing an RC file.
The syntax of the top-level declarations is described below.
Opening/closing brackets on the same line ({ ... }) are used to represent
a sequence of 0 or more elements. Brackets on their own line are real bracket
characters.
toplevel-declarations ::=
{ declaration }
declaration ::=
include-file | pixmap-path | style-definition | binding-definition |
enable-resource
include-file ::=
include string_literal
pixmap-path ::=
pixmap_path string_literal
style-definition ::=
style resource-name [ = parent ]
{
sequence-of-style
}
binding-definition ::=
binding resource-name
{
sequence-of-binding
}
enable-resource ::=
class "widget-name" (binding | style) resource-name
resource-name ::=
string_literal
|
The table below describes the meaning of each of these toplevel declarations:
include filename
pixmap_path path
style name [ = parent ] { ... }
style "my-style" = "default" { ... }
|
See Defining new styles for more details.
binding name { ... }
class widget-name (binding | style) name
resource-name
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
For example, the following code will change the background color of any button, when it is pressed. It will also set a background pixmap when it is not pressed. The style also inherits from the one above, so that the buttons also use the default font.
pixmap_path "directory_that_contains_the_pixmap"
style "custom-button" = "default"
{
bg_pixmap[NORMAL]="pixmap_file"
bg[ACTIVE]="blue"
}
class "GtkButton" style "custom-button"
|
Here is the syntax for defining styles:
sequence-of-style ::=
{ style | property }
style ::=
style-name[state] = string_literal
style-name ::=
bg | fg | base | text | bg_pixmap | font_name
state ::=
NORMAL | ACTIVE | PRELIGHT | SELECTED | INSENSITIVE
property ::=
widget-name::widget-property = value
widget-property ::=
cursor-aspect-ratio | cursor-color
|
The table below describes the meaning of each of these elements:
bg[state] = color
fg[state] = color
base[state] = color
text[state] = color
bg_pixmap[state] = pixmap
font_name = font
GtkTextView::cursor-aspect-ratio = value
GtkTextView::cursor-color = color
The colors and background pixmaps are specified as a function of the state of the visual object. The states are:
NORMAL
ACTIVE
PRELIGHT
SELECTED
INSENSITIVE
Colors can be specified as a string containing a color name (under Unix
systems, GTK+ knows all names from the X color database /usr/lib/X11/rgb.txt),
in one of the hexadecimal forms #rrrrggggbbbb, #rrrgggbbb,
#rrggbb, or #rgb, where r, g and b
are hex digits, or they can be specified as a triplet {r, g, b}, where
r, g and b are either integers in the range 0-65535 or floats in the range
0.0-1.0.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
sequence-of-binding ::=
{ binding }
binding ::=
bind "key-name"
{
sequence-of-commands
}
sequence-of-commands ::=
{ command }
command ::=
"command-kind" (parameters)
parameters ::=
[first-parameter {, number}]
widget-name ::=
GtkButton | GtkDialog | GtkEntry | GtkMenuItem |
GtkMenuShell | GtkTextView | GtkTreeView
command-kind ::=
move-cursor | page-horizontally | set-anchor | insert-at-cursor |
delete-from-cursor | cut-clipboard | copy-clipboard | paste-clipboard |
toggle-overwrite | move-focus | activate | select-all | unselect-all |
select-cursor-row | toggle-cursor-row | expand-collapse-cursor-row |
select-cursor-parent | start-interactive-search | clicked | close |
move-current
first-parameter ::=
movement-step | count | extend-selection | delete-type | start-editing |
logical | expand | expand-all | menu-direction | string_litteral
number ::=
[-|+]digit{digit}
key-name ::=
{modifier}key
modifier ::=
<ctrl> | <alt> | <shift>
key ::=
letter | digit |
BackSpace | Tab | Return | Pause | Scroll_Lock | Sys_Req | Escape |
Delete | Home | Left | Up | Right | Down | Page_Up | Page_Down | End |
Insert | Break | Num_Lock |
F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 |
Caps_Lock | space | exclam | quotedbl | numbersign | dollar | percent |
ampersand | apostrophe | quoteright | parenleft | parenright | asterisk |
plus | comma | minus | period | slash | colon | semicolon | less |
equal | greater | question | at | bracketleft | backslash |
bracketright | underscore | grave | quoteleft | braceleft | bar |
braceright
|
The list of valid command-kind values and their parameters depend on
the widget name:
GtkButton
clicked ()
GtkDialog
close ()
GtkEntry
activate ()
move-cursor (movement-step, count, extend-selection)
insert-at-cursor (string)
delete-from-cursor (delete-type, count)
cut-clipboard ()
copy-clipboard ()
paste-clipboard ()
toggle-overwrite ()
GtkMenuItem
activate ()
GtkMenuShell
move-current (menu-direction)
GtkTextView
move-cursor (movement-step, count, extend-selection)
page-horizontally (count, extend-selection)
set-anchor ()
insert-at-cursor (string)
delete-from-cursor (delete-type, count)
cut-clipboard ()
copy-clipboard ()
paste-clipboard ()
toggle-overwrite ()
GtkTreeView
move-cursor (movement-step, count)
select-all ()
unselect-all ()
select-cursor-row (start-editing)
toggle-cursor-row ()
expand-collapse-cursor-row (logical, expand, expand-all)
select-cursor-parent ()
start-interactive-search ()
The possible values of the parameters listed above are:
count
string
extend-selection, start-editing, logical, expand, expand-all:
delete-type
chars
word-ends
paragraph-ends
paragraphs
whitespace
menu-direction
parent
child
next
prev
movement-step
logical-positions
visual-positions
words
display-lines
display-line-ends
paragraphs
paragraph-ends
pages
buffer-ends
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
15.6.1 Scripts 15.6.2 The GPS Shell
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Scripts are small programs that interact with GPS and allow you to perform complex tasks repetitively and easily. GPS includes support for two scripting languages currently, although additional languages might be added in the future. These two languages are described in the following section.
Support for scripting is currently work in progress in GPS. As a result, not many commands are currently exported by GPS, although their number is increasing daily. These commands are similar to what is available to people who extend GPS directly in Ada, but with a strong advantage: they do not require any recompilation of the GPS core, and can be tested and executed interactively.
The goal of such scripts is to be able to help automate processes such as builds, automatic generation of graphs,...
All the scripting languages share the same set of commands exported by GPS, thanks to a abstract interface defined in the GPS core. As a result, GPS modules do not have to be modified when new scripting languages are added.
Scripts can be executed immediately upon startup of GPS by using the
command line switch --load. Specifying the following command
line:
gps --load=shell:mytest.gps |
will force the gps script `mytest.gps' to be executed immediately, before GPS starts reacting to user's requests. This is useful if you want to do some special initializations of the environment. It can also be used as a command line interface to GPS, if you script's last command is to exit GPS.
In line commands can also be given directly on the command line through
--eval command line switch.
For instance, if you want to analyze an entity in the entity browser from the command line, you would pass the following command switches:
gps --eval=shell:'Entity entity_name file_name; Entity.show %1' |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The GPS shell is a very simple-minded, line-oriented language. It is
accessible through the Shell window at the bottom of the GPS
window. It is similar to a Unix shell, or a command window on Windows
systems.
Type help at the prompt to get the list of available commands,
or help followed by the name of a command to get more
information on that specific command.
The following example shows how to get some information on a source entity, and find all references to this entity in the application. It searches for the entity "entity_name", which has at least one reference anywhere in the file "file_name.adb". After the first command, GPS returns an identifier for this entity, which can be used for all commands that need an entity as a parameter, as is the case for the second command. When run, the second command will automatically display all matching references in the location window.
GPS> Entity my_entity file_name.adb <Entity_0x09055790> GPS> Entity.find_all_refs <Entity_0x09055790> |
Since the GPS shell is very simple, it doesn't provide any reference
counting for the result types. As a result, all the values returned by
a command, such as <Entity_0x09055790> in the example above,
are kept in memory.
The GPS shell provides the command clear_cache which removes
all such values from the memory. After this command is run, you can no
longer use references obtained from previous commands, although of
course you can run these commands again to get a new reference.
The return value of the 9 previous commands can easily be recalled by
passing %1, %2,... on the command line. For instance,
the previous example could be rewritten as
GPS> Entity my_entity file_name.adb <Entity_0x09055790> GPS> Entity.find_all_refs %1 |
These return values will be modified also for internal commands sent
by GPS, so you should really only use this when you emit multiple
commands at the same time, and don't do any other action in GPS. This
is mostly useful when used for command-line scripts (see --eval
and --load), or for custom files, See section 15.2 Customizing the Menu and Tool Bar.
In future versions of GPS, it will be possible to use more advanced scripting
languages such as Python.
| [ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |