gpt4 book ai didi

VIM 和 Scala -- 缩进问题?

转载 作者:行者123 更新时间:2023-12-03 22:35:12 25 4
gpt4 key购买 nike

我下载了 Scala 2.8,安装了包含的 vim 脚本并尝试输入一些 Scala 代码。当我输入 val x = 1 + 2然后按 ENTER,缩进到 v 下方。当我输入 val x = (1 + 2) 时,缩进在 x 下方!

如果任何人都将 VIM 用于 Scala,那么这个错误应该早就被发现了。还是只有我一个人看到了?

最佳答案

indent/scala.vim从当前的 2.8.0.final 版本我得到了相同的结果......但我知道,它在早期版本中工作,因为我在这里有一个文件可以工作。这里是:

" 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

但我不知道更改是从哪里引入的...试图在 https://codereview.scala-lang.org/fisheye/browse/scala-svn/scala-tool-support/trunk/src/vim/indent/scala.vim 的 SVN 历史记录中找到它。

关于VIM 和 Scala -- 缩进问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3605986/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com