Skip to content

Commit 0d36f06

Browse files
committed
Fix Autoimport on unsaved file
1 parent b65f669 commit 0d36f06

File tree

5 files changed

+15
-9
lines changed

5 files changed

+15
-9
lines changed

autoload/pymode.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ fun! pymode#save() "{{{
8686
try
8787
noautocmd write
8888
catch /E212/
89-
call pymode#error("File modified and I can't save it. Cancel code checking.")
89+
call pymode#error("File modified and I can't save it. Please save it manually.")
9090
return 0
9191
endtry
9292
endif
93-
return 1
93+
return expand('%') != ''
9494
endfunction "}}}
9595

9696
fun! pymode#reload_buf_by_nr(nr) "{{{

autoload/pymode/rope.vim

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,6 @@ fun! pymode#rope#module_to_package() "{{{
161161
endfunction "}}}
162162

163163
fun! pymode#rope#autoimport(word) "{{{
164-
if !pymode#save()
165-
return 0
166-
endif
167164
PymodePython rope.autoimport()
168165
endfunction "}}}
169166

pymode/rope.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,13 @@ def complete_check():
909909

910910

911911
def _insert_import(name, module, ctx):
912+
if not ctx.resource:
913+
source, _ = get_assist_params()
914+
lineno = ctx.importer.find_insertion_line(source)
915+
line = 'from %s import %s' % (module, name)
916+
vim.current.buffer[lineno - 1:lineno - 1] = [line]
917+
return True
918+
912919
pyobject = ctx.project.pycore.resource_to_pyobject(ctx.resource)
913920
import_tools = importutils.ImportTools(ctx.project.pycore)
914921
module_imports = import_tools.module_imports(pyobject)

t/plugin.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ describe 'pymode-plugin'
2727
Expect getline('$') == 'test success'
2828
end
2929

30+
it 'pymode save'
31+
Expect expand('%') == ''
32+
Expect pymode#save() == 0
33+
end
34+
3035
end
3136

3237

t/rope.vim

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
let g:pymode_rope_completion_bind = 'X'
22
let g:pymode_rope_autoimport = 0
3-
43
source plugin/pymode.vim
54

65
describe 'pymode-plugin'
@@ -15,15 +14,13 @@ describe 'pymode-plugin'
1514
end
1615

1716
it 'pymode rope auto open project in current working directory'
18-
let project_path = getcwd() . '/.ropeproject'
17+
let project_path = '.ropeproject'
1918
Expect isdirectory(project_path) == 0
2019
call pymode#rope#complete(0)
2120
Expect isdirectory(project_path) == 1
2221
end
2322

2423
it 'pymode rope completion'
25-
source after/ftplugin/python.vim
26-
Expect &ft == 'python'
2724
normal oimporX
2825
Expect getline('.') == 'import'
2926
end

0 commit comments

Comments
 (0)