forked from python-mode/python-mode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpymode.vim
More file actions
148 lines (131 loc) · 4.03 KB
/
pymode.vim
File metadata and controls
148 lines (131 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
" Pymode core functions
" DESC: Check variable and set default value if it not exists
fun! pymode#default(name, default) "{{{
if !exists(a:name)
let {a:name} = a:default
return 0
endif
return 1
endfunction "}}}
" DESC: Import python libs
fun! pymode#init(plugin_root, paths) "{{{
PymodePython import sys, vim
PymodePython sys.path.insert(0, vim.eval('a:plugin_root'))
PymodePython sys.path = vim.eval('a:paths') + sys.path
endfunction "}}}
" DESC: Show wide message
fun! pymode#wide_message(msg) "{{{
let x=&ruler | let y=&showcmd
set noruler noshowcmd
redraw
echohl Debug | echo strpart("[Pymode] " . a:msg, 0, &columns-1) | echohl none
let &ruler=x | let &showcmd=y
endfunction "}}}
" DESC: Show error
fun! pymode#error(msg) "{{{
execute "normal \<Esc>"
echohl ErrorMsg
echomsg "[Pymode]: error: " . a:msg
echohl None
endfunction "}}}
" DESC: Open quickfix window
fun! pymode#quickfix_open(onlyRecognized, maxHeight, minHeight, jumpError) "{{{
let numErrors = len(filter(getqflist(), 'v:val.valid'))
let numOthers = len(getqflist()) - numErrors
if numErrors > 0 || (!a:onlyRecognized && numOthers > 0)
let num = winnr()
botright copen
exe max([min([line("$"), a:maxHeight]), a:minHeight]) . "wincmd _"
if a:jumpError
cc
elseif num != winnr()
wincmd p
endif
else
cclose
endif
redraw
if numOthers > 0
call pymode#wide_message(printf('Quickfix: %d(+%d)', numErrors, numOthers))
elseif numErrors > 0
call pymode#wide_message(printf('Quickfix: %d', numErrors))
endif
endfunction "}}}
" DESC: Open temp buffer.
fun! pymode#tempbuffer_open(name) "{{{
pclose
exe g:pymode_preview_position . " " . g:pymode_preview_height . "new " . a:name
setlocal buftype=nofile bufhidden=delete noswapfile nowrap previewwindow
redraw
endfunction "}}}
" DESC: Remove unused whitespaces
fun! pymode#trim_whitespaces() "{{{
if g:pymode_trim_whitespaces
let cursor_pos = getpos('.')
silent! %s/\s\+$//e
call setpos('.', cursor_pos)
endif
endfunction "}}}
fun! pymode#save() "{{{
if &modifiable && &modified
try
noautocmd write
catch /E212/
call pymode#error("File modified and I can't save it. Please save it manually.")
return 0
endtry
endif
return expand('%') != ''
endfunction "}}}
fun! pymode#reload_buf_by_nr(nr) "{{{
let cur = bufnr("")
try
exe "buffer " . a:nr
catch /E86/
return
endtry
exe "e!"
exe "buffer " . cur
endfunction "}}}
fun! pymode#buffer_pre_write() "{{{
let b:pymode_modified = &modified
endfunction "}}}
fun! pymode#buffer_post_write() "{{{
if g:pymode_rope
if g:pymode_rope_regenerate_on_write && b:pymode_modified
call pymode#debug('regenerate')
call pymode#rope#regenerate()
endif
endif
if g:pymode_lint
if g:pymode_lint_unmodified || (g:pymode_lint_on_write && b:pymode_modified)
call pymode#debug('check code')
call pymode#lint#check()
endif
endif
endfunction "}}}
fun! pymode#debug(msg) "{{{
" Pymode's debug function.
" Should be called by other pymode's functions to report outputs. See
" the function PymodeDebugFolding for example.
" TODO: why echom here creates a problem?
" echom '' . a:msg + '|||||||||||'
let l:info_separator = repeat('-', 79)
if g:pymode_debug
if ! exists('g:pymode_debug_counter')
let g:pymode_debug_counter = 0
endif
let g:pymode_debug_counter += 1
" NOTE: Print a separator for every message except folding ones (since
" they could be many).
if a:msg !~ 'has folding:'
echom l:info_separator
endif
echom '' . 'pymode debug msg ' . g:pymode_debug_counter . ': ' . a:msg
endif
endfunction "}}}
fun! pymode#quit() "{{{
augroup pymode
au! * <buffer>
augroup END
endfunction "}}}