mirror of https://github.com/amix/vimrc.git
parent
26861f69b1
commit
6b48dc598f
@ -0,0 +1,22 @@ |
||||
"============================================================================ |
||||
"File: mixedindentlint.vim |
||||
"Description: Mixed indentation linter for vim |
||||
"Maintainer: Payton Swick <payton@foolord.com> |
||||
"License: This program is free software. It comes without any warranty, |
||||
" to the extent permitted by applicable law. You can redistribute |
||||
" it and/or modify it under the terms of the Do What The Fuck You |
||||
" Want To Public License, Version 2, as published by Sam Hocevar. |
||||
" See http://sam.zoy.org/wtfpl/COPYING for more details. |
||||
"============================================================================ |
||||
|
||||
if exists('g:loaded_syntastic_css_mixedindentlint_checker') |
||||
finish |
||||
endif |
||||
let g:loaded_syntastic_css_mixedindentlint_checker = 1 |
||||
|
||||
call g:SyntasticRegistry.CreateAndRegisterChecker({ |
||||
\ 'filetype': 'css', |
||||
\ 'name': 'mixedindentlint', |
||||
\ 'redirect': 'javascript/mixedindentlint'}) |
||||
|
||||
" vim: set et sts=4 sw=4: |
@ -0,0 +1,40 @@ |
||||
"============================================================================ |
||||
"File: mixedindentlint.vim |
||||
"Description: Mixed indentation linter for vim |
||||
"Maintainer: Payton Swick <payton@foolord.com> |
||||
"License: This program is free software. It comes without any warranty, |
||||
" to the extent permitted by applicable law. You can redistribute |
||||
" it and/or modify it under the terms of the Do What The Fuck You |
||||
" Want To Public License, Version 2, as published by Sam Hocevar. |
||||
" See http://sam.zoy.org/wtfpl/COPYING for more details. |
||||
"============================================================================ |
||||
|
||||
if exists('g:loaded_syntastic_javascript_mixedindentlint_checker') |
||||
finish |
||||
endif |
||||
let g:loaded_syntastic_javascript_mixedindentlint_checker = 1 |
||||
|
||||
let s:save_cpo = &cpo |
||||
set cpo&vim |
||||
|
||||
function! SyntaxCheckers_javascript_mixedindentlint_GetLocList() dict |
||||
let makeprg = self.makeprgBuild({}) |
||||
|
||||
let errorformat = 'Line %l in "%f" %.%#' |
||||
|
||||
return SyntasticMake({ |
||||
\ 'makeprg': makeprg, |
||||
\ 'errorformat': errorformat, |
||||
\ 'subtype': 'Style', |
||||
\ 'defaults': { 'text': 'Indentation differs from rest of file' }, |
||||
\ 'returns': [0, 1] }) |
||||
endfunction |
||||
|
||||
call g:SyntasticRegistry.CreateAndRegisterChecker({ |
||||
\ 'filetype': 'javascript', |
||||
\ 'name': 'mixedindentlint'}) |
||||
|
||||
let &cpo = s:save_cpo |
||||
unlet s:save_cpo |
||||
|
||||
" vim: set sw=4 sts=4 et fdm=marker: |
@ -0,0 +1,22 @@ |
||||
"============================================================================ |
||||
"File: mixedindentlint.vim |
||||
"Description: Mixed indentation linter for vim |
||||
"Maintainer: Payton Swick <payton@foolord.com> |
||||
"License: This program is free software. It comes without any warranty, |
||||
" to the extent permitted by applicable law. You can redistribute |
||||
" it and/or modify it under the terms of the Do What The Fuck You |
||||
" Want To Public License, Version 2, as published by Sam Hocevar. |
||||
" See http://sam.zoy.org/wtfpl/COPYING for more details. |
||||
"============================================================================ |
||||
|
||||
if exists('g:loaded_syntastic_scss_mixedindentlint_checker') |
||||
finish |
||||
endif |
||||
let g:loaded_syntastic_scss_mixedindentlint_checker = 1 |
||||
|
||||
call g:SyntasticRegistry.CreateAndRegisterChecker({ |
||||
\ 'filetype': 'scss', |
||||
\ 'name': 'mixedindentlint', |
||||
\ 'redirect': 'javascript/mixedindentlint'}) |
||||
|
||||
" vim: set et sts=4 sw=4: |
@ -0,0 +1,168 @@ |
||||
" s:jobs is a global reference to all jobs started with Spawn() or with the |
||||
" internal function s:spawn |
||||
let s:jobs = {} |
||||
|
||||
" Spawn is a wrapper around s:spawn. It can be executed by other files and |
||||
" scripts if needed. Desc defines the description for printing the status |
||||
" during the job execution (useful for statusline integration). |
||||
function! go#jobcontrol#Spawn(desc, args) |
||||
" autowrite is not enabled for jobs |
||||
call go#cmd#autowrite() |
||||
|
||||
let job = s:spawn(a:desc, a:args) |
||||
return job.id |
||||
endfunction |
||||
|
||||
" Statusline returns the current status of the job |
||||
function! go#jobcontrol#Statusline() abort |
||||
if empty(s:jobs) |
||||
return '' |
||||
endif |
||||
|
||||
let import_path = go#package#ImportPath(expand('%:p:h')) |
||||
|
||||
for job in values(s:jobs) |
||||
if job.importpath != import_path |
||||
continue |
||||
endif |
||||
|
||||
if job.state == "SUCCESS" |
||||
return '' |
||||
endif |
||||
|
||||
return printf("%s ... [%s]", job.desc, job.state) |
||||
endfor |
||||
|
||||
return '' |
||||
endfunction |
||||
|
||||
" spawn spawns a go subcommand with the name and arguments with jobstart. Once |
||||
" a job is started a reference will be stored inside s:jobs. spawn changes the |
||||
" GOPATH when g:go_autodetect_gopath is enabled. The job is started inside the |
||||
" current files folder. |
||||
function! s:spawn(desc, args) |
||||
let job = { |
||||
\ 'desc': a:desc, |
||||
\ 'winnr': winnr(), |
||||
\ 'importpath': go#package#ImportPath(expand('%:p:h')), |
||||
\ 'state': "RUNNING", |
||||
\ 'stderr' : [], |
||||
\ 'stdout' : [], |
||||
\ 'on_stdout': function('s:on_stdout'), |
||||
\ 'on_stderr': function('s:on_stderr'), |
||||
\ 'on_exit' : function('s:on_exit'), |
||||
\ } |
||||
|
||||
" modify GOPATH if needed |
||||
let old_gopath = $GOPATH |
||||
let $GOPATH = go#path#Detect() |
||||
|
||||
" execute go build in the files directory |
||||
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' |
||||
|
||||
" cleanup previous jobs for this file |
||||
for jb in values(s:jobs) |
||||
if jb.importpath == job.importpath |
||||
unlet s:jobs[jb.id] |
||||
endif |
||||
endfor |
||||
|
||||
let dir = getcwd() |
||||
|
||||
execute cd . fnameescape(expand("%:p:h")) |
||||
|
||||
" append the subcommand, such as 'build' |
||||
let argv = ['go'] + a:args |
||||
|
||||
" run, forrest, run! |
||||
let id = jobstart(argv, job) |
||||
let job.id = id |
||||
let s:jobs[id] = job |
||||
|
||||
execute cd . fnameescape(dir) |
||||
|
||||
" restore back GOPATH |
||||
let $GOPATH = old_gopath |
||||
|
||||
return job |
||||
endfunction |
||||
|
||||
" on_exit is the exit handler for jobstart(). It handles cleaning up the job |
||||
" references and also displaying errors in the quickfix window collected by |
||||
" on_stderr handler. If there are no errors and a quickfix window is open, |
||||
" it'll be closed. |
||||
function! s:on_exit(job_id, data) |
||||
let std_combined = self.stderr + self.stdout |
||||
if empty(std_combined) |
||||
call go#list#Clean() |
||||
call go#list#Window() |
||||
|
||||
let self.state = "SUCCESS" |
||||
return |
||||
endif |
||||
|
||||
let errors = go#tool#ParseErrors(std_combined) |
||||
let errors = go#tool#FilterValids(errors) |
||||
|
||||
if !len(errors) |
||||
" no errors could be past, just return |
||||
call go#list#Clean() |
||||
call go#list#Window() |
||||
|
||||
let self.state = "SUCCESS" |
||||
return |
||||
endif |
||||
|
||||
let self.state = "FAILED" |
||||
|
||||
" if we are still in the same windows show the list |
||||
if self.winnr == winnr() |
||||
call go#list#Populate(errors) |
||||
call go#list#Window(len(errors)) |
||||
call go#list#JumpToFirst() |
||||
endif |
||||
endfunction |
||||
|
||||
" on_stdout is the stdout handler for jobstart(). It collects the output of |
||||
" stderr and stores them to the jobs internal stdout list. |
||||
function! s:on_stdout(job_id, data) |
||||
call extend(self.stdout, a:data) |
||||
endfunction |
||||
|
||||
" on_stderr is the stderr handler for jobstart(). It collects the output of |
||||
" stderr and stores them to the jobs internal stderr list. |
||||
function! s:on_stderr(job_id, data) |
||||
call extend(self.stderr, a:data) |
||||
endfunction |
||||
|
||||
" abort_all aborts all current jobs created with s:spawn() |
||||
function! s:abort_all() |
||||
if empty(s:jobs) |
||||
return |
||||
endif |
||||
|
||||
for id in keys(s:jobs) |
||||
if id > 0 |
||||
silent! call jobstop(id) |
||||
endif |
||||
endfor |
||||
|
||||
let s:jobs = {} |
||||
endfunction |
||||
|
||||
" abort aborts the job with the given name, where name is the first argument |
||||
" passed to s:spawn() |
||||
function! s:abort(path) |
||||
if empty(s:jobs) |
||||
return |
||||
endif |
||||
|
||||
for job in values(s:jobs) |
||||
if job.importpath == path && job.id > 0 |
||||
silent! call jobstop(job.id) |
||||
unlet s:jobs['job.id'] |
||||
endif |
||||
endfor |
||||
endfunction |
||||
|
||||
" vim:ts=2:sw=2:et |
@ -0,0 +1,124 @@ |
||||
if has('nvim') && !exists("g:go_term_mode") |
||||
let g:go_term_mode = 'vsplit' |
||||
endif |
||||
|
||||
" s:jobs is a global reference to all jobs started with new() |
||||
let s:jobs = {} |
||||
|
||||
" new creates a new terminal with the given command. Mode is set based on the |
||||
" global variable g:go_term_mode, which is by default set to :vsplit |
||||
function! go#term#new(cmd) |
||||
call go#term#newmode(a:cmd, g:go_term_mode) |
||||
endfunction |
||||
|
||||
" new creates a new terminal with the given command and window mode. |
||||
function! go#term#newmode(cmd, mode) |
||||
let mode = a:mode |
||||
if empty(mode) |
||||
let mode = g:go_term_mode |
||||
endif |
||||
|
||||
" modify GOPATH if needed |
||||
let old_gopath = $GOPATH |
||||
let $GOPATH = go#path#Detect() |
||||
|
||||
" execute go build in the files directory |
||||
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' |
||||
let dir = getcwd() |
||||
|
||||
execute cd . fnameescape(expand("%:p:h")) |
||||
|
||||
execute mode.' __go_term__' |
||||
|
||||
setlocal filetype=goterm |
||||
setlocal bufhidden=delete |
||||
setlocal winfixheight |
||||
setlocal noswapfile |
||||
setlocal nobuflisted |
||||
|
||||
let job = { |
||||
\ 'stderr' : [], |
||||
\ 'stdout' : [], |
||||
\ 'on_stdout': function('s:on_stdout'), |
||||
\ 'on_stderr': function('s:on_stderr'), |
||||
\ 'on_exit' : function('s:on_exit'), |
||||
\ } |
||||
|
||||
let id = termopen(a:cmd, job) |
||||
|
||||
execute cd . fnameescape(dir) |
||||
|
||||
" restore back GOPATH |
||||
let $GOPATH = old_gopath |
||||
|
||||
let job.id = id |
||||
startinsert |
||||
|
||||
" resize new term if needed. |
||||
let height = get(g:, 'go_term_height', winheight(0)) |
||||
let width = get(g:, 'go_term_width', winwidth(0)) |
||||
|
||||
" we are careful how to resize. for example it's vertical we don't change |
||||
" the height. The below command resizes the buffer |
||||
if a:mode == "split" |
||||
exe 'resize ' . height |
||||
elseif a:mode == "vertical" |
||||
exe 'vertical resize ' . width |
||||
endif |
||||
|
||||
" we also need to resize the pty, so there you go... |
||||
call jobresize(id, width, height) |
||||
|
||||
let s:jobs[id] = job |
||||
return id |
||||
endfunction |
||||
|
||||
function! s:on_stdout(job_id, data) |
||||
if !has_key(s:jobs, a:job_id) |
||||
return |
||||
endif |
||||
let job = s:jobs[a:job_id] |
||||
|
||||
call extend(job.stdout, a:data) |
||||
endfunction |
||||
|
||||
function! s:on_stderr(job_id, data) |
||||
if !has_key(s:jobs, a:job_id) |
||||
return |
||||
endif |
||||
let job = s:jobs[a:job_id] |
||||
|
||||
call extend(job.stderr, a:data) |
||||
endfunction |
||||
|
||||
function! s:on_exit(job_id, data) |
||||
if !has_key(s:jobs, a:job_id) |
||||
return |
||||
endif |
||||
let job = s:jobs[a:job_id] |
||||
|
||||
" usually there is always output so never branch into this clause |
||||
if empty(job.stdout) |
||||
call go#list#Clean() |
||||
call go#list#Window() |
||||
else |
||||
let errors = go#tool#ParseErrors(job.stdout) |
||||
let errors = go#tool#FilterValids(errors) |
||||
if !empty(errors) |
||||
" close terminal we don't need it |
||||
close |
||||
|
||||
call go#list#Populate(errors) |
||||
call go#list#Window(len(errors)) |
||||
call go#list#JumpToFirst() |
||||
else |
||||
call go#list#Clean() |
||||
call go#list#Window() |
||||
endif |
||||
|
||||
endif |
||||
|
||||
unlet s:jobs[a:job_id] |
||||
endfunction |
||||
|
||||
" vim:ts=4:sw=4:et |
Loading…
Reference in new issue