Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] add commands to focus specific makers #2440

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions autoload/neomake/cmd.vim
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,88 @@ function! neomake#cmd#display_status() abort
endfor
let msg .= '.'

" Information about focused makers.
let focused = neomake#config#get_with_source('_saved_for_focus')
if focused[1] !=# 'default'
" NOTE: only looks at new-style config.
let effective = neomake#config#get_with_source('enabled_makers')

if focused[0][-1][1] ==# effective[0]
let msg .= printf(' Focused %s for %s.', join(effective[0], ', '), focused[1])
else
let msg .= printf(' Focused for %s, but effective makers are different (%s != %s).',
\ focused[1], join(focused[-1][1], ', '), join(effective[0], ', '))
endif
endif

echom msg
call neomake#log#debug(msg)
endfunction
" }}}

function! s:update_for_focus() abort
call neomake#configure#automake()
call neomake#statusline#clear_cache()
endfunction

function! s:msg(msg) abort
echom a:msg
call neomake#log#debug(a:msg)
endfunction

function! neomake#cmd#focus(scope, ...) abort
let unset = g:neomake#config#undefined

let new = a:000
let cur = get(get(a:scope, 'neomake', {}), 'enabled_makers', unset)

let stash = get(get(a:scope, 'neomake', {}), '_saved_for_focus', [])

if !empty(stash)
\ && stash[-1][1] == a:000
call s:msg(printf('Already focused %s.', join(new, ', ')))
else
call add(stash, [cur, new])
call neomake#config#set_dict(a:scope, 'neomake._saved_for_focus', stash)
call s:msg(printf('Focusing %s.', join(new, ', ')))
call neomake#config#set_dict(a:scope, 'neomake.enabled_makers', a:000)
call s:update_for_focus()
endif
endfunction

function! neomake#cmd#unfocus(bang, scope, ...) abort
let unset = g:neomake#config#undefined

let stash = get(get(a:scope, 'neomake', {}), '_saved_for_focus', unset)
if stash is unset
call neomake#log#error('nothing to unfocus')
return
endif

if a:bang
" Back to orig/first.
let prev = stash[0][0]
let stash = []
else
let prev = remove(stash, -1)[0]
endif

" Update stash.
if empty(stash)
call neomake#config#unset_dict(a:scope, 'neomake._saved_for_focus')
else
call neomake#config#set_dict(a:scope, 'neomake._saved_for_focus', stash)
endif

if prev is unset
call s:msg('Unfocus: unset enabled_makers.')
call neomake#config#unset_dict(a:scope, 'neomake.enabled_makers')
else
call s:msg(printf('Unfocus: set enabled_makers back to %s.', join(prev, ', ')))
call neomake#config#set_dict(a:scope, 'neomake.enabled_makers', prev)
endif

call s:update_for_focus()
endfunction

" vim: ts=4 sw=4 et
7 changes: 6 additions & 1 deletion autoload/neomake/debug.vim
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,12 @@ function! neomake#debug#_get_info_lines() abort
let r += [join(map(split(neomake#utils#redir('verb set makeprg?'), '\n'), 's:trim(v:val)'), ', ')]

let r += ['']
let r += ['##### Enabled makers']
let focused_source = neomake#config#get_with_source('_saved_for_focus')[1]
if focused_source !=# 'default'
let r += [printf('##### Enabled makers (focused for %s)', focused_source)]
else
let r += ['##### Enabled makers']
endif
let r += ['']
let r += ['For the current filetype ("'.ft.'", used with :Neomake):']
let r += s:get_makers_info(ft)
Expand Down
5 changes: 5 additions & 0 deletions plugin/neomake.vim
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ command! -bar NeomakeEnable call neomake#cmd#enable(g:)
command! -bar NeomakeEnableBuffer call neomake#cmd#enable(b:)
command! -bar NeomakeEnableTab call neomake#cmd#enable(t:)

command! -bar -nargs=+ -complete=customlist,neomake#cmd#complete_makers
\ NeomakeFocusBuffer call neomake#cmd#focus(b:, <f-args>)
command! -bang -bar -nargs=0 -complete=customlist,neomake#cmd#complete_makers
\ NeomakeUnfocusBuffer call neomake#cmd#unfocus(<bang>0, b:)

command! NeomakeStatus call neomake#cmd#display_status()

" NOTE: experimental, no default mappings.
Expand Down
30 changes: 30 additions & 0 deletions tests/cmd_focus.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
" Tests for the NeomakeInfo command.
Include: include/setup.vader

Execute (NeomakeFocus):
noautocmd setfiletype neomake_tests

call NeomakeTestsSetVimMessagesMarker()

NeomakeStatus
AssertEqual NeomakeTestsGetVimMessages(), ['Neomake is enabled.']

NeomakeFocus maker_without_exe
AssertEqual NeomakeTestsGetVimMessages(), ['Focusing maker_without_exe.']
NeomakeStatus
AssertEqual NeomakeTestsGetVimMessages(), ['Neomake is enabled. Focused maker_without_exe for buffer.']

NeomakeFocus maker_without_exe
AssertEqual NeomakeTestsGetVimMessages(), ['Already focused maker_without_exe.']

NeomakeFocus nonexisting
AssertEqual NeomakeTestsGetVimMessages(), ['Focusing nonexisting.']

NeomakeFocus maker_without_exe
AssertEqual NeomakeTestsGetVimMessages(), ['Focusing maker_without_exe.']

NeomakeUnfocus
AssertEqual NeomakeTestsGetVimMessages(), ['Unfocus: set enabled_makers back to nonexisting.']

NeomakeUnfocus!
AssertEqual NeomakeTestsGetVimMessages(), ['Unfocus: unset enabled_makers.']
1 change: 1 addition & 0 deletions tests/main.vader
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

~ Features
Include (:NeomakeInfo): cmd_neomakeinfo.vader
Include (:NeomakeFocus): cmd_focus.vader
Include (Automaking): automake.vader
Include (Action queue): action_queue.vader
Include (Cancellation): cancellation.vader
Expand Down