0
votes

I'm looking in to a way to improve the autocomplete for GPS ADA (Version: GPS 6.0.1 with GNAT Pro 6.4.2).

GPS autocomplete searches for matches which begin with the text you entered.

I would like to match my string anywhere in the text.

Currently the regex would be something like: /myString.*/i

I would like it to be: /.*myString.*/i

  1. Is there an option I've missed to do this?
  2. Does anyone know of a GPS plugin that does this?

I've also had a look into writing this plugin myself, the documentation at http://docs.adacore.com/gps-docs/users_guide/_build/html/GPS.html#GPS.Completion which references "completion.py" - which i haven't been able to find - i'm guessing this may have only been included with later verisons of GPS.

1
Those are the Pro versions - a bit out of date, as you suggest - are you supported by AdaCore? If so, best to upgrade if at all possible, they may have already done what you want. The rest of us are on at most 5.2.1. - Simon Wright

1 Answers

2
votes

You could indeed write this yourself (recent developments of GPS do not include this feature, which I believe was never requested before).

The goal is to define an action, which you can then bind to a key shortcut. So for instance the plug-in would start with something like:

import GPS, gps_utils

@gps_utils.interactive(name='My Completion', filter='Source editor'):
def my_completion():
    buffer = GPS.EditorBuffer.get()       # the current editor
    loc = buffer.current_view().cursor()  # the current location
    start = loc.forward_word(-1)          # beginning of word
    end = loc.forward_word(1)             # end of word
    text = buffer.get_chars(start, end)   # the text the user is currently typing

    # then search in current buffer (or elsewhere) for matching text
    match = buffer.beginning_of_buffer().search(text)
    if match:
       match_start, match_end = match
       match_text = buffer.get_chars(match_start, match_end)

       # then go back to initial location, remove text and replace with match
       buffer.delete(start, end)
       buffer.insert(start, match_text)

This is a rough outline, there are likely hundreds of details that I did not look at. It should get your started though.