@@ -91,10 +91,8 @@ def open_project(self, root=None):
91
91
if not self .env .y_or_n ('Project not exists in %s, create one?' % root ):
92
92
self .env .message ("Project creation aborted" )
93
93
return
94
-
95
94
progress = self .env .create_progress ('Opening [%s] project' % root )
96
95
self .project = rope .base .project .Project (root )
97
-
98
96
if self .env .get ('enable_autoimport' ):
99
97
underlined = self .env .get ('autoimport_underlineds' )
100
98
self .autoimport = autoimport .AutoImport (self .project ,
@@ -182,21 +180,24 @@ def _base_definition_location(self):
182
180
@decorators .local_command ('a d' ,'P' ,'C-c d' )
183
181
def show_doc (self ,prefix ):
184
182
self ._check_project ()
185
- self ._base_show_doc (prefix ,codeassist .get_doc )
183
+ self ._base_show_doc (prefix ,self . _base_get_doc ( codeassist .get_doc ) )
186
184
187
- @decorators .local_command ('a c' , 'P' )
188
- def show_calltip (self , prefix ):
185
+ @decorators .local_command ()
186
+ def get_calltip (self ):
189
187
self ._check_project ()
190
188
def _get_doc (project ,text ,offset ,* args ,** kwds ):
191
189
try :
192
190
offset = text .rindex ('(' ,0 ,offset )- 1
193
191
except ValueError :
194
192
return None
195
193
return codeassist .get_calltip (project ,text ,offset ,* args ,** kwds )
196
- self ._base_show_doc ( prefix , _get_doc )
194
+ return self ._base_get_doc ( _get_doc )
197
195
198
- def _base_show_doc (self ,prefix ,get_doc ):
199
- docs = self ._base_get_doc (get_doc )
196
+ @decorators .local_command ('a c' ,'P' )
197
+ def show_calltip (self ,prefix ):
198
+ self ._base_show_doc (prefix ,self .get_calltip ())
199
+
200
+ def _base_show_doc (self ,prefix ,docs ):
200
201
if docs :
201
202
self .env .show_doc (docs ,prefix )
202
203
else :
@@ -302,31 +303,29 @@ def _check_autoimport(self):
302
303
303
304
@decorators .global_command ('g' )
304
305
def generate_autoimport_cache (self ):
305
-
306
306
if not self ._check_autoimport ():
307
307
return
308
-
309
308
modules = self .env .get ('autoimport_modules' )
310
309
modules = [m if isinstance (m ,basestring )else m .value ()for m in modules ]
311
310
312
- def gen (handle ):
311
+ def generate (handle ):
313
312
self .autoimport .generate_cache (task_handle = handle )
314
313
self .autoimport .generate_modules_cache (modules ,task_handle = handle )
315
314
316
- refactor .runtask (self .env ,gen ,'Generate autoimport cache' )
315
+ refactor .runtask (self .env ,generate ,'Generate autoimport cache' )
317
316
self .write_project ()
318
317
319
318
@decorators .global_command ('f' ,'P' )
320
319
def find_file (self ,prefix ):
321
- f = self ._base_find_file (prefix )
322
- if f is not None :
323
- self .env .find_file (f .real_path )
320
+ file = self ._base_find_file (prefix )
321
+ if file is not None :
322
+ self .env .find_file (file .real_path )
324
323
325
324
@decorators .global_command ('4 f' ,'P' )
326
325
def find_file_other_window (self ,prefix ):
327
- f = self ._base_find_file (prefix )
328
- if f is not None :
329
- self .env .find_file (f .real_path ,other = True )
326
+ file = self ._base_find_file (prefix )
327
+ if file is not None :
328
+ self .env .find_file (file .real_path ,other = True )
330
329
331
330
def _base_find_file (self ,prefix ):
332
331
self ._check_project ()
@@ -338,14 +337,14 @@ def _base_find_file(self, prefix):
338
337
339
338
def _ask_file (self ,files ):
340
339
names = []
341
- for f in files :
342
- names .append ('<' .join (reversed (f .path .split ('/' ))))
340
+ for file in files :
341
+ names .append ('<' .join (reversed (file .path .split ('/' ))))
343
342
result = self .env .ask_values ('Rope Find File: ' ,names )
344
343
if result is not None :
345
344
path = '/' .join (reversed (result .split ('<' )))
346
- f = self .project .get_file (path )
347
- return f
348
- self .env .message ('Nof selected' )
345
+ file = self .project .get_file (path )
346
+ return file
347
+ self .env .message ('Nofile selected' )
349
348
350
349
@decorators .local_command ('a j' )
351
350
def jump_to_global (self ):
@@ -464,6 +463,13 @@ def resource(self):
464
463
if resource and resource .exists ():
465
464
return resource
466
465
466
+ @decorators .global_command ()
467
+ def get_project_root (self ):
468
+ if self .project is not None :
469
+ return self .project .root .real_path
470
+ else :
471
+ return None
472
+
467
473
def _check_project (self ):
468
474
if self .project is None :
469
475
if self .env .get ('guess_project' ):
@@ -490,12 +496,10 @@ def _reload_buffers(self, changes, undo=False):
490
496
changes .get_changed_resources (),
491
497
self ._get_moved_resources (changes ,undo ))
492
498
493
- def _reload_buffers_for_changes (self ,changed ,moved = None ):
494
- if moved is None :
495
- moved = dict ()
496
-
499
+ def _reload_buffers_for_changes (self ,changed ,moved = {}):
497
500
filenames = [resource .real_path for resource in changed ]
498
- moved = dict ((resource .real_path ,moved [resource ].real_path )for resource in moved )
501
+ moved = dict ([(resource .real_path ,moved [resource ].real_path )
502
+ for resource in moved ])
499
503
self .env .reload_files (filenames ,moved )
500
504
501
505
def _get_moved_resources (self ,changes ,undo = False ):
@@ -595,7 +599,6 @@ def lucky_assist(self, prefix):
595
599
self ._apply_assist (result )
596
600
597
601
def auto_import (self ):
598
-
599
602
if not self .interface ._check_autoimport ():
600
603
return
601
604
@@ -604,7 +607,6 @@ def auto_import(self):
604
607
605
608
name = self .env .current_word ()
606
609
modules = self .autoimport .get_modules (name )
607
-
608
610
if modules :
609
611
if len (modules )== 1 :
610
612
module = modules [0 ]
@@ -644,7 +646,7 @@ def _calculate_proposals(self):
644
646
proposals = codeassist .code_assist (
645
647
self .interface .project ,self .source ,self .offset ,
646
648
resource ,maxfixes = maxfixes )
647
- if self .env .get ('sorted_completions' ):
649
+ if self .env .get ('sorted_completions' , True ):
648
650
proposals = codeassist .sorted_proposals (proposals )
649
651
if self .autoimport is not None :
650
652
if self .starting .strip ()and '.' not in self .expression :