Gem #66: GPS's Key Shortcuts Editor

Let's get started…

There are several ways in which the keyshortcuts can be changed in GPS.

One of the common cases is a user previously using the Emacs editor. GPS comes with a plug-in that will change the default key bindings in GPS. You just need to go to the /Tools/Plug-ins menu, and activate the "emacs.xml" plug-in. Note that for full compatibility with Emacs, you should also load some additional plug-ins (these are documented in the Description tab).

Similar plug-ins can be built for other editors, and shared with the rest of your team.

The most flexible method, however, is to go to the /Edit/Key Shortcuts menu. This will open a dialog in which you can configure shortcuts for any of the menus or any of the actions that GPS has created.

At this point, we should explain the difference between actions and menus. Internally, GPS exports its various features to the GUI as named actions. These actions are implemented either in Ada or using one of the scripting languages supported by GPS (python or XML for instance). They are organized into categories to make them easier to find. You can also create your own actions through XML files (see the GPS documentation for more details).

Most of the time, these actions are hidden and called in the background. But you can activate the "execute extended" plug-in if you want to be able to directly execute these commands by name, as Emacs does through its "M-x" key binding.

Some of these actions are then bound to menus or contextual menus.

Back to the Key Shortcuts editor. The main part of the dialog shows the list of actions exported by GPS. These are organized into categories. One of them is special, and is called "Menus". It gives you access to all the menus of GPS (so some actions are accessible in two places, either by category/name, or by the menu). If you activate the "Flat List" button, the actions will instead be listed alphabetically and the categories will no longer be visible.

Next to each action or menu, GPS displays the shortcut associated with that action. One limitation here is that the shortcut is either shown next to the menu or next to the action (depending on how it was setup), but not both.

Here's a small trick if you want to find out what a shortcut is bound to. You can click on both the "Flat List" and the "Shortcuts Only" buttons. This will list only those actions which currently have a shortcut associated. By clicking on the "Shortcut" column header, you can then sort the list by shortcut, thus making it easy to find out what a specific key shortcut does.

Through this dialog, you can change the shortcut for any of the actions. Simply select that action in the list, then press the "Grab" button, and you can then press the keyboard shortcut that you want to assign to it.

Key shortcuts are not limited to a single key (which on a standard keyboard would not provide enough shortcuts for those Emacs users). You can in fact have a series of shortcuts, as in "Control-x k", which is used in Emacs to close the current window. Due to limitations in the gtk+ toolkit on which GPS is based, however, the menus are only able to display single shortcuts, so if you assign the above shortcut to a menu you can use the shortcut but it will not be visible in the menu itself.

Once you close the dialog with "OK", the shortcut becomes effective immediately, and will be preserved from session to session. In fact, the key shortcuts you just created are saved in an XML file (keys.xml) in your $HOME/.gps directory. You can thus copy this file to other accounts or setups to automatically get the same shortcuts again.


Last Updated: 10/26/2017
Posted on: 6/1/2009