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
196 lines (160 loc) · 4.71 KB
/
pymode.vim
File metadata and controls
196 lines (160 loc) · 4.71 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
" Python-mode base functions
fun! pymode#Default(name, default) "{{{
" DESC: Set default value if it not exists
"
if !exists(a:name)
let {a:name} = a:default
return 0
endif
return 1
endfunction "}}}
fun! pymode#Option(name) "{{{
let name = 'b:pymode_' . a:name
if exists(name)
return eval(name)
endif
let name = 'g:pymode_' . a:name
return eval(name)
endfunction "}}}
fun! pymode#QuickfixOpen(onlyRecognized, holdCursor, maxHeight, minHeight, jumpError) "{{{
" DESC: Open quickfix window
"
let numErrors = len(filter(getqflist(), 'v:val.valid'))
let numOthers = len(getqflist()) - numErrors
if numErrors > 0 || (!a:onlyRecognized && numOthers > 0)
botright copen
exe max([min([line("$"), a:maxHeight]), a:minHeight]) . "wincmd _"
if a:jumpError
cc
elseif !a:holdCursor
wincmd p
endif
else
cclose
endif
redraw
if numOthers > 0
echo printf('Quickfix: %d(+%d)', numErrors, numOthers)
else
echo printf('Quickfix: %d', numErrors)
endif
endfunction "}}}
fun! pymode#PlaceSigns(bnum) "{{{
" DESC: Place error signs
"
if has('signs')
call pymode#Default('b:pymode_signs', [])
for item in b:pymode_signs
execute printf('sign unplace %d buffer=%d', item.lnum, item.bufnr)
endfor
let b:pymode_signs = []
if !pymode#Default("g:pymode_lint_signs_always_visible", 0) || g:pymode_lint_signs_always_visible
call RopeShowSignsRulerIfNeeded()
endif
for item in filter(getqflist(), 'v:val.bufnr != ""')
call add(b:pymode_signs, item)
execute printf('sign place %d line=%d name=%s buffer=%d', item.lnum, item.lnum, "Pymode".item.type, item.bufnr)
endfor
endif
endfunction "}}}
fun! pymode#CheckProgram(name, append) "{{{
" DESC: Check program is executable or redifined by user.
"
let name = 'g:' . a:name
if pymode#Default(name, a:name)
return 1
endif
if !executable(eval(l:name))
echoerr "Can't find '".eval(name)."'. Please set ".name .", or extend $PATH, ".a:append
return 0
endif
return 1
endfunction "}}}
fun! pymode#TempBuffer() "{{{
" DESC: Open temp buffer.
"
pclose | botright 8new
setlocal buftype=nofile bufhidden=delete noswapfile nowrap previewwindow
redraw
endfunction "}}}
fun! pymode#ShowStr(str) "{{{
" DESC: Open temp buffer with `str`.
"
let g:pymode_curbuf = bufnr("%")
call pymode#TempBuffer()
put! =a:str
wincmd p
redraw
endfunction "}}}
fun! pymode#ShowCommand(cmd) "{{{
" DESC: Run command and open temp buffer with result
"
call pymode#TempBuffer()
try
silent exec 'r!' . a:cmd
catch /.*/
close
echoerr 'Command fail: '.a:cmd
endtry
redraw
normal gg
wincmd p
endfunction "}}}
fun! pymode#WideMessage(msg) "{{{
" DESC: Show wide message
let x=&ruler | let y=&showcmd
set noruler noshowcmd
redraw
echohl Debug | echo strpart(a:msg, 0, &columns-1) | echohl none
let &ruler=x | let &showcmd=y
endfunction "}}}
fun! pymode#BlockStart(lnum, ...) "{{{
let pattern = a:0 ? a:1 : '^\s*\(@\|class\s.*:\|def\s\)'
let lnum = a:lnum + 1
let indent = 100
while lnum
let lnum = prevnonblank(lnum - 1)
let test = indent(lnum)
let line = getline(lnum)
if line =~ '^\s*#' " Skip comments
continue
elseif !test " Zero-level regular line
return lnum
elseif test >= indent " Skip deeper or equal lines
continue
" Indent is strictly less at this point: check for def/class
elseif line =~ pattern && line !~ '^\s*@'
return lnum
endif
let indent = indent(lnum)
endwhile
return 0
endfunction "}}}
fun! pymode#BlockEnd(lnum, ...) "{{{
let indent = a:0 ? a:1 : indent(a:lnum)
let lnum = a:lnum
while lnum
let lnum = nextnonblank(lnum + 1)
if getline(lnum) =~ '^\s*#' | continue
elseif lnum && indent(lnum) <= indent
return lnum - 1
endif
endwhile
return line('$')
endfunction "}}}
fun! pymode#Modeline() "{{{
let modeline = getline(prevnonblank('$'))
if modeline =~ '^#\s\+pymode:'
for ex in split(modeline, ':')[1:]
let [name, value] = split(ex, '=')
let {'b:pymode_'.name} = value
endfor
endif
au BufRead <buffer> call pymode#Modeline()
endfunction "}}}
fun! pymode#TrimWhiteSpace() "{{{
let cursor_pos = getpos('.')
silent! %s/\s\+$//
call setpos('.', cursor_pos)
endfunction "}}}
" vim: fdm=marker:fdl=0