Skip to content

Vim hangs when the file is opened #808

Closed

Description

@kostochkin

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

Activity

  1. fmv1992 commented on Nov 13, 2017

    @fmv1992
    Contributor

    That is correct. I can confirm this bug and is very annoying.

    We should revisit our folding file:

    https://github.com/python-mode/python-mode/blob/bf018e262a0601bf5c9290e02d038f4694ff03cc/autoload/pymode/folding.vim

    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 :)

  2. fmv1992 commented on Nov 14, 2017

    @fmv1992
    Contributor

    Or even better, help us fixing this problem : )

  3. kostochkin commented on Nov 14, 2017

    @kostochkin
    Author

    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)
    
  4. fmv1992 commented on Nov 15, 2017

    @fmv1992
    Contributor

    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 : )

  5. fmv1992 commented on Nov 16, 2017

    @fmv1992
    Contributor

    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!

  6. fmv1992 commented on Nov 18, 2017

    @fmv1992
    Contributor

    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 1: Starting debug on: 2017-11-18 20:06:19 with file /tmp/pymode_debug_file.txt
    -------------------------------------------------------------------------------
    pymode debug msg 2: Operating system: Linux
    -------------------------------------------------------------------------------
    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
     22: ~/dev/pud/python-mode/autoload/pymode/debug.vim
    -------------------------------------------------------------------------------
    pymode debug msg 4: Pymode variables:
    pymode                #1
    pymode_breakpoint     #1
    pymode_breakpoint_bind  <leader>b
    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        <leader>r
    pymode_trim_whitespaces #1
    pymode_version         0.9.4
    pymode_virtualenv     #1
    pymode_virtualenv_enabled  
    pymode_virtualenv_path  
    pymode_warning        #1
    -------------------------------------------------------------------------------
    pymode debug msg 5: Git commit: 
    6d497a405a66096ef5c0b51fd7ce260236ea5fda
    -------------------------------------------------------------------------------
    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
    
  7. fmv1992 commented on Nov 19, 2017

    @fmv1992
    Contributor

    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
    c7e6baa .

    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 1: Starting debug on: 2017-11-18 23:02:35 with file /tmp/pymode_debug_file.txt
    -------------------------------------------------------------------------------
    pymode debug msg 2: Operating system: Linux
    -------------------------------------------------------------------------------
    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
     22: ~/dev/pud/python-mode/autoload/pymode/debug.vim
    -------------------------------------------------------------------------------
    pymode debug msg 4: Pymode variables:
    pymode                #1
    pymode_breakpoint     #1
    pymode_breakpoint_bind  <leader>b
    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        <leader>r
    pymode_trim_whitespaces #1
    pymode_version         0.9.4
    pymode_virtualenv     #1
    pymode_virtualenv_enabled  
    pymode_virtualenv_path  
    pymode_warning        #1
    -------------------------------------------------------------------------------
    pymode debug msg 5: Git commit: 
    (removed because HEAD was unclean)
    -------------------------------------------------------------------------------
    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:=
    
      1 class TerrainType:
    -------------------------------------------------------------------------------
    pymode debug msg 11: Session history:
          #  cmd history
    >     1  xa
    
  8. kostochkin commented on Nov 19, 2017

    @kostochkin
    Author

    It solved the problem for me. Works as expected. Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions