Skip to content

Commit

Permalink
✨feat: gtgTのときだけタブを表示
Browse files Browse the repository at this point in the history
  • Loading branch information
utubo committed Dec 3, 2024
1 parent 598fbe1 commit cba7f20
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 16 deletions.
79 changes: 79 additions & 0 deletions .vim/autoload/vimrc/bufline.vim
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
35 changes: 21 additions & 14 deletions .vim/autoload/vimrc/lazyload.vim
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ au vimrc SafeState * ++once B()
enddef
au vimrc BufReadPost * C()
C()
nm <SID>(buf)n <Cmd>bnext<CR><SID>(buf)
nm <SID>(buf)p <Cmd>bprevious<CR><SID>(buf)
nm <SID>(buf)n <Cmd>bnext<CR><Cmd>call vimrc#bufline#Show()<CR><SID>(buf)
nm <SID>(buf)p <Cmd>bprevious<CR><Cmd>call vimrc#bufline#Show()<CR><SID>(buf)
nm gn <SID>(buf)n
nm gp <SID>(buf)p
g:recentBufnr = 0
Expand Down Expand Up @@ -255,6 +255,13 @@ echow expand('%:p:h')
enddef
nn <script> <C-g> <ScriptCmd>D()<CR>
set tabline=%!vimrc#tabline#MyTabline()
set showtabline=0
def E(t: string)
set showtabline=1
exe $'normal! g{t}'
au SafeState * ++once au CursorMoved * ++once set showtabline=0
enddef
Each t,T nmap g{} <SID>(tab){}|nm <SID>(tab){} <ScriptCmd>E('{}')<CR><SID>(tab)
nn <Space>e G?\cErr\\|Exception<CR>
nn <expr> <Space>f $'{(getreg('"') =~ '^\d\+$' ? ':' : '/')}{getreg('"')}<CR>'
nm <Space>. :
Expand All @@ -269,7 +276,7 @@ nn <Space>a A
nn <Space>h ^
nn <Space>l $
nn <Space>y yiw
def E()
def F()
if !!bufname()
update
return
Expand Down Expand Up @@ -304,7 +311,7 @@ if !!e
exe 'sav' e
endif
enddef
com! AutoNamingAndSave E()
com! AutoNamingAndSave F()
cno ;n <CR>
Each nnoremap,inoremap ;n <Esc><Cmd>AutoNamingAndSave<CR>
ino ;m <Esc>`^
Expand Down Expand Up @@ -449,31 +456,31 @@ nn <silent> <F10> <ESC>1<C-w>s:1<CR><C-w>w
xn <F10> <ESC>1<C-w>s<C-w>w
nn <F9> my
nn <Space><F9> 'y
def F()
def G()
for a in get(w:, 'my_syntax', [])
sil! matchdelete(a)
endfor
w:my_syntax = []
enddef
def G(a: string, b: string)
def H(a: string, b: string)
w:my_syntax->add(matchadd(a, b))
enddef
au vimrc Syntax * F()
au vimrc Syntax * G()
au vimrc Syntax javascript {
G('SpellRare', '\s[=!]=\s')
H('SpellRare', '\s[=!]=\s')
}
au vimrc Syntax vim {
G('SpellRare', '\s[=!]=\s')
G('SpellBad', '\s[=!]==\s')
G('SpellBad', '\s\~[=!][=#]\?\s')
G('SpellRare', '\<normal!\@!')
H('SpellRare', '\s[=!]=\s')
H('SpellBad', '\s[=!]==\s')
H('SpellBad', '\s\~[=!][=#]\?\s')
H('SpellRare', '\<normal!\@!')
}
set report=9999
def g:EchoYankText(t: number)
vimrc#echoyanktext#EchoYankText()
enddef
au vimrc TextYankPost * timer_start(1, g:EchoYankText)
def H()
def I()
normal! "vygv
var a = @v->substitute('\n', '', 'g')
popup_create($'{strlen(a)}chars', {
Expand All @@ -484,7 +491,7 @@ moved: 'any',
padding: [1, 1, 1, 1],
})
enddef
xn <C-g> <ScriptCmd>H()<CR>
xn <C-g> <ScriptCmd>I()<CR>
com! -nargs=1 Brep vimrc#myutil#Brep(<q-args>, <q-mods>)
Each f,b nmap <C-{0}> <C-{0}><SID>(hold-ctrl)
Each f,b nnoremap <script> <SID>(hold-ctrl){0} <C-{0}><SID>(hold-ctrl)
Expand Down
107 changes: 107 additions & 0 deletions src/.vim/autoload/vimrc/bufline.src.vim
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

14 changes: 12 additions & 2 deletions src/.vim/autoload/vimrc/lazyload.src.vim
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,16 @@ SetupTabstopLazy()

# ------------------------------------------------------
# バッファ操作 {{{
nmap <SID>(buf)n <Cmd>bnext<CR><SID>(buf)
nmap <SID>(buf)p <Cmd>bprevious<CR><SID>(buf)
# gnとgpで移動
nmap <SID>(buf)n <Cmd>bnext<CR><Cmd>call vimrc#bufline#Show()<CR><SID>(buf)
nmap <SID>(buf)p <Cmd>bprevious<CR><Cmd>call vimrc#bufline#Show()<CR><SID>(buf)
nmap gn <SID>(buf)n
nmap gp <SID>(buf)p
# grで直前のバッファ
g:recentBufnr = 0
au vimrc BufLeave * g:recentBufnr = bufnr()
nnoremap <expr> gr $"\<Cmd>b{g:recentBufnr}\<CR>"
# BでCtrlpBuffer
command! CtrlPBuffer delc CtrlPBuffer|vimrc#ctrlp#LazyLoad()|CtrlPBuffer
nnoremap B <ScriptCmd>CtrlPBuffer<CR>
#}}}
Expand Down Expand Up @@ -377,6 +380,13 @@ nnoremap <script> <C-g> <ScriptCmd>ShowBufInfo()<CR>
# ------------------------------------------------------
# Tabline {{{
set tabline=%!vimrc#tabline#MyTabline()
set showtabline=0
def TabNP(t: string)
set showtabline=1
execute $'normal! g{t}'
au SafeState * ++once au CursorMoved * ++once set showtabline=0
enddef
Each t,T nmap g{} <SID>(tab){}|nmap <SID>(tab){} <ScriptCmd>TabNP('{}')<CR><SID>(tab)
#}}}

# ------------------------------------------------------
Expand Down

0 comments on commit cba7f20

Please sign in to comment.