OCamlPro/ocp-index — pull request #43 by Drup (2014-07-27 07:36:18+00:00)
Title: ocp-browser, revisited

I started working on it last week again, and I'm quite happy with it now, so here it is. It's not mergeable just yet, though.

Basically, it's a reimplementation of ocp-browser with lambda-term. For now, it produces an executable called ocp-lambda, but I will replace ocp-browser before merging.
As far as I can tell, it's feature par with the current version of ocp-browser with some improvements:
- A correct line editor mode (the same as utop, and share with it most shortcuts).
- Doesn't segfault on terminal resizing anymore.
- Is utf-8 aware.
- Configurable themes, as utop (and key bindings once I add it).
- Module movement mode, using alt + arrow keys.
- Various misc stuff.

There is room for improvement before merging:
- The code is a bit too big. Several functions are general purpose and should be merged into the appropriate library. In particular the 200 lines `line_editor` class and most of the style text manipulation.
- Once the next version of lambda-term lands, I will be able to add modal dialogs and implement an help menu inside the application.
- Restrict input to only ascii chars (since they are the only one valid in OCaml's identifier) ?
- Try to preserve the "cursor" position at various occasions (when moving inside the input line or when going back in the module hierarchy).
- A shortcut to print more informations on the selected identifier (library origin, doc through cmt's (printed by default for now, but shouldn't), etc).
- Figure out what to do with long module names.
- Improve how is chosen the set of value viewed in the output box (so that, for example, everything is always shown when everything fit in the window).

Some note on the implementation:

The terminal is separated in two widgets : the `completion_box` and the `show_box`. `completion_box` is inside a `frame_info`, a normal frame with kind informations on the right top. `completion_box` is a `line_editor` invoking `LibIndex.complete` each time the list of completion is requested. `show_box` is a widget containg a list of `LibIndex.info` and will draw as much entry as fit in the window every time asked too.
The two are connected by signals processed by the function `show_completion`.

- I use variant and record disambiguation a lot in this file (mostly due to the way lambda-term is architectured) so I disabled warning 40.
- There is a piece of code that uses a string Hashtbl to pass color though Format's tag ... I don't like this code **at all**. If you have any better proposition, I'll take it.
- As I said, `line_editor` is big (and I didn't actually wrote most of it) and it's bit hard to decipher, but I hope it will be merged in lambda-term.