set background=dark
set hlsearch
set aw
set t_BE=
filetype plugin indent on

" highlight trailing whitespace
let c_space_errors=1
" highlight WhitespaceEOL ctermbg=red guibg=red
" match WhitespaceEOL /\s\+$/

if has('mouse')
	set mouse=a
endif

if has("cscope") && filereadable("/usr/bin/cscope")
   set csprg=/usr/bin/cscope
   set csto=0
   set cst
   set nocsverb
   " add any database in current directory
   if filereadable("cscope.out")
      cs add cscope.out
   " else add database pointed to by environment
   elseif $CSCOPE_DB != ""
      cs add $CSCOPE_DB
   endif
   set csverb
endif

function InsertInterpreter(pat)
	if a:pat =~ "sh"
		call _InsertInterpreter("bash")
	elseif a:pat =~ "pl"
		call _InsertInterpreter("perl")
	elseif a:pat =~ "py"
		call _InsertInterpreter("python")
	endif
endfun

function SetExecutableBit()
	let fname = expand("%:p")
	checktime
	exec "au FileChangedShell " . fname . " :echo"
	setlocal autoread
	silent !chmod a+x %
	checktime
	exec "au! FileChangedShell " . fname
endfun

augroup filetype
	au! BufRead,BufNewFile *.ll	set filetype=llvm
	au! BufRead,BufNewFile *.g	set filetype=antlr3
	au! BufRead,BufNewFile *.td	set filetype=tablegen
	au BufNewFile *.c		:0r /usr/share/slaby-scripts/skeleton.c
	au BufNewFile *.{pl,py,sh}      call InsertInterpreter(expand("<afile>"))
	au BufNewFile *.{pl,py,sh}      call SetExecutableBit()
augroup END

"autocmd FileType c set cin
"autocmd FileType gitcommit set tw=70 "nocin
"autocmd FileType gitcommit 1

imap <F3> <Esc>:wN<CR>
map <F3> :wN<CR>
imap <F4> <Esc>:wn<CR>
map <F4> :wn<CR>
imap <F5> <Esc>l[si
map <F5> [s
imap <F6> <Esc>l]si
map <F6> ]s
imap <F7> <Esc>:mak<CR>
map <F7> :mak<CR>
imap <C-F7> <Esc>:mak!<CR>
map <C-F7> :mak!<CR>
map <F11> :cp<CR>
map <F12> :cn<CR>
imap <C-K> <Esc>lc<End>
imap <C-U> <Esc>ld<Home>
map <C-K> d<End>
map <C-U> d<Home>
map <C-N> ?^@@<CR>V/^@@\\|\\%$<CR>:s/^[- ]//n<CR>
map <C-M> ?^@@<CR>V/^@@\\|\\%$<CR>:s/^[+ ]//n<CR>
