mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-09 08:00:05 +08:00
Fix location list statusline (#3653)
This commit is contained in:
parent
bea44f4b60
commit
c0dd1c3f05
@ -11,62 +11,62 @@ let s:self = {}
|
|||||||
let s:CMP = SpaceVim#api#import('vim#compatible')
|
let s:CMP = SpaceVim#api#import('vim#compatible')
|
||||||
|
|
||||||
function! s:self.jumps() abort
|
function! s:self.jumps() abort
|
||||||
let result = []
|
let result = []
|
||||||
for jump in split(s:CMP.execute('jumps'), '\n')[1:]
|
for jump in split(s:CMP.execute('jumps'), '\n')[1:]
|
||||||
let list = split(jump)
|
let list = split(jump)
|
||||||
if len(list) < 4
|
if len(list) < 4
|
||||||
continue
|
continue
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let [linenr, col, file_text] = [list[1], list[2]+1, join(list[3:])]
|
let [linenr, col, file_text] = [list[1], list[2]+1, join(list[3:])]
|
||||||
let lines = getbufline(file_text, linenr)
|
let lines = getbufline(file_text, linenr)
|
||||||
let path = file_text
|
let path = file_text
|
||||||
let bufnr = bufnr(file_text)
|
let bufnr = bufnr(file_text)
|
||||||
if empty(lines)
|
if empty(lines)
|
||||||
if stridx(join(split(getline(linenr))), file_text) == 0
|
if stridx(join(split(getline(linenr))), file_text) == 0
|
||||||
let lines = [file_text]
|
let lines = [file_text]
|
||||||
let path = bufname('%')
|
let path = bufname('%')
|
||||||
let bufnr = bufnr('%')
|
let bufnr = bufnr('%')
|
||||||
elseif filereadable(path)
|
elseif filereadable(path)
|
||||||
let bufnr = 0
|
let bufnr = 0
|
||||||
let lines = ['buffer unloaded']
|
let lines = ['buffer unloaded']
|
||||||
else
|
else
|
||||||
" Skip.
|
" Skip.
|
||||||
continue
|
continue
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if getbufvar(bufnr, '&filetype') ==# 'unite'
|
if getbufvar(bufnr, '&filetype') ==# 'unite'
|
||||||
" Skip unite buffer.
|
" Skip unite buffer.
|
||||||
continue
|
continue
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call add(result, [linenr, col, file_text, path, bufnr, lines])
|
call add(result, [linenr, col, file_text, path, bufnr, lines])
|
||||||
endfor
|
endfor
|
||||||
return result
|
return result
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:self.parse_string(line) abort
|
function! s:self.parse_string(line) abort
|
||||||
let expr = '`[^`]*`'
|
let expr = '`[^`]*`'
|
||||||
let i = 0
|
let i = 0
|
||||||
let line = []
|
let line = []
|
||||||
while i < strlen(a:line) || i != -1
|
while i < strlen(a:line) || i != -1
|
||||||
let [rst, m, n] = matchstrpos(a:line, expr, i)
|
let [rst, m, n] = matchstrpos(a:line, expr, i)
|
||||||
if m == -1
|
if m == -1
|
||||||
call add(line, a:line[ i : -1 ])
|
call add(line, a:line[ i : -1 ])
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
call add(line, a:line[ i : m-1])
|
call add(line, a:line[ i : m-1])
|
||||||
try
|
try
|
||||||
let rst = eval(rst[1:-2])
|
let rst = eval(rst[1:-2])
|
||||||
catch
|
catch
|
||||||
let rst = ''
|
let rst = ''
|
||||||
endtry
|
endtry
|
||||||
call add(line, rst)
|
call add(line, rst)
|
||||||
endif
|
endif
|
||||||
let i = n
|
let i = n
|
||||||
endwhile
|
endwhile
|
||||||
return join(line, '')
|
return join(line, '')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
@ -78,44 +78,44 @@ endfunction
|
|||||||
|
|
||||||
|
|
||||||
if exists('*nvim_win_set_cursor')
|
if exists('*nvim_win_set_cursor')
|
||||||
function! s:self.win_set_cursor(win, pos) abort
|
function! s:self.win_set_cursor(win, pos) abort
|
||||||
call nvim_win_set_cursor(a:win, a:pos)
|
call nvim_win_set_cursor(a:win, a:pos)
|
||||||
endfunction
|
endfunction
|
||||||
elseif exists('*win_execute')
|
elseif exists('*win_execute')
|
||||||
function! s:self.win_set_cursor(win, pos) abort
|
function! s:self.win_set_cursor(win, pos) abort
|
||||||
" @fixme use g` to move to cursor line
|
" @fixme use g` to move to cursor line
|
||||||
" this seem to be a bug of vim
|
" this seem to be a bug of vim
|
||||||
" https://github.com/vim/vim/issues/5022
|
" https://github.com/vim/vim/issues/5022
|
||||||
call win_execute(a:win, ':call cursor(' . a:pos[0] . ', ' . a:pos[1] . ')')
|
call win_execute(a:win, ':call cursor(' . a:pos[0] . ', ' . a:pos[1] . ')')
|
||||||
" call win_execute(a:win, ':' . a:pos[0])
|
" call win_execute(a:win, ':' . a:pos[0])
|
||||||
call win_execute(a:win, ':normal! g"')
|
call win_execute(a:win, ':normal! g"')
|
||||||
endfunction
|
endfunction
|
||||||
elseif has('lua')
|
elseif has('lua')
|
||||||
function! s:self.win_set_cursor(win, pos) abort
|
function! s:self.win_set_cursor(win, pos) abort
|
||||||
lua local winindex = vim.eval("win_id2win(a:win) - 1")
|
lua local winindex = vim.eval("win_id2win(a:win) - 1")
|
||||||
lua local w = vim.window(winindex)
|
lua local w = vim.window(winindex)
|
||||||
lua w.line = vim.eval("a:pos[0]")
|
lua w.line = vim.eval("a:pos[0]")
|
||||||
lua w.col = vim.eval("a:pos[1]")
|
lua w.col = vim.eval("a:pos[1]")
|
||||||
endfunction
|
endfunction
|
||||||
else
|
else
|
||||||
function! s:self.win_set_cursor(win, pos) abort
|
function! s:self.win_set_cursor(win, pos) abort
|
||||||
|
|
||||||
endfunction
|
endfunction
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if exists('*nvim_buf_line_count')
|
if exists('*nvim_buf_line_count')
|
||||||
function! s:self.buf_line_count(buf) abort
|
function! s:self.buf_line_count(buf) abort
|
||||||
return nvim_buf_line_count(a:buf)
|
return nvim_buf_line_count(a:buf)
|
||||||
endfunction
|
endfunction
|
||||||
elseif has('lua')
|
elseif has('lua')
|
||||||
function! s:self.buf_line_count(buf) abort
|
function! s:self.buf_line_count(buf) abort
|
||||||
" lua numbers are floats, so use float2nr
|
" lua numbers are floats, so use float2nr
|
||||||
return float2nr(luaeval('#vim.buffer(vim.eval("a:buf"))'))
|
return float2nr(luaeval('#vim.buffer(vim.eval("a:buf"))'))
|
||||||
endfunction
|
endfunction
|
||||||
else
|
else
|
||||||
function! s:self.buf_line_count(buf) abort
|
function! s:self.buf_line_count(buf) abort
|
||||||
return len(getbufline(a:buf, 1, '$'))
|
return len(getbufline(a:buf, 1, '$'))
|
||||||
endfunction
|
endfunction
|
||||||
endif
|
endif
|
||||||
|
|
||||||
function! s:self.setbufvar(buf, dict) abort
|
function! s:self.setbufvar(buf, dict) abort
|
||||||
@ -124,6 +124,16 @@ function! s:self.setbufvar(buf, dict) abort
|
|||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! SpaceVim#api#vim#get() abort
|
function! s:self.get_qf_winnr() abort
|
||||||
return deepcopy(s:self)
|
let wins = filter(getwininfo(), 'v:val.quickfix && !v:val.loclist')
|
||||||
|
" assert(len(wins) <= 1)
|
||||||
|
return empty(wins) ? 0 : wins[0].winnr
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:self.is_qf_win(winnr) abort
|
||||||
|
return a:winnr ==# self.get_qf_winnr()
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! SpaceVim#api#vim#get() abort
|
||||||
|
return deepcopy(s:self)
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -27,6 +27,7 @@ let s:STATUSLINE = SpaceVim#api#import('vim#statusline')
|
|||||||
let s:VIMCOMP = SpaceVim#api#import('vim#compatible')
|
let s:VIMCOMP = SpaceVim#api#import('vim#compatible')
|
||||||
let s:SYSTEM = SpaceVim#api#import('system')
|
let s:SYSTEM = SpaceVim#api#import('system')
|
||||||
let s:ICON = SpaceVim#api#import('unicode#icon')
|
let s:ICON = SpaceVim#api#import('unicode#icon')
|
||||||
|
let s:VIM = SpaceVim#api#import('vim')
|
||||||
|
|
||||||
" init
|
" init
|
||||||
let s:separators = {
|
let s:separators = {
|
||||||
@ -366,17 +367,31 @@ function! SpaceVim#layers#core#statusline#get(...) abort
|
|||||||
\ . '%#SpaceVim_statusline_b#'
|
\ . '%#SpaceVim_statusline_b#'
|
||||||
\ . ' vimfiler %#SpaceVim_statusline_b_SpaceVim_statusline_c#'
|
\ . ' vimfiler %#SpaceVim_statusline_b_SpaceVim_statusline_c#'
|
||||||
\ . s:lsep
|
\ . s:lsep
|
||||||
elseif &filetype ==# 'qf'
|
elseif &filetype ==# 'qf'
|
||||||
return '%#SpaceVim_statusline_ia#'
|
if s:VIM.is_qf_win(winnr())
|
||||||
\ . s:winnr(1)
|
return '%#SpaceVim_statusline_ia#'
|
||||||
\ . '%#SpaceVim_statusline_ia_SpaceVim_statusline_b#' . s:lsep
|
\ . s:winnr(1)
|
||||||
\ . '%#SpaceVim_statusline_b#'
|
\ . '%#SpaceVim_statusline_ia_SpaceVim_statusline_b#' . s:lsep
|
||||||
\ . ' QuickFix %#SpaceVim_statusline_b_SpaceVim_statusline_c#'
|
\ . '%#SpaceVim_statusline_b#'
|
||||||
\ . s:lsep
|
\ . ' QuickFix %#SpaceVim_statusline_b_SpaceVim_statusline_c#'
|
||||||
\ . ( has('patch-8.0.1384') ? ((getqflist({'title' : 0}).title ==# ':setqflist()') ? '' :
|
\ . s:lsep
|
||||||
\ '%#SpaceVim_statusline_c#'
|
\ . ( has('patch-8.0.1384') ? ((getqflist({'title' : 0}).title ==# ':setqflist()') ? '' :
|
||||||
\ . getqflist({'title' : 0}).title . '%#SpaceVim_statusline_c_SpaceVim_statusline_z#' . s:lsep
|
\ '%#SpaceVim_statusline_c#'
|
||||||
\ ) : '')
|
\ . getqflist({'title' : 0}).title . '%#SpaceVim_statusline_c_SpaceVim_statusline_z#' . s:lsep
|
||||||
|
\ ) : '')
|
||||||
|
else
|
||||||
|
return '%#SpaceVim_statusline_ia#'
|
||||||
|
\ . s:winnr(1)
|
||||||
|
\ . '%#SpaceVim_statusline_ia_SpaceVim_statusline_b#' . s:lsep
|
||||||
|
\ . '%#SpaceVim_statusline_b#'
|
||||||
|
\ . ' Location List %#SpaceVim_statusline_b_SpaceVim_statusline_c#'
|
||||||
|
\ . s:lsep
|
||||||
|
\ . ( has('patch-8.0.1384') ? ((getloclist(winnr(),{'title' : 0}).title ==# ':setloclist()') ? '' :
|
||||||
|
\ '%#SpaceVim_statusline_c#'
|
||||||
|
\ . getloclist(winnr(),{'title' : 0}).title . '%#SpaceVim_statusline_c_SpaceVim_statusline_z#' . s:lsep
|
||||||
|
\ ) : '')
|
||||||
|
|
||||||
|
endif
|
||||||
elseif &filetype ==# 'defx'
|
elseif &filetype ==# 'defx'
|
||||||
return '%#SpaceVim_statusline_ia#' . s:winnr(1) . '%#SpaceVim_statusline_ia_SpaceVim_statusline_b#' . s:lsep
|
return '%#SpaceVim_statusline_ia#' . s:winnr(1) . '%#SpaceVim_statusline_ia_SpaceVim_statusline_b#' . s:lsep
|
||||||
\ . '%#SpaceVim_statusline_b# defx %#SpaceVim_statusline_b_SpaceVim_statusline_c#' . s:lsep . ' '
|
\ . '%#SpaceVim_statusline_b# defx %#SpaceVim_statusline_b_SpaceVim_statusline_c#' . s:lsep . ' '
|
||||||
|
Loading…
Reference in New Issue
Block a user