22# Copyright (c) 2013, Maxim Grechkin
33# This file is licensed under GNU General Public License version 3
44# See COPYING for details.
5-
5+ from __future__ import print_function
66import sublime
77try :
8- from SublimeIPythonNotebook import ipy_connection
9- except ImportError :
8+ from . import ipy_connection
9+ except :
1010 import ipy_connection
1111import re
1212
@@ -97,6 +97,9 @@ def get_input_content(self):
9797 return self .view .substr (input_region )
9898 else :
9999 return ""
100+
101+ def check_R (self ):
102+ pass
100103
101104
102105class CodeCellView (BaseCellView ):
@@ -210,7 +213,7 @@ def rewrite_prompt_number(self, edit):
210213 out_reg = self .get_region ("inb_output" )
211214 line = self .view .line (out_reg .begin () - 1 )
212215 self .view .replace (edit , line , "#Output[%s]" % self .prompt )
213-
216+
214217
215218
216219 def output_result (self , edit ):
@@ -285,7 +288,7 @@ def __init__(self, view, notebook_id, baseurl):
285288 self .baseurl = baseurl
286289 view .set_scratch (True )
287290 #view.set_syntax_file("Packages/Python/Python.tmLanguage")
288- view .set_syntax_file ("Packages/SublimeIPythonNotebook /SublimeIPythonNotebook.tmLanguage" )
291+ view .set_syntax_file ("Packages/IPython Notebook /SublimeIPythonNotebook.tmLanguage" )
289292 view .settings ().set ("ipython_notebook" , True )
290293 self .cells = []
291294 self .notebook_id = notebook_id
@@ -356,7 +359,7 @@ def on_modified(self):
356359 for s in self .view .sel ():
357360 for i , reg in enumerate (regset ):
358361 reg = sublime .Region (reg .begin ()+ 1 , reg .end ()- 1 )
359- if reg .contains (s ):
362+ if reg .contains (s ) and ( i < len ( self . cells )) :
360363 self .cells [i ].check_R ()
361364 break
362365
@@ -461,7 +464,7 @@ def render_notebook(self, edit):
461464
462465 for cell in self .cells :
463466 cell .draw (edit )
464-
467+
465468 if len (self .cells ) > 0 :
466469 self .cells [0 ].select ()
467470
@@ -484,6 +487,11 @@ def set_status():
484487 sublime .set_timeout (set_status , 0 )
485488
486489 def handle_completions (self , view , prefix , locations ):
490+ cell_index = self .get_current_cell_index ()
491+ if cell_index < 0 :
492+ return None
493+ if not isinstance (self .cells [cell_index ], CodeCellView ):
494+ return None
487495 sel = view .sel ()
488496 if len (sel ) > 1 :
489497 return []
@@ -492,7 +500,7 @@ def handle_completions(self, view, prefix, locations):
492500 row , col = view .rowcol (sel .begin ())
493501 compl = self .kernel .get_completitions (line , col , timeout = 0.7 )
494502
495-
503+
496504 if len (compl ) > 0 :
497505 def get_last_word (s ): # needed for file/directory completion
498506 if s .endswith ("/" ):
@@ -668,4 +676,4 @@ def on_close(self, view):
668676 if id in self .views :
669677 del self .views [id ]
670678
671- manager = NotebookViewManager ()
679+ manager = NotebookViewManager ()
0 commit comments