Last active
September 18, 2019 13:15
-
-
Save tamago324/6d8cfa4fcd74f18232a38985894006ca to your computer and use it in GitHub Desktop.
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
" TODO: :global に対応 | |
" ガッガッと | |
let s:search_popwinid = 0 | |
" XXX: ctx を scirpt に持たせていいのか微妙なところ? | |
" なぜ、そう思う? | |
let s:popctx = {} | |
" from qfpreview.vim | |
" https://github.com/bfrg/vim-qf-preview/blob/1439b3834a8a02fde864c78adc6d3ee37ec08bf8/autoload/qfpreview.vim#L63-L65 | |
function! s:below_line(wininfo) abort | |
" カレントウィンドウの一番下の位置 (スクリーン上での位置) | |
" winrow は 1 始まりのため -1 | |
" let win_bottom_line = a:wininfo.height + a:wininfo.winrow - 1 | |
return a:wininfo.height + a:wininfo.winrow - 1 | |
endfunction | |
function! OpenSearchPopup() | |
let wininfo = getwininfo(win_getid())[0] | |
let popctx = { | |
\ 'lines': getline(1, '$'), | |
\ 'height': 15, | |
\} | |
let opts = { | |
\ 'borderchars': [' '], | |
\ 'maxheight': popctx.height, | |
\ 'minwidth': wininfo.width, | |
\ 'maxwidth': wininfo.width, | |
\ 'scrollbar': 0, | |
\ 'line': s:below_line(wininfo), | |
\ 'col': wininfo.wincol, | |
\ 'fixed': 1, | |
\ 'pos': 'botleft', | |
\ 'wrap': 0, | |
\} | |
let popctx.id = popup_create(popctx.lines, opts) | |
let s:search_popwinid = popctx.id | |
let s:popctx = popctx | |
endfunction | |
" / と同じように 検索処理を行う | |
function! RefreshSearchPopup() abort | |
" マッチする行のみ表示 | |
let pat = getcmdline() | |
let disp_lines = [] | |
let idx = 1 | |
for line in s:popctx.lines | |
if match(line, pat) != -1 | |
" 行番号を右揃え | |
let num = printf('%'.len(line('$')).'d', idx) | |
call add(disp_lines, num.': '.line) | |
endif | |
let idx += 1 | |
endfor | |
" マッチした箇所をハイライトをする | |
" text property? | |
" がんばるぞい! | |
" let s:popctx.display_lines = s:popctx.display_lines[1:] | |
call popup_settext(s:popctx.id, disp_lines) | |
endfunction | |
function! CloseSearchPopup() abort | |
call popup_close(s:search_popwinid) | |
let s:search_popwinid = 0 | |
endfunction | |
function! JumpSearchPopup() abort | |
" popup window で行を選択し、その行へジャンプする | |
endfunction | |
augroup SearchPopup | |
autocmd! | |
autocmd CmdlineEnter * call OpenSearchPopup() | |
autocmd CmdlineLeave * call CloseSearchPopup() | |
autocmd CmdlineChanged * call RefreshSearchPopup() | |
augroup END |
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
scriptencoding utf-8 | |
let s:search_popwinid = 0 | |
" XXX: ctx を scirpt に持たせていいのか微妙なところ? | |
" なぜ、そう思う? | |
let s:popctx = {} | |
" from https://github.com/bfrg/vim-qf-preview | |
function! s:below_line(wininfo) abort | |
" カレントウィンドウの一番下の位置 (スクリーン上での位置) | |
" winrow は 1 始まりのため -1 | |
" let win_bottom_line = a:wininfo.height + a:wininfo.winrow - 1 | |
return a:wininfo.height + a:wininfo.winrow - 1 | |
endfunction | |
function! s:setup_textprop(winid) abort | |
let _bufnr = winbufnr(a:winid) | |
" 見つからなくてもエラーにならないため、これでOK | |
call prop_type_delete('search',{ | |
\ 'bufnr': _bufnr | |
\}) | |
call prop_type_add('search', { | |
\ 'highlight': 'Search', | |
\ 'bufnr': _bufnr | |
\}) | |
endfunction | |
function! OpenSearchPopup() | |
let wininfo = getwininfo(win_getid())[0] | |
let popctx = { | |
\ 'lines': getline(1, '$'), | |
\ 'height': 15, | |
\ 'id': 0, | |
\} | |
let opts = { | |
\ 'borderchars': [' '], | |
\ 'maxheight': popctx.height, | |
\ 'minwidth': wininfo.width, | |
\ 'maxwidth': wininfo.width, | |
\ 'scrollbar': 0, | |
\ 'line': s:below_line(wininfo), | |
\ 'col': wininfo.wincol, | |
\ 'fixed': 1, | |
\ 'pos': 'botleft', | |
\ 'wrap': 0, | |
\ 'filter': function('s:popup_filter', [popctx]), | |
\ 'highlight': 'Normal', | |
\} | |
" XXX: 普通の カーソル行のハイライトにしたいな | |
" text-properties を使う | |
let popctx.id = popup_create(popctx.lines, opts) | |
let s:search_popwinid = popctx.id | |
let s:popctx = popctx | |
endfunction | |
" TODO: 実際のバッファが見えるように、表示位置を変えてあげる必要がある? | |
" n を押した時、カーソルがジャンプするけど、popup window で見えなくなっ | |
" てしまうため | |
" / と同じように 検索処理を行う | |
function! RefreshSearchPopup() abort | |
" ハイライトのリセット | |
call s:setup_textprop(s:popctx.id) | |
let pat = getcmdline() | |
let lines = {} | |
let showlines = [] | |
" マッチする行のみ表示 | |
let lnum = 1 | |
for line in s:popctx.lines | |
let m = matchstrpos(line, pat) | |
if m[2] == -1 | |
let col = m[1] + 1 | |
let length = len(m[0]) | |
let lines[lnum] = { | |
\ 'line': line, | |
\ 'col': col, | |
\ 'length': length, | |
\} | |
let lnum += 1 | |
call add(showlines, line) | |
endif | |
endfor | |
call popup_settext(s:popctx.id, showlines) | |
" ハイライト | |
let _bufnr = winbufnr(s:popctx.id) | |
for [lnum, info] in items(lines) | |
call prop_add(lnum, info.col, { | |
\ 'length': info.length, | |
\ 'type': 'search', | |
\ 'bufnr': _bufnr, | |
\}) | |
endfor | |
endfunction | |
function! CloseSearchPopup() abort | |
call popup_close(s:search_popwinid) | |
let s:search_popwinid = 0 | |
endfunction | |
function! JumpSearchPopup() abort | |
" popup window で行を選択し、その行へジャンプする | |
endfunction | |
function! s:popup_filter(popctx, winid, key) abort | |
return 0 | |
endfunction | |
augroup SearchPopup | |
autocmd! | |
autocmd CmdlineEnter /,\? call OpenSearchPopup() | |
autocmd CmdlineLeave /,\? call CloseSearchPopup() | |
autocmd CmdlineChanged /,\? call RefreshSearchPopup() | |
augroup END |
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
scriptencoding utf-8 | |
let s:popctx = {} | |
" from https://github.com/bfrg/vim-qf-preview | |
function! s:below_line(wininfo) abort | |
" カレントウィンドウの一番下の位置 (スクリーン上での位置) | |
" winrow は 1 始まりのため -1 | |
" let win_bottom_line = a:wininfo.height + a:wininfo.winrow - 1 | |
return a:wininfo.height + a:wininfo.winrow - 1 | |
endfunction | |
function! s:setup_textprop(winid) abort | |
let _bufnr = winbufnr(a:winid) | |
" 見つからなくてもエラーにならないため、これでOK | |
call prop_type_delete('search',{ | |
\ 'bufnr': _bufnr | |
\}) | |
call prop_type_add('search', { | |
\ 'highlight': 'Search', | |
\ 'bufnr': _bufnr | |
\}) | |
endfunction | |
function! OpenSearchPopup() | |
let wininfo = getwininfo(win_getid())[0] | |
let s:popctx = { | |
\ 'lines': getline(1, '$'), | |
\ 'height': 15, | |
\ 'id': 0, | |
\} | |
" 上のみ、border をつける | |
let opts = { | |
\ 'border': [1, 1, 1, 1], | |
\ 'maxheight': s:popctx.height, | |
\ 'minwidth': wininfo.width -2, | |
\ 'maxwidth': wininfo.width -2, | |
\ 'scrollbar': 0, | |
\ 'line': s:below_line(wininfo), | |
\ 'col': wininfo.wincol, | |
\ 'fixed': 1, | |
\ 'pos': 'botleft', | |
\ 'wrap': 0, | |
\ 'filter': function('s:popup_filter', [s:popctx]), | |
\ 'highlight': 'Normal', | |
\} | |
" XXX: 普通の カーソル行のハイライトにしたいな | |
" text-properties を使う | |
let s:popctx.id = popup_create(s:popctx.lines, opts) | |
endfunction | |
" TODO: 実際のバッファが見えるように、表示位置を変えてあげる必要がある? | |
" n を押した時、カーソルがジャンプするけど、popup window で見えなくなっ | |
" てしまうため | |
" / と同じように 検索処理を行う | |
function! RefreshSearchPopup() abort | |
" ハイライトのリセット | |
call s:setup_textprop(s:popctx.id) | |
let pat = getcmdline() | |
let lines = {} | |
let showlines = [] | |
" マッチする行のみ表示 | |
let lnum = 1 | |
for line in s:popctx.lines | |
let m = matchstrpos(line, pat) | |
if m[2] != -1 | |
let col = m[1] + 1 | |
let length = len(m[0]) | |
let lines[lnum] = { | |
\ 'line': line, | |
\ 'col': col, | |
\ 'length': length, | |
\} | |
let lnum += 1 | |
call add(showlines, line) | |
endif | |
endfor | |
if len(showlines) == 0 | |
call popup_settext(s:popctx.id, 'Pattern not found.') | |
call popup_setoptions(s:popctx.id, {'highlight': 'Error'}) | |
else | |
call popup_settext(s:popctx.id, showlines) | |
call popup_setoptions(s:popctx.id, {'highlight': 'Normal'}) | |
" ハイライト | |
let _bufnr = winbufnr(s:popctx.id) | |
for [lnum, info] in items(lines) | |
call prop_add(lnum, info.col, { | |
\ 'length': info.length, | |
\ 'type': 'search', | |
\ 'bufnr': _bufnr, | |
\}) | |
endfor | |
endif | |
endfunction | |
function! CloseSearchPopup() abort | |
call popup_close(s:popctx.id) | |
endfunction | |
function! JumpSearchPopup() abort | |
" popup window で行を選択し、その行へジャンプする | |
endfunction | |
function! s:popup_filter(popctx, winid, key) abort | |
return 0 | |
endfunction | |
augroup SearchPopup | |
autocmd! | |
autocmd CmdlineEnter /,\? call OpenSearchPopup() | |
autocmd CmdlineLeave /,\? call CloseSearchPopup() | |
autocmd CmdlineChanged /,\? call RefreshSearchPopup() | |
augroup END |
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
scriptencoding utf-8 | |
let s:popctx = {} | |
hi PatternNotFound guifg=red guibg=bg | |
" from https://github.com/bfrg/vim-qf-preview | |
function! s:below_line(wininfo) abort | |
" カレントウィンドウの一番下の位置 (スクリーン上での位置) | |
" winrow は 1 始まりのため -1 | |
" let win_bottom_line = a:wininfo.height + a:wininfo.winrow - 1 | |
return a:wininfo.height + a:wininfo.winrow - 1 | |
endfunction | |
function! s:reset_textprop(winid) abort | |
let _bufnr = winbufnr(a:winid) | |
" 見つからなくてもエラーにならないため、これでOK | |
call prop_type_delete('search',{ | |
\ 'bufnr': _bufnr | |
\}) | |
call prop_type_add('search', { | |
\ 'highlight': 'Search', | |
\ 'bufnr': _bufnr | |
\}) | |
endfunction | |
function! s:title(n, m) abort | |
return printf(' match (%s/%s) ', a:n, a:m) | |
endfunction | |
function! OpenSearchPopup() abort | |
let wininfo = getwininfo(win_getid())[0] | |
let s:popctx = { | |
\ 'lines': getline(1, '$'), | |
\ 'height': 15, | |
\ 'id': 0, | |
\} | |
" 上のみ、border をつける | |
let opts = { | |
\ 'border': [1, 1, 1, 1], | |
\ 'maxheight': s:popctx.height, | |
\ 'minwidth': wininfo.width -2, | |
\ 'maxwidth': wininfo.width -2, | |
\ 'scrollbar': 0, | |
\ 'line': s:below_line(wininfo), | |
\ 'col': wininfo.wincol, | |
\ 'fixed': 1, | |
\ 'pos': 'botleft', | |
\ 'wrap': 0, | |
\ 'filter': function('s:popup_filter', [s:popctx]), | |
\ 'highlight': 'Normal', | |
\ 'title': s:title(1, len(s:popctx.lines)), | |
\} | |
" XXX: 普通の カーソル行のハイライトにしたいな | |
" text-properties を使う | |
let s:popctx.id = popup_create(s:popctx.lines, opts) | |
endfunction | |
" TODO: 実際のバッファが見えるように、表示位置を変えてあげる必要がある? | |
" n を押した時、カーソルがジャンプするけど、popup window で見えなくなっ | |
" てしまうため | |
" / と同じように 検索処理を行う | |
function! RefreshSearchPopup() abort | |
" ハイライトのリセット | |
call s:reset_textprop(s:popctx.id) | |
let pat = getcmdline() | |
let lines = {} | |
let showlines = [] | |
" マッチする行のみ表示 | |
let lnum = 1 | |
for line in s:popctx.lines | |
let m = matchstrpos(line, pat) | |
if m[2] != -1 | |
let col = m[1] + 1 | |
let length = len(m[0]) | |
let lines[lnum] = { | |
\ 'line': line, | |
\ 'col': col, | |
\ 'length': length, | |
\} | |
let lnum += 1 | |
call add(showlines, line) | |
endif | |
endfor | |
let highlight = '' | |
let title = '' | |
if len(showlines) == 0 | |
let showlines = 'Pattern not found.' | |
let highlight = 'PatternNotFound' | |
else | |
let highlight = 'Normal' | |
" マッチ数を表示する | |
let title = s:title(1, len(showlines)) | |
" TODO: カーソル移動に合わせて、title を変更する | |
" popup_filter の仕事? | |
endif | |
call popup_settext(s:popctx.id, showlines) | |
call popup_setoptions(s:popctx.id, { | |
\ 'highlight': highlight, | |
\ 'title': title, | |
\}) | |
" ハイライト | |
let _bufnr = winbufnr(s:popctx.id) | |
for [lnum, info] in items(lines) | |
call prop_add(lnum, info.col, { | |
\ 'length': info.length, | |
\ 'type': 'search', | |
\ 'bufnr': _bufnr, | |
\}) | |
endfor | |
endfunction | |
function! CloseSearchPopup() abort | |
call popup_close(s:popctx.id) | |
endfunction | |
function! JumpSearchPopup() abort | |
" popup window で行を選択し、その行へジャンプする | |
endfunction | |
function! s:popup_filter(popctx, winid, key) abort | |
return 0 | |
endfunction | |
augroup SearchPopup | |
autocmd! | |
autocmd CmdlineEnter /,\? call OpenSearchPopup() | |
autocmd CmdlineLeave /,\? call CloseSearchPopup() | |
autocmd CmdlineChanged /,\? call RefreshSearchPopup() | |
augroup END | |
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
scriptencoding utf-8 | |
let s:popctx = {} | |
hi PatternNotFound guifg=red guibg=bg | |
" from https://github.com/bfrg/vim-qf-preview | |
function! s:below_line(wininfo) abort | |
" カレントウィンドウの一番下の位置 (スクリーン上での位置) | |
" winrow は 1 始まりのため -1 | |
" let win_bottom_line = a:wininfo.height + a:wininfo.winrow - 1 | |
return a:wininfo.height + a:wininfo.winrow - 1 | |
endfunction | |
function! s:reset_textprop(winid) abort | |
let _bufnr = winbufnr(a:winid) | |
" 見つからなくてもエラーにならないため、これでOK | |
call prop_type_delete('search',{ | |
\ 'bufnr': _bufnr | |
\}) | |
call prop_type_add('search', { | |
\ 'highlight': 'Search', | |
\ 'bufnr': _bufnr | |
\}) | |
endfunction | |
function! s:title(n, m) abort | |
return printf(' match (%s/%s) ', a:n, a:m) | |
endfunction | |
function! OpenSearchPopup() abort | |
let wininfo = getwininfo(win_getid())[0] | |
let s:popctx = { | |
\ 'lines': getline(1, '$'), | |
\ 'height': 15, | |
\ 'id': 0, | |
\} | |
" 上のみ、border をつける | |
let opts = { | |
\ 'border': [1, 1, 1, 1], | |
\ 'maxheight': s:popctx.height, | |
\ 'minwidth': wininfo.width -2, | |
\ 'maxwidth': wininfo.width -2, | |
\ 'scrollbar': 0, | |
\ 'line': s:below_line(wininfo), | |
\ 'col': wininfo.wincol, | |
\ 'fixed': 1, | |
\ 'pos': 'botleft', | |
\ 'wrap': 0, | |
\ 'filter': function('s:popup_filter', [s:popctx]), | |
\ 'highlight': 'Normal', | |
\ 'title': s:title(1, len(s:popctx.lines)), | |
\} | |
" XXX: 普通の カーソル行のハイライトにしたいな | |
" text-properties を使う | |
let s:popctx.id = popup_create(s:popctx.lines, opts) | |
endfunction | |
" TODO: 実際のバッファが見えるように、表示位置を変えてあげる必要がある? | |
" n を押した時、カーソルがジャンプするけど、popup window で見えなくなっ | |
" てしまうため | |
" / と同じように 検索処理を行う | |
function! RefreshSearchPopup() abort | |
" ハイライトのリセット | |
call s:reset_textprop(s:popctx.id) | |
let pat = getcmdline() | |
let lines = {} | |
let showlines = [] | |
" マッチする行のみ表示 | |
let lnum = 1 | |
for line in s:popctx.lines | |
try | |
let m = matchstrpos(line, pat) | |
catch /.*/ | |
let showlines = '' | |
break | |
endtry | |
if m[2] != -1 | |
let col = m[1] + 1 | |
let length = len(m[0]) | |
let lines[lnum] = { | |
\ 'line': line, | |
\ 'col': col, | |
\ 'length': length, | |
\} | |
let lnum += 1 | |
call add(showlines, line) | |
endif | |
endfor | |
let highlight = '' | |
let title = '' | |
if len(showlines) == 0 | |
let showlines = 'Pattern not found.' | |
let highlight = 'PatternNotFound' | |
else | |
let highlight = 'Normal' | |
" マッチ数を表示する | |
let title = s:title(1, len(showlines)) | |
" TODO: カーソル移動に合わせて、title を変更する | |
" popup_filter の仕事? | |
endif | |
call popup_settext(s:popctx.id, showlines) | |
call popup_setoptions(s:popctx.id, { | |
\ 'highlight': highlight, | |
\ 'title': title, | |
\}) | |
" ハイライト | |
let _bufnr = winbufnr(s:popctx.id) | |
for [lnum, info] in items(lines) | |
call prop_add(lnum, info.col, { | |
\ 'length': info.length, | |
\ 'type': 'search', | |
\ 'bufnr': _bufnr, | |
\}) | |
endfor | |
endfunction | |
function! CloseSearchPopup() abort | |
call popup_close(s:popctx.id) | |
endfunction | |
function! JumpSearchPopup() abort | |
" popup window で行を選択し、その行へジャンプする | |
endfunction | |
function! s:popup_filter(popctx, winid, key) abort | |
return 0 | |
endfunction | |
augroup SearchPopup | |
autocmd! | |
autocmd CmdlineEnter /,\? call OpenSearchPopup() | |
autocmd CmdlineLeave /,\? call CloseSearchPopup() | |
autocmd CmdlineChanged /,\? call RefreshSearchPopup() | |
augroup END | |
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
scriptencoding utf-8 | |
let s:popctx = {} | |
hi PatternNotFound guifg=red guibg=bg | |
" from https://github.com/bfrg/vim-qf-preview | |
function! s:below_line(wininfo) abort | |
" カレントウィンドウの一番下の位置 (スクリーン上での位置) | |
" winrow は 1 始まりのため -1 | |
" let win_bottom_line = a:wininfo.height + a:wininfo.winrow - 1 | |
return a:wininfo.height + a:wininfo.winrow - 1 | |
endfunction | |
function! s:reset_textprop(winid) abort | |
let _bufnr = winbufnr(a:winid) | |
" 見つからなくてもエラーにならないため、これでOK | |
call prop_type_delete('search',{ | |
\ 'bufnr': _bufnr | |
\}) | |
call prop_type_add('search', { | |
\ 'highlight': 'Search', | |
\ 'bufnr': _bufnr | |
\}) | |
endfunction | |
function! s:title(n, m) abort | |
return printf(' match (%s/%s) ', a:n, a:m) | |
endfunction | |
function! OpenSearchPopup() abort | |
let wininfo = getwininfo(win_getid())[0] | |
let s:popctx = { | |
\ 'lines': getline(1, '$'), | |
\ 'height': 15, | |
\ 'id': 0, | |
\} | |
" 上のみ、border をつける | |
let opts = { | |
\ 'border': [1, 1, 1, 1], | |
\ 'maxheight': s:popctx.height, | |
\ 'minwidth': wininfo.width -2, | |
\ 'maxwidth': wininfo.width -2, | |
\ 'scrollbar': 0, | |
\ 'line': s:below_line(wininfo), | |
\ 'col': wininfo.wincol, | |
\ 'fixed': 1, | |
\ 'pos': 'botleft', | |
\ 'wrap': 0, | |
\ 'filter': function('s:popup_filter', [s:popctx]), | |
\ 'highlight': 'Normal', | |
\ 'title': s:title(1, len(s:popctx.lines)), | |
\} | |
" XXX: 普通の カーソル行のハイライトにしたいな | |
" text-properties を使う | |
let s:popctx.id = popup_create(s:popctx.lines, opts) | |
endfunction | |
" TODO: 実際のバッファが見えるように、表示位置を変えてあげる必要がある? | |
" n を押した時、カーソルがジャンプするけど、popup window で見えなくなっ | |
" てしまうため | |
" / と同じように 検索処理を行う | |
function! RefreshSearchPopup() abort | |
" ハイライトのリセット | |
call s:reset_textprop(s:popctx.id) | |
let pat = getcmdline() | |
let lines = {} | |
let showlines = [] | |
" マッチする行のみ表示 | |
let lnum = 1 | |
for line in s:popctx.lines | |
let start = 0 | |
try | |
let m = matchstrpos(line, pat, start) | |
catch /.*/ | |
let showlines = '' | |
break | |
endtry | |
if m[2] != -1 | |
let col = m[1] + 1 | |
let length = len(m[0]) | |
let lines[lnum] = { | |
\ 'line': line, | |
\ 'col': col, | |
\ 'length': length, | |
\} | |
let lnum += 1 | |
call add(showlines, line) | |
endif | |
endfor | |
let highlight = '' | |
let title = '' | |
if len(showlines) == 0 | |
let showlines = 'Pattern not found.' | |
let highlight = 'PatternNotFound' | |
else | |
let highlight = 'Normal' | |
" マッチ数を表示する | |
let title = s:title(1, len(showlines)) | |
" TODO: カーソル移動に合わせて、title を変更する | |
" popup_filter の仕事? | |
endif | |
call popup_settext(s:popctx.id, showlines) | |
call popup_setoptions(s:popctx.id, { | |
\ 'highlight': highlight, | |
\ 'title': title, | |
\}) | |
" ハイライト | |
let _bufnr = winbufnr(s:popctx.id) | |
for [lnum, info] in items(lines) | |
call prop_add(lnum, info.col, { | |
\ 'length': info.length, | |
\ 'type': 'search', | |
\ 'bufnr': _bufnr, | |
\}) | |
endfor | |
endfunction | |
function! CloseSearchPopup() abort | |
call popup_close(s:popctx.id) | |
endfunction | |
function! JumpSearchPopup() abort | |
" popup window で行を選択し、その行へジャンプする | |
endfunction | |
function! s:popup_filter(popctx, winid, key) abort | |
" TODO: title の更新 | |
" TODO: カーソルの移動 | |
" TODO: scrolloff の設定 | |
if a:key ==# '\<C-j>' | |
" 下へ | |
elseif a:key ==# '\<C-k>' | |
" 上へ | |
endif | |
return 0 | |
endfunction | |
augroup SearchPopup | |
autocmd! | |
autocmd CmdlineEnter /,\? call OpenSearchPopup() | |
autocmd CmdlineLeave /,\? call CloseSearchPopup() | |
autocmd CmdlineChanged /,\? call RefreshSearchPopup() | |
augroup END | |
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
scriptencoding utf-8 | |
" TODO: Fuzzy mode をつける あいまい検索したいときとか便利 | |
let s:popctx = {} | |
hi PatternNotFound guifg=red guibg=bg | |
" from https://github.com/bfrg/vim-qf-preview | |
function! s:below_line(wininfo) abort | |
" カレントウィンドウの一番下の位置 (スクリーン上での位置) | |
" winrow は 1 始まりのため -1 | |
" let win_bottom_line = a:wininfo.height + a:wininfo.winrow - 1 | |
return a:wininfo.height + a:wininfo.winrow - 1 | |
endfunction | |
function! s:reset_textprop(winid) abort | |
let _bufnr = winbufnr(a:winid) | |
" 検索のマッチ文字列 | |
call prop_type_delete('search',{ | |
\ 'bufnr': _bufnr | |
\}) | |
call prop_type_add('search', { | |
\ 'highlight': 'Search', | |
\ 'bufnr': _bufnr | |
\}) | |
" カーソル行 | |
call prop_type_delete('search_cursorline',{ | |
\ 'bufnr': _bufnr | |
\}) | |
call prop_type_add('search_cursorline', { | |
\ 'highlight': 'CursorLine', | |
\ 'bufnr': _bufnr | |
\}) | |
endfunction | |
function! s:title(n, m) abort | |
return printf(' match (%s/%s) ', a:n, a:m) | |
endfunction | |
function! OpenSearchPopup() abort | |
let wininfo = getwininfo(win_getid())[0] | |
let s:popctx = { | |
\ 'lines': getline(1, '$'), | |
\ 'height': 15, | |
\ 'id': 0, | |
\ 'lnum': 0, | |
\ 'width': wininfo.width -2, | |
\} | |
" 上のみ、border をつける | |
let opts = { | |
\ 'border': [1, 1, 1, 1], | |
\ 'maxheight': s:popctx.height, | |
\ 'minwidth': s:popctx.width, | |
\ 'maxwidth': s:popctx.width, | |
\ 'scrollbar': 0, | |
\ 'line': s:below_line(wininfo), | |
\ 'col': wininfo.wincol, | |
\ 'fixed': 1, | |
\ 'pos': 'botleft', | |
\ 'wrap': 0, | |
\ 'filter': function('s:popup_filter', [s:popctx]), | |
\ 'highlight': 'Normal', | |
\ 'title': s:title(1, len(s:popctx.lines)), | |
\} | |
" XXX: 普通の カーソル行のハイライトにしたいな | |
" text-properties を使う | |
let s:popctx.id = popup_create(s:popctx.lines, opts) | |
endfunction | |
" TODO: 実際のバッファが見えるように、表示位置を変えてあげる必要がある? | |
" n を押した時、カーソルがジャンプするけど、popup window で見えなくなっ | |
" てしまうため | |
" / と同じように 検索処理を行う | |
function! RefreshSearchPopup() abort | |
" 検索文字列 ハイライトのリセット | |
call s:reset_textprop(s:popctx.id) | |
let pat = getcmdline() | |
let lines = {} | |
let showlines = [] | |
" TODO: 1行で複数箇所にマッチするパターンを処理できるようにする | |
" マッチする行のみ表示 | |
let lnum = 1 | |
for line in s:popctx.lines | |
let start = 0 | |
try | |
let m = matchstrpos(line, pat, start) | |
catch /.*/ | |
let showlines = '' | |
break | |
endtry | |
if m[2] != -1 | |
let col = m[1] + 1 | |
let length = len(m[0]) | |
let lines[lnum] = { | |
\ 'line': line, | |
\ 'col': col, | |
\ 'length': length, | |
\} | |
let lnum += 1 | |
call add(showlines, line) | |
endif | |
endfor | |
let highlight = '' | |
let title = '' | |
if len(showlines) == 0 | |
let showlines = 'Pattern not found.' | |
let highlight = 'PatternNotFound' | |
else | |
let highlight = 'Normal' | |
" マッチ数を表示する | |
let title = s:title(1, len(showlines)) | |
" TODO: カーソル移動に合わせて、title を変更する | |
" popup_filter の仕事? | |
endif | |
call popup_settext(s:popctx.id, showlines) | |
call popup_setoptions(s:popctx.id, { | |
\ 'highlight': highlight, | |
\ 'title': title, | |
\}) | |
" ハイライト | |
let _bufnr = winbufnr(s:popctx.id) | |
for [lnum, info] in items(lines) | |
call prop_add(lnum, info.col, { | |
\ 'length': info.length, | |
\ 'type': 'search', | |
\ 'bufnr': _bufnr, | |
\}) | |
endfor | |
endfunction | |
function! CloseSearchPopup() abort | |
call popup_close(s:popctx.id) | |
endfunction | |
function! JumpSearchPopup() abort | |
" popup window で行を選択し、その行へジャンプする | |
endfunction | |
function! s:popup_filter(popctx, winid, key) abort | |
" TODO: title の更新 | |
" TODO: カーソルの移動 | |
" TODO: scrolloff の設定 | |
if a:key ==# '\<C-j>' | |
" 下へ | |
let a:popctx.lnum += 1 | |
call s:curosr_highlight(a:popctx) | |
return 1 | |
elseif a:key ==# '\<C-k>' | |
" 上へ | |
let a:popctx.lnum -= 1 | |
call s:curosr_highlight(a:popctx) | |
return 1 | |
endif | |
return 0 | |
endfunction | |
function! s:curosr_highlight(popctx) abort | |
let lnum = a:popctx.lnum | |
let _bufnr = winbufnr(a:popctx.id) | |
" popup window の winid を id とする | |
call prop_remove({'id': a:popctx.id}) | |
" XXX: length は調整必要? | |
call prop_add(1, 1, { | |
\ 'id': a:popctx.id, | |
\ 'type': 'search_cursorline', | |
\ 'length': a:popctx.width, | |
\ 'bufnr': _bufnr, | |
\}) | |
endfunction | |
augroup SearchPopup | |
autocmd! | |
autocmd CmdlineEnter /,\? call OpenSearchPopup() | |
autocmd CmdlineLeave /,\? call CloseSearchPopup() | |
autocmd CmdlineChanged /,\? call RefreshSearchPopup() | |
augroup END | |
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
scriptencoding utf-8 | |
" TODO: Fuzzy mode をつける あいまい検索したいときとか便利 | |
let s:popctx = {} | |
hi PatternNotFound guifg=red guibg=bg | |
" from https://github.com/bfrg/vim-qf-preview | |
function! s:below_line(wininfo) abort | |
" カレントウィンドウの一番下の位置 (スクリーン上での位置) | |
" winrow は 1 始まりのため -1 | |
" let win_bottom_line = a:wininfo.height + a:wininfo.winrow - 1 | |
return a:wininfo.height + a:wininfo.winrow - 1 | |
endfunction | |
function! s:reset_textprop(winid) abort | |
let _bufnr = winbufnr(a:winid) | |
" 検索のマッチ文字列 | |
call prop_type_delete('search',{ | |
\ 'bufnr': _bufnr | |
\}) | |
call prop_type_add('search', { | |
\ 'highlight': 'Search', | |
\ 'bufnr': _bufnr | |
\}) | |
" カーソル行 | |
call prop_type_delete('search_cursorline',{ | |
\ 'bufnr': _bufnr | |
\}) | |
call prop_type_add('search_cursorline', { | |
\ 'highlight': 'CursorLine', | |
\ 'bufnr': _bufnr | |
\}) | |
endfunction | |
function! s:title(n, m) abort | |
return printf(' match (%s/%s) ', a:n, a:m) | |
endfunction | |
function! OpenSearchPopup() abort | |
let wininfo = getwininfo(win_getid())[0] | |
let s:popctx = { | |
\ 'lines': getline(1, '$'), | |
\ 'height': 15, | |
\ 'id': 0, | |
\ 'lnum': 0, | |
\ 'width': wininfo.width -2, | |
\} | |
" 上のみ、border をつける | |
" mapping に 0 を渡すと、filter で mapping されていない素のキーが取得できる | |
let opts = { | |
\ 'border': [1, 1, 1, 1], | |
\ 'maxheight': s:popctx.height, | |
\ 'minwidth': s:popctx.width, | |
\ 'maxwidth': s:popctx.width, | |
\ 'scrollbar': 0, | |
\ 'line': s:below_line(wininfo), | |
\ 'col': wininfo.wincol, | |
\ 'fixed': 1, | |
\ 'pos': 'botleft', | |
\ 'wrap': 0, | |
\ 'filter': function('s:popup_filter', [s:popctx]), | |
\ 'highlight': 'Normal', | |
\ 'title': s:title(1, len(s:popctx.lines)), | |
\ 'mapping': v:false | |
\} | |
" XXX: 普通の カーソル行のハイライトにしたいな | |
" text-properties を使う | |
let s:popctx.id = popup_create(s:popctx.lines, opts) | |
endfunction | |
" TODO: 実際のバッファが見えるように、表示位置を変えてあげる必要がある? | |
" n を押した時、カーソルがジャンプするけど、popup window で見えなくなっ | |
" てしまうため | |
" / と同じように 検索処理を行う | |
function! RefreshSearchPopup() abort | |
" 検索文字列 ハイライトのリセット | |
call s:reset_textprop(s:popctx.id) | |
let pat = getcmdline() | |
let lines = {} | |
let showlines = [] | |
" TODO: 1行で複数箇所にマッチするパターンを処理できるようにする | |
" マッチする行のみ表示 | |
let lnum = 1 | |
for line in s:popctx.lines | |
let start = 0 | |
try | |
let m = matchstrpos(line, pat, start) | |
catch /.*/ | |
let showlines = '' | |
break | |
endtry | |
if m[2] != -1 | |
let col = m[1] + 1 | |
let length = len(m[0]) | |
let lines[lnum] = { | |
\ 'line': line, | |
\ 'col': col, | |
\ 'length': length, | |
\} | |
let lnum += 1 | |
call add(showlines, line) | |
endif | |
endfor | |
let highlight = '' | |
let title = '' | |
if len(showlines) == 0 | |
let showlines = 'Pattern not found.' | |
let highlight = 'PatternNotFound' | |
else | |
let highlight = 'Normal' | |
" マッチ数を表示する | |
let title = s:title(1, len(showlines)) | |
" TODO: カーソル移動に合わせて、title を変更する | |
" popup_filter の仕事? | |
endif | |
call popup_settext(s:popctx.id, showlines) | |
call popup_setoptions(s:popctx.id, { | |
\ 'highlight': highlight, | |
\ 'title': title, | |
\}) | |
" ハイライト | |
let _bufnr = winbufnr(s:popctx.id) | |
for [lnum, info] in items(lines) | |
call prop_add(lnum, info.col, { | |
\ 'length': info.length, | |
\ 'type': 'search', | |
\ 'bufnr': _bufnr, | |
\}) | |
endfor | |
endfunction | |
function! CloseSearchPopup() abort | |
call popup_close(s:popctx.id) | |
endfunction | |
function! JumpSearchPopup() abort | |
" popup window で行を選択し、その行へジャンプする | |
endfunction | |
function! s:popup_filter(popctx, winid, key) abort | |
" TODO: title の更新 | |
" TODO: カーソルの移動 | |
" TODO: scrolloff の設定 | |
if a:key ==# '\<C-j>' | |
" 下へ | |
let a:popctx.lnum += 1 | |
call s:curosr_highlight(a:popctx) | |
return 1 | |
elseif a:key ==# '\<C-k>' | |
" 上へ | |
let a:popctx.lnum -= 1 | |
call s:curosr_highlight(a:popctx) | |
return 1 | |
endif | |
return 0 | |
endfunction | |
function! s:curosr_highlight(popctx) abort | |
let lnum = a:popctx.lnum | |
let _bufnr = winbufnr(a:popctx.id) | |
" popup window の winid を id とする | |
call prop_remove({'id': a:popctx.id}) | |
" XXX: length は調整必要? | |
call prop_add(1, 1, { | |
\ 'id': a:popctx.id, | |
\ 'type': 'search_cursorline', | |
\ 'length': a:popctx.width, | |
\ 'bufnr': _bufnr, | |
\}) | |
endfunction | |
augroup SearchPopup | |
autocmd! | |
autocmd CmdlineEnter /,\? call OpenSearchPopup() | |
autocmd CmdlineLeave /,\? call CloseSearchPopup() | |
autocmd CmdlineChanged /,\? call RefreshSearchPopup() | |
augroup END | |
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
scriptencoding utf-8 | |
" TODO: Fuzzy mode をつける あいまい検索したいときとか便利 | |
let s:popctx = {} | |
hi PatternNotFound guifg=red guibg=bg | |
" from https://github.com/bfrg/vim-qf-preview | |
function! s:below_line(wininfo) abort | |
" カレントウィンドウの一番下の位置 (スクリーン上での位置) | |
" winrow は 1 始まりのため -1 | |
" let win_bottom_line = a:wininfo.height + a:wininfo.winrow - 1 | |
return a:wininfo.height + a:wininfo.winrow - 1 | |
endfunction | |
function! s:reset_textprop(winid) abort | |
let _bufnr = winbufnr(a:winid) | |
" 検索のマッチ文字列 | |
call prop_type_delete('search',{ | |
\ 'bufnr': _bufnr | |
\}) | |
call prop_type_add('search', { | |
\ 'highlight': 'Search', | |
\ 'bufnr': _bufnr | |
\}) | |
" カーソル行 | |
call prop_type_delete('search_cursorline',{ | |
\ 'bufnr': _bufnr | |
\}) | |
call prop_type_add('search_cursorline', { | |
\ 'highlight': 'CursorLine', | |
\ 'bufnr': _bufnr | |
\}) | |
endfunction | |
function! s:title(n, m) abort | |
return printf(' match (%s/%s) ', a:n, a:m) | |
endfunction | |
function! OpenSearchPopup() abort | |
let wininfo = getwininfo(win_getid())[0] | |
let s:popctx = { | |
\ 'lines': getline(1, '$'), | |
\ 'height': 15, | |
\ 'id': 0, | |
\ 'lnum': 0, | |
\ 'width': wininfo.width -2, | |
\} | |
" 上のみ、border をつける | |
" mapping に 0 を渡すと、filter で mapping されていない素のキーが取得できる | |
let opts = { | |
\ 'border': [1, 1, 1, 1], | |
\ 'maxheight': s:popctx.height, | |
\ 'minwidth': s:popctx.width, | |
\ 'maxwidth': s:popctx.width, | |
\ 'scrollbar': 0, | |
\ 'line': s:below_line(wininfo), | |
\ 'col': wininfo.wincol, | |
\ 'fixed': 1, | |
\ 'pos': 'botleft', | |
\ 'wrap': 0, | |
\ 'filter': function('s:popup_filter', [s:popctx]), | |
\ 'highlight': 'Normal', | |
\ 'title': s:title(1, len(s:popctx.lines)), | |
\ 'mapping': v:false | |
\} | |
" XXX: 普通の カーソル行のハイライトにしたいな | |
" text-properties を使う | |
let s:popctx.id = popup_create(s:popctx.lines, opts) | |
endfunction | |
" TODO: 実際のバッファが見えるように、表示位置を変えてあげる必要がある? | |
" n を押した時、カーソルがジャンプするけど、popup window で見えなくなっ | |
" てしまうため | |
" / と同じように 検索処理を行う | |
function! RefreshSearchPopup() abort | |
" 検索文字列 ハイライトのリセット | |
call s:reset_textprop(s:popctx.id) | |
let pat = getcmdline() | |
let lines = {} | |
let showlines = [] | |
" TODO: 1行で複数箇所にマッチするパターンを処理できるようにする | |
" マッチする行のみ表示 | |
let lnum = 1 | |
for line in s:popctx.lines | |
let start = 0 | |
try | |
let m = matchstrpos(line, pat, start) | |
catch /.*/ | |
let showlines = '' | |
break | |
endtry | |
if m[2] != -1 | |
let col = m[1] + 1 | |
let length = len(m[0]) | |
let lines[lnum] = { | |
\ 'line': line, | |
\ 'col': col, | |
\ 'length': length, | |
\} | |
let lnum += 1 | |
call add(showlines, line) | |
endif | |
endfor | |
let highlight = '' | |
let title = '' | |
if len(showlines) == 0 | |
let showlines = 'Pattern not found.' | |
let highlight = 'PatternNotFound' | |
else | |
let highlight = 'Normal' | |
" マッチ数を表示する | |
let title = s:title(1, len(showlines)) | |
" TODO: カーソル移動に合わせて、title を変更する | |
" popup_filter の仕事? | |
endif | |
call popup_settext(s:popctx.id, showlines) | |
call popup_setoptions(s:popctx.id, { | |
\ 'highlight': highlight, | |
\ 'title': title, | |
\}) | |
" ハイライト | |
let _bufnr = winbufnr(s:popctx.id) | |
for [lnum, info] in items(lines) | |
call prop_add(lnum, info.col, { | |
\ 'length': info.length, | |
\ 'type': 'search', | |
\ 'bufnr': _bufnr, | |
\}) | |
endfor | |
endfunction | |
function! CloseSearchPopup() abort | |
call popup_close(s:popctx.id) | |
endfunction | |
function! JumpSearchPopup() abort | |
" popup window で行を選択し、その行へジャンプする | |
endfunction | |
function! s:popup_filter(popctx, winid, key) abort | |
" TODO: title の更新 | |
" TODO: カーソルの移動 | |
" TODO: scrolloff の設定 | |
" XXX: エスケープする場合、 " で囲むこと! | |
if a:key ==# "\<C-j>" | |
" 下へ | |
let a:popctx.lnum += 1 | |
call s:curosr_highlight(a:popctx) | |
return 1 | |
elseif a:key ==# "\<C-k>" | |
" 上へ | |
let a:popctx.lnum -= 1 | |
call s:curosr_highlight(a:popctx) | |
return 1 | |
else | |
echomsg a:key | |
endif | |
return 0 | |
endfunction | |
function! s:curosr_highlight(popctx) abort | |
let lnum = a:popctx.lnum | |
let _bufnr = winbufnr(a:popctx.id) | |
echomsg 'buffername' _bufnr | |
" popup window の winid を id とする | |
call prop_remove({'id': a:popctx.id}) | |
" XXX: length は調整必要? | |
call prop_add(1, 1, { | |
\ 'id': a:popctx.id, | |
\ 'type': 'search_cursorline', | |
\ 'length': a:popctx.width, | |
\ 'bufnr': _bufnr, | |
\}) | |
endfunction | |
augroup SearchPopup | |
autocmd! | |
autocmd CmdlineEnter /,\? call OpenSearchPopup() | |
autocmd CmdlineLeave /,\? call CloseSearchPopup() | |
autocmd CmdlineChanged /,\? call RefreshSearchPopup() | |
augroup END | |
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
scriptencoding utf-8 | |
" TODO: Fuzzy mode をつける あいまい検索したいときとか便利 | |
let s:popctx = {} | |
hi PatternNotFound guifg=red guibg=bg | |
" from https://github.com/bfrg/vim-qf-preview | |
function! s:below_line(wininfo) abort | |
" カレントウィンドウの一番下の位置 (スクリーン上での位置) | |
" winrow は 1 始まりのため -1 | |
" let win_bottom_line = a:wininfo.height + a:wininfo.winrow - 1 | |
return a:wininfo.height + a:wininfo.winrow - 1 | |
endfunction | |
function! s:reset_textprop(winid) abort | |
let _bufnr = winbufnr(a:winid) | |
" | |
" " 検索のマッチ文字列 | |
call prop_type_delete('search',{ | |
\}) | |
" \ 'bufnr': _bufnr | |
call prop_type_add('search', { | |
\ 'highlight': 'Search', | |
\}) | |
" \ 'bufnr': _bufnr | |
" | |
" " カーソル行 | |
call prop_type_delete('search_cursorline',{ | |
\}) | |
" \ 'bufnr': _bufnr | |
call prop_type_add('search_cursorline', { | |
\ 'highlight': 'PmenuSel', | |
\}) | |
" \ 'bufnr': _bufnr | |
endfunction | |
function! s:title(n, m) abort | |
return printf(' match (%s/%s) ', a:n, a:m) | |
endfunction | |
function! OpenSearchPopup() abort | |
let wininfo = getwininfo(win_getid())[0] | |
let s:popctx = { | |
\ 'lines': getline(1, '$'), | |
\ 'height': 15, | |
\ 'id': 0, | |
\ 'lnum': 0, | |
\ 'width': wininfo.width -2, | |
\} | |
" 上のみ、border をつける | |
" mapping に 0 を渡すと、filter で mapping されていない素のキーが取得できる | |
let opts = { | |
\ 'border': [1, 1, 1, 1], | |
\ 'maxheight': s:popctx.height, | |
\ 'minwidth': s:popctx.width, | |
\ 'maxwidth': s:popctx.width, | |
\ 'scrollbar': 0, | |
\ 'line': s:below_line(wininfo), | |
\ 'col': wininfo.wincol, | |
\ 'fixed': 1, | |
\ 'pos': 'botleft', | |
\ 'wrap': 0, | |
\ 'filter': function('s:popup_filter', [s:popctx]), | |
\ 'highlight': 'Normal', | |
\ 'title': s:title(1, len(s:popctx.lines)), | |
\ 'mapping': v:false | |
\} | |
" XXX: 普通の カーソル行のハイライトにしたいな | |
" text-properties を使う | |
let s:popctx.id = popup_create(s:popctx.lines, opts) | |
" 検索文字列 ハイライトのリセット | |
call s:reset_textprop(s:popctx.id) | |
endfunction | |
" TODO: 実際のバッファが見えるように、表示位置を変えてあげる必要がある? | |
" n を押した時、カーソルがジャンプするけど、popup window で見えなくなっ | |
" てしまうため | |
" / と同じように 検索処理を行う | |
function! RefreshSearchPopup() abort | |
let pat = getcmdline() | |
let lines = {} | |
let showlines = [] | |
" TODO: 1行で複数箇所にマッチするパターンを処理できるようにする | |
" マッチする行のみ表示 | |
let lnum = 1 | |
for line in s:popctx.lines | |
let start = 0 | |
try | |
let m = matchstrpos(line, pat, start) | |
catch /.*/ | |
let showlines = '' | |
break | |
endtry | |
if m[2] != -1 | |
let col = m[1] + 1 | |
let length = len(m[0]) | |
let lines[lnum] = { | |
\ 'line': line, | |
\ 'col': col, | |
\ 'length': length, | |
\} | |
let lnum += 1 | |
call add(showlines, line) | |
endif | |
endfor | |
let highlight = '' | |
let title = '' | |
if len(showlines) == 0 | |
let showlines = 'Pattern not found.' | |
let highlight = 'PatternNotFound' | |
else | |
let highlight = 'Normal' | |
" マッチ数を表示する | |
let title = s:title(1, len(showlines)) | |
" TODO: カーソル移動に合わせて、title を変更する | |
" popup_filter の仕事? | |
endif | |
call popup_settext(s:popctx.id, showlines) | |
call popup_setoptions(s:popctx.id, { | |
\ 'highlight': highlight, | |
\ 'title': title, | |
\}) | |
" ハイライト | |
let _bufnr = winbufnr(s:popctx.id) | |
for [lnum, info] in items(lines) | |
call prop_add(lnum, info.col, { | |
\ 'length': info.length, | |
\ 'type': 'search', | |
\ 'bufnr': _bufnr, | |
\}) | |
endfor | |
call prop_remove({'type': 'search_cursorline', 'bufnr': _bufnr}) | |
call prop_add(1, 1, { | |
\ 'type': 'search_cursorline', | |
\ 'length': s:popctx.width, | |
\ 'bufnr': _bufnr, | |
\}) | |
endfunction | |
function! CloseSearchPopup() abort | |
call popup_close(s:popctx.id) | |
endfunction | |
function! JumpSearchPopup() abort | |
" popup window で行を選択し、その行へジャンプする | |
endfunction | |
function! s:popup_filter(popctx, winid, key) abort | |
" TODO: title の更新 | |
" TODO: カーソルの移動 | |
" TODO: scrolloff の設定 | |
" XXX: エスケープする場合、 " で囲むこと! | |
if a:key ==# "\<C-j>" | |
" 下へ | |
let a:popctx.lnum += 1 | |
call s:curosr_highlight(a:popctx) | |
return 1 | |
elseif a:key ==# "\<C-k>" | |
" 上へ | |
let a:popctx.lnum -= 1 | |
call s:curosr_highlight(a:popctx) | |
return 1 | |
endif | |
return 0 | |
endfunction | |
function! s:curosr_highlight(popctx) abort | |
let lnum = a:popctx.lnum | |
let _bufnr = winbufnr(s:popctx.id) | |
" popup window の winid を id とする | |
call prop_remove({'type': 'search_cursorline', 'bufnr': _bufnr}) | |
" XXX: length は調整必要? | |
call prop_add(lnum, 1, { | |
\ 'type': 'search_cursorline', | |
\ 'length': 10, | |
\ 'bufnr': _bufnr, | |
\}) | |
" \ 'length': a:popctx.width, | |
endfunction | |
augroup SearchPopup | |
autocmd! | |
autocmd CmdlineEnter /,\? call OpenSearchPopup() | |
autocmd CmdlineLeave /,\? call CloseSearchPopup() | |
autocmd CmdlineChanged /,\? call RefreshSearchPopup() | |
augroup END | |
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
scriptencoding utf-8 | |
" TODO: Fuzzy mode をつける あいまい検索したいときとか便利 | |
let s:popctx = {} | |
hi PatternNotFound guifg=red guibg=bg | |
call s:reset_textprop() | |
" from https://github.com/bfrg/vim-qf-preview | |
function! s:below_line(wininfo) abort | |
" カレントウィンドウの一番下の位置 (スクリーン上での位置) | |
" winrow は 1 始まりのため -1 | |
" let win_bottom_line = a:wininfo.height + a:wininfo.winrow - 1 | |
return a:wininfo.height + a:wininfo.winrow - 1 | |
endfunction | |
" function! s:reset_textprop(winid) abort | |
function! s:reset_textprop() abort | |
" let _bufnr = winbufnr(a:winid) | |
" | |
" " 検索のマッチ文字列 | |
call prop_type_delete('search',{ | |
\}) | |
" \ 'bufnr': _bufnr | |
call prop_type_add('search', { | |
\ 'highlight': 'Search', | |
\}) | |
" \ 'bufnr': _bufnr | |
" | |
" " カーソル行 | |
call prop_type_delete('search_cursorline',{ | |
\}) | |
" \ 'bufnr': _bufnr | |
call prop_type_add('search_cursorline', { | |
\ 'highlight': 'CursorLine', | |
\ 'priority': 10, | |
\}) | |
" \ 'bufnr': _bufnr | |
endfunction | |
function! s:title(n, m) abort | |
return printf(' match (%s/%s) ', a:n, a:m) | |
endfunction | |
function! OpenSearchPopup() abort | |
let wininfo = getwininfo(win_getid())[0] | |
let s:popctx = { | |
\ 'lines': getline(1, '$'), | |
\ 'height': 15, | |
\ 'id': 0, | |
\ 'lnum': 0, | |
\ 'width': wininfo.width -2, | |
\} | |
" 上のみ、border をつける | |
" mapping に 0 を渡すと、filter で mapping されていない素のキーが取得できる | |
let opts = { | |
\ 'border': [1, 1, 1, 1], | |
\ 'maxheight': s:popctx.height, | |
\ 'minwidth': s:popctx.width, | |
\ 'maxwidth': s:popctx.width, | |
\ 'scrollbar': 0, | |
\ 'line': s:below_line(wininfo), | |
\ 'col': wininfo.wincol, | |
\ 'fixed': 1, | |
\ 'pos': 'botleft', | |
\ 'wrap': 0, | |
\ 'filter': function('s:popup_filter', [s:popctx]), | |
\ 'highlight': 'Normal', | |
\ 'title': s:title(1, len(s:popctx.lines)), | |
\ 'mapping': 0, | |
\} | |
" XXX: 普通の カーソル行のハイライトにしたいな | |
" text-properties を使う | |
let s:popctx.id = popup_create(s:popctx.lines, opts) | |
" 検索文字列 ハイライトのリセット | |
endfunction | |
" TODO: 実際のバッファが見えるように、表示位置を変えてあげる必要がある? | |
" n を押した時、カーソルがジャンプするけど、popup window で見えなくなっ | |
" てしまうため | |
" / と同じように 検索処理を行う | |
function! RefreshSearchPopup() abort | |
let pat = getcmdline() | |
let lines = {} | |
let showlines = [] | |
" TODO: 1行で複数箇所にマッチするパターンを処理できるようにする | |
" マッチする行のみ表示 | |
let lnum = 1 | |
for line in s:popctx.lines | |
let start = 0 | |
try | |
let m = matchstrpos(line, pat, start) | |
catch /.*/ | |
let showlines = '' | |
break | |
endtry | |
if m[2] != -1 | |
let col = m[1] + 1 | |
let length = len(m[0]) | |
let lines[lnum] = { | |
\ 'line': line, | |
\ 'col': col, | |
\ 'length': length, | |
\} | |
let lnum += 1 | |
call add(showlines, line) | |
endif | |
endfor | |
let highlight = '' | |
let title = '' | |
if len(showlines) == 0 | |
let showlines = 'Pattern not found.' | |
let highlight = 'PatternNotFound' | |
else | |
let highlight = 'Normal' | |
" マッチ数を表示する | |
let title = s:title(1, len(showlines)) | |
" TODO: カーソル移動に合わせて、title を変更する | |
" popup_filter の仕事? | |
endif | |
call popup_settext(s:popctx.id, showlines) | |
call popup_setoptions(s:popctx.id, { | |
\ 'highlight': highlight, | |
\ 'title': title, | |
\}) | |
" ハイライト | |
let _bufnr = winbufnr(s:popctx.id) | |
for [lnum, info] in items(lines) | |
call prop_add(lnum, info.col, { | |
\ 'length': info.length, | |
\ 'type': 'search', | |
\ 'bufnr': _bufnr, | |
\}) | |
endfor | |
call prop_remove({'type': 'search_cursorline', 'bufnr': _bufnr}) | |
call prop_add(1, 1, { | |
\ 'type': 'search_cursorline', | |
\ 'length': s:popctx.width, | |
\ 'bufnr': _bufnr, | |
\}) | |
endfunction | |
function! CloseSearchPopup() abort | |
call popup_close(s:popctx.id) | |
endfunction | |
function! JumpSearchPopup() abort | |
" popup window で行を選択し、その行へジャンプする | |
endfunction | |
function! s:popup_filter(popctx, winid, key) abort | |
" TODO: title の更新 | |
" TODO: カーソルの移動 | |
" TODO: scrolloff の設定 | |
" offset は 先頭行からの位置 | |
" lnum は実際の行の位置 | |
" XXX: エスケープする場合、 " で囲むこと! | |
if a:key ==# "\<C-j>" | |
" 下へ | |
let a:popctx.offset += 1 | |
call s:curosr_highlight(a:popctx) | |
return 1 | |
elseif a:key ==# "\<C-k>" | |
" 上へ | |
let a:popctx.offset -= 1 | |
call s:curosr_highlight(a:popctx) | |
redraw | |
return 1 | |
endif | |
return 0 | |
endfunction | |
function! s:curosr_highlight(popctx) abort | |
let lnum = a:popctx.lnum | |
let _bufnr = winbufnr(s:popctx.id) | |
" popup window の winid を id とする | |
call prop_remove({'type': 'search_cursorline', 'bufnr': _bufnr}) | |
" XXX: length は調整必要? | |
call prop_add(lnum, 1, { | |
\ 'type': 'search_cursorline', | |
\ 'bufnr': _bufnr, | |
\ 'length': a:popctx.width, | |
\}) | |
" これ必須! | |
redraw | |
endfunction | |
augroup SearchPopup | |
autocmd! | |
autocmd CmdlineEnter /,\? call OpenSearchPopup() | |
autocmd CmdlineLeave /,\? call CloseSearchPopup() | |
autocmd CmdlineChanged /,\? call RefreshSearchPopup() | |
augroup END | |
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
" TODO: :global に対応 | |
" ガッガッと | |
let s:search_popwinid = 0 | |
" XXX: ctx を scirpt に持たせていいのか微妙なところ? | |
" なぜ、そう思う? | |
let s:popctx = {} | |
" from qfpreview.vim | |
" https://github.com/bfrg/vim-qf-preview/blob/1439b3834a8a02fde864c78adc6d3ee37ec08bf8/autoload/qfpreview.vim#L63-L65 | |
function! s:below_line(wininfo) abort | |
" カレントウィンドウの一番下の位置 (スクリーン上での位置) | |
" winrow は 1 始まりのため -1 | |
" let win_bottom_line = a:wininfo.height + a:wininfo.winrow - 1 | |
return a:wininfo.height + a:wininfo.winrow - 1 | |
endfunction | |
function! OpenSearchPopup() | |
let wininfo = getwininfo(win_getid())[0] | |
let popctx = { | |
\ 'lines': getline(1, '$'), | |
\ 'height': 15, | |
\} | |
let opts = { | |
\ 'borderchars': [' '], | |
\ 'maxheight': popctx.height, | |
\ 'minwidth': wininfo.width, | |
\ 'maxwidth': wininfo.width, | |
\ 'scrollbar': 0, | |
\ 'line': s:below_line(wininfo), | |
\ 'col': wininfo.wincol, | |
\ 'fixed': 1, | |
\ 'pos': 'botleft', | |
\ 'wrap': 0, | |
\} | |
" XXX: 普通の カーソル行のハイライトにしたいな | |
let popctx.id = popup_create(popctx.lines, opts) | |
let s:search_popwinid = popctx.id | |
let s:popctx = popctx | |
endfunction | |
" TODO: 実際のバッファが見えるように、表示位置を変えてあげる必要がある? | |
" n を押した時、カーソルがジャンプするけど、popup window で見えなくなっ | |
" てしまうため | |
" / と同じように 検索処理を行う | |
function! RefreshSearchPopup() abort | |
" マッチする行のみ表示 | |
let pat = getcmdline() | |
let disp_lines = [] | |
let idx = 1 | |
for line in s:popctx.lines | |
if match(line, pat) != -1 | |
" 行番号を右揃え | |
let num = printf('%'.len(line('$')).'d', idx) | |
call add(disp_lines, num.': '.line) | |
endif | |
let idx += 1 | |
endfor | |
" マッチした箇所をハイライトをする | |
" text property? | |
" がんばるぞい! | |
" let s:popctx.display_lines = s:popctx.display_lines[1:] | |
call popup_settext(s:popctx.id, disp_lines) | |
endfunction | |
function! CloseSearchPopup() abort | |
" if s:search_popwinid != 0 | |
call popup_close(s:search_popwinid) | |
let s:search_popwinid = 0 | |
" endif | |
endfunction | |
function! JumpSearchPopup() abort | |
" popup window で行を選択し、その行へジャンプする | |
endfunction | |
function! s:popup_filter(popctx, winid, key) abort | |
if a:key ==# '\<C-j>' | |
let line = popup_getoptions(a:winidm).firstline | |
let newfirstline = line | |
elseif a:key ==# '\<C-k>' | |
endif | |
return 0 | |
endfunction | |
augroup SearchPopup | |
autocmd! | |
autocmd CmdlineEnter /,\? call OpenSearchPopup() | |
autocmd CmdlineLeave /,\? call CloseSearchPopup() | |
autocmd CmdlineChanged /,\? call RefreshSearchPopup() | |
augroup END | |
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
scriptencoding utf-8 | |
" TODO: Fuzzy mode をつける あいまい検索したいときとか便利 | |
let s:popctx = {} | |
hi PatternNotFound guifg=red guibg=bg | |
" cursorline 使用時に使う ハイライト | |
hi link PopupSelected CursorLine | |
call s:reset_textprop() | |
" from https://github.com/bfrg/vim-qf-preview | |
function! s:below_line(wininfo) abort | |
" カレントウィンドウの一番下の位置 (スクリーン上での位置) | |
" winrow は 1 始まりのため -1 | |
" let win_bottom_line = a:wininfo.height + a:wininfo.winrow - 1 | |
return a:wininfo.height + a:wininfo.winrow - 1 | |
endfunction | |
" function! s:reset_textprop(winid) abort | |
function! s:reset_textprop() abort | |
" let _bufnr = winbufnr(a:winid) | |
" | |
" " 検索のマッチ文字列 | |
call prop_type_delete('search',{ | |
\}) | |
" \ 'bufnr': _bufnr | |
call prop_type_add('search', { | |
\ 'highlight': 'Search', | |
\}) | |
" \ 'bufnr': _bufnr | |
" " カーソル行 | |
" call prop_type_delete('search_cursorline',{ | |
" \}) | |
" " \ 'bufnr': _bufnr | |
" | |
" call prop_type_add('search_cursorline', { | |
" \ 'highlight': 'PmenuSel', | |
" \ 'priority': 10, | |
" \}) | |
" " \ 'bufnr': _bufnr | |
endfunction | |
function! s:title(n, m) abort | |
return printf(' match (%s/%s) ', a:n, a:m) | |
endfunction | |
function! OpenSearchPopup() abort | |
let wininfo = getwininfo(win_getid())[0] | |
let s:popctx = { | |
\ 'lines': getline(1, '$'), | |
\ 'height': 15, | |
\ 'id': 0, | |
\ 'lnum': 0, | |
\ 'width': wininfo.width -2, | |
\} | |
" 上のみ、border をつける | |
" mapping に 0 を渡すと、filter で mapping されていない素のキーが取得できる | |
let opts = { | |
\ 'border': [1, 1, 1, 1], | |
\ 'maxheight': s:popctx.height, | |
\ 'minwidth': s:popctx.width, | |
\ 'maxwidth': s:popctx.width, | |
\ 'scrollbar': 0, | |
\ 'line': s:below_line(wininfo), | |
\ 'col': wininfo.wincol, | |
\ 'fixed': 1, | |
\ 'pos': 'botleft', | |
\ 'cursorline': 1, | |
\ 'wrap': 0, | |
\ 'filter': function('s:popup_filter', [s:popctx]), | |
\ 'highlight': 'Normal', | |
\ 'title': s:title(1, len(s:popctx.lines)), | |
\ 'mapping': 0, | |
\} | |
" XXX: 普通の カーソル行のハイライトにしたいな | |
" text-properties を使う | |
let s:popctx.id = popup_create(s:popctx.lines, opts) | |
" 検索文字列 ハイライトのリセット | |
endfunction | |
" TODO: 実際のバッファが見えるように、表示位置を変えてあげる必要がある? | |
" n を押した時、カーソルがジャンプするけど、popup window で見えなくなっ | |
" てしまうため | |
" / と同じように 検索処理を行う | |
function! RefreshSearchPopup() abort | |
let pat = getcmdline() | |
let lines = {} | |
let showlines = [] | |
" TODO: 1行で複数箇所にマッチするパターンを処理できるようにする | |
" マッチする行のみ表示 | |
let lnum = 1 | |
for line in s:popctx.lines | |
let start = 0 | |
try | |
let m = matchstrpos(line, pat, start) | |
catch /.*/ | |
let showlines = '' | |
break | |
endtry | |
if m[2] != -1 | |
let col = m[1] + 1 | |
let length = len(m[0]) | |
let lines[lnum] = { | |
\ 'line': line, | |
\ 'col': col, | |
\ 'length': length, | |
\} | |
let lnum += 1 | |
call add(showlines, line) | |
endif | |
endfor | |
let highlight = '' | |
let title = '' | |
if len(showlines) == 0 | |
let showlines = 'Pattern not found.' | |
let highlight = 'PatternNotFound' | |
else | |
let highlight = 'Normal' | |
" マッチ数を表示する | |
let title = s:title(1, len(showlines)) | |
" TODO: カーソル移動に合わせて、title を変更する | |
" popup_filter の仕事? | |
endif | |
call popup_settext(s:popctx.id, showlines) | |
call popup_setoptions(s:popctx.id, { | |
\ 'highlight': highlight, | |
\ 'title': title, | |
\}) | |
" ハイライト | |
let _bufnr = winbufnr(s:popctx.id) | |
for [lnum, info] in items(lines) | |
call prop_add(lnum, info.col, { | |
\ 'length': info.length, | |
\ 'type': 'search', | |
\ 'bufnr': _bufnr, | |
\}) | |
endfor | |
call prop_remove({'type': 'search_cursorline', 'bufnr': _bufnr}) | |
call prop_add(1, 1, { | |
\ 'type': 'search_cursorline', | |
\ 'length': s:popctx.width, | |
\ 'bufnr': _bufnr, | |
\}) | |
endfunction | |
function! CloseSearchPopup() abort | |
call popup_close(s:popctx.id) | |
endfunction | |
function! JumpSearchPopup() abort | |
" popup window で行を選択し、その行へジャンプする | |
endfunction | |
function! s:popup_filter(popctx, winid, key) abort | |
" TODO: title の更新 | |
" TODO: カーソルの移動 | |
" TODO: scrolloff の設定 | |
" offset は 先頭行からの位置 | |
" lnum は実際の行の位置 | |
" カーソル行の強調は | |
" XXX: エスケープする場合、 " で囲むこと! | |
if a:key ==# "\<C-j>" | |
" 下へ | |
let a:popctx.lnum += 1 | |
call s:curosr_highlight(a:popctx) | |
return 1 | |
elseif a:key ==# "\<C-k>" | |
" 上へ | |
let a:popctx.lnum -= 1 | |
call s:curosr_highlight(a:popctx) | |
return 1 | |
endif | |
return 0 | |
endfunction | |
" function! s:curosr_highlight(popctx) abort | |
" let lnum = a:popctx.lnum | |
" let _bufnr = winbufnr(s:popctx.id) | |
" | |
" " popup window の winid を id とする | |
" " call prop_remove({'type': 'search_cursorline', 'bufnr': _bufnr}) | |
" | |
" " " XXX: length は調整必要? | |
" " call prop_add(lnum, 1, { | |
" " \ 'type': 'search_cursorline', | |
" " \ 'bufnr': _bufnr, | |
" " \ 'length': a:popctx.width, | |
" " \}) | |
" " これ必須! | |
" redraw | |
" | |
" endfunction | |
augroup SearchPopup | |
autocmd! | |
autocmd CmdlineEnter /,\? call OpenSearchPopup() | |
autocmd CmdlineLeave /,\? call CloseSearchPopup() | |
autocmd CmdlineChanged /,\? call RefreshSearchPopup() | |
augroup END | |
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
scriptencoding utf-8 | |
" TODO: Fuzzy mode をつける あいまい検索したいときとか便利 | |
let s:popctx = {} | |
hi PatternNotFound guifg=red guibg=bg | |
" cursorline 使用時に使う ハイライト | |
hi link PopupSelected CursorLine | |
call s:reset_textprop() | |
" from https://github.com/bfrg/vim-qf-preview | |
function! s:below_line(wininfo) abort | |
" カレントウィンドウの一番下の位置 (スクリーン上での位置) | |
" winrow は 1 始まりのため -1 | |
" let win_bottom_line = a:wininfo.height + a:wininfo.winrow - 1 | |
return a:wininfo.height + a:wininfo.winrow - 1 | |
endfunction | |
" function! s:reset_textprop(winid) abort | |
function! s:reset_textprop() abort | |
" let _bufnr = winbufnr(a:winid) | |
" | |
" " 検索のマッチ文字列 | |
call prop_type_delete('search',{ | |
\}) | |
" \ 'bufnr': _bufnr | |
call prop_type_add('search', { | |
\ 'highlight': 'Search', | |
\}) | |
" \ 'bufnr': _bufnr | |
" " カーソル行 | |
" call prop_type_delete('search_cursorline',{ | |
" \}) | |
" " \ 'bufnr': _bufnr | |
" | |
" call prop_type_add('search_cursorline', { | |
" \ 'highlight': 'PmenuSel', | |
" \ 'priority': 10, | |
" \}) | |
" " \ 'bufnr': _bufnr | |
endfunction | |
function! s:title(n, m) abort | |
return printf(' match (%s/%s) ', a:n, a:m) | |
endfunction | |
function! OpenSearchPopup() abort | |
let wininfo = getwininfo(win_getid())[0] | |
let s:popctx = { | |
\ 'lines': getline(1, '$'), | |
\ 'height': 15, | |
\ 'id': 0, | |
\ 'lnum': 0, | |
\ 'width': wininfo.width -2, | |
\} | |
" 上のみ、border をつける | |
" mapping に 0 を渡すと、filter で mapping されていない素のキーが取得できる | |
let opts = { | |
\ 'border': [1, 1, 1, 1], | |
\ 'maxheight': s:popctx.height, | |
\ 'minwidth': s:popctx.width, | |
\ 'maxwidth': s:popctx.width, | |
\ 'scrollbar': 0, | |
\ 'line': s:below_line(wininfo), | |
\ 'col': wininfo.wincol, | |
\ 'fixed': 1, | |
\ 'pos': 'botleft', | |
\ 'cursorline': 1, | |
\ 'wrap': 0, | |
\ 'filter': function('s:popup_filter', [s:popctx]), | |
\ 'highlight': 'Normal', | |
\ 'title': s:title(1, len(s:popctx.lines)), | |
\ 'mapping': 0, | |
\} | |
" XXX: 普通の カーソル行のハイライトにしたいな | |
" PatternNotFound を定義する | |
let s:popctx.id = popup_create(s:popctx.lines, opts) | |
endfunction | |
" TODO: 実際のバッファが見えるように、表示位置を変えてあげる必要がある? | |
" n を押した時、カーソルがジャンプするけど、popup window で見えなくなっ | |
" てしまうため | |
" / と同じように 検索処理を行う | |
function! RefreshSearchPopup() abort | |
let pat = getcmdline() | |
let lines = {} | |
let showlines = [] | |
" TODO: 1行で複数箇所にマッチするパターンを処理できるようにする | |
" マッチする行のみ表示 | |
let lnum = 1 | |
for line in s:popctx.lines | |
let start = 0 | |
try | |
let m = matchstrpos(line, pat, start) | |
catch /.*/ | |
let showlines = '' | |
break | |
endtry | |
if m[2] != -1 | |
let col = m[1] + 1 | |
let length = len(m[0]) | |
let lines[lnum] = { | |
\ 'line': line, | |
\ 'col': col, | |
\ 'length': length, | |
\} | |
let lnum += 1 | |
call add(showlines, line) | |
endif | |
endfor | |
let highlight = '' | |
let title = '' | |
if len(showlines) == 0 | |
let showlines = 'Pattern not found.' | |
let highlight = 'PatternNotFound' | |
else | |
let highlight = 'Normal' | |
" マッチ数を表示する | |
let title = s:title(1, len(showlines)) | |
" TODO: カーソル移動に合わせて、title を変更する | |
" popup_filter の仕事? | |
endif | |
call popup_settext(s:popctx.id, showlines) | |
call popup_setoptions(s:popctx.id, { | |
\ 'highlight': highlight, | |
\ 'title': title, | |
\}) | |
" ハイライト | |
let _bufnr = winbufnr(s:popctx.id) | |
for [lnum, info] in items(lines) | |
call prop_add(lnum, info.col, { | |
\ 'length': info.length, | |
\ 'type': 'search', | |
\ 'bufnr': _bufnr, | |
\}) | |
endfor | |
call prop_remove({'type': 'search_cursorline', 'bufnr': _bufnr}) | |
call prop_add(1, 1, { | |
\ 'type': 'search_cursorline', | |
\ 'length': s:popctx.width, | |
\ 'bufnr': _bufnr, | |
\}) | |
endfunction | |
function! CloseSearchPopup() abort | |
call popup_close(s:popctx.id) | |
endfunction | |
function! JumpSearchPopup() abort | |
" popup window で行を選択し、その行へジャンプする | |
endfunction | |
function! s:popup_filter(popctx, winid, key) abort | |
" TODO: title の更新 | |
" TODO: カーソルの移動 | |
" TODO: scrolloff の設定 | |
" offset は 先頭行からの位置 | |
" lnum は実際の行の位置 | |
" カーソル行の強調は cursorline で行うことにした | |
" もしかして、カーソル位置の移動は cursor() を使う? | |
" XXX: エスケープする場合、 " で囲むこと! | |
if a:key ==# "\<C-j>" | |
" 下へ | |
let a:popctx.lnum += 1 | |
win_execute(a:popctx.id, 'cursor(a:popctx.lnum, 1)') | |
return 1 | |
elseif a:key ==# "\<C-k>" | |
" 上へ | |
let a:popctx.lnum -= 1 | |
return 1 | |
endif | |
return 0 | |
endfunction | |
augroup SearchPopup | |
autocmd! | |
autocmd CmdlineEnter /,\? call OpenSearchPopup() | |
autocmd CmdlineLeave /,\? call CloseSearchPopup() | |
autocmd CmdlineChanged /,\? call RefreshSearchPopup() | |
augroup END | |
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
scriptencoding utf-8 | |
" TODO: Fuzzy mode をつける あいまい検索したいときとか便利 | |
let s:popctx = {} | |
hi PatternNotFound guifg=red guibg=bg | |
" cursorline 使用時に使う ハイライト | |
hi link PopupSelected CursorLine | |
call s:reset_textprop() | |
" from https://github.com/bfrg/vim-qf-preview | |
function! s:below_line(wininfo) abort | |
" カレントウィンドウの一番下の位置 (スクリーン上での位置) | |
" winrow は 1 始まりのため -1 | |
" let win_bottom_line = a:wininfo.height + a:wininfo.winrow - 1 | |
return a:wininfo.height + a:wininfo.winrow - 1 | |
endfunction | |
" function! s:reset_textprop(winid) abort | |
function! s:reset_textprop() abort | |
" let _bufnr = winbufnr(a:winid) | |
" | |
" " 検索のマッチ文字列 | |
call prop_type_delete('search',{ | |
\}) | |
" \ 'bufnr': _bufnr | |
call prop_type_add('search', { | |
\ 'highlight': 'Search', | |
\}) | |
" \ 'bufnr': _bufnr | |
" " カーソル行 | |
" call prop_type_delete('search_cursorline',{ | |
" \}) | |
" " \ 'bufnr': _bufnr | |
" | |
" call prop_type_add('search_cursorline', { | |
" \ 'highlight': 'PmenuSel', | |
" \ 'priority': 10, | |
" \}) | |
" " \ 'bufnr': _bufnr | |
endfunction | |
function! s:title(n, m) abort | |
return printf(' match (%s/%s) ', a:n, a:m) | |
endfunction | |
function! OpenSearchPopup() abort | |
let wininfo = getwininfo(win_getid())[0] | |
let s:popctx = { | |
\ 'lines': getline(1, '$'), | |
\ 'height': 15, | |
\ 'id': 0, | |
\ 'lnum': 0, | |
\ 'width': wininfo.width -2, | |
\} | |
" 上のみ、border をつける | |
" mapping に 0 を渡すと、filter で mapping されていない素のキーが取得できる | |
let opts = { | |
\ 'border': [1, 1, 1, 1], | |
\ 'maxheight': s:popctx.height, | |
\ 'minwidth': s:popctx.width, | |
\ 'maxwidth': s:popctx.width, | |
\ 'scrollbar': 0, | |
\ 'line': s:below_line(wininfo), | |
\ 'col': wininfo.wincol, | |
\ 'fixed': 1, | |
\ 'pos': 'botleft', | |
\ 'cursorline': 1, | |
\ 'wrap': 0, | |
\ 'filter': function('s:popup_filter', [s:popctx]), | |
\ 'highlight': 'Normal', | |
\ 'title': s:title(1, len(s:popctx.lines)), | |
\ 'mapping': 0, | |
\} | |
" XXX: 普通の カーソル行のハイライトにしたいな | |
" PatternNotFound を定義する | |
let s:popctx.id = popup_create(s:popctx.lines, opts) | |
endfunction | |
" TODO: 実際のバッファが見えるように、表示位置を変えてあげる必要がある? | |
" n を押した時、カーソルがジャンプするけど、popup window で見えなくなっ | |
" てしまうため | |
" / と同じように 検索処理を行う | |
function! RefreshSearchPopup() abort | |
let pat = getcmdline() | |
let lines = {} | |
let showlines = [] | |
" TODO: 1行で複数箇所にマッチするパターンを処理できるようにする | |
" マッチする行のみ表示 | |
let lnum = 1 | |
for line in s:popctx.lines | |
let start = 0 | |
try | |
let m = matchstrpos(line, pat, start) | |
catch /.*/ | |
let showlines = '' | |
break | |
endtry | |
if m[2] != -1 | |
let col = m[1] + 1 | |
let length = len(m[0]) | |
let lines[lnum] = { | |
\ 'line': line, | |
\ 'col': col, | |
\ 'length': length, | |
\} | |
let lnum += 1 | |
call add(showlines, line) | |
endif | |
endfor | |
let highlight = '' | |
let title = '' | |
if len(showlines) == 0 | |
let showlines = 'Pattern not found.' | |
let highlight = 'PatternNotFound' | |
else | |
let highlight = 'Normal' | |
" マッチ数を表示する | |
let title = s:title(1, len(showlines)) | |
" TODO: カーソル移動に合わせて、title を変更する | |
" popup_filter の仕事? | |
endif | |
call popup_settext(s:popctx.id, showlines) | |
call popup_setoptions(s:popctx.id, { | |
\ 'highlight': highlight, | |
\ 'title': title, | |
\}) | |
" ハイライト | |
let _bufnr = winbufnr(s:popctx.id) | |
for [lnum, info] in items(lines) | |
call prop_add(lnum, info.col, { | |
\ 'length': info.length, | |
\ 'type': 'search', | |
\ 'bufnr': _bufnr, | |
\}) | |
endfor | |
call prop_remove({'type': 'search_cursorline', 'bufnr': _bufnr}) | |
call prop_add(1, 1, { | |
\ 'type': 'search_cursorline', | |
\ 'length': s:popctx.width, | |
\ 'bufnr': _bufnr, | |
\}) | |
endfunction | |
function! CloseSearchPopup() abort | |
call popup_close(s:popctx.id) | |
endfunction | |
function! JumpSearchPopup() abort | |
" popup window で行を選択し、その行へジャンプする | |
endfunction | |
function! s:popup_filter(popctx, winid, key) abort | |
" TODO: title の更新 | |
" TODO: カーソルの移動 | |
" TODO: scrolloff の設定 | |
" offset は 先頭行からの位置 | |
" lnum は実際の行の位置 | |
" カーソル行の強調は cursorline で行うことにした | |
" もしかして、カーソル位置の移動は cursor() を使う? | |
" XXX: エスケープする場合、 " で囲むこと! | |
if a:key ==# "\<C-j>" | |
" 下へ | |
let a:popctx.lnum += 1 | |
call popup_setoptions(a:popctx.id, {'firstline': a:popctx.lnum}) | |
return 1 | |
elseif a:key ==# "\<C-k>" | |
" 上へ | |
let a:popctx.lnum -= 1 | |
return 1 | |
endif | |
return 0 | |
endfunction | |
augroup SearchPopup | |
autocmd! | |
autocmd CmdlineEnter /,\? call OpenSearchPopup() | |
autocmd CmdlineLeave /,\? call CloseSearchPopup() | |
autocmd CmdlineChanged /,\? call RefreshSearchPopup() | |
augroup END | |
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
scriptencoding utf-8 | |
" TODO: Fuzzy mode をつける あいまい検索したいときとか便利 | |
let s:popctx = {} | |
hi PatternNotFound guifg=red guibg=bg | |
" cursorline 使用時に使う ハイライト | |
hi link PopupSelected CursorLine | |
" from https://github.com/bfrg/vim-qf-preview | |
function! s:below_line(wininfo) abort | |
" カレントウィンドウの一番下の位置 (スクリーン上での位置) | |
" winrow は 1 始まりのため -1 | |
" let win_bottom_line = a:wininfo.height + a:wininfo.winrow - 1 | |
return a:wininfo.height + a:wininfo.winrow - 1 | |
endfunction | |
" function! s:reset_textprop(winid) abort | |
function! s:reset_textprop() abort | |
" let _bufnr = winbufnr(a:winid) | |
" | |
" " 検索のマッチ文字列 | |
call prop_type_delete('search',{ | |
\}) | |
" \ 'bufnr': _bufnr | |
call prop_type_add('search', { | |
\ 'highlight': 'Search', | |
\}) | |
" \ 'bufnr': _bufnr | |
" " カーソル行 | |
" call prop_type_delete('search_cursorline',{ | |
" \}) | |
" " \ 'bufnr': _bufnr | |
" | |
" call prop_type_add('search_cursorline', { | |
" \ 'highlight': 'PmenuSel', | |
" \ 'priority': 10, | |
" \}) | |
" " \ 'bufnr': _bufnr | |
endfunction | |
function! s:title(n, m) abort | |
return printf(' match (%s/%s) ', a:n, a:m) | |
endfunction | |
function! OpenSearchPopup() abort | |
let wininfo = getwininfo(win_getid())[0] | |
let s:popctx = { | |
\ 'lines': getline(1, '$'), | |
\ 'height': 15, | |
\ 'id': 0, | |
\ 'lnum': 0, | |
\ 'width': wininfo.width -2, | |
\} | |
" 上のみ、border をつける | |
" mapping に 0 を渡すと、filter で mapping されていない素のキーが取得できる | |
let opts = { | |
\ 'border': [1, 1, 1, 1], | |
\ 'maxheight': s:popctx.height, | |
\ 'minwidth': s:popctx.width, | |
\ 'maxwidth': s:popctx.width, | |
\ 'scrollbar': 0, | |
\ 'line': s:below_line(wininfo), | |
\ 'col': wininfo.wincol, | |
\ 'fixed': 1, | |
\ 'pos': 'botleft', | |
\ 'cursorline': 1, | |
\ 'wrap': 0, | |
\ 'filter': function('s:popup_filter', [s:popctx]), | |
\ 'highlight': 'Normal', | |
\ 'title': s:title(1, len(s:popctx.lines)), | |
\ 'mapping': 0, | |
\} | |
" XXX: 普通の カーソル行のハイライトにしたいな | |
" PatternNotFound を定義する | |
let s:popctx.id = popup_create(s:popctx.lines, opts) | |
endfunction | |
" TODO: 実際のバッファが見えるように、表示位置を変えてあげる必要がある? | |
" n を押した時、カーソルがジャンプするけど、popup window で見えなくなっ | |
" てしまうため | |
" / と同じように 検索処理を行う | |
function! RefreshSearchPopup() abort | |
let pat = getcmdline() | |
let lines = {} | |
let showlines = [] | |
" TODO: 1行で複数箇所にマッチするパターンを処理できるようにする | |
" マッチする行のみ表示 | |
let lnum = 1 | |
for line in s:popctx.lines | |
let start = 0 | |
try | |
let m = matchstrpos(line, pat, start) | |
catch /.*/ | |
let showlines = '' | |
break | |
endtry | |
if m[2] != -1 | |
let col = m[1] + 1 | |
let length = len(m[0]) | |
let lines[lnum] = { | |
\ 'line': line, | |
\ 'col': col, | |
\ 'length': length, | |
\} | |
let lnum += 1 | |
call add(showlines, line) | |
endif | |
endfor | |
let highlight = '' | |
let title = '' | |
if len(showlines) == 0 | |
let showlines = 'Pattern not found.' | |
let highlight = 'PatternNotFound' | |
else | |
let highlight = 'Normal' | |
" マッチ数を表示する | |
let title = s:title(1, len(showlines)) | |
" TODO: カーソル移動に合わせて、title を変更する | |
" popup_filter の仕事? | |
endif | |
call popup_settext(s:popctx.id, showlines) | |
call popup_setoptions(s:popctx.id, { | |
\ 'highlight': highlight, | |
\ 'title': title, | |
\}) | |
" ハイライト | |
let _bufnr = winbufnr(s:popctx.id) | |
for [lnum, info] in items(lines) | |
call prop_add(lnum, info.col, { | |
\ 'length': info.length, | |
\ 'type': 'search', | |
\ 'bufnr': _bufnr, | |
\}) | |
endfor | |
" call prop_remove({'type': 'search_cursorline', 'bufnr': _bufnr}) | |
" | |
" call prop_add(1, 1, { | |
" \ 'type': 'search_cursorline', | |
" \ 'length': s:popctx.width, | |
" \ 'bufnr': _bufnr, | |
" \}) | |
endfunction | |
function! CloseSearchPopup() abort | |
call popup_close(s:popctx.id) | |
endfunction | |
function! JumpSearchPopup() abort | |
" popup window で行を選択し、その行へジャンプする | |
endfunction | |
function! s:popup_filter(popctx, winid, key) abort | |
" TODO: title の更新 | |
" TODO: カーソルの移動 | |
" TODO: scrolloff の設定 | |
" offset は 先頭行からの位置 | |
" lnum は実際の行の位置 | |
" カーソル行の強調は cursorline で行うことにした | |
" もしかして、カーソル位置の移動は cursor() を使う? | |
" XXX: エスケープする場合、 " で囲むこと! | |
if a:key ==# "\<C-j>" | |
" 下へ | |
" 設定取得 | |
let line - popup_getoptions(a:winid).firstline | |
" popup window 内の最終行を取得 | |
call win_execute(a:winid, 'let g:nlines = line("$")') | |
" 2 ずつスクロールダウン | |
let newline = line < g:nlines ? (line + 2) : g:nlines | |
unlet g:nlines | |
" セット | |
call popup_setoptions(a:winid, {'firstline': newline}) | |
return 1 | |
elseif a:key ==# "\<C-k>" | |
" 上へ | |
" 現在の opions を取得 | |
let line = popup_getoptions(a:winid).firstline | |
" 2 ずつ、スクロールアップ しているため | |
let newline = (line - 2) > 0 ? (line - 2) : 1 | |
" セット | |
call popup_setoptions(a:winid, {'firstline': newline}) | |
return 1 | |
endif | |
return 0 | |
endfunction | |
augroup SearchPopup | |
autocmd! | |
autocmd CmdlineEnter /,\? call OpenSearchPopup() | |
autocmd CmdlineLeave /,\? call CloseSearchPopup() | |
autocmd CmdlineChanged /,\? call RefreshSearchPopup() | |
augroup END | |
call s:reset_textprop() |
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
scriptencoding utf-8 | |
" TODO: :global に対応 | |
" ガッガッと | |
let s:search_popwinid = 0 | |
" XXX: ctx を scirpt に持たせていいのか微妙なところ? | |
" なぜ、そう思う? | |
let s:popctx = {} | |
" from qfpreview.vim | |
" https://github.com/bfrg/vim-qf-preview/blob/1439b3834a8a02fde864c78adc6d3ee37ec08bf8/autoload/qfpreview.vim#L63-L65 | |
function! s:below_line(wininfo) abort | |
" カレントウィンドウの一番下の位置 (スクリーン上での位置) | |
" winrow は 1 始まりのため -1 | |
" let win_bottom_line = a:wininfo.height + a:wininfo.winrow - 1 | |
return a:wininfo.height + a:wininfo.winrow - 1 | |
endfunction | |
function! s:setup_textprop(winid) abort | |
let _bufnr = winbufnr(a:winid) | |
" 見つからなくてもエラーにならないため、これでOK | |
call prop_type_delete('search',{ | |
\ 'bufnr': _bufnr | |
\}) | |
call prop_type_add('search', { | |
\ 'highlight': 'Search', | |
\ 'bufnr': _bufnr | |
\}) | |
endfunction | |
function! OpenSearchPopup() | |
let wininfo = getwininfo(win_getid())[0] | |
let popctx = { | |
\ 'lines': getline(1, '$'), | |
\ 'height': 15, | |
\} | |
let opts = { | |
\ 'borderchars': [' '], | |
\ 'maxheight': popctx.height, | |
\ 'minwidth': wininfo.width, | |
\ 'maxwidth': wininfo.width, | |
\ 'scrollbar': 0, | |
\ 'line': s:below_line(wininfo), | |
\ 'col': wininfo.wincol, | |
\ 'fixed': 1, | |
\ 'pos': 'botleft', | |
\ 'wrap': 0, | |
\ 'id': 0 | |
\} | |
" XXX: 普通の カーソル行のハイライトにしたいな | |
" text-properties を使う | |
let popctx.id = popup_create(popctx.lines, opts) | |
let s:search_popwinid = popctx.id | |
let s:popctx = popctx | |
call s:setup_textprop(popctx.id) | |
endfunction | |
" TODO: 実際のバッファが見えるように、表示位置を変えてあげる必要がある? | |
" n を押した時、カーソルがジャンプするけど、popup window で見えなくなっ | |
" てしまうため | |
" / と同じように 検索処理を行う | |
function! RefreshSearchPopup() abort | |
let pat = getcmdline() | |
let disp_lines = [] | |
let _bufnr = winbufnr(s:popctx.id) | |
" マッチする行のみ表示 | |
let idx = 1 | |
for line in s:popctx.lines | |
if match(line, pat) != -1 | |
" 行番号を右揃え | |
let num = printf('%'.len(line('$')).'d', idx) | |
call add(disp_lines, num.': '.line) | |
endif | |
let idx += 1 | |
endfor | |
" ハイライトをクリア | |
call prop_clear(1, len(disp_lines), {'bufnr': _bufnr}) | |
" ハイライト | |
" TODO: 上のループでマッチした桁/長さを保持して、propをつけるの良いかも | |
let lnum = 1 | |
for line in disp_lines | |
" マッチ箇所を取得 | |
let m = matchstrpos(line, pat) | |
let col = m[1] | |
let length = m[2] | |
call prop_add(lnum, col, { | |
\ 'length': length, | |
\ 'type': 'search', | |
\ 'bufnr': _bufnr, | |
\}) | |
let lnum += 1 | |
endfor | |
call popup_settext(s:popctx.id, disp_lines) | |
endfunction | |
function! CloseSearchPopup() abort | |
call popup_close(s:search_popwinid) | |
let s:search_popwinid = 0 | |
endfunction | |
function! JumpSearchPopup() abort | |
" popup window で行を選択し、その行へジャンプする | |
endfunction | |
augroup SearchPopup | |
autocmd! | |
autocmd CmdlineEnter /,\? call OpenSearchPopup() | |
autocmd CmdlineLeave /,\? call CloseSearchPopup() | |
autocmd CmdlineChanged /,\? call RefreshSearchPopup() | |
augroup END |
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
scriptencoding utf-8 | |
" TODO: :global に対応 | |
" ガッガッと | |
let s:search_popwinid = 0 | |
" XXX: ctx を scirpt に持たせていいのか微妙なところ? | |
" なぜ、そう思う? | |
let s:popctx = {} | |
" from qfpreview.vim | |
" https://github.com/bfrg/vim-qf-preview/blob/1439b3834a8a02fde864c78adc6d3ee37ec08bf8/autoload/qfpreview.vim#L63-L65 | |
function! s:below_line(wininfo) abort | |
" カレントウィンドウの一番下の位置 (スクリーン上での位置) | |
" winrow は 1 始まりのため -1 | |
" let win_bottom_line = a:wininfo.height + a:wininfo.winrow - 1 | |
return a:wininfo.height + a:wininfo.winrow - 1 | |
endfunction | |
function! s:setup_textprop(winid) abort | |
let _bufnr = winbufnr(a:winid) | |
" 見つからなくてもエラーにならないため、これでOK | |
call prop_type_delete('search',{ | |
\ 'bufnr': _bufnr | |
\}) | |
call prop_type_add('search', { | |
\ 'highlight': 'Search', | |
\ 'bufnr': _bufnr | |
\}) | |
endfunction | |
function! OpenSearchPopup() | |
let wininfo = getwininfo(win_getid())[0] | |
let popctx = { | |
\ 'lines': getline(1, '$'), | |
\ 'height': 15, | |
\} | |
let opts = { | |
\ 'borderchars': [' '], | |
\ 'maxheight': popctx.height, | |
\ 'minwidth': wininfo.width, | |
\ 'maxwidth': wininfo.width, | |
\ 'scrollbar': 0, | |
\ 'line': s:below_line(wininfo), | |
\ 'col': wininfo.wincol, | |
\ 'fixed': 1, | |
\ 'pos': 'botleft', | |
\ 'wrap': 0, | |
\ 'id': 0 | |
\} | |
" XXX: 普通の カーソル行のハイライトにしたいな | |
" text-properties を使う | |
let popctx.id = popup_create(popctx.lines, opts) | |
let s:search_popwinid = popctx.id | |
let s:popctx = popctx | |
endfunction | |
" TODO: 実際のバッファが見えるように、表示位置を変えてあげる必要がある? | |
" n を押した時、カーソルがジャンプするけど、popup window で見えなくなっ | |
" てしまうため | |
" / と同じように 検索処理を行う | |
function! RefreshSearchPopup() abort | |
" ハイライト | |
call s:setup_textprop(s:popctx.id) | |
let pat = getcmdline() | |
let disp_lines = [] | |
let _bufnr = winbufnr(s:popctx.id) | |
" カレントウィンドウの行数 | |
let lines = len(line('$')) | |
" マッチする行のみ表示 | |
let idx = 1 | |
for line in s:popctx.lines | |
if match(line, pat) != -1 | |
" " 行番号を右揃え | |
" let num = printf('%'.lines.'d', idx) | |
" call add(disp_lines, num.': '.line) | |
call add(disp_lines, line) | |
endif | |
let idx += 1 | |
endfor | |
call popup_settext(s:popctx.id, disp_lines) | |
" ハイライト | |
" TODO: 上のループでマッチした桁/長さを保持して、propをつけるの良いかも | |
let lnum = 1 | |
for line in disp_lines | |
let m = matchstrpos(line, pat) | |
" 0 始まりのため | |
let col = m[1] + 1 | |
let length = len(m[0]) | |
if col != -1 | |
call prop_add(lnum, col, { | |
\ 'length': length, | |
\ 'type': 'search', | |
\ 'bufnr': _bufnr, | |
\}) | |
endif | |
let lnum += 1 | |
endfor | |
endfunction | |
function! CloseSearchPopup() abort | |
call popup_close(s:search_popwinid) | |
let s:search_popwinid = 0 | |
endfunction | |
function! JumpSearchPopup() abort | |
" popup window で行を選択し、その行へジャンプする | |
endfunction | |
augroup SearchPopup | |
autocmd! | |
autocmd CmdlineEnter /,\? call OpenSearchPopup() | |
autocmd CmdlineLeave /,\? call CloseSearchPopup() | |
autocmd CmdlineChanged /,\? call RefreshSearchPopup() | |
augroup END |
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
scriptencoding utf-8 | |
" TODO: :global に対応 | |
" ガッガッと | |
let s:search_popwinid = 0 | |
" XXX: ctx を scirpt に持たせていいのか微妙なところ? | |
" なぜ、そう思う? | |
let s:popctx = {} | |
" from qfpreview.vim | |
" https://github.com/bfrg/vim-qf-preview/blob/1439b3834a8a02fde864c78adc6d3ee37ec08bf8/autoload/qfpreview.vim#L63-L65 | |
function! s:below_line(wininfo) abort | |
" カレントウィンドウの一番下の位置 (スクリーン上での位置) | |
" winrow は 1 始まりのため -1 | |
" let win_bottom_line = a:wininfo.height + a:wininfo.winrow - 1 | |
return a:wininfo.height + a:wininfo.winrow - 1 | |
endfunction | |
function! s:setup_textprop(winid) abort | |
let _bufnr = winbufnr(a:winid) | |
" 見つからなくてもエラーにならないため、これでOK | |
call prop_type_delete('search',{ | |
\ 'bufnr': _bufnr | |
\}) | |
call prop_type_add('search', { | |
\ 'highlight': 'Search', | |
\ 'bufnr': _bufnr | |
\}) | |
endfunction | |
function! OpenSearchPopup() | |
let wininfo = getwininfo(win_getid())[0] | |
let popctx = { | |
\ 'lines': getline(1, '$'), | |
\ 'height': 15, | |
\} | |
let opts = { | |
\ 'borderchars': [' '], | |
\ 'maxheight': popctx.height, | |
\ 'minwidth': wininfo.width, | |
\ 'maxwidth': wininfo.width, | |
\ 'scrollbar': 0, | |
\ 'line': s:below_line(wininfo), | |
\ 'col': wininfo.wincol, | |
\ 'fixed': 1, | |
\ 'pos': 'botleft', | |
\ 'wrap': 0, | |
\ 'id': 0 | |
\} | |
" XXX: 普通の カーソル行のハイライトにしたいな | |
" text-properties を使う | |
let popctx.id = popup_create(popctx.lines, opts) | |
let s:search_popwinid = popctx.id | |
let s:popctx = popctx | |
endfunction | |
" TODO: 実際のバッファが見えるように、表示位置を変えてあげる必要がある? | |
" n を押した時、カーソルがジャンプするけど、popup window で見えなくなっ | |
" てしまうため | |
" / と同じように 検索処理を行う | |
function! RefreshSearchPopup() abort | |
" ハイライト | |
call s:setup_textprop(s:popctx.id) | |
let pat = getcmdline() | |
let _bufnr = winbufnr(s:popctx.id) | |
let lines = {} | |
" マッチする行のみ表示 | |
let idx = 1 | |
for line in s:popctx.lines | |
let m = matchstrpos(line, pat) | |
" 0 始まりのため、1足す | |
let length = len(m[0]) | |
if length != -1 | |
let lines[idx] = { | |
\ 'line': line, | |
\ 'col': m[1] + 1, | |
\ 'length': length, | |
\} | |
endif | |
let idx += 1 | |
endfor | |
" line をセット | |
call popup_settext(s:popctx.id, map(values(lines), values('v:val.line'))) | |
" ハイライト | |
" TODO: 上のループでマッチした桁/長さを保持して、propをつけるの良いかも | |
for [lnum, info] in items(lines) | |
" " 行番号を右揃え | |
" let num = printf('%'.lines.'d', idx) | |
" call add(disp_lines, num.': '.line) | |
if info.col != -1 | |
call prop_add(lnum, info.col, { | |
\ 'length': info.length, | |
\ 'type': 'search', | |
\ 'bufnr': _bufnr, | |
\}) | |
endif | |
endfor | |
endfunction | |
function! CloseSearchPopup() abort | |
call popup_close(s:search_popwinid) | |
let s:search_popwinid = 0 | |
endfunction | |
function! JumpSearchPopup() abort | |
" popup window で行を選択し、その行へジャンプする | |
endfunction | |
augroup SearchPopup | |
autocmd! | |
autocmd CmdlineEnter /,\? call OpenSearchPopup() | |
autocmd CmdlineLeave /,\? call CloseSearchPopup() | |
autocmd CmdlineChanged /,\? call RefreshSearchPopup() | |
augroup END |
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
scriptencoding utf-8 | |
" TODO: :global に対応 | |
" ガッガッと | |
let s:search_popwinid = 0 | |
" XXX: ctx を scirpt に持たせていいのか微妙なところ? | |
" なぜ、そう思う? | |
let s:popctx = {} | |
" from qfpreview.vim | |
" https://github.com/bfrg/vim-qf-preview/blob/1439b3834a8a02fde864c78adc6d3ee37ec08bf8/autoload/qfpreview.vim#L63-L65 | |
function! s:below_line(wininfo) abort | |
" カレントウィンドウの一番下の位置 (スクリーン上での位置) | |
" winrow は 1 始まりのため -1 | |
" let win_bottom_line = a:wininfo.height + a:wininfo.winrow - 1 | |
return a:wininfo.height + a:wininfo.winrow - 1 | |
endfunction | |
function! s:setup_textprop(winid) abort | |
let _bufnr = winbufnr(a:winid) | |
" 見つからなくてもエラーにならないため、これでOK | |
call prop_type_delete('search',{ | |
\ 'bufnr': _bufnr | |
\}) | |
call prop_type_add('search', { | |
\ 'highlight': 'Search', | |
\ 'bufnr': _bufnr | |
\}) | |
endfunction | |
function! OpenSearchPopup() | |
let wininfo = getwininfo(win_getid())[0] | |
let popctx = { | |
\ 'lines': getline(1, '$'), | |
\ 'height': 15, | |
\} | |
let opts = { | |
\ 'borderchars': [' '], | |
\ 'maxheight': popctx.height, | |
\ 'minwidth': wininfo.width, | |
\ 'maxwidth': wininfo.width, | |
\ 'scrollbar': 0, | |
\ 'line': s:below_line(wininfo), | |
\ 'col': wininfo.wincol, | |
\ 'fixed': 1, | |
\ 'pos': 'botleft', | |
\ 'wrap': 0, | |
\ 'id': 0 | |
\} | |
" XXX: 普通の カーソル行のハイライトにしたいな | |
" text-properties を使う | |
let popctx.id = popup_create(popctx.lines, opts) | |
let s:search_popwinid = popctx.id | |
let s:popctx = popctx | |
endfunction | |
" TODO: 実際のバッファが見えるように、表示位置を変えてあげる必要がある? | |
" n を押した時、カーソルがジャンプするけど、popup window で見えなくなっ | |
" てしまうため | |
" / と同じように 検索処理を行う | |
function! RefreshSearchPopup() abort | |
" ハイライト | |
call s:setup_textprop(s:popctx.id) | |
let pat = getcmdline() | |
let _bufnr = winbufnr(s:popctx.id) | |
let lines = {} | |
" マッチする行のみ表示 | |
let idx = 1 | |
for line in s:popctx.lines | |
let m = matchstrpos(line, pat) | |
" 0 始まりのため、1足す | |
let col = m[1] + 1 | |
let length = len(m[0]) | |
if col != 0 | |
let lines[idx] = { | |
\ 'line': line, | |
\ 'col': col, | |
\ 'length': length, | |
\} | |
endif | |
let idx += 1 | |
endfor | |
" line をセット | |
call popup_settext(s:popctx.id, map(values(lines), 'v:val.line')) | |
" ハイライト | |
" TODO: 上のループでマッチした桁/長さを保持して、propをつけるの良いかも | |
for [lnum, info] in items(lines) | |
" " 行番号を右揃え | |
" let num = printf('%'.lines.'d', idx) | |
" call add(disp_lines, num.': '.line) | |
echomsg info.col | |
if info.col != -1 | |
call prop_add(lnum, info.col, { | |
\ 'length': info.length, | |
\ 'type': 'search', | |
\ 'bufnr': _bufnr, | |
\}) | |
endif | |
endfor | |
endfunction | |
function! CloseSearchPopup() abort | |
call popup_close(s:search_popwinid) | |
let s:search_popwinid = 0 | |
endfunction | |
function! JumpSearchPopup() abort | |
" popup window で行を選択し、その行へジャンプする | |
endfunction | |
augroup SearchPopup | |
autocmd! | |
autocmd CmdlineEnter /,\? call OpenSearchPopup() | |
autocmd CmdlineLeave /,\? call CloseSearchPopup() | |
autocmd CmdlineChanged /,\? call RefreshSearchPopup() | |
augroup END |
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
scriptencoding utf-8 | |
" TODO: :global に対応 | |
" ガッガッと | |
let s:search_popwinid = 0 | |
" XXX: ctx を scirpt に持たせていいのか微妙なところ? | |
" なぜ、そう思う? | |
let s:popctx = {} | |
" from qfpreview.vim | |
" https://github.com/bfrg/vim-qf-preview/blob/1439b3834a8a02fde864c78adc6d3ee37ec08bf8/autoload/qfpreview.vim#L63-L65 | |
function! s:below_line(wininfo) abort | |
" カレントウィンドウの一番下の位置 (スクリーン上での位置) | |
" winrow は 1 始まりのため -1 | |
" let win_bottom_line = a:wininfo.height + a:wininfo.winrow - 1 | |
return a:wininfo.height + a:wininfo.winrow - 1 | |
endfunction | |
function! s:setup_textprop(winid) abort | |
let _bufnr = winbufnr(a:winid) | |
" 見つからなくてもエラーにならないため、これでOK | |
call prop_type_delete('search',{ | |
\ 'bufnr': _bufnr | |
\}) | |
call prop_type_add('search', { | |
\ 'highlight': 'Search', | |
\ 'bufnr': _bufnr | |
\}) | |
endfunction | |
function! OpenSearchPopup() | |
let wininfo = getwininfo(win_getid())[0] | |
let popctx = { | |
\ 'lines': getline(1, '$'), | |
\ 'height': 15, | |
\} | |
let opts = { | |
\ 'borderchars': [' '], | |
\ 'maxheight': popctx.height, | |
\ 'minwidth': wininfo.width, | |
\ 'maxwidth': wininfo.width, | |
\ 'scrollbar': 0, | |
\ 'line': s:below_line(wininfo), | |
\ 'col': wininfo.wincol, | |
\ 'fixed': 1, | |
\ 'pos': 'botleft', | |
\ 'wrap': 0, | |
\ 'id': 0 | |
\} | |
" XXX: 普通の カーソル行のハイライトにしたいな | |
" text-properties を使う | |
let popctx.id = popup_create(popctx.lines, opts) | |
let s:search_popwinid = popctx.id | |
let s:popctx = popctx | |
endfunction | |
" TODO: 実際のバッファが見えるように、表示位置を変えてあげる必要がある? | |
" n を押した時、カーソルがジャンプするけど、popup window で見えなくなっ | |
" てしまうため | |
" / と同じように 検索処理を行う | |
function! RefreshSearchPopup() abort | |
" ハイライト | |
call s:setup_textprop(s:popctx.id) | |
let pat = getcmdline() | |
let _bufnr = winbufnr(s:popctx.id) | |
let lines = {} | |
let displines = [] | |
" マッチする行のみ表示 | |
let lnum = 1 | |
for line in s:popctx.lines | |
let m = matchstrpos(line, pat) | |
" 0 始まりのため、1足す | |
let col = m[1] + 1 | |
let length = len(m[0]) | |
if col != 0 | |
let lines[lnum] = { | |
\ 'line': line, | |
\ 'col': col, | |
\ 'length': length, | |
\} | |
call add(displines, line) | |
let lnum += 1 | |
endif | |
endfor | |
" line をセット | |
call popup_settext(s:popctx.id, displines) | |
" ハイライト | |
" TODO: 上のループでマッチした桁/長さを保持して、propをつけるの良いかも | |
for [lnum, info] in items(lines) | |
echomsg info.length | |
if info.col != -1 | |
call prop_add(lnum, info.col, { | |
\ 'length': info.length, | |
\ 'type': 'search', | |
\ 'bufnr': _bufnr, | |
\}) | |
endif | |
endfor | |
endfunction | |
function! CloseSearchPopup() abort | |
call popup_close(s:search_popwinid) | |
let s:search_popwinid = 0 | |
endfunction | |
function! JumpSearchPopup() abort | |
" popup window で行を選択し、その行へジャンプする | |
endfunction | |
augroup SearchPopup | |
autocmd! | |
autocmd CmdlineEnter /,\? call OpenSearchPopup() | |
autocmd CmdlineLeave /,\? call CloseSearchPopup() | |
autocmd CmdlineChanged /,\? call RefreshSearchPopup() | |
augroup END |
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
scriptencoding utf-8 | |
let s:search_popwinid = 0 | |
" XXX: ctx を scirpt に持たせていいのか微妙なところ? | |
" なぜ、そう思う? | |
let s:popctx = {} | |
" from https://github.com/bfrg/vim-qf-preview | |
function! s:below_line(wininfo) abort | |
" カレントウィンドウの一番下の位置 (スクリーン上での位置) | |
" winrow は 1 始まりのため -1 | |
" let win_bottom_line = a:wininfo.height + a:wininfo.winrow - 1 | |
return a:wininfo.height + a:wininfo.winrow - 1 | |
endfunction | |
function! s:setup_textprop(winid) abort | |
let _bufnr = winbufnr(a:winid) | |
" 見つからなくてもエラーにならないため、これでOK | |
call prop_type_delete('search',{ | |
\ 'bufnr': _bufnr | |
\}) | |
call prop_type_add('search', { | |
\ 'highlight': 'Search', | |
\ 'bufnr': _bufnr | |
\}) | |
endfunction | |
function! OpenSearchPopup() | |
let wininfo = getwininfo(win_getid())[0] | |
let popctx = { | |
\ 'lines': getline(1, '$'), | |
\ 'height': 15, | |
\} | |
let opts = { | |
\ 'borderchars': [' '], | |
\ 'maxheight': popctx.height, | |
\ 'minwidth': wininfo.width, | |
\ 'maxwidth': wininfo.width, | |
\ 'scrollbar': 0, | |
\ 'line': s:below_line(wininfo), | |
\ 'col': wininfo.wincol, | |
\ 'fixed': 1, | |
\ 'pos': 'botleft', | |
\ 'wrap': 0, | |
\ 'id': 0 | |
\} | |
" XXX: 普通の カーソル行のハイライトにしたいな | |
" text-properties を使う | |
let popctx.id = popup_create(popctx.lines, opts) | |
let s:search_popwinid = popctx.id | |
let s:popctx = popctx | |
endfunction | |
" TODO: 実際のバッファが見えるように、表示位置を変えてあげる必要がある? | |
" n を押した時、カーソルがジャンプするけど、popup window で見えなくなっ | |
" てしまうため | |
" / と同じように 検索処理を行う | |
function! RefreshSearchPopup() abort | |
" ハイライトのリセット | |
call s:setup_textprop(s:popctx.id) | |
let pat = getcmdline() | |
let lines = {} | |
let showlines = [] | |
" マッチする行のみ表示 | |
let lnum = 1 | |
for line in s:popctx.lines | |
let m = matchstrpos(line, pat) | |
if m[2] == -1 | |
continue | |
endif | |
let col = m[1] + 1 | |
let length = len(m[0]) | |
let lines[lnum] = { | |
\ 'line': line, | |
\ 'col': col, | |
\ 'length': length, | |
\} | |
let lnum += 1 | |
call add(showlines, line) | |
endfor | |
call popup_settext(s:popctx.id, showlines) | |
" ハイライト | |
let _bufnr = winbufnr(s:popctx.id) | |
for [lnum, info] in items(lines) | |
call prop_add(lnum, info.col, { | |
\ 'length': info.length, | |
\ 'type': 'search', | |
\ 'bufnr': _bufnr, | |
\}) | |
endfor | |
endfunction | |
function! CloseSearchPopup() abort | |
call popup_close(s:search_popwinid) | |
let s:search_popwinid = 0 | |
endfunction | |
function! JumpSearchPopup() abort | |
" popup window で行を選択し、その行へジャンプする | |
endfunction | |
augroup SearchPopup | |
autocmd! | |
autocmd CmdlineEnter /,\? call OpenSearchPopup() | |
autocmd CmdlineLeave /,\? call CloseSearchPopup() | |
autocmd CmdlineChanged /,\? call RefreshSearchPopup() | |
augroup END |
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
scriptencoding utf-8 | |
" TODO: Fuzzy mode をつける あいまい検索したいときとか便利 | |
let s:popctx = {} | |
hi PatternNotFound guifg=red guibg=bg | |
call s:reset_textprop() | |
" from https://github.com/bfrg/vim-qf-preview | |
function! s:below_line(wininfo) abort | |
" カレントウィンドウの一番下の位置 (スクリーン上での位置) | |
" winrow は 1 始まりのため -1 | |
" let win_bottom_line = a:wininfo.height + a:wininfo.winrow - 1 | |
return a:wininfo.height + a:wininfo.winrow - 1 | |
endfunction | |
" function! s:reset_textprop(winid) abort | |
function! s:reset_textprop() abort | |
" let _bufnr = winbufnr(a:winid) | |
" | |
" " 検索のマッチ文字列 | |
call prop_type_delete('search',{ | |
\}) | |
" \ 'bufnr': _bufnr | |
call prop_type_add('search', { | |
\ 'highlight': 'Search', | |
\}) | |
" \ 'bufnr': _bufnr | |
" | |
" " カーソル行 | |
call prop_type_delete('search_cursorline',{ | |
\}) | |
" \ 'bufnr': _bufnr | |
call prop_type_add('search_cursorline', { | |
\ 'highlight': 'PmenuSel', | |
\ 'priority': 10, | |
\}) | |
" \ 'bufnr': _bufnr | |
endfunction | |
function! s:title(n, m) abort | |
return printf(' match (%s/%s) ', a:n, a:m) | |
endfunction | |
function! OpenSearchPopup() abort | |
let wininfo = getwininfo(win_getid())[0] | |
let s:popctx = { | |
\ 'lines': getline(1, '$'), | |
\ 'height': 15, | |
\ 'id': 0, | |
\ 'lnum': 0, | |
\ 'width': wininfo.width -2, | |
\} | |
" 上のみ、border をつける | |
" mapping に 0 を渡すと、filter で mapping されていない素のキーが取得できる | |
let opts = { | |
\ 'border': [1, 1, 1, 1], | |
\ 'maxheight': s:popctx.height, | |
\ 'minwidth': s:popctx.width, | |
\ 'maxwidth': s:popctx.width, | |
\ 'scrollbar': 0, | |
\ 'line': s:below_line(wininfo), | |
\ 'col': wininfo.wincol, | |
\ 'fixed': 1, | |
\ 'pos': 'botleft', | |
\ 'wrap': 0, | |
\ 'filter': function('s:popup_filter', [s:popctx]), | |
\ 'highlight': 'Normal', | |
\ 'title': s:title(1, len(s:popctx.lines)), | |
\ 'mapping': 0, | |
\} | |
" XXX: 普通の カーソル行のハイライトにしたいな | |
" text-properties を使う | |
let s:popctx.id = popup_create(s:popctx.lines, opts) | |
" 検索文字列 ハイライトのリセット | |
endfunction | |
" TODO: 実際のバッファが見えるように、表示位置を変えてあげる必要がある? | |
" n を押した時、カーソルがジャンプするけど、popup window で見えなくなっ | |
" てしまうため | |
" / と同じように 検索処理を行う | |
function! RefreshSearchPopup() abort | |
let pat = getcmdline() | |
let lines = {} | |
let showlines = [] | |
" TODO: 1行で複数箇所にマッチするパターンを処理できるようにする | |
" マッチする行のみ表示 | |
let lnum = 1 | |
for line in s:popctx.lines | |
let start = 0 | |
try | |
let m = matchstrpos(line, pat, start) | |
catch /.*/ | |
let showlines = '' | |
break | |
endtry | |
if m[2] != -1 | |
let col = m[1] + 1 | |
let length = len(m[0]) | |
let lines[lnum] = { | |
\ 'line': line, | |
\ 'col': col, | |
\ 'length': length, | |
\} | |
let lnum += 1 | |
call add(showlines, line) | |
endif | |
endfor | |
let highlight = '' | |
let title = '' | |
if len(showlines) == 0 | |
let showlines = 'Pattern not found.' | |
let highlight = 'PatternNotFound' | |
else | |
let highlight = 'Normal' | |
" マッチ数を表示する | |
let title = s:title(1, len(showlines)) | |
" TODO: カーソル移動に合わせて、title を変更する | |
" popup_filter の仕事? | |
endif | |
call popup_settext(s:popctx.id, showlines) | |
call popup_setoptions(s:popctx.id, { | |
\ 'highlight': highlight, | |
\ 'title': title, | |
\}) | |
" ハイライト | |
let _bufnr = winbufnr(s:popctx.id) | |
for [lnum, info] in items(lines) | |
call prop_add(lnum, info.col, { | |
\ 'length': info.length, | |
\ 'type': 'search', | |
\ 'bufnr': _bufnr, | |
\}) | |
endfor | |
call prop_remove({'type': 'search_cursorline', 'bufnr': _bufnr}) | |
call prop_add(1, 1, { | |
\ 'type': 'search_cursorline', | |
\ 'length': s:popctx.width, | |
\ 'bufnr': _bufnr, | |
\}) | |
endfunction | |
function! CloseSearchPopup() abort | |
call popup_close(s:popctx.id) | |
endfunction | |
function! JumpSearchPopup() abort | |
" popup window で行を選択し、その行へジャンプする | |
endfunction | |
function! s:popup_filter(popctx, winid, key) abort | |
" TODO: title の更新 | |
" TODO: カーソルの移動 | |
" TODO: scrolloff の設定 | |
" offset は 先頭行からの位置 | |
" lnum は実際の行の位置 | |
" XXX: エスケープする場合、 " で囲むこと! | |
if a:key ==# "\<C-j>" | |
" 下へ | |
let a:popctx.lnum += 1 | |
call s:curosr_highlight(a:popctx) | |
return 1 | |
elseif a:key ==# "\<C-k>" | |
" 上へ | |
let a:popctx.lnum -= 1 | |
call s:curosr_highlight(a:popctx) | |
return 1 | |
endif | |
return 0 | |
endfunction | |
function! s:curosr_highlight(popctx) abort | |
let lnum = a:popctx.lnum | |
let _bufnr = winbufnr(s:popctx.id) | |
" popup window の winid を id とする | |
call prop_remove({'type': 'search_cursorline', 'bufnr': _bufnr}) | |
" XXX: length は調整必要? | |
call prop_add(lnum, 1, { | |
\ 'type': 'search_cursorline', | |
\ 'bufnr': _bufnr, | |
\ 'length': a:popctx.width, | |
\}) | |
" これ必須! | |
redraw | |
endfunction | |
augroup SearchPopup | |
autocmd! | |
autocmd CmdlineEnter /,\? call OpenSearchPopup() | |
autocmd CmdlineLeave /,\? call CloseSearchPopup() | |
autocmd CmdlineChanged /,\? call RefreshSearchPopup() | |
augroup END | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment