summaryrefslogtreecommitdiffstats
path: root/runtime/indent/erlang.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2013-06-06 21:36:40 +0200
committerBram Moolenaar <Bram@vim.org>2013-06-06 21:36:40 +0200
commit203d04d76413fb46ada3feb73144f3172b1a9e05 (patch)
treef21c19b07ab9f7f327d2ba4e3df7fbc58cd6d737 /runtime/indent/erlang.vim
parent4cd92d5aae72098baed6e630f548c92dbe54c448 (diff)
Updated runtime files.
Diffstat (limited to 'runtime/indent/erlang.vim')
-rw-r--r--runtime/indent/erlang.vim109
1 files changed, 62 insertions, 47 deletions
diff --git a/runtime/indent/erlang.vim b/runtime/indent/erlang.vim
index 416c40e935..c11bbeb4b7 100644
--- a/runtime/indent/erlang.vim
+++ b/runtime/indent/erlang.vim
@@ -4,7 +4,7 @@
" Contributors: Edwin Fine <efine145_nospam01 at usa dot net>
" Pawel 'kTT' Salata <rockplayer.pl@gmail.com>
" Ricardo Catalinas Jiménez <jimenezrick@gmail.com>
-" Last Update: 2013-Mar-05
+" Last Update: 2013-Jun-01
" License: Vim license
" URL: https://github.com/hcs42/vim-erlang
@@ -1086,62 +1086,74 @@ function! s:ErlangCalcIndent2(lnum, stack)
endif
endif
- elseif token == 'end'
- let [lnum_new, col_new] = s:SearchEndPair(lnum, curr_col)
+ elseif index(['end', ')', ']', '}', '>>'], token) != -1
- if lnum_new == 0
- return s:IndentError('Matching token for "end" not found',
- \token, stack)
- else
- if lnum_new != lnum
- call s:Log(' Tokenize for "end" <<<<')
- let [lnum, indtokens] = s:TokenizeLine(lnum_new, 'up')
- call s:Log(' >>>> Tokenize for "end"')
- endif
+ " If we can be sure that there is synchronization in the Erlang
+ " syntax, we use searchpair to make the script quicker. Otherwise we
+ " just push the token onto the stack and keep parsing.
+
+ " No synchronization -> no searchpair optimization
+ if !exists('b:erlang_syntax_synced')
+ call s:Push(stack, token)
- let [success, i] = s:GetIndtokenAtCol(indtokens, col_new)
- if !success | return i | endif
- let [token, curr_vcol, curr_col] = indtokens[i]
- call s:Log(' Match for "end" in line ' . lnum_new . ': ' .
- \string(indtokens[i]))
- endif
+ " We don't have searchpair optimization for '>>'
+ elseif token == '>>'
+ call s:Push(stack, token)
- elseif index([')', ']', '}'], token) != -1
+ elseif token == 'end'
+ let [lnum_new, col_new] = s:SearchEndPair(lnum, curr_col)
- call s:Push(stack, token)
+ if lnum_new == 0
+ return s:IndentError('Matching token for "end" not found',
+ \token, stack)
+ else
+ if lnum_new != lnum
+ call s:Log(' Tokenize for "end" <<<<')
+ let [lnum, indtokens] = s:TokenizeLine(lnum_new, 'up')
+ call s:Log(' >>>> Tokenize for "end"')
+ endif
+
+ let [success, i] = s:GetIndtokenAtCol(indtokens, col_new)
+ if !success | return i | endif
+ let [token, curr_vcol, curr_col] = indtokens[i]
+ call s:Log(' Match for "end" in line ' . lnum_new . ': ' .
+ \string(indtokens[i]))
+ endif
- " We have to escape '[', because this string will be interpreted as a
- " regexp
- let open_paren = (token == ')' ? '(' :
- \token == ']' ? '\[' :
- \ '{')
+ else " token is one of the following: ')', ']', '}'
- let [lnum_new, col_new] = s:SearchPair(lnum, curr_col,
- \open_paren, '', token)
+ call s:Push(stack, token)
- if lnum_new == 0
- return s:IndentError('Matching token not found',
- \token, stack)
- else
- if lnum_new != lnum
- call s:Log(' Tokenize the opening paren <<<<')
- let [lnum, indtokens] = s:TokenizeLine(lnum_new, 'up')
- call s:Log(' >>>>')
- endif
+ " We have to escape '[', because this string will be interpreted as a
+ " regexp
+ let open_paren = (token == ')' ? '(' :
+ \token == ']' ? '\[' :
+ \ '{')
- let [success, i] = s:GetIndtokenAtCol(indtokens, col_new)
- if !success | return i | endif
- let [token, curr_vcol, curr_col] = indtokens[i]
- call s:Log(' Match in line ' . lnum_new . ': ' .
- \string(indtokens[i]))
+ let [lnum_new, col_new] = s:SearchPair(lnum, curr_col,
+ \open_paren, '', token)
- " Go back to the beginning of the loop and handle the opening paren
- continue
+ if lnum_new == 0
+ return s:IndentError('Matching token not found',
+ \token, stack)
+ else
+ if lnum_new != lnum
+ call s:Log(' Tokenize the opening paren <<<<')
+ let [lnum, indtokens] = s:TokenizeLine(lnum_new, 'up')
+ call s:Log(' >>>>')
+ endif
+
+ let [success, i] = s:GetIndtokenAtCol(indtokens, col_new)
+ if !success | return i | endif
+ let [token, curr_vcol, curr_col] = indtokens[i]
+ call s:Log(' Match in line ' . lnum_new . ': ' .
+ \string(indtokens[i]))
+
+ " Go back to the beginning of the loop and handle the opening paren
+ continue
+ endif
endif
- elseif token == '>>'
- call s:Push(stack, token)
-
elseif token == ';'
if empty(stack)
@@ -1323,7 +1335,10 @@ function! ErlangIndent()
let curr_col = len(ml[1])
- if ml[2] == 'end'
+ " If we can be sure that there is synchronization in the Erlang
+ " syntax, we use searchpair to make the script quicker.
+ if ml[2] == 'end' && exists('b:erlang_syntax_synced')
+
let [lnum, col] = s:SearchEndPair(v:lnum, curr_col)
if lnum == 0