Capture the goal from the interactive mode

I am looking for a predicate that captures the goal from the interactive mode.
When I am in the interactive mode, I would like something like this:

Welcome to SWI-Prolog (threaded, 64 bits, version 8.0.3)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit http://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- append([this, is, some], [predicate], X), capture_goal(G).
X = [this, is, some, predicate],
G = ['append([this, is, some], [predicate], X)', 'capture_goal(G)'].

I know how to capture the command line entry with current_prolog_glag(os_argv, Args) but I want to capture the goal inside the interactive mode.
Running swipl -g is not an option for me.

There are two options. Misuse this https://www.swi-prolog.org/pldoc/doc_for?object=expand_query/4 hook or make sure one of the command line history libraries is included and query that. There is no official and documented interface for that. What do you want to achieve?

Possibly https://www.swi-prolog.org/pldoc/man?section=wizard is related and provides hints?

1 Like