Toplevel Completion, Readline Tweaks, Future Stuff

Ian Tegebo <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <CAFBOwCbhsOfck7fabNttxG+ftiJOwzTn7R_tCo+FPJBz+F=ZXg@mail.gmail.com>
After triggering completion, I'm used to getting a list of candidates
or some kind of feedback about what's possible.  The following tweak's
helped me:

~/.plrc
:- rl_read_init_file('~/.swipl-inputrc').

~/.swi-inputrc
set show-all-if-unmodified On
Control-Space: menu-complete

The "menu-complete" binding is just an extra convenience, I wouldn't
normally expect it.

For the future, I thought I'd look around to see what else is going on
with completion.  I found,

http://stackoverflow.com/questions/17373629/swi-prolog-stream-i-o-and-tab-completion-in-the-swipl-window

which linked to,

https://www.dropbox.com/s/qn246pndp0a08u8/tabber.pl
https://lists.iai.uni-bonn.de/pipermail/swi-prolog/2013/010602.html
https://github.com/CapelliC/pqConsole

I joined this list after the "Console selection headaches" thread took
place.  Jan mentioned something about work going on with CodeMirror
and the desire to leave most of the "heavy lifting" to Prolog and keep
it out of whatever external development environments get used.  What's
the status of both the CodeMirror work (is it available) as well as
any "common completion interface" development?

In any case, I prefer Emacs but use PceEmacs because of its improved
highlighting and feedback.  It would be great if subsequent tools had
an "editor agnostic" approach similar to other projects:

https://github.com/clojure/tools.nrepl
http://ternjs.net/
http://www.typerex.org/

In the short-term, I'd like to have a completion function that
displayed candidates similar to what Zsh can do by parsing '--help'
output.  Here's an example of the kind of output I'd like:

?- foo_<TAB>
foo_bar(+In, -Out) is semidet.                        (A bit of a summary.)
foo_bar(+In, -Out, +Options) is semidet.         (Blah blah blah.)
foo_baz(?SomeInput, ?Something) is nondet. (Another summary.)

This would be quite useful for me as I'm still learning common
predicates, their options, and their modes.  Also, I have a terrible
memory.  Anyway, it looks like I can get the hard parts done when
pldoc_process:doc_comment/4 can be used.

Still, I'd not know exactly how to define the readline completion
function necessary for configuration via ~/.inputrc.  It would appear
that src/os/pl-rl.c is a good guess (and I think Jan mentioned it in
the aforementioned thread), but I'm neither familiar with the FFI nor
the codebase generally.  Right now, I assume I'll need to:

a) Define my completion function in Prolog.
b) Write C code using the FFI to wrap my function.
c) Register the function like: rl_add_defun("prolog-complete",
prolog_complete, '\t');

Is that correct?

As I think about it more, perhaps it's better to expose more of the
readline library to Prolog, esp. rl_add_defun.  That way anyone can
easily register a completion function.  What do you think?

--
Ian Tegebo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.