jimenezrick/vimerl

MacVim freezes on quitting/INSERT mode

pmichna opened this issue · 16 comments

I use MacVim 7.3 and I installed vimerl via vundle. My .vimrc:

set nocompatible
filetype off

set rtp+=~/.vim/bundle/vundle
call vundle#rc()

Bundle 'gmarik/vundle'
Bundle 'jimenezrick/vimerl'

filetype plugin indent on
syntax on
set autoindent

Executing ~/.vim/bundle/vimerl/indent/erlang_indent.erl -f foo.erl 1 (or 2 or 3) gives no output for foo.erl:

foo() ->
    z = 1 +
            2,
    ok.

When I open some .erl file in vim, it freezes when I try to quit vim or it freezes after a second or two when switching to INSERT mode.

evnu commented

I encounter similar problems sometimes. Can you check if you also see a beam.smp process taking up 100% of one core? This is reproducable on my machine (ArchLinux, Erlang R16B) when I run

erlc erlang_indent.erl

The compilation takes multiple minutes (~2 min. here), which could be the cause of a freezing vim.

This compilation is fast: ~1 sec. However, I get an error and a bunch of warnings. What to do about that?

mac-mini-pawel:erlang pmichna$ erlc ~/.vim/bundle/vimerl/indent/erlang_indent.erl
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:1: syntax error before: '#'
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:21: no module definition
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:23: Warning: function main/1 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:41: Warning: function read_fifo/1 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:44: Warning: function write_fifo/2 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:47: Warning: function read_file/1 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:51: Warning: function format_indentation/1 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:56: Warning: function source_indentation/2 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:66: Warning: function tokenize_source/1 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:69: Warning: function tokenize_source2/1 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:77: Warning: function eat_shebang/1 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:82: Warning: function split_prev_block/2 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:90: Warning: function category/1 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:94: Warning: function line/1 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:98: Warning: function column/1 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:102: Warning: function indentation_between/2 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:157: Warning: function parse_tokens/1 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:166: Warning: function parse_datum/2 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:171: Warning: function parse_attribute/2 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:180: Warning: function parse_function/2 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:187: Warning: function parse_next/2 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:190: Warning: function parse_next2/2 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:282: Warning: function indent/2 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:285: Warning: function indent/3 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:290: Warning: function indent_after/3 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:295: Warning: function reindent/2 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:298: Warning: function reindent/3 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:303: Warning: function unindent/1 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:306: Warning: function push/3 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:309: Warning: function push/4 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:312: Warning: function pop/1 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:315: Warning: function next_relevant_token/1 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:318: Warning: function irrelevant_token/1 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:324: Warning: function same_line/2 is unused
/Users/pmichna/.vim/bundle/vimerl/indent/erlang_indent.erl:332: Warning: function symmetrical/1 is unused
evnu commented

My bad, to make it compilable you have to add -module(nameofthefile). to the beginning and delete the shebang #.

Do you mean to add -module(erlang_indent). to erlang_indent.erl in the 1st line? Doing so in the 3rd line haven't helped as well. I removed the # from the shebang arguments and still nothing.

The beginning of erlang_indent.erl:

-module(erlang_indent).
#!/usr/bin/env escript
%%! -detached

-mode(compile).

Compilation:

