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
153 lines (130 loc) · 3.62 KB
/
Copy pathpymode.vim
File metadata and controls
153 lines (130 loc) · 3.62 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
" 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#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() "{{{
" DESC: Place error signs
"
if has('signs')
sign unplace *
for item in filter(getqflist(), 'v:val.bufnr != ""')
execute printf('silent! sign place 1 line=%d name=%s buffer=%d', item.lnum, 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
redraw
normal gg
wincmd p
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
echo strpart(a:msg, 0, &columns-1)
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 "}}}
" vim: fdm=marker:fdl=0