brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.0 KiB · 2cc8ae9 Raw
229 lines · plain
1" LLVM coding guidelines conformance for VIM2" $Revision$3"4" Maintainer: The LLVM Team, http://llvm.org5" WARNING:    Read before you source in all these commands and macros!  Some6"             of them may change VIM behavior that you depend on.7"8" You can run VIM with these settings without changing your current setup with:9" $ vim -u /path/to/llvm/utils/vim/vimrc10 11" It's VIM, not VI12set nocompatible13 14" A tab produces a 2-space indentation15set softtabstop=216set shiftwidth=217set expandtab18 19" Highlight trailing whitespace and lines longer than 80 columns.20highlight LongLine ctermbg=DarkYellow guibg=DarkYellow21highlight WhitespaceEOL ctermbg=DarkYellow guibg=DarkYellow22if v:version >= 70223  " Lines longer than 80 columns.24  au BufWinEnter * let w:m0=matchadd('LongLine', '\%>80v.\+', -1)25 26  " Whitespace at the end of a line. This little dance suppresses27  " whitespace that has just been typed.28  au BufWinEnter * let w:m1=matchadd('WhitespaceEOL', '\s\+$', -1)29  au InsertEnter * call matchdelete(w:m1)30  au InsertEnter * let w:m2=matchadd('WhitespaceEOL', '\s\+\%#\@<!$', -1)31  au InsertLeave * call matchdelete(w:m2)32  au InsertLeave * let w:m1=matchadd('WhitespaceEOL', '\s\+$', -1)33else34  au BufRead,BufNewFile * syntax match LongLine /\%>80v.\+/35  au InsertEnter * syntax match WhitespaceEOL /\s\+\%#\@<!$/36  au InsertLeave * syntax match WhitespaceEOL /\s\+$/37endif38 39" Enable filetype detection40filetype on41 42" Optional43" C/C++ programming helpers44augroup csrc45  au!46  autocmd FileType *      set nocindent smartindent47  autocmd FileType c,cpp  set cindent48augroup END49" Set a few indentation parameters. See the VIM help for cinoptions-values for50" details.  These aren't absolute rules; they're just an approximation of51" common style in LLVM source.52set cinoptions=:0,g0,(0,Ws,l153" Add and delete spaces in increments of `shiftwidth' for tabs54set smarttab55 56" Highlight syntax in programming languages57syntax on58 59" LLVM Makefiles can have names such as Makefile.rules or TEST.nightly.Makefile,60" so it's important to categorize them as such.61augroup filetype62  au! BufRead,BufNewFile *Makefile* set filetype=make63augroup END64 65" In Makefiles, don't expand tabs to spaces, since we need the actual tabs66autocmd FileType make set noexpandtab67 68" Useful macros for cleaning up code to conform to LLVM coding guidelines69 70" Delete trailing whitespace and tabs at the end of each line71command! DeleteTrailingWs :%s/\s\+$//72 73" Convert all tab characters to two spaces74command! Untab :%s/\t/  /g75 76" Enable syntax highlighting for LLVM files. To use, copy77" utils/vim/syntax/llvm.vim to ~/.vim/syntax .78augroup filetype79  au! BufRead,BufNewFile *.ll     set filetype=llvm80augroup END81 82" Enable syntax highlighting for tablegen files. To use, copy83" utils/vim/syntax/tablegen.vim to ~/.vim/syntax .84augroup filetype85  au! BufRead,BufNewFile *.td     set filetype=tablegen86augroup END87 88" Enable syntax highlighting for reStructuredText files. To use, copy89" rest.vim (http://www.vim.org/scripts/script.php?script_id=973)90" to ~/.vim/syntax .91augroup filetype92 au! BufRead,BufNewFile *.rst     set filetype=rest93augroup END94 95" Additional vim features to optionally uncomment.96"set showcmd97"set showmatch98"set showmode99"set incsearch100"set ruler101 102" Clang code-completion support. This is somewhat experimental!103 104" A path to a clang executable.105let g:clang_path = "clang++"106 107" A list of options to add to the clang commandline, for example to add108" include paths, predefined macros, and language options.109let g:clang_opts = [110  \ "-x","c++",111  \ "-D__STDC_LIMIT_MACROS=1","-D__STDC_CONSTANT_MACROS=1",112  \ "-Iinclude" ]113 114function! ClangComplete(findstart, base)115   if a:findstart == 1116      " In findstart mode, look for the beginning of the current identifier.117      let l:line = getline('.')118      let l:start = col('.') - 1119      while l:start > 0 && l:line[l:start - 1] =~ '\i'120         let l:start -= 1121      endwhile122      return l:start123   endif124 125   " Get the current line and column numbers.126   let l:l = line('.')127   let l:c = col('.')128 129   " Build a clang commandline to do code completion on stdin.130   let l:the_command = shellescape(g:clang_path) .131                     \ " -cc1 -code-completion-at=-:" . l:l . ":" . l:c132   for l:opt in g:clang_opts133      let l:the_command .= " " . shellescape(l:opt)134   endfor135 136   " Copy the contents of the current buffer into a string for stdin.137   " TODO: The extra space at the end is for working around clang's138   " apparent inability to do code completion at the very end of the139   " input.140   " TODO: Is it better to feed clang the entire file instead of truncating141   " it at the current line?142   let l:process_input = join(getline(1, l:l), "\n") . " "143 144   " Run it!145   let l:input_lines = split(system(l:the_command, l:process_input), "\n")146 147   " Parse the output.148   for l:input_line in l:input_lines149      " Vim's substring operator is annoyingly inconsistent with python's.150      if l:input_line[:11] == 'COMPLETION: '151         let l:value = l:input_line[12:]152 153        " Chop off anything after " : ", if present, and move it to the menu.154        let l:menu = ""155        let l:spacecolonspace = stridx(l:value, " : ")156        if l:spacecolonspace != -1157           let l:menu = l:value[l:spacecolonspace+3:]158           let l:value = l:value[:l:spacecolonspace-1]159        endif160 161        " Chop off " (Hidden)", if present, and move it to the menu.162        let l:hidden = stridx(l:value, " (Hidden)")163        if l:hidden != -1164           let l:menu .= " (Hidden)"165           let l:value = l:value[:l:hidden-1]166        endif167 168        " Handle "Pattern". TODO: Make clang less weird.169        if l:value == "Pattern"170           let l:value = l:menu171           let l:pound = stridx(l:value, "#")172           " Truncate the at the first [#, <#, or {#.173           if l:pound != -1174              let l:value = l:value[:l:pound-2]175           endif176        endif177 178         " Filter out results which don't match the base string.179         if a:base != ""180            if l:value[:strlen(a:base)-1] != a:base181               continue182            end183         endif184 185        " TODO: Don't dump the raw input into info, though it's nice for now.186        " TODO: The kind string?187        let l:item = {188          \ "word": l:value,189          \ "menu": l:menu,190          \ "info": l:input_line,191          \ "dup": 1 }192 193        " Report a result.194        if complete_add(l:item) == 0195           return []196        endif197        if complete_check()198           return []199        endif200 201      elseif l:input_line[:9] == "OVERLOAD: "202         " An overload candidate. Use a crazy hack to get vim to203         " display the results. TODO: Make this better.204         let l:value = l:input_line[10:]205         let l:item = {206           \ "word": " ",207           \ "menu": l:value,208           \ "info": l:input_line,209           \ "dup": 1}210 211        " Report a result.212        if complete_add(l:item) == 0213           return []214        endif215        if complete_check()216           return []217        endif218 219      endif220   endfor221 222 223   return []224endfunction ClangComplete225 226" This to enables the somewhat-experimental clang-based227" autocompletion support.228set omnifunc=ClangComplete229