2010-08-31 34 views
13

Tôi đã tải xuống Scala 2.8, cài đặt các tập lệnh vim được bao gồm và cố gắng nhập vào một số mã Scala. Khi tôi gõ vào val x = 1 + 2 và nhấn ENTER, thụt đầu dòng xuống bên dưới v. Khi tôi nhập vào val x = (1 + 2), thụt đầu dòng nằm dưới x!VIM và Scala - vấn đề thụt đầu dòng?

Nếu VIM được sử dụng bởi bất kỳ ai ở tất cả cho Scala, lỗi này nên đã được nhìn thấy từ lâu. Hay tôi là người duy nhất nhìn thấy điều này?

Trả lời

8

Với số indent/scala.vim từ phiên bản 2.8.0.final hiện tại tôi có cùng kết quả ... Nhưng tôi biết, nó đã hoạt động trong bản phát hành trước đó, bởi vì tôi có một tệp ở đây mà nó hoạt động. Ở đây là:

" Vim indent file 
" Language : Scala (http://scala-lang.org/) 
" Maintainer : Stefan Matthias Aust 
" Last Change: 2006 Apr 13 

if exists("b:did_indent") 
    finish 
endif 
let b:did_indent = 1 

setlocal indentexpr=GetScalaIndent() 

setlocal indentkeys=0{,0},0),!^F,<>>,<CR> 

setlocal autoindent sw=2 et 

if exists("*GetScalaIndent") 
    finish 
endif 

function! CountParens(line) 
    let line = substitute(a:line, '"\(.\|\\"\)*"', '', 'g') 
    let open = substitute(line, '[^(]', '', 'g') 
    let close = substitute(line, '[^)]', '', 'g') 
    return strlen(open) - strlen(close) 
endfunction 

function! GetScalaIndent() 
    " Find a non-blank line above the current line. 
    let lnum = prevnonblank(v:lnum - 1) 

    " Hit the start of the file, use zero indent. 
    if lnum == 0 
    return 0 
    endif 

    let ind = indent(lnum) 
    let prevline = getline(lnum) 

    "Indent html literals 
    if prevline !~ '/>\s*$' && prevline =~ '^\s*<[a-zA-Z][^>]*>\s*$' 
    return ind + &shiftwidth 
    endif 

    "### Taken from mail on scala mailing list 
    "### ------------------------------------- 
    " Add a 'shiftwidth' after lines that start a block 
    " If if, for or while end with), this is a one-line block 
    " If val, var, def end with =, this is a one-line block 
    "if prevline =~ '^\s*\<\(\(else\s\+\)\?if\|for\|while\|va[lr]\|def\)\>.*[)=]\s*$' 
     "\ || prevline =~ '^\s*\<else\>\s*$' 
     "\ || prevline =~ '{\s*$' 
     "let ind = ind + &shiftwidth 
     "endif 
     " Add a 'shiftwidth' after lines that start a block 
     " If if, for or while end with), this is a one-line block 
     " If val, var, def end with =, this is a one-line block 
     if prevline =~ '^\s*\<\(\(else\s\+\)\?if\|for\|while\)\>.*[)]\s*$' 
        \ || prevline =~ '^\s*\<\(\(va[lr]\|def\)\>.*[=]\s*$' 
        \ || prevline =~ '^\s*\<else\>\s*$' 
        \ || prevline =~ '{\s*$' 
      let ind = ind + &shiftwidth 
     endif 

    " If parenthesis are unbalanced, indent or dedent 
    let c = CountParens(prevline) 
    echo c 
    if c > 0 
    let ind = ind + &shiftwidth 
    elseif c < 0 
    let ind = ind - &shiftwidth 
    endif 

    "### Taken from mail on scala mailing list 
    "### ------------------------------------- 
    " Dedent after if, for, while and val, var, def without block 
    "let pprevline = getline(prevnonblank(lnum - 1)) 
    "if pprevline =~ '^\s*\<\(\(else\s\+\)\?if\|for\|while\|va[lr]\|def\)\>.*[)=]\s*$' 
     "\ || pprevline =~ '^\s*\<else\>\s*$' 
     "let ind = ind - &shiftwidth 
     "endif 
     " Dedent after if, for, while and val, var, def without block 
     "let pprevline = getline(prevnonblank(lnum - 1)) 
     if pprevline =~ '^\s*\<\(\(else\s\+\)\?if\|for\|while\)\>.*[)]\s*$' 
        \ || pprevline =~ '^\s*\<\(\va[lr]\|def\)\>.*[=]\s*$' 
        \ || pprevline =~ '^\s*\<else\>\s*$' 
      let ind = ind - &shiftwidth 
     endif 

    " Align 'for' clauses nicely 
    if prevline =~ '^\s*\<for\> (.*;\s*$' 
    let ind = ind - &shiftwidth + 5 
    endif 

    " Subtract a 'shiftwidth' on '}' or html 
    let thisline = getline(v:lnum) 
    if thisline =~ '^\s*[})]' 
     \ || thisline =~ '^\s*</[a-zA-Z][^>]*>' 
    let ind = ind - &shiftwidth 
    endif 

    return ind 
endfunction 

Nhưng tôi không có đầu mối, nơi sự thay đổi đã được giới thiệu ... Cố gắng để tìm thấy nó trong lịch sử SVN tại https://codereview.scala-lang.org/fisheye/browse/scala-svn/scala-tool-support/trunk/src/vim/indent/scala.vim

Các vấn đề liên quan