Re: Toplevel Completion, Readline Tweaks, Future Stuff
Jan Wielemaker <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
On 07/18/2013 12:10 AM, Ian Tegebo wrote:
> 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?
The CodeMirror work defines a mode that is based on a complete Prolog
tokeniser. It provides smart indentation. There is a partially working
prototype to achieve server enhanced syntax highlighting that makes the
output look about the same as PceEmacs. Looks like this is feasible,
although more work needs to be done to make it good enough for practical
work. The current code base is a bit of a mess. Mostly because my lack
of experience with JavaScript and the CodeMirror code base caused quite
some experimenting and backtracking. I'm happy to publish the git repo,
but I fear in the current state it only makes sense if you want to
contribute, not if you just want to use it.
I wrote a small demo completer and sent that to Carlo. He promised to
call that from pqConsole. pqConsole is in a much healthier state than
the Prolog mode for CodeMirror. It isn't ready for prime time and there
are lots of things that can be added with ease. If you have some
experience with C++, you might want to checkout the source, comment and
submit patches.
The overall plan (now) is to make all this work smoothly from pqConsole.
The Prolog code can then be called from the various environments. I
considered adding a common C API to access the completion code. Studying
some of the interface concepts, I started realising that it is probably
just as good to call the Prolog predicate directly from C/C++, though a
socket, or whatever. The common C interface didn't appear to make the
job significantly easier.
> 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?
Something along these lines. The provisional interface is
prolog:complete_input(+BeforeCaret, +AfterCaret, -Completions),
where Completions is a list if atoms that can be inserted at the
current location. I like the idea of allowing comments. Maybe by
providing the completions as pairs
Extend-Comment
So, prolog:complete_input("foo_", "", List) can yield
[ bar-'foo_bar(+In, -Out) is semidet. ....',
bar-'foo_bar(+In, -Out, +Options) is semidet. ...',
baz-'foo_baz(?SomeInput, ?Something) is nondet. ...'
]
Would that be a plan? This almost asks for an option list because
some interfaces might not be interested and computing the comments
for no reason seems a bit wasteful.
> 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?
Not sure about that. I guess that will in general remain gnu readline
specific. My current guess is that we will move away from gnu readline.
pqConsole has much more potential. If you want to invest time, please
invest it there. If you like Eclipse better, invest it in PDT. In any
case, write the reusable parts of the logic in Prolog.
Cheers --- Jan