1

Nemerle 是一种类似 C 的语言,并且大多与cindent. 然而,它的构造类似于switch被称为match

match (x)                // switch (x)
{                        // {
| "Hello World" => ...   // case "Hello World": ...
| _ => ...               // default: ...
}                        // }

是否可以将cinoptionsforswitch语句应用于此构造?也许我可以在某处设置一个正则表达式。如果没有,我可以让垂直条以另一种方式与大括号对齐吗?


更新

这是我想出的:

" Vim indent file
" Language:   Nemerle
" Maintainer: Alexey Badalov

" Only load this indent file when no other was loaded.
if exists("b:did_indent")
   finish
endif
let b:did_indent = 1

" Nemerle is C-like, but without switch statements or labels.
setlocal cindent cinoptions=L0

" Enable '|', disable ':'.
setlocal indentkeys=0{,0},0),0#,0\|,!^F,o,O,e

setlocal indentexpr=GetNemerleIndent()

let b:undo_indent = "setl cin< cino< indentkeys< indentexpr<"

function! GetNemerleIndent()
    " Nemerle is C-like; use built-in C indentation as a basis.
    let indent = cindent(v:lnum)

    " Set alignment for lines starting with '|' in line with the opening
    " brace. Use default indentation outside of blocks.
    if getline(v:lnum) =~ '^\s*|'
        call cursor(v:lnum, 1)
        silent! normal [{
        if line('.') == v:lnum
            return indent
        endif
        return indent(line('.'))
    endif

    return indent
endfunction
4

1 回答 1

3

See :h indent-expression to get a foothold in the Vim documentation. Basically I think you will want to write your own "indent file" for your filetype, which will return an indentexpr with appropriate spaces for your match structure, and otherwise (assuming that's only change) return the usual cindent() value. It involves a little more than just setting a regular expression, the indent file will have Vim commands and structures to evaluate lines and return correct value. As documentation says, best way to learn how they work is to look at some of the indent files for other languages. . . . (C doesn't have an indent file for you to look at because it's all integrated into Vim's own c source code, but most other languages have indent files using Vimscript.)

于 2011-11-28T08:26:43.173 回答