1+ " Python-mode base functions
2+
3+
14fun ! pymode#Default (name, default) " {{{
5+ " DESC: Set default value if it not exists
6+ "
27 if ! exists (a: name )
38 let {a: name } = a: default
49 return 0
510 endif
611 return 1
712endfunction " }}}
813
14+
915fun ! pymode#QuickfixOpen (onlyRecognized, holdCursor, maxHeight, minHeight, jumpError) " {{{
16+ " DESC: Open quickfix window
17+ "
1018 let numErrors = len (filter (getqflist (), ' v:val.valid' ))
1119 let numOthers = len (getqflist ()) - numErrors
1220 if numErrors > 0 || (! a: onlyRecognized && numOthers > 0 )
@@ -30,6 +38,8 @@ endfunction "}}}
3038
3139
3240fun ! pymode#PlaceSigns () " {{{
41+ " DESC: Place error signs
42+ "
3343 sign unplace *
3444 for item in filter (getqflist (), ' v:val.bufnr != ""' )
3545 execute printf (' silent! sign place 1 line=%d name=%s buffer=%d' , item.lnum, item.type , item.bufnr )
@@ -38,6 +48,8 @@ endfunction "}}}
3848
3949
4050fun ! pymode#CheckProgram (name, append ) " {{{
51+ " DESC: Check program is executable or redifined by user.
52+ "
4153 let name = ' g:' . a: name
4254 if pymode#Default (name, a: name )
4355 return 1
@@ -49,21 +61,29 @@ fun! pymode#CheckProgram(name, append) "{{{
4961 return 1
5062endfunction " }}}
5163
64+
5265fun ! pymode#TempBuffer () " {{{
66+ " DESC: Open temp buffer.
67+ "
5368 pclose | botright 8 new
5469 setlocal buftype = nofile bufhidden = delete noswapfile nowrap previewwindow
5570 redraw
5671endfunction " }}}
5772
73+
5874fun ! pymode#ShowStr (str) " {{{
75+ " DESC: Open temp buffer with `str`.
76+ "
5977 call pymode#TempBuffer ()
6078 put ! = a: str
6179 redraw
62- normal gg
63- wincmd p
80+ normal gg | wincmd p
6481endfunction " }}}
6582
83+
6684fun ! pymode#ShowCommand (cmd) " {{{
85+ " DESC: Run command and open temp buffer with result
86+ "
6787 call pymode#TempBuffer ()
6888 try
6989 silent exec ' r!' . a: cmd
@@ -72,16 +92,57 @@ fun! pymode#ShowCommand(cmd) "{{{
7292 echoerr ' Command fail: ' .a: cmd
7393 endtry
7494 redraw
75- normal gg
76- wincmd p
95+ normal gg | wincmd p
7796endfunction " }}}
7897
7998
80- " DESC: Show wide message
8199fun ! pymode#WideMessage (msg) " {{{
100+ " DESC: Show wide message
101+
82102 let x = &ruler | let y = &showcmd
83103 set noruler noshowcmd
84104 redraw
85105 echo strpart (a: msg , 0 , &columns - 1 )
86106 let &ruler = x | let &showcmd = y
87107endfunction " }}}
108+
109+
110+ fun ! pymode#BlockStart (lnum, ... ) " {{{
111+ let pattern = a: 0 ? a: 1 : ' ^\s*\(@\|class\s.*:\|def\s\)'
112+ let lnum = a: lnum + 1
113+ let indent = 100
114+ while lnum
115+ let lnum = prevnonblank (lnum - 1 )
116+ let test = indent (lnum)
117+ let line = getline (lnum)
118+ if line = ~ ' ^\s*#' " Skip comments
119+ continue
120+ elseif ! test " Zero-level regular line
121+ return lnum
122+ elseif test >= indent " Skip deeper or equal lines
123+ continue
124+ " Indent is strictly less at this point: check for def/class
125+ elseif line = ~ pattern && line !~ ' ^\s*@'
126+ return lnum
127+ endif
128+ let indent = indent (lnum)
129+ endwhile
130+ return 0
131+ endfunction " }}}
132+
133+
134+ fun ! pymode#BlockEnd (lnum, ... ) " {{{
135+ let indent = a: 0 ? a: 1 : indent (a: lnum )
136+ let lnum = a: lnum
137+ while lnum
138+ let lnum = nextnonblank (lnum + 1 )
139+ if getline (lnum) = ~ ' ^\s*#' | continue
140+ elseif lnum && indent (lnum) <= indent
141+ return lnum - 1
142+ endif
143+ endwhile
144+ return line (' $' )
145+ endfunction " }}}
146+
147+
148+ " vim: fdm = marker:fdl = 0
0 commit comments