Skip to content

Commit

Permalink
customqf enhancements
Browse files Browse the repository at this point in the history
- restore initial lines / remove annotations
- wrap/tighten changing of local settings to where it is necessary
- add highlighting for neomakeBufferName (linking to qfFileName used by
  Vim itself since 8.0.1332 - not yet in Neovim)

Closes neomake#1857.
  • Loading branch information
blueyed committed Feb 16, 2018
1 parent 85d2b7e commit 7d658ff
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 6 deletions.
40 changes: 34 additions & 6 deletions autoload/neomake/quickfix.vim
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ function! neomake#quickfix#enable() abort
autocmd!
autocmd FileType qf call neomake#quickfix#FormatQuickfix()
augroup END
if &filetype ==# 'qf'
call neomake#quickfix#FormatQuickfix()
endif
endfunction


function! neomake#quickfix#disable() abort
let s:is_enabled = 0
if &filetype ==# 'qf'
call neomake#quickfix#FormatQuickfix()
endif
endfunction


Expand Down Expand Up @@ -56,13 +62,26 @@ function! neomake#quickfix#set_syntax(names) abort
endfor
endfunction

function! s:set_qf_lines(lines) abort
let ul = &l:undolevels
setlocal modifiable nonumber undolevels=-1

call setline(1, a:lines)

let &l:undolevels = ul
setlocal nomodifiable nomodified
endfunction

function! s:clean_qf_annotations() abort
if exists('b:_neomake_maker_match_id')
silent! call matchdelete(b:_neomake_maker_match_id)
endif
if exists('b:_neomake_gutter_match_id')
silent! call matchdelete(b:_neomake_gutter_match_id)
endif
if exists('b:_neomake_bufname_match_id')
silent! call matchdelete(b:_neomake_bufname_match_id)
endif
if exists('b:_neomake_cursor_match_id')
silent! call matchdelete(b:_neomake_cursor_match_id)
endif
Expand All @@ -74,10 +93,15 @@ function! neomake#quickfix#FormatQuickfix() abort
if !s:is_enabled || &filetype !=# 'qf'
if exists('b:neomake_qf')
call neomake#signs#Clean(buf, 'file')
if exists('b:_neomake_qf_orig_lines')
call s:set_qf_lines(b:_neomake_qf_orig_lines)
unlet b:_neomake_qf_orig_lines
endif
unlet! b:neomake_qf
augroup neomake_qf
autocmd! * <buffer>
augroup END
call s:clean_qf_annotations()
endif
return
endif
Expand All @@ -104,9 +128,6 @@ function! neomake#quickfix#FormatQuickfix() abort
let b:neomake_qf = 'project'
endif

let ul = &l:undolevels
setlocal modifiable nonumber undolevels=-1

let lines = []
let signs = []
let i = 0
Expand Down Expand Up @@ -214,9 +235,10 @@ function! neomake#quickfix#FormatQuickfix() abort
endif
endfor

call setline(1, lines)
let &l:undolevels = ul
setlocal nomodifiable nomodified
if !exists('b:_neomake_qf_orig_lines')
let b:_neomake_qf_orig_lines = getbufline('%', 1, '$')
endif
call s:set_qf_lines(lines)

if exists('+breakindent')
" Keeps the text aligned with the fake gutter.
Expand All @@ -242,6 +264,12 @@ function! neomake#quickfix#FormatQuickfix() abort
\ '\%>'.(maker_width).'c'
\ .'.*\%<'.(b:neomake_start_col + 2).'c',
\ s:match_base_priority+2)
if exists('b:_neomake_bufname_match_id')
silent! call matchdelete(b:_neomake_bufname_match_id)
endif
let b:_neomake_bufname_match_id = matchadd('neomakeBufferName',
\ '.*\%<'.(maker_width + 1).'c',
\ s:match_base_priority+3)
endif

augroup neomake_qf
Expand Down
1 change: 1 addition & 0 deletions syntax/neomake/qf.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ let b:current_syntax = 'neomake_qf'
highlight default link neomakeListNr LineNr
highlight default link neomakeCursorListNr CursorLineNr
highlight default link neomakeMakerName FoldColumn
highlight default link neomakeBufferName qfFileName
61 changes: 61 additions & 0 deletions tests/customqf.vader
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,64 @@ Execute (custom qf gets disabled with manual setloclist()):
finally
call neomake#quickfix#disable()
endtry

Execute (disabling it restores initial lines (in qf window)):
new
call setloclist(0, [{
\ 'lnum': 1,
\ 'text': 'Text with marker nmcfg:{"name": "b", "short": "b"}',
\}])
lopen
AssertEqual getline(1), '|1| Text with marker nmcfg:{"name": "b", "short": "b"}'
call neomake#quickfix#enable()
try
AssertEqual getline(1), 'b 1:- Text with marker'
call neomake#quickfix#disable()
AssertEqual getline(1), '|1| Text with marker nmcfg:{"name": "b", "short": "b"}'
lclose
bwipe
finally
call neomake#quickfix#disable()
endtry

Execute (enabling does not touch existing lists (in another window)):
new
call setloclist(0, [{
\ 'lnum': 1,
\ 'text': 'Text with marker nmcfg:{"name": "b", "short": "b"}',
\}])
lopen
AssertEqual getline(1), '|1| Text with marker nmcfg:{"name": "b", "short": "b"}'
wincmd p
call neomake#quickfix#enable()
try
wincmd p
AssertEqual getline(1), '|1| Text with marker nmcfg:{"name": "b", "short": "b"}'
call neomake#quickfix#disable()
AssertEqual getline(1), '|1| Text with marker nmcfg:{"name": "b", "short": "b"}'
lclose
bwipe
finally
call neomake#quickfix#disable()
endtry

Execute (enabling does not touch existing lists (in another window)):
new
call setloclist(0, [{
\ 'lnum': 1,
\ 'text': 'Text with marker nmcfg:{"name": "b", "short": "b"}',
\}])
lopen
AssertEqual getline(1), '|1| Text with marker nmcfg:{"name": "b", "short": "b"}'
call neomake#quickfix#enable()
try
AssertEqual getline(1), 'b 1:- Text with marker'
wincmd p
call neomake#quickfix#disable()
wincmd p
AssertEqual getline(1), 'b 1:- Text with marker'
lclose
bwipe
finally
call neomake#quickfix#disable()
endtry

0 comments on commit 7d658ff

Please sign in to comment.