Repository: ipython/ipython

Issue:
curious behavior on Ijulia on IPython3.0b1 on windows
Hi,

Trying `Pkg.`+`<Tab>` on a cell of a IJulia notebook, I can select `build` in the dropdown window, but when I validate it, only `build`remains in my cell (instead of `Pkg.build`)

(on Firefox as on Chrome)



Discussion:
IPython 3 ? 

My guess problem with the adapter. 
Ping @minrk. 

Will try to reproduce and dig deeper.

Yes,

Python3.4 (as on 2.7, I have  an unexpected "utf-8"  error in tornado / json as soon as I start an Ijulia notebook)
Julia0.3.5 

Doing `Pkg.build` , I notice also that IJulia rebuilds itself as if I was using an old `2.x`kernel

```
INFO: Building IJulia
Found IPython version 3.0.0-b1 ... ok.
Creating julia profile in IPython...
[ProfileCreate] Generating default config file: 'D:\\WinPython\\basedir34\\buildFlavorJulia035\\winpython-3.4.2\\settings\\.ipython\\profile_julia\\ipython_config.py'
[ProfileCreate] Generating default config file: 'D:\\WinPython\\basedir34\\buildFlavorJulia035\\winpython-3.4.2\\settings\\.ipython\\profile_julia\\ipython_kernel_config.py'
[ProfileCreate] Generating default config file: 'D:\\WinPython\\basedir34\\buildFlavorJulia035\\winpython-3.4.2\\settings\\.ipython\\profile_julia\\ipython_console_config.py'
[ProfileCreate] Generating default config file: 'D:\\WinPython\\basedir34\\buildFlavorJulia035\\winpython-3.4.2\\settings\\.ipython\\profile_julia\\ipython_qtconsole_config.py'
[ProfileCreate] Generating default config file: 'D:\\WinPython\\basedir34\\buildFlavorJulia035\\winpython-3.4.2\\settings\\.ipython\\profile_julia\\ipython_notebook_config.py'
[ProfileCreate] Generating default config file: 'D:\\WinPython\\basedir34\\buildFlavorJulia035\\winpython-3.4.2\\settings\\.ipython\\profile_julia\\ipython_nbconvert_config.py'
Adding KernelManager.kernel_cmd = ["D:\\WinPython\\basedir34\\buildFlavorJulia035\\winpython-3.4.2\\tools\\Julia\\bin\\julia.exe", "-i", "-F", "D:\\WinPython\\basedir34\\buildFlavorJulia035\\winpython-3.4.2\\settings\\.julia\\v0.3\\IJulia\\src\\kernel.jl", "{connection_file}"] to ipython_config.py...
Adding IPythonWidget.execute_on_complete_input = False to ipython_qtconsole_config.py...
Adding FrontendWidget.lexer_class = 'pygments.lexers.JuliaLexer' to ipython_qtconsole_config.py...
Adding NotebookApp.port = 8998 to ipython_notebook_config.py...
Copying ijulialogo.png to Julia IPython profile.
Copying ijulialogo.svg to Julia IPython profile.
Copying ijuliafavicon.ico to Julia IPython profile.
Copying custom.js to Julia IPython profile.
Copying julia.js to Julia IPython profile.
```

Hi @Carreau 

Also, `%load_ext julia.magic` doesn't work anymore, and I'm clueless

If you have the Berkeley VM on Windows next to you, I would be happy if you could give it a try 
(on Julia0.3.5, otherwise 0.3.6 as it's soon released)

> %load_ext julia.magic

Make only sens on a python kernel.

naturally, with Ipython3.0b1 I'm testing these two kernels
(until a binary windows IRkernel drops on the floor)

Ok, I'm rebuilding my julia and will try

Ok, so from what I can tell this should be fixed once IJulia adapt to message spec v5, the issue right now is that we are in an indeterminate state when completing just after the dot.

For example in Python `np.<tab>`  would propose `np.histogram` as completion, including the `np.` in the response. Julia only provide the part "after the dot". The issues is the completer also ask from where the completion should be replaced. And either you index from the beginning of the cell with positive integers, or negative integers from the cursor. for `Pkg.b<tab>` you would say `(build, -1)`. Issue is with `Pkg.<tab>` you get `(build,0)`, which is interpreted as from beginning of the cell.

If we fix it by assuming `0` mean from the cursor, then you break the other case when `np.hi<tab>` reply `(np.histogram,0)` which became `np.histnp.histogram`.

Yeah, we can't have 0 mean the cursor position, because then there's no way to specify the start of the cell. I guess we need -0 ;-)

More seriously, should we have a special value like JSON `null` that we use to indicate completions starting at the cursor position?

I don't think so, I believe this is just a problem with messagespec v4 and adapter.
We had to have negative indexing as we were not sending the all cell. 

If Ipython/Jupyter does know that Ijulia is speaking message spec <v5, could this simple `workaround patch` around the meaning of '0' be implemented ? 


Resolving patch:
diff --git a/IPython/kernel/adapter.py b/IPython/kernel/adapter.py
--- a/IPython/kernel/adapter.py
+++ b/IPython/kernel/adapter.py
@@ -262,12 +262,17 @@ def complete_request(self, msg):
     
     def complete_reply(self, msg):
         # complete_reply needs more context than we have to get cursor_start and end.
-        # use special value of `-1` to indicate to frontend that it should be at
-        # the current cursor position.
+        # use special end=null to indicate current cursor position and negative offset
+        # for start relative to the cursor.
+        # start=None indicates that start == end (accounts for no -0).
         content = msg['content']
         new_content = msg['content'] = {'status' : 'ok'}
         new_content['matches'] = content['matches']
-        new_content['cursor_start'] = -len(content['matched_text'])
+        if content['matched_text']:
+            new_content['cursor_start'] = -len(content['matched_text'])
+        else:
+            # no -0, use None to indicate that start == end
+            new_content['cursor_start'] = None
         new_content['cursor_end'] = None
         new_content['metadata'] = {}
         return msg


Test patch: