X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=utils%2Fvim%2Fvimrc;h=3dfa5c931fba0b2c4f6a0523ad6d6160bc243954;hb=ecf93e4ab3b8ac5972ee3747a3a90a12e6cbadd6;hp=6efd59c305b01d6caf6647b74b26ab44ee0d503b;hpb=3d6eea518c73fc28740cccaa49fc77034e1977e4;p=oota-llvm.git diff --git a/utils/vim/vimrc b/utils/vim/vimrc index 6efd59c305b..3dfa5c931fb 100644 --- a/utils/vim/vimrc +++ b/utils/vim/vimrc @@ -1,25 +1,65 @@ " LLVM coding guidelines conformance for VIM -" Maintainer: LLVM Team, http://llvm.cs.uiuc.edu -" Updated: 2005-04-24 +" $Revision$ +" +" Maintainer: The LLVM Team, http://llvm.org " WARNING: Read before you source in all these commands and macros! Some -" of them may change VIM behavior that you depend on and the -" settings here may depend on other settings that you may have. +" of them may change VIM behavior that you depend on. +" +" You can run VIM with these settings without changing your current setup with: +" $ vim -u /path/to/llvm/utils/vim/vimrc -" Wrap text at 80 cols -set textwidth=80 +" It's VIM, not VI +set nocompatible " A tab produces a 2-space indentation -set tabstop=2 +set softtabstop=2 set shiftwidth=2 set expandtab +" Highlight trailing whitespace and lines longer than 80 columns. +highlight LongLine ctermbg=DarkYellow guibg=DarkYellow +highlight WhitespaceEOL ctermbg=DarkYellow guibg=DarkYellow +if v:version >= 702 + " Lines longer than 80 columns. + au BufWinEnter * let w:m0=matchadd('LongLine', '\%>80v.\+', -1) + + " Whitespace at the end of a line. This little dance suppresses + " whitespace that has just been typed. + au BufWinEnter * let w:m1=matchadd('WhitespaceEOL', '\s\+$', -1) + au InsertEnter * call matchdelete(w:m1) + au InsertEnter * let w:m2=matchadd('WhitespaceEOL', '\s\+\%#\@80v.\+/ + au InsertEnter * syntax match WhitespaceEOL /\s\+\%#\@ 0 && l:line[l:start - 1] =~ '\i' + let l:start -= 1 + endwhile + return l:start + endif + + " Get the current line and column numbers. + let l:l = line('.') + let l:c = col('.') + + " Build a clang commandline to do code completion on stdin. + let l:the_command = shellescape(g:clang_path) . + \ " -cc1 -code-completion-at=-:" . l:l . ":" . l:c + for l:opt in g:clang_opts + let l:the_command .= " " . shellescape(l:opt) + endfor + + " Copy the contents of the current buffer into a string for stdin. + " TODO: The extra space at the end is for working around clang's + " apparent inability to do code completion at the very end of the + " input. + " TODO: Is it better to feed clang the entire file instead of truncating + " it at the current line? + let l:process_input = join(getline(1, l:l), "\n") . " " + + " Run it! + let l:input_lines = split(system(l:the_command, l:process_input), "\n") + + " Parse the output. + for l:input_line in l:input_lines + " Vim's substring operator is annoyingly inconsistent with python's. + if l:input_line[:11] == 'COMPLETION: ' + let l:value = l:input_line[12:] + + " Chop off anything after " : ", if present, and move it to the menu. + let l:menu = "" + let l:spacecolonspace = stridx(l:value, " : ") + if l:spacecolonspace != -1 + let l:menu = l:value[l:spacecolonspace+3:] + let l:value = l:value[:l:spacecolonspace-1] + endif + + " Chop off " (Hidden)", if present, and move it to the menu. + let l:hidden = stridx(l:value, " (Hidden)") + if l:hidden != -1 + let l:menu .= " (Hidden)" + let l:value = l:value[:l:hidden-1] + endif + + " Handle "Pattern". TODO: Make clang less weird. + if l:value == "Pattern" + let l:value = l:menu + let l:pound = stridx(l:value, "#") + " Truncate the at the first [#, <#, or {#. + if l:pound != -1 + let l:value = l:value[:l:pound-2] + endif + endif + + " Filter out results which don't match the base string. + if a:base != "" + if l:value[:strlen(a:base)-1] != a:base + continue + end + endif + + " TODO: Don't dump the raw input into info, though it's nice for now. + " TODO: The kind string? + let l:item = { + \ "word": l:value, + \ "menu": l:menu, + \ "info": l:input_line, + \ "dup": 1 } + + " Report a result. + if complete_add(l:item) == 0 + return [] + endif + if complete_check() + return [] + endif + + elseif l:input_line[:9] == "OVERLOAD: " + " An overload candidate. Use a crazy hack to get vim to + " display the results. TODO: Make this better. + let l:value = l:input_line[10:] + let l:item = { + \ "word": " ", + \ "menu": l:value, + \ "info": l:input_line, + \ "dup": 1} + + " Report a result. + if complete_add(l:item) == 0 + return [] + endif + if complete_check() + return [] + endif + + endif + endfor + + + return [] +endfunction ClangComplete + +" Uncomment this to enable the highly-broken autocompletion support. +"set omnifunc=ClangComplete