code completion in SWIPL

View: New views
4 Messages — Rating Filter:   Alert me  

code completion in SWIPL

by Jean-Marc Vanel-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

There is some code completion in the standard query input, with the
tab key, as explained here:

http://hcs.science.uva.nl/projects/SWI-Prolog/articles/wlpe-03.pdf
inspect the possible alternative (using Alt-?)

The relevant paragraph in the The GNU Readline Library documentation is
http://tiswww.case.edu/php/chet/readline/rluserman.html#SEC19

For your convenience, I paste this paragraph :
[cite]
- complete (TAB) Attempt to perform completion on the text before
point. The actual completion performed is application-specific. The
default is filename completion.

- possible-completions (M-?) List the possible completions of the text
before point.

- insert-completions (M-*) Insert all completions of the text before
point that would have been generated by possible-completions.

menu-complete () Similar to complete, but replaces the word to be
completed with a single match from the list of possible completions.
Repeated execution of menu-complete steps through the list of possible
completions, inserting each match in turn. At the end of the list of
completions, the bell is rung (subject to the setting of bell-style)
and the original text is restored. An argument of n moves n positions
forward in the list of matches; a negative argument may be used to
move backward through the list. **This command is intended to be bound
to TAB, but is unbound by default.**


It should not be difficult to bind menu-complete in SWIPL to TAB,
since this behavior of menu-complete is similar to the current
behavior of TAB but better. For those who know, this is the behavior
of the zsh shell.


I could'nt understand how code completion in the XPCE editor works,
looking on the inline help "PceEmacs Bluffers Guide":
[cite]
4.  Prompting for arguments

Any command that requires an argument prompts for them one-by-one in the
``mini-window'' (little window at the bottom).  While the prompt is there, all
typing goes to the prompted-for value.  When all arguments are collected, the
command is executed.  Again, \C-g aborts (entering) the command.

4.1.  Argument completion

If you don't know what to answer, type TAB to see possible alternatives
(completion).


4.2.  Argument history

Each method (=command) maintains a history of arguments you entered before.
The key-strokes \ep and \en move back- and forwards through this history list,
allowing you to reuse previously entered arguments.  This also applies for the
command \ex (see "Commands by Name").


--
Jean-Marc Vanel
http://jmvanel.free.fr/
_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog




Re: code completion in SWIPL

by Jan Wielemaker :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Jean-Marc,

On Monday 19 May 2008 14:35, Jean-Marc Vanel wrote:

> menu-complete () Similar to complete, but replaces the word to be
> completed with a single match from the list of possible completions.
> Repeated execution of menu-complete steps through the list of possible
> completions, inserting each match in turn. At the end of the list of
> completions, the bell is rung (subject to the setting of bell-style)
> and the original text is restored. An argument of n moves n positions
> forward in the list of matches; a negative argument may be used to
> move backward through the list. **This command is intended to be bound
> to TAB, but is unbound by default.**
>
> It should not be difficult to bind menu-complete in SWIPL to TAB,
> since this behavior of menu-complete is similar to the current
> behavior of TAB but better. For those who know, this is the behavior
> of the zsh shell.

I'd assume you can do that in your ~/.inputrc? Otherwise use
rl_read_init_file/1 to read an additional init file for Prolog only.

> I could'nt understand how code completion in the XPCE editor works,
> looking on the inline help "PceEmacs Bluffers Guide":
> [cite]
> 4.  Prompting for arguments
>
> Any command that requires an argument prompts for them one-by-one in the
> ``mini-window'' (little window at the bottom).  While the prompt is there,
> all typing goes to the prompted-for value.  When all arguments are
> collected, the command is executed.  Again, \C-g aborts (entering) the
> command.
>
> 4.1.  Argument completion
>
> If you don't know what to answer, type TAB to see possible alternatives
> (completion).
>
>
> 4.2.  Argument history
>
> Each method (=command) maintains a history of arguments you entered before.
> The key-strokes \ep and \en move back- and forwards through this history
> list, allowing you to reuse previously entered arguments.  This also
> applies for the command \ex (see "Commands by Name").

This must be rewritten.  Since quite a while it starts a dialog window with
a field for each argument.  Arrows and M-[np] go through the history, where
each command that requires arguments has its own history.

If the argument has known values, a drop-down menu is associated to it.

        Cheers --- Jan

_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog

Re: code completion in SWIPL

by Jean-Marc Vanel-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Response below.

2008/5/20 Jan Wielemaker <wielemak@...>:

> Jean-Marc,
>
> On Monday 19 May 2008 14:35, Jean-Marc Vanel wrote:
>> menu-complete () Similar to complete, but replaces the word to be
>> completed with a single match from the list of possible completions.
>> Repeated execution of menu-complete steps through the list of possible
>> completions, inserting each match in turn. At the end of the list of
>> completions, the bell is rung (subject to the setting of bell-style)
>> and the original text is restored. An argument of n moves n positions
>> forward in the list of matches; a negative argument may be used to
>> move backward through the list. **This command is intended to be bound
>> to TAB, but is unbound by default.**
>>
>> It should not be difficult to bind menu-complete in SWIPL to TAB,
>> since this behavior of menu-complete is similar to the current
>> behavior of TAB but better. For those who know, this is the behavior
>> of the zsh shell.
>
> I'd assume you can do that in your ~/.inputrc? Otherwise use
> rl_read_init_file/1 to read an additional init file for Prolog only.

Thanks.
I added just one line in $HOME/.inputrc
TAB: menu-complete

It works ! :-). Maybe the completion could be fed with a opening
parenthesis added for predicates.

Of course the behavior is changed for every application that uses
libreadline, but it's OK. I think it would be good to change the SWI
default system initialization, calling rl_read_init_file/1 on a file
containing just "TAB: menu-complete" .

--
Jean-Marc Vanel
http://jmvanel.free.fr/
_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog

Re: code completion in SWIPL

by Jan Wielemaker :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tuesday 20 May 2008 18:45:11 Jean-Marc Vanel wrote:

> Response below.
>
> 2008/5/20 Jan Wielemaker <wielemak@...>:
> > Jean-Marc,
> >
> > On Monday 19 May 2008 14:35, Jean-Marc Vanel wrote:
> >> menu-complete () Similar to complete, but replaces the word to be
> >> completed with a single match from the list of possible completions.
> >> Repeated execution of menu-complete steps through the list of possible
> >> completions, inserting each match in turn. At the end of the list of
> >> completions, the bell is rung (subject to the setting of bell-style)
> >> and the original text is restored. An argument of n moves n positions
> >> forward in the list of matches; a negative argument may be used to
> >> move backward through the list. **This command is intended to be bound
> >> to TAB, but is unbound by default.**
> >>
> >> It should not be difficult to bind menu-complete in SWIPL to TAB,
> >> since this behavior of menu-complete is similar to the current
> >> behavior of TAB but better. For those who know, this is the behavior
> >> of the zsh shell.
> >
> > I'd assume you can do that in your ~/.inputrc? Otherwise use
> > rl_read_init_file/1 to read an additional init file for Prolog only.
>
> Thanks.
> I added just one line in $HOME/.inputrc
> TAB: menu-complete
>
> It works ! :-). Maybe the completion could be fed with a opening
> parenthesis added for predicates.
>
> Of course the behavior is changed for every application that uses
> libreadline, but it's OK. I think it would be good to change the SWI
> default system initialization, calling rl_read_init_file/1 on a file
> containing just "TAB: menu-complete" .

As far as I'm concerned, I prefer to stick with the readline defaults.
Let everyone adjust these to his/her favourite and let the readline
community decide on the best defaults.  It might be nice to put quotes
around completed filenames that require it and put a ( at the end of
something that must be a predicate with non-zero arity.  I'll leave
that to whoever wants to do a bit of hacking in pl-rl.c.  If you are
really brave, turn completion into a call to Prolog and add a Prolog
library doing clever things :-)

        Cheers --- Jan

 

_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
LightInTheBox - Buy quality products at wholesale price