mac-mini-pawel:indent pmichna$ erlc erlang_indent.erl 
erlang_indent.erl:2: syntax error before: '#'
erlang_indent.erl:339: syntax error before: '.'
erlang_indent.erl:350: redefining macro 'PRINT_ERROR'
erlang_indent.erl:351: redefining macro 'PRINT_STATE'
erlang_indent.erl:354: redefining macro 'IS'
erlang_indent.erl:355: redefining macro 'OPEN_BRACKET'
erlang_indent.erl:356: redefining macro 'CLOSE_BRACKET'
erlang_indent.erl:357: redefining macro 'BRANCH_EXPR'
erlang_indent.erl:500: syntax error before: 
erlang_indent.erl:207: function symmetrical/1 undefined
erlang_indent.erl:360: record state already defined
erlang_indent.erl:362: function main/1 already defined
erlang_indent.erl:380: function read_fifo/1 already defined
erlang_indent.erl:383: function write_fifo/2 already defined
erlang_indent.erl:386: function read_file/1 already defined
erlang_indent.erl:390: function format_indentation/1 already defined
erlang_indent.erl:395: function source_indentation/2 already defined
erlang_indent.erl:405: function tokenize_source/1 already defined
erlang_indent.erl:408: function tokenize_source2/1 already defined
erlang_indent.erl:416: function eat_shebang/1 already defined
erlang_indent.erl:421: function split_prev_block/2 already defined
erlang_indent.erl:429: function category/1 already defined
erlang_indent.erl:433: function line/1 already defined
erlang_indent.erl:437: function column/1 already defined
erlang_indent.erl:441: function indentation_between/2 already defined
erlang_indent.erl:25: Warning: function main/1 is unused
erlang_indent.erl:43: Warning: function read_fifo/1 is unused
erlang_indent.erl:46: Warning: function write_fifo/2 is unused
erlang_indent.erl:49: Warning: function read_file/1 is unused
erlang_indent.erl:53: Warning: function format_indentation/1 is unused
erlang_indent.erl:58: Warning: function source_indentation/2 is unused
erlang_indent.erl:68: Warning: function tokenize_source/1 is unused
erlang_indent.erl:71: Warning: function tokenize_source2/1 is unused
erlang_indent.erl:79: Warning: function eat_shebang/1 is unused
erlang_indent.erl:84: Warning: function split_prev_block/2 is unused
erlang_indent.erl:92: Warning: function category/1 is unused
erlang_indent.erl:96: Warning: function line/1 is unused
erlang_indent.erl:100: Warning: function column/1 is unused
erlang_indent.erl:104: Warning: function indentation_between/2 is unused
erlang_indent.erl:159: Warning: function parse_tokens/1 is unused
erlang_indent.erl:168: Warning: function parse_datum/2 is unused
erlang_indent.erl:173: Warning: function parse_attribute/2 is unused
erlang_indent.erl:182: Warning: function parse_function/2 is unused
erlang_indent.erl:189: Warning: function parse_next/2 is unused
erlang_indent.erl:192: Warning: function parse_next2/2 is unused
erlang_indent.erl:230: Warning: function parse_next3/2 is unused
erlang_indent.erl:286: Warning: function indent/2 is unused
erlang_indent.erl:289: Warning: function indent/3 is unused
erlang_indent.erl:294: Warning: function indent_after/3 is unused
erlang_indent.erl:299: Warning: function reindent/2 is unused
erlang_indent.erl:302: Warning: function reindent/3 is unused
erlang_indent.erl:307: Warning: function unindent/1 is unused
erlang_indent.erl:310: Warning: function push/3 is unused
erlang_indent.erl:313: Warning: function push/4 is unused
erlang_indent.erl:316: Warning: function pop/1 is unused
erlang_indent.erl:319: Warning: function next_relevant_token/1 is unused
erlang_indent.erl:322: Warning: function irrelevant_token/1 is unused
erlang_indent.erl:328: Warning: function same_line/2 is unused
erlang_indent.erl:362: Warning: function main/1 is unused
erlang_indent.erl:380: Warning: function read_fifo/1 is unused
erlang_indent.erl:383: Warning: function write_fifo/2 is unused
erlang_indent.erl:386: Warning: function read_file/1 is unused
erlang_indent.erl:390: Warning: function format_indentation/1 is unused
erlang_indent.erl:395: Warning: function source_indentation/2 is unused
erlang_indent.erl:405: Warning: function tokenize_source/1 is unused
erlang_indent.erl:408: Warning: function tokenize_source2/1 is unused
erlang_indent.erl:416: Warning: function eat_shebang/1 is unused
erlang_indent.erl:421: Warning: function split_prev_block/2 is unused
erlang_indent.erl:429: Warning: function category/1 is unused
erlang_indent.erl:433: Warning: function line/1 is unused
erlang_indent.erl:437: Warning: function column/1 is unused
erlang_indent.erl:441: Warning: function indentation_between/2 is unused
evnu commented

The beginning of the file should look similar to this:

-module(erlang_indent).
%%! -detached

-mode(compile).

The warnings on unused functions are ok (there is no -export([...]).).

Now I get two syntax errors:

erlang_indent.erl:338: syntax error before: '.'
erlang_indent.erl:499: syntax error before: 

I guess in line 338 I have to delete #!/usr/bin/env escript but what about the line 499?

495 parse_tokens(Tokens = [{'-', _} | _]) ->
496         parse_attribute(Tokens, #state{});
497 parse_tokens(Tokens = [{atom, _, _} | _]) ->
498         parse_function(Tokens, #state{});
499 parse_tokens(Tokens = [{T, _} | _])
EOF
evnu commented

The file is only ~340 lines long here. Are you sure that 1. you are looking at the correct file indent/erlang_indent.erl and 2. you are using this repository?

I just did git clone git://github.com/jimenezrick/vimerl.git and [...]/vimerl/indent/erlang_indent.erl is exactly 499 lines long.

evnu commented

I don't get it..:

$ cd /tmp; git clone git://github.com/jimenezrick/vimerl.git && wc -l vimerl/indent/erlang_indent.erl
Cloning into 'vimerl'...
remote: Counting objects: 1922, done.
remote: Compressing objects: 100% (843/843), done.
remote: Total 1922 (delta 985), reused 1834 (delta 911)
Receiving objects: 100% (1922/1922), 270.14 KiB | 327 KiB/s, done.
Resolving deltas: 100% (985/985), done.
335 vimerl/indent/erlang_indent.erl

335 here. Does wc -l return 499 for you as well? (Anyways, I doubt that we are talking about different files.. I submitted a push request to speed up compilation of said file, maybe you could try if that is working for you?)

It doesn't make sense trying to compile the erlang_indent.erl file, as it is an escript (man escript).

Ok, now I get 335 lines. However, if I try to install it via vundle, there are 499 lines.

I am trying to compile the erlang_indent.erl with the edits you pointed and, as you said, the process beam.smp is taking ~100% CPU and about 2 minutes. How to fix this?

EDIT: whether it makes sens to compile erlang_indent.erl or not, I still have to wait a long time till the MacVim quits. However, I can switch to INSERT mode now without problems.

evnu commented

@jimenezrick the file is compiled by escript (-mode(compile)). By making it compilable on the command line, one can check if the compiler is taking a very long time to compile it. R15 is fast to compile, R16 takes ages.

I downgraded to R15B03-1 and it works fine.

It is very strange the file takes so long to be compiled under R16. Did you try removing -mode(compile)? Maybe a compiler bug?

I'm using R16B, vim 7.3 (66), and I'm on a Mac 10.8.4.

My vim and gVim (MacVim) we're hanging after writing -module(demo) . It wouldn't let me write the dot.
The process beam.smp was taking 100% of the cpu and vim was just useless, even after minutes of waiting.

I did what @jimenezrick said, and I commented out the mode(compile). Everything works fine now.

With the release R16B01 the issue should be resolved. The master branch of Vimerl already has the compile directive uncommented so everything should be back to normal.