Skip to content

Instantly share code, notes, and snippets.

@tweekmonster
Last active February 5, 2017 02:22
Show Gist options
  • Save tweekmonster/8f9cfb36a56d7d1bb6a73e0f9589d81f to your computer and use it in GitHub Desktop.
Save tweekmonster/8f9cfb36a56d7d1bb6a73e0f9589d81f to your computer and use it in GitHub Desktop.
.nvimrc script for Neovim development using Neomake
if !has('nvim')
finish
endif
let s:path = expand('<sfile>:p:h')
let s:target = 'all'
let s:error_path = s:path.'/tmp/errors.json'
let s:errors_url = 'https://raw.githubusercontent.com/neovim/doc/gh-pages/reports/clint/errors.json'
let g:neomake_make_maker = {
\ 'exe': 'make',
\ 'args': ['VERBOSE=1', 'dev'],
\ 'errorformat': '%.%#../%f:%l:%c: %t%.%#: %m',
\ }
" Add `clang` if you use deoplete-clang2 (electric boogaloo)
" https://github.com/tweekmonster/deoplete-clang2
let g:neomake_c_enabled_makers = ['clint']
function! s:clint_args(...) abort
return ['--suppress-errors='.s:path.'/tmp/errors.json', expand('%')]
endfunction
let g:neomake_c_clint_maker = {
\ 'exe': s:path.'/src/clint.py',
\ 'append_file': 0,
\ 'args': function('s:clint_args'),
\ 'cwd': s:path,
\ 'errorformat': '%f:%l: %m',
\ }
let g:neomake_c_nvimtags_maker = {
\ 'exe': 'ctags',
\ 'append_file': 0,
\ 'args': ['--languages=C,C++,Lua', '-R', '-I', 'EXTERN', '-I', 'INIT',
\ '--exclude=.git*', 'src', 'build/include', 'build/src/nvim/auto',
\ '.deps/build/src'],
\ 'cwd': s:path,
\ }
let g:neomake_lua_testlint_maker = {
\ 'exe': 'make testlint',
\ }
function! s:dl_handler(job, data, event) dict abort
if a:event == 'stdout'
for line in a:data
if line =~? '^Content-Length:'
let self.remote_size = str2nr(matchstr(line, '\d\+'))
endif
endfor
elseif a:event == 'exit'
if self.size != self.remote_size
echomsg 'Updating errors.json'
call jobstart('curl -sSL "'.s:errors_url.'" > "'.s:error_path.'"')
else
echomsg 'errors.json is up to date'
endif
endif
endfunction
function! s:download_errors_json() abort
let opts = {'size': 0, 'remote_size': 0,
\ 'on_stdout': function('s:dl_handler'),
\ 'on_exit': function('s:dl_handler')}
if filereadable(s:error_path)
let opts.size = getfsize(s:error_path)
endif
call jobstart(['curl', '-sI', s:errors_url], opts)
endfunction
function! s:setup_c() abort
setlocal expandtab shiftwidth=2 softtabstop=2 textwidth=80
setlocal modelines=0 cinoptions=0(
setlocal comments=:///,://
endfunction
function! s:neomake_project_finished(mode) abort
if !a:mode && len(filter(getqflist(), 'v:val.valid'))
let buf = getqflist()[0].bufnr
if buf != winbufnr(0)
if exists('s:last_win') && winbufnr(s:last_win) == buf
let win = s:last_win
else
let win = bufwinnr(buf)
endif
execute win 'wincmd w'
endif
belowright cwindow 5
let w:quickfix_title = 'Neomake!'
wincmd p
endif
unlet! s:last_win
endfunction
augroup nvimrc
autocmd!
autocmd VimEnter * call s:download_errors_json()
autocmd User NeomakeFinished call s:neomake_project_finished(g:neomake_hook_context.file_mode)
" autocmd BufWritePost *.c,*.h,*.vim if !exists('s:last_win') | let s:last_win = winnr() | cclose | Neomake! make | endif
autocmd BufRead,BufNewFile *.h set filetype=c
autocmd FileType c call s:setup_c()
" autocmd BufWritePost * Neomake
" autocmd VimLeave * let g:neomake_verbose = 0
augroup END
.PHONY: .release-vars .dev-vars dev local-install
CMAKE_EXTRA_FLAGS := -DBUSTED_OUTPUT_TYPE=gtest
.dev-vars:
@-grep 'Configuration: Release' build/rules.ninja && $(MAKE) distclean
$(eval CMAKE_BUILD_TYPE = Debug)
$(eval CMAKE_FLAGS := -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE))
# \$(eval CMAKE_EXTRA_FLAGS = -DCMAKE_INSTALL_PREFIX=$(PWD)/build)
$(eval CMAKE_EXTRA_FLAGS = "-DCLANG_ASAN_UBSAN=ON -DCMAKE_INSTALL_PREFIX=$(HOME)/tmp/nvim")
rm -f tags
test ! -f tags.lock && \
touch tags.lock && \
ctags --languages=C,C++,Lua -R -I EXTERN -I INIT --exclude='.git*' \
src build/include build/src/nvim/auto .deps/build/src && \
rm -f tags.lock
.release-vars:
@-grep 'Configuration: Debug' build/rules.ninja && $(MAKE) distclean
# $(eval CMAKE_BUILD_TYPE = Release)
$(eval CMAKE_BUILD_TYPE = RelWithDebInfo)
$(eval CMAKE_FLAGS := -DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE))
$(eval CMAKE_EXTRA_FLAGS = "-DCMAKE_INSTALL_PREFIX=$(HOME)/.local")
dev: .dev-vars nvim
local-install: .release-vars nvim install
#!/usr/bin/env bash
DEV=$PWD
# export ASAN_SYMBOLIZER_PATH=/usr/lib/llvm-3.8/bin/llvm-symbolizer
# export ASAN_OPTIONS="log_path=${HOME}/.logs/asan"
# export MSAN_SYMBOLIZER_PATH=/usr/lib/llvm-3.8/bin/llvm-symbolizer
# export TSAN_OPTIONS="external_symbolizer_path=/usr/lib/llvm-3.8/bin/llvm-symbolizer log_path=${HOME}/.logs/tsan"
cd tmp && exec env VIMRUNTIME=$DEV/runtime $DEV/build/bin/nvim "$@"
# cd tmp && exec env VIMRUNTIME=$DEV/runtime gdb -ex run --args $DEV/build/bin/nvim "$@"
@teto
Copy link

teto commented Jan 23, 2017

You should make a plugin out of it :) !
On startup; I have "Using not in a script context: s:dl_handler" .
I tried changing replacing the mentions with Funcref in let opts = {'size': 0, 'remote_size': 0, \ 'on_stdout': 's:dl_handler', 'on_exit': 's:dl_handler'} but then it triggered other errors. Any idea ?

@tweekmonster
Copy link
Author

@teto Fixed.

@tweekmonster
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment