Skip to content

Commit 6d497a4

Browse files
committed
changed troubleshooting mechanism and updated documentation on development guidelines
1 parent 5a29192 commit 6d497a4

File tree

11 files changed

+339
-303
lines changed

11 files changed

+339
-303
lines changed

autoload/pymode.vim

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ fun! pymode#trim_whitespaces() "{{{
7676
endif
7777
endfunction "}}}
7878

79-
8079
fun! pymode#save() "{{{
8180
if &modifiable && &modified
8281
try
@@ -120,9 +119,25 @@ fun! pymode#buffer_post_write() "{{{
120119
endfunction "}}}
121120

122121
fun! pymode#debug(msg) "{{{
122+
" Pymode's debug function.
123+
" Should be called by other pymode's functions to report outputs. See
124+
" the function PymodeDebugFolding for example.
125+
" TODO: why echom here creates a problem?
126+
" echom '' . a:msg + '|||||||||||'
127+
128+
let l:info_separator = repeat('-', 79)
129+
123130
if g:pymode_debug
124-
let g:pymode_debug += 1
125-
echom string(g:pymode_debug) . ': ' . string(a:msg)
131+
if ! exists('g:pymode_debug_counter')
132+
let g:pymode_debug_counter = 0
133+
endif
134+
let g:pymode_debug_counter += 1
135+
" NOTE: Print a separator for every message except folding ones (since
136+
" they could be many).
137+
if a:msg !~ 'has folding:'
138+
echom l:info_separator
139+
endif
140+
echom '' . 'pymode debug msg ' . g:pymode_debug_counter . ': ' . a:msg
126141
endif
127142
endfunction "}}}
128143

autoload/pymode/debug.vim

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
" Set debugging functions.
2+
3+
" DESC: Get debug information about pymode problem.
4+
fun! pymode#debug#sysinfo() "{{{
5+
" OS info. {{{
6+
let l:os_name = "Unknown"
7+
if has('win16') || has('win32') || has('win64')
8+
let l:os_name = "Windows"
9+
else
10+
let l:os_name = substitute(system('uname'), "\n", "", "")
11+
endif
12+
call pymode#debug("Operating system: " . l:os_name)
13+
" }}}
14+
" Loaded scripts info. {{{
15+
call pymode#debug("Scriptnames:")
16+
let l:scriptnames_var = execute('scriptnames')
17+
" }}}
18+
" Variables info. {{{
19+
" Drop verbose file temporarily to prevent the 'let' from showing up.
20+
let l:tmp = &verbosefile
21+
set verbosefile=
22+
let l:all_variables = filter(
23+
\ split(execute('let', 'silent!'), '\n'),
24+
\ 'v:val =~ "^pymode"')
25+
let &verbosefile = l:tmp
26+
" NOTE: echom does not display multiline messages. Thus a for loop is
27+
" needed.
28+
call pymode#debug("Pymode variables:")
29+
for pymodevar in sort(l:all_variables)
30+
echom pymodevar
31+
endfor
32+
" }}}
33+
" Github commit info. {{{
34+
" Find in the scriptnames the first occurence of 'python-mode'. Then parse
35+
" the result outputting its path. This is in turn fed into the git command.
36+
call pymode#debug("Git commit: ")
37+
let l:pymode_folder = substitute(
38+
\ filter(
39+
\ split(l:scriptnames_var, '\n'),
40+
\ 'v:val =~ "/python-mode/"')[0],
41+
\ '\(^\s\+[0-9]\+:\s\+\)\([/~].*python-mode\/\)\(.*\)',
42+
\ '\2',
43+
\ '')
44+
let l:git_head_sha1 = system('git -C ' . expand(l:pymode_folder). ' rev-parse HEAD ' )
45+
echom join(filter(split(l:git_head_sha1, '\zs'), 'v:val =~? "[0-9A-Fa-f]"'), '')
46+
" }}}
47+
call pymode#debug("End of pymode#debug#sysinfo")
48+
endfunction "}}}
49+
50+
" DESC: Define debug folding function.
51+
function! pymode#debug#foldingexpr(lnum) "{{{
52+
let l:get_folding_result = pymode#folding#expr(a:lnum)
53+
" NOTE: the 'has folding:' expression is special in the pymode#debug.
54+
call pymode#debug('line ' . a:lnum . ' has folding:' . l:get_folding_result)
55+
return pymode#folding#expr(a:lnum)
56+
endfunction
57+
" }}}

autoload/pymode/folding.vim

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ if s:symbol == ''
2020
endif
2121
" ''''''''
2222

23-
2423
fun! pymode#folding#text() " {{{
2524
let fs = v:foldstart
2625
while getline(fs) !~ s:def_regex && getline(fs) !~ s:docstring_begin_regex
@@ -182,8 +181,6 @@ fun! s:BlockStart(line_number) "{{{
182181
let max_indent = max([indent(prevnonblank(a:line_number)) - &shiftwidth, 0])
183182
endif
184183

185-
" " Debug:
186-
187184
return searchpos('\v^\s{,'.max_indent.'}(def |class )\w', 'bcnW')[0]
188185

189186
endfunction "}}}

autoload/pymode/troubleshooting.vim

Lines changed: 0 additions & 89 deletions
This file was deleted.

debug.vim

Lines changed: 0 additions & 13 deletions
This file was deleted.

debugvimrc.vim

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
" Use this settings for testing the plugin.
2+
"
3+
" Run vim with command:
4+
"
5+
" $ vim -u ./debug.vim /my/py/file.py
6+
"
7+
" Only python-mode will be loaded.
8+
9+
" Modify vimrc configuration.
10+
execute('set rtp+='. expand('<sfile>:p:h'))
11+
set rtp -=$HOME/.vim
12+
set rtp -=$HOME/.vim/after
13+
set nocompatible
14+
15+
" Activate debugging.
16+
let g:pymode_debug = 1
17+
18+
" Define a common shell for non Windows systems.
19+
if ! (has('win16') || has('win32') || has('win64'))
20+
set shell=/bin/bash
21+
endif

0 commit comments

Comments
 (0)