2005-04-25 01:05:04 +08:00
|
|
|
" LLVM coding guidelines conformance for VIM
|
2010-02-27 05:38:04 +08:00
|
|
|
" $Revision$
|
2009-01-03 00:26:14 +08:00
|
|
|
"
|
|
|
|
" Maintainer: The LLVM Team, http://llvm.org
|
2005-04-25 01:05:04 +08:00
|
|
|
" WARNING: Read before you source in all these commands and macros! Some
|
2005-05-13 05:41:48 +08:00
|
|
|
" of them may change VIM behavior that you depend on.
|
2009-01-03 00:26:14 +08:00
|
|
|
"
|
|
|
|
" You can run VIM with these settings without changing your current setup with:
|
|
|
|
" $ vim -u /path/to/llvm/utils/vim/vimrc
|
|
|
|
|
|
|
|
" It's VIM, not VI
|
|
|
|
set nocompatible
|
2005-04-25 01:05:04 +08:00
|
|
|
|
|
|
|
" A tab produces a 2-space indentation
|
2009-01-04 08:05:43 +08:00
|
|
|
set softtabstop=2
|
2005-04-25 01:05:04 +08:00
|
|
|
set shiftwidth=2
|
|
|
|
set expandtab
|
|
|
|
|
2010-02-27 05:24:46 +08:00
|
|
|
" Highlight trailing whitespace and lines longer than 80 columns.
|
|
|
|
highlight LongLine ctermbg=DarkYellow guibg=DarkYellow
|
2009-01-03 00:26:14 +08:00
|
|
|
highlight WhitespaceEOL ctermbg=DarkYellow guibg=DarkYellow
|
2010-02-27 05:24:46 +08:00
|
|
|
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
|
2010-02-27 05:45:37 +08:00
|
|
|
" whitespace that has just been typed.
|
2010-02-27 05:24:46 +08:00
|
|
|
au BufWinEnter * let w:m1=matchadd('WhitespaceEOL', '\s\+$', -1)
|
|
|
|
au InsertEnter * call matchdelete(w:m1)
|
|
|
|
au InsertEnter * let w:m2=matchadd('WhitespaceEOL', '\s\+\%#\@<!$', -1)
|
|
|
|
au InsertLeave * call matchdelete(w:m2)
|
|
|
|
au InsertLeave * let w:m1=matchadd('WhitespaceEOL', '\s\+$', -1)
|
|
|
|
else
|
|
|
|
au BufRead,BufNewFile * syntax match LongLine /\%>80v.\+/
|
|
|
|
au InsertEnter * syntax match WhitespaceEOL /\s\+\%#\@<!$/
|
|
|
|
au InsertLeave * syntax match WhitespaceEOL /\s\+$/
|
|
|
|
endif
|
2009-01-03 00:26:14 +08:00
|
|
|
|
2009-01-22 05:30:25 +08:00
|
|
|
" Enable filetype detection
|
|
|
|
filetype on
|
|
|
|
|
2005-05-13 05:41:48 +08:00
|
|
|
" Optional
|
|
|
|
" C/C++ programming helpers
|
2009-01-22 05:30:25 +08:00
|
|
|
augroup csrc
|
|
|
|
au!
|
|
|
|
autocmd FileType * set nocindent smartindent
|
|
|
|
autocmd FileType c,cpp set cindent
|
|
|
|
augroup END
|
2009-01-05 02:59:55 +08:00
|
|
|
" Set a few indentation parameters. See the VIM help for cinoptions-values for
|
|
|
|
" details. These aren't absolute rules; they're just an approximation of
|
|
|
|
" common style in LLVM source.
|
2010-01-10 01:15:21 +08:00
|
|
|
set cinoptions=:0,g0,(0,Ws,l1
|
2005-05-13 05:41:48 +08:00
|
|
|
" Add and delete spaces in increments of `shiftwidth' for tabs
|
|
|
|
set smarttab
|
|
|
|
|
2009-01-03 00:26:14 +08:00
|
|
|
" Highlight syntax in programming languages
|
|
|
|
syntax on
|
|
|
|
|
2005-04-25 01:05:04 +08:00
|
|
|
" LLVM Makefiles can have names such as Makefile.rules or TEST.nightly.Makefile,
|
|
|
|
" so it's important to categorize them as such.
|
|
|
|
augroup filetype
|
2009-01-03 00:26:14 +08:00
|
|
|
au! BufRead,BufNewFile *Makefile* set filetype=make
|
2005-04-25 01:05:04 +08:00
|
|
|
augroup END
|
|
|
|
|
|
|
|
" In Makefiles, don't expand tabs to spaces, since we need the actual tabs
|
|
|
|
autocmd FileType make set noexpandtab
|
|
|
|
|
|
|
|
" Useful macros for cleaning up code to conform to LLVM coding guidelines
|
|
|
|
|
|
|
|
" Delete trailing whitespace and tabs at the end of each line
|
2009-01-08 10:17:30 +08:00
|
|
|
command! DeleteTrailingWs :%s/\s\+$//
|
2005-04-25 01:05:04 +08:00
|
|
|
|
|
|
|
" Convert all tab characters to two spaces
|
2009-01-03 00:26:14 +08:00
|
|
|
command! Untab :%s/\t/ /g
|
2009-01-22 05:47:51 +08:00
|
|
|
|
|
|
|
" Enable syntax highlighting for LLVM files. To use, copy
|
2017-02-01 05:33:21 +08:00
|
|
|
" utils/vim/syntax/llvm.vim to ~/.vim/syntax .
|
2009-01-22 05:47:51 +08:00
|
|
|
augroup filetype
|
|
|
|
au! BufRead,BufNewFile *.ll set filetype=llvm
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
" Enable syntax highlighting for tablegen files. To use, copy
|
2017-02-01 05:33:21 +08:00
|
|
|
" utils/vim/syntax/tablegen.vim to ~/.vim/syntax .
|
2009-01-22 05:47:51 +08:00
|
|
|
augroup filetype
|
|
|
|
au! BufRead,BufNewFile *.td set filetype=tablegen
|
|
|
|
augroup END
|
2010-02-27 05:24:46 +08:00
|
|
|
|
2013-02-28 14:43:24 +08:00
|
|
|
" Enable syntax highlighting for reStructuredText files. To use, copy
|
|
|
|
" rest.vim (http://www.vim.org/scripts/script.php?script_id=973)
|
|
|
|
" to ~/.vim/syntax .
|
|
|
|
augroup filetype
|
|
|
|
au! BufRead,BufNewFile *.rst set filetype=rest
|
|
|
|
augroup END
|
|
|
|
|
2010-02-27 05:24:46 +08:00
|
|
|
" Additional vim features to optionally uncomment.
|
|
|
|
"set showcmd
|
|
|
|
"set showmatch
|
|
|
|
"set showmode
|
|
|
|
"set incsearch
|
|
|
|
"set ruler
|
2010-08-27 02:12:22 +08:00
|
|
|
|
2010-10-27 07:24:54 +08:00
|
|
|
" Clang code-completion support. This is somewhat experimental!
|
2010-08-27 02:12:22 +08:00
|
|
|
|
2010-08-27 23:15:31 +08:00
|
|
|
" A path to a clang executable.
|
|
|
|
let g:clang_path = "clang++"
|
2010-08-27 02:12:22 +08:00
|
|
|
|
|
|
|
" A list of options to add to the clang commandline, for example to add
|
|
|
|
" include paths, predefined macros, and language options.
|
|
|
|
let g:clang_opts = [
|
|
|
|
\ "-x","c++",
|
|
|
|
\ "-D__STDC_LIMIT_MACROS=1","-D__STDC_CONSTANT_MACROS=1",
|
|
|
|
\ "-Iinclude" ]
|
|
|
|
|
|
|
|
function! ClangComplete(findstart, base)
|
|
|
|
if a:findstart == 1
|
|
|
|
" In findstart mode, look for the beginning of the current identifier.
|
|
|
|
let l:line = getline('.')
|
|
|
|
let l:start = col('.') - 1
|
|
|
|
while l:start > 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
|
|
|
|
|
2010-08-27 23:16:09 +08:00
|
|
|
" 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
|
|
|
|
|
2010-08-27 23:16:40 +08:00
|
|
|
" Handle "Pattern". TODO: Make clang less weird.
|
2010-08-27 02:12:22 +08:00
|
|
|
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
|
|
|
|
|
2010-10-27 07:24:54 +08:00
|
|
|
" This to enables the somewhat-experimental clang-based
|
|
|
|
" autocompletion support.
|
|
|
|
set omnifunc=ClangComplete
|