mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-15 07:59:57 +00:00
Enhanced vim support.
This brings the utils/vim folder into a more vim-like format by moving the syntax hightlighting files into a syntax subdirectory. It adds some minimal settings that everyone should agree on to ftdetect/ftplugin and features a new indentation plugin for .ll files. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235369 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6fbedc4cfd
commit
b1675e5355
@ -1,33 +1,12 @@
|
||||
-*- llvm/utils/vim/README -*-
|
||||
|
||||
These are syntax highlighting files for the VIM editor. Included are:
|
||||
This directory contains settings for the vim editor to work on llvm *.ll and
|
||||
tablegen *.td files. It comes with filetype detection rules in the (ftdetect),
|
||||
syntax highlighting (syntax), some minimal sensible default settings (ftplugin)
|
||||
and indentation plugins (indent).
|
||||
|
||||
* llvm.vim
|
||||
|
||||
Syntax highlighting mode for LLVM assembly files. To use, copy `llvm.vim' to
|
||||
~/.vim/syntax and add this code to your ~/.vimrc :
|
||||
|
||||
augroup filetype
|
||||
au! BufRead,BufNewFile *.ll set filetype=llvm
|
||||
augroup END
|
||||
|
||||
* tablegen.vim
|
||||
|
||||
Syntax highlighting mode for TableGen description files. To use, copy
|
||||
`tablegen.vim' to ~/.vim/syntax and add this code to your ~/.vimrc :
|
||||
|
||||
augroup filetype
|
||||
au! BufRead,BufNewFile *.td set filetype=tablegen
|
||||
augroup END
|
||||
|
||||
|
||||
If you prefer, instead of making copies you can make symlinks from
|
||||
~/.vim/syntax/... to the syntax files in your LLVM source tree. Apparently
|
||||
this did not work with older versions of vim however, so if this doesn't
|
||||
work you may need to make actual copies of the files.
|
||||
|
||||
Another option, if you do not already have a ~/.vim/syntax directory, is
|
||||
to symlink ~/.vim/syntax itself to llvm/utils/vim .
|
||||
To install copy all subdirectories to your $HOME/.vim or if you prefer create
|
||||
symlinks to the files here. Do not copy the vimrc file here it is only meant as an inspiration and starting point for those working on llvm c++ code.
|
||||
|
||||
Note: If you notice missing or incorrect syntax highlighting, please contact
|
||||
<llvmbugs [at] cs.uiuc.edu>; if you wish to provide a patch to improve the
|
||||
|
1
utils/vim/ftdetect/llvm.vim
Normal file
1
utils/vim/ftdetect/llvm.vim
Normal file
@ -0,0 +1 @@
|
||||
au BufRead,BufNewFile *.ll set filetype=llvm
|
1
utils/vim/ftdetect/tablegen.vim
Normal file
1
utils/vim/ftdetect/tablegen.vim
Normal file
@ -0,0 +1 @@
|
||||
au BufRead,BufNewFile *.td set filetype=tablegen
|
11
utils/vim/ftplugin/llvm.vim
Normal file
11
utils/vim/ftplugin/llvm.vim
Normal file
@ -0,0 +1,11 @@
|
||||
" Vim filetype plugin file
|
||||
" Language: LLVM Assembly
|
||||
" Maintainer: The LLVM team, http://llvm.org/
|
||||
|
||||
if exists("b:did_ftplugin")
|
||||
finish
|
||||
endif
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
setlocal softtabstop=2 shiftwidth=2
|
||||
setlocal expandtab
|
12
utils/vim/ftplugin/tablegen.vim
Normal file
12
utils/vim/ftplugin/tablegen.vim
Normal file
@ -0,0 +1,12 @@
|
||||
" Vim filetype plugin file
|
||||
" Language: LLVM TableGen
|
||||
" Maintainer: The LLVM team, http://llvm.org/
|
||||
|
||||
if exists("b:did_ftplugin")
|
||||
finish
|
||||
endif
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
setlocal matchpairs+=<:>
|
||||
setlocal softtabstop=2 shiftwidth=2
|
||||
setlocal expandtab
|
72
utils/vim/indent/llvm.vim
Normal file
72
utils/vim/indent/llvm.vim
Normal file
@ -0,0 +1,72 @@
|
||||
" Vim indent file
|
||||
" Language: llvm
|
||||
" Maintainer: The LLVM team, http://llvm.org/
|
||||
" What this indent plugin currently does:
|
||||
" - If no other rule matches copy indent from previous non-empty,
|
||||
" non-commented line
|
||||
" - On '}' align the same as the line containing the matching '{'
|
||||
" - If previous line ends with ':' increase indentation
|
||||
" - If the current line ends with ':' indent at the same level as the
|
||||
" enclosing '{'/'}' block
|
||||
" Stuff that would be nice to add:
|
||||
" - Continue comments on next line
|
||||
" - If there is an opening+unclosed parenthesis on previous line indent to that
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal shiftwidth=2 expandtab
|
||||
|
||||
setlocal indentkeys=0{,0},<:>,!^F,o,O,e
|
||||
setlocal indentexpr=GetLLVMIndent()
|
||||
|
||||
if exists("*GetLLVMIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
function! FindOpenBracket(lnum)
|
||||
call cursor(a:lnum, 1)
|
||||
return searchpair('{', '', '}', 'bW')
|
||||
endfun
|
||||
|
||||
function! GetLLVMIndent()
|
||||
" On '}' align the same as the line containing the matching '{'
|
||||
let thisline = getline(v:lnum)
|
||||
if thisline =~ '^\s*}'
|
||||
call cursor(v:lnum, 1)
|
||||
silent normal %
|
||||
let opening_lnum = line('.')
|
||||
if opening_lnum != v:lnum
|
||||
return indent(opening_lnum)
|
||||
endif
|
||||
endif
|
||||
|
||||
" Indent labels the same as the current opening block
|
||||
if thisline =~ ':\s*$'
|
||||
let blockbegin = FindOpenBracket(v:lnum)
|
||||
if blockbegin > 0
|
||||
return indent(blockbegin)
|
||||
endif
|
||||
endif
|
||||
|
||||
" Find a non-blank not-completely commented line above the current line.
|
||||
let prev_lnum = prevnonblank(v:lnum - 1)
|
||||
while prev_num > 0 && synIDattr(synID(prev_lnum, indent(prev_lnum)+1, 0), "name") =? "string\|comment"
|
||||
let prev_lnum = prevnonblank(prev_lnum-1)
|
||||
endwhile
|
||||
" Hit the start of the file, use zero indent.
|
||||
if prev_lnum == 0
|
||||
return 0
|
||||
endif
|
||||
|
||||
let ind = indent(prev_lnum)
|
||||
let prevline = getline(prev_lnum)
|
||||
|
||||
" Add a 'shiftwidth' after lines that start a block or labels
|
||||
if prevline =~ '{\s*$' || prevline =~ ':\s*$'
|
||||
let ind = ind + &shiftwidth
|
||||
endif
|
||||
|
||||
return ind
|
||||
endfunction
|
Loading…
Reference in New Issue
Block a user