Skip to content
Andrew Ray edited this page Feb 19, 2014 · 2 revisions

Tips and tricks

Keyboard shortcuts

ctrl+m- most keyboard commands are prefixed by this followed by one more keypress

ctrl+m-h show popup with available keyboard shortcuts

Code execution

shift+enter execute the current cell, then move down to the next one. If there is no cell below create one.

ctrl+enter execute and stay in the current cell

ctrl+m-. restart iocaml kernel (doesn't quit page)

Inserting cells

ctrl+m-a insert cell above

ctrl+m-b insert cell below

Cell types

ctrl+m-m markdown cell

ctrl+m-y code cell

ctrl+m-1,2 etc heading level

Code completion and info

IOCaml uses the ocp-index tool to look up information about identifiers from system installed libraries.

If the character directly to the left of the cursor could be part of an identifier the notebook will send a completion request. IOcaml will respond by scanning backwards until it reaches a character that is not alpha-numeric, a dot, a hash or an underscore. This token is then looked up by ocp-index to find possible completions and sent back to the notebook. The user can then select an identifier from a popup list. A further tab press will complete the word or escape will dismiss the popup. If there is only one possible completion the popup is not shown and the word is completed. The system also completes ocaml keywords.

An object information request creates a popup with type information and, possibly, documentation strings. The notebook sends this message when tab is pressed and there is an identifier followed by one space (or open bracket) before the cursor. Pressing tab a second time expands the window. A third press will make the window stay up for a further 10 seconds while the user types. A fourth press sends the token being queried back to iocaml with a trailing question mark and a request for code execution. This is an IPython artifact which should cause the pager to pop up with full documentation. At the moment it just tends execute an invalid phrase in the top level. It should be disabled if I can find that behaviour in the javascript.

iocaml does not really do enough analysis of the context to be really accurate here, however, even this simple scheme is really very useful.

Probably the most important improvement would be tracking identifiers defined within the notebook.

#install_printer

For a general type t you can write a function printer_function : Format.formatter -> t -> unit which is supposed to print a representation of t to the formatter. It can then be installed to the top level with

#install_printer printer_function

Lets say we have a function mime_printer : t -> unit which displays a nice html based representation of t. We can write printer_function as

let printer_function fmt t = 
    mime_printer t;
    Format.fprintf fmt "<t>"

When installed the top level will now respond with rich representations of user datatypes.