-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
219 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
vim9script | ||
g:buflist_term_sign = get(g:, 'buflist_term_sign', "\uf489") | ||
var k = 0 | ||
var n = '' | ||
var q = '' | ||
var t = '' | ||
def A() | ||
q = '' | ||
var a = [] | ||
const b = execute('ls')->split("\n") | ||
const c = &columns / (!b ? 1 : len(b)) | ||
for d in b | ||
const m = d->matchlist('^ *\([0-9]\+\) \([^"]*\)"\(.*\)" [^0-9]\+ [0-9]\+') | ||
if m->empty() | ||
continue | ||
endif | ||
const e = m[1] | ||
var f = m[3] | ||
if m[2][2] =~# '[RF?]' | ||
f = g:buflist_term_sign .. | ||
term_getline(str2nr(e), '.') | ||
->substitute('\s*[%#>$]\s*$', '', '') | ||
endif | ||
f = f->pathshorten() | ||
const l = len(f) | ||
if c < l | ||
f = '<' .. f->strcharpart(l - c) | ||
endif | ||
const h = $'{e}:{f}' | ||
const i = m[2][0] ==# '%' | ||
if i | ||
n = a->join(' ') | ||
q = (!n ? '' : ' ') .. h .. ' ' | ||
a = [] | ||
else | ||
add(a, h) | ||
endif | ||
endfor | ||
t = a->join(' ') | ||
enddef | ||
export def Popup() | ||
if !n && !t | ||
return | ||
endif | ||
var w = &columns | ||
const o = getwininfo(win_getid(1))[0].textoff | ||
w -= o | ||
const s = q->substitute($'\%{w}v.*', '', '') | ||
w -= strdisplaywidth(s) | ||
var l = n->reverse()->substitute($'\%{w}v.*', '', '')->reverse() | ||
if l !=# n | ||
l = l->substitute('^.', '<', '') | ||
endif | ||
w -= strdisplaywidth(l) | ||
var r = t->substitute($'\%{w}v.*', '', '') | ||
if r !=# t | ||
r = r->substitute('.$', '>', '') | ||
endif | ||
w -= strdisplaywidth(r) | ||
const p = max([0, w]) | ||
var a = popup_create($'{l}{s}{r}', { | ||
line: 1, | ||
col: 1, | ||
fixed: true, | ||
highlight: 'TabLine', | ||
padding: [0, p, 0, o], | ||
moved: 'any', | ||
}) | ||
if !!k | ||
popup_close(k) | ||
endif | ||
k = a | ||
enddef | ||
export def Show() | ||
A() | ||
Popup() | ||
enddef | ||
export def Setup() | ||
enddef |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
vim9script | ||
|
||
# 複数bufを開いている場合、一覧を画面上部に表示する | ||
|
||
# `>_`みたいなアイコン | ||
g:buflist_term_sign = get(g:, 'buflist_term_sign', "\uf489") | ||
|
||
var pum = 0 | ||
var left = '' | ||
var select = '' | ||
var right = '' | ||
def RefreshBufList() | ||
select = '' | ||
var bufs = [] | ||
const ls_result = execute('ls')->split("\n") | ||
const max_len = &columns / (!ls_result ? 1 : len(ls_result)) | ||
for ls in ls_result | ||
const m = ls->matchlist('^ *\([0-9]\+\) \([^"]*\)"\(.*\)" [^0-9]\+ [0-9]\+') | ||
if m->empty() | ||
continue | ||
endif | ||
const nr = m[1] | ||
var name = m[3] | ||
if m[2][2] =~# '[RF?]' | ||
name = g:buflist_term_sign .. | ||
term_getline(str2nr(nr), '.') | ||
->substitute('\s*[%#>$]\s*$', '', '') | ||
endif | ||
name = name->pathshorten() | ||
const l = len(name) | ||
if max_len < l | ||
name = '<' .. name->strcharpart(l - max_len) | ||
endif | ||
const label = $'{nr}:{name}' | ||
const current = m[2][0] ==# '%' | ||
if current | ||
left = bufs->join(' ') | ||
select = (!left ? '' : ' ') .. label .. ' ' | ||
bufs = [] | ||
else | ||
add(bufs, label) | ||
endif | ||
endfor | ||
right = bufs->join(' ') | ||
enddef | ||
|
||
export def Popup() | ||
if !left && !right | ||
return | ||
endif | ||
var w = &columns | ||
# 左オフセット | ||
const o = getwininfo(win_getid(1))[0].textoff | ||
w -= o | ||
# 選択バッファ | ||
const s = select->substitute($'\%{w}v.*', '', '') | ||
w -= strdisplaywidth(s) | ||
# 選択より左側 | ||
var l = left->reverse()->substitute($'\%{w}v.*', '', '')->reverse() | ||
if l !=# left | ||
l = l->substitute('^.', '<', '') | ||
endif | ||
w -= strdisplaywidth(l) | ||
# 選択より右側 | ||
var r = right->substitute($'\%{w}v.*', '', '') | ||
if r !=# right | ||
r = r->substitute('.$', '>', '') | ||
endif | ||
w -= strdisplaywidth(r) | ||
# 右パディング | ||
const p = max([0, w]) | ||
# 表示 | ||
#redraw | ||
var newpum = popup_create($'{l}{s}{r}', { | ||
line: 1, | ||
col: 1, | ||
fixed: true, | ||
highlight: 'TabLine', | ||
padding: [0, p, 0, o], | ||
moved: 'any', | ||
}) | ||
#echoh TabLineFill | ||
#echon repeat(' ', o) | ||
#echoh TabLine | ||
#echon l | ||
#echoh TabLineSel | ||
#echon s | ||
#echoh TabLine | ||
#echon r | ||
#echoh TabLineFill | ||
#echon repeat(' ', p) | ||
#echoh Normal | ||
if !!pum | ||
popup_close(pum) | ||
endif | ||
pum = newpum | ||
enddef | ||
|
||
export def Show() | ||
RefreshBufList() | ||
Popup() | ||
enddef | ||
|
||
export def Setup() | ||
# nop | ||
enddef | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters