Vim hangs due to the bug in the autofolding. With disabled autofolding (g:pymode_folding = 0), everything is ok.
To repeat the error, try to open a file whose first line contains the class definition. For example:
class TerrainType:
PLAIN = 0
SWAMP = 1
FOREST = 2
That is correct. I can confirm this bug and is very annoying.
We should revisit our folding file:
Meanwhile I suggest that you either put a blank line on top of the file (not so elegant) or put a docstring on it (which is recommended anyways). Those recommendations to not nullify the problem.
Thanks for reporting :)
Or even better, help us fixing this problem : )
I have no experience in the VIM scripting, but this small change resolve the problem for me:
Before:
162 while previous_definition != [0, 0] && indent(previous_definition[0]) >= indent(a:line_number)
After:
162 while previous_definition != [0, 0] && a:line_number != previous_definition[0] && indent(previous_definition[0]) >= indent(a:line_number)
This did not solve for me using the example of pymode/__init__.py (using the first definition as definition). The following worked but then messed up the nested class declaration:
while previous_definition != [0, 0]
\ && previous_definition != [1, 1]
\ && indent(previous_definition[0]) >= indent(a:line_number)
I'll keep investigating. I have already spent hours (if not days) on this folding file and it never gets perfect : )
I think a found a solution.
However the folding function is a recurrent trouble. Therefore I'm improving python-modes debugging functionlity rather than just doing a quickfix. Hang on tight, I'll post it within a week!
As per our new troubleshooting mechanism I can more accurately describe our
problem.
We can see that the first line of the code gets its indent level correctly but
the second causes vim to hang:
pymode debug msg 3: Scriptnames:
1: ~/dev/pud/python-mode/debugvimrc.vim
2: /usr/local/share/vim/vim80/plugin/getscriptPlugin.vim
3: /usr/local/share/vim/vim80/plugin/gzip.vim
4: /usr/local/share/vim/vim80/plugin/logiPat.vim
5: /usr/local/share/vim/vim80/plugin/manpager.vim
6: /usr/local/share/vim/vim80/plugin/matchparen.vim
7: /usr/local/share/vim/vim80/plugin/netrwPlugin.vim
8: /usr/local/share/vim/vim80/plugin/rrhelper.vim
9: /usr/local/share/vim/vim80/plugin/spellfile.vim
10: /usr/local/share/vim/vim80/plugin/tarPlugin.vim
11: /usr/local/share/vim/vim80/plugin/tohtml.vim
12: /usr/local/share/vim/vim80/plugin/vimballPlugin.vim
13: /usr/local/share/vim/vim80/plugin/zipPlugin.vim
14: ~/dev/pud/python-mode/plugin/pymode.vim
15: ~/dev/pud/python-mode/autoload/pymode.vim
16: /usr/local/share/vim/vim80/filetype.vim
17: /usr/local/share/vim/vim80/ftplugin.vim
18: /usr/local/share/vim/vim80/ftplugin/python.vim
19: ~/dev/pud/python-mode/ftplugin/python/pymode.vim
20: ~/dev/pud/python-mode/autoload/pymode/virtualenv.vim
21: ~/dev/pud/python-mode/autoload/pymode/breakpoint.vim
pymode debug msg 4: Pymode variables:
pymode #1
pymode_breakpoint #1
pymode_breakpoint_bind
pymode_breakpoint_cmd import ipdb; ipdb.set_trace() # XXX BREAKPOINT
pymode_debug #1
pymode_debug_counter #3
pymode_debug_tempfile /tmp/pymode_debug_file.txt
pymode_doc #1
pymode_doc_bind K
pymode_doc_vertical #0
pymode_folding #1
pymode_folding_nest_limit #1000
pymode_folding_regex ^\s*\%(class\|def\|async\s+def) .+(:\s+\w)\@!
pymode_indent #1
pymode_init #1
pymode_lint #1
pymode_lint_async #1
pymode_lint_async_updatetime #1000
pymode_lint_checkers ['pyflakes', 'pep8', 'mccabe']
pymode_lint_comment_symbol CC
pymode_lint_cwindow #1
pymode_lint_docs_symbol DD
pymode_lint_error_symbol EE
pymode_lint_ignore
pymode_lint_info_symbol II
pymode_lint_message #1
pymode_lint_on_fly #0
pymode_lint_on_write #1
pymode_lint_options_mccabe {'complexity': 12}
pymode_lint_options_pep257 {}
pymode_lint_options_pep8 {'max_line_length': 79}
pymode_lint_options_pyflakes {'builtins': '_'}
pymode_lint_options_pylint {'max-line-length': 79}
pymode_lint_pyflakes_symbol FF
pymode_lint_select
pymode_lint_signs #1
pymode_lint_sort []
pymode_lint_todo_symbol WW
pymode_lint_unmodified #0
pymode_lint_visual_symbol RR
pymode_motion #1
pymode_options #1
pymode_options_colorcolumn #1
pymode_options_max_line_length #79
pymode_paths []
pymode_python python3
pymode_quickfix_maxheight #6
pymode_quickfix_minheight #3
pymode_rope #0
pymode_run #1
pymode_run_bind
pymode_trim_whitespaces #1
pymode_version 0.9.4
pymode_virtualenv #1
pymode_virtualenv_enabled
pymode_virtualenv_path
pymode debug msg 5: Git commit:
pymode debug msg 6: End of pymode#debug#sysinfo
pymode debug msg 7: line 1 has folding:>1
Error detected while processing /home/monteiro/dev/pud/python-mode/autoload/pymode/tools/signs.vim:
line 1:
Interrupted
~~
Hey @kostochkin,
I think it was easier than expected.
Just removing the 'c' from searchpos() seems to have solved the issue.
Please give me feedback on this (if it solves for you as well).
Do not forget to checkout a version equal to or after
c7e6baa189d6da94941276cdcf84d1b83f7a2406 .
Indeed very tricky this folding issue.
Hope to hear from you soon.
Sample file:
~~
class TerrainType:
PLAIN = 0
SWAMP = 1
FOREST = 2
~~
Result of debug:
pymode debug msg 3: Scriptnames:
1: ~/dev/pud/python-mode/debugvimrc.vim
2: /usr/local/share/vim/vim80/plugin/getscriptPlugin.vim
3: /usr/local/share/vim/vim80/plugin/gzip.vim
4: /usr/local/share/vim/vim80/plugin/logiPat.vim
5: /usr/local/share/vim/vim80/plugin/manpager.vim
6: /usr/local/share/vim/vim80/plugin/matchparen.vim
7: /usr/local/share/vim/vim80/plugin/netrwPlugin.vim
8: /usr/local/share/vim/vim80/plugin/rrhelper.vim
9: /usr/local/share/vim/vim80/plugin/spellfile.vim
10: /usr/local/share/vim/vim80/plugin/tarPlugin.vim
11: /usr/local/share/vim/vim80/plugin/tohtml.vim
12: /usr/local/share/vim/vim80/plugin/vimballPlugin.vim
13: /usr/local/share/vim/vim80/plugin/zipPlugin.vim
14: ~/dev/pud/python-mode/plugin/pymode.vim
15: ~/dev/pud/python-mode/autoload/pymode.vim
16: /usr/local/share/vim/vim80/filetype.vim
17: /usr/local/share/vim/vim80/ftplugin.vim
18: /usr/local/share/vim/vim80/ftplugin/python.vim
19: ~/dev/pud/python-mode/ftplugin/python/pymode.vim
20: ~/dev/pud/python-mode/autoload/pymode/virtualenv.vim
21: ~/dev/pud/python-mode/autoload/pymode/breakpoint.vim
pymode debug msg 4: Pymode variables:
pymode #1
pymode_breakpoint #1
pymode_breakpoint_bind
pymode_breakpoint_cmd import ipdb; ipdb.set_trace() # XXX BREAKPOINT
pymode_debug #1
pymode_debug_counter #3
pymode_debug_tempfile /tmp/pymode_debug_file.txt
pymode_doc #1
pymode_doc_bind K
pymode_doc_vertical #0
pymode_folding #1
pymode_folding_nest_limit #1000
pymode_folding_regex ^\s*\%(class\|def\|async\s+def) .+(:\s+\w)\@!
jymode_indent #1
pymode_init #1
pymode_lint #1
pymode_lint_async #1
pymode_lint_async_updatetime #1000
pymode_lint_checkers ['pyflakes', 'pep8', 'mccabe']
pymode_lint_comment_symbol CC
pymode_lint_cwindow #1
pymode_lint_docs_symbol DD
pymode_lint_error_symbol EE
pymode_lint_ignore
pymode_lint_info_symbol II
pymode_lint_message #1
pymode_lint_on_fly #0
pymode_lint_on_write #1
pymode_lint_options_mccabe {'complexity': 12}
pymode_lint_options_pep257 {}
pymode_lint_options_pep8 {'max_line_length': 79}
pymode_lint_options_pyflakes {'builtins': '_'}
pymode_lint_options_pylint {'max-line-length': 79}
pymode_lint_pyflakes_symbol FF
pymode_lint_select
pymode_lint_signs #1
pymode_lint_sort []
pymode_lint_todo_symbol WW
pymode_lint_unmodified #0
pymode_lint_visual_symbol RR
pymode_motion #1
pymode_options #1
pymode_options_colorcolumn #1
pymode_options_max_line_length #79
pymode_paths []
pymode_python python3
pymode_quickfix_maxheight #6
pymode_quickfix_minheight #3
pymode_rope #0
pymode_run #1
pymode_run_bind
pymode_trim_whitespaces #1
pymode_version 0.9.4
pymode_virtualenv #1
pymode_virtualenv_enabled
pymode_virtualenv_path
pymode debug msg 5: Git commit:
pymode debug msg 6: End of pymode#debug#sysinfo
pymode debug msg 7: line 1 has folding:>1
pymode debug msg 8: line 2 has folding:=
pymode debug msg 9: line 3 has folding:=
pymode debug msg 10: line 4 has folding:=
pymode debug msg 11: Session history:
# cmd history
1 xa
~~
It solved the problem for me. Works as expected. Thank you :)