diff --git a/.vim/autoload/vimrc/gh.vim b/.vim/autoload/vimrc/gh.vim new file mode 100644 index 0000000..ab588da --- /dev/null +++ b/.vim/autoload/vimrc/gh.vim @@ -0,0 +1,36 @@ +vim9script noclear +def A(a: any) +var p = str2nr($'{b:repo_list.param.page}') +if a ==# '+' +p += 1 +elseif p < 2 +return +else +p -= 1 +endif +b:repo_list.param.page = $'{p}' +const c = printf( +'e gh://%s/repos?%s', +b:repo_list.owner, +gh#http#encode_param(b:repo_list.param) +) +gh#gh#delete_buffer(b:, 'gh_repo_list_bufid') +execute(c) +enddef +if !exists('*GhRepoListChangePage') +g:GhRepoListChangePage = (op: any) => { +A(op) +} +endif +export def ReposKeymap() +nn i execute 'edit!' ['gh:/', getline('.')->matchstr('\S\+'), 'issues']->join('/') +gh#map#add('gh-buffer-repo-list', 'nnoremap', '', 'call g:GhRepoListChangePage("-")') +gh#map#add('gh-buffer-repo-list', 'nnoremap', '', 'call g:GhRepoListChangePage("+")') +enddef +export def IssuesKeymap() +nn execute 'new' [expand('%'), getline('.')->matchstr('[0-9]\+'), 'comments']->join('/') +nn r execute 'edit!' expand('%:h:h') .. '/repos' +enddef +export def IssueCommentsKeymap() +nn execute 'bo vsplit' [expand('%'), getline('.')->matchstr('[0-9]\+')]->join('/')setlocal wrap +enddef diff --git a/.vim/autoload/vimrc/lazyload.vim b/.vim/autoload/vimrc/lazyload.vim index 3f194d8..d979c39 100644 --- a/.vim/autoload/vimrc/lazyload.vim +++ b/.vim/autoload/vimrc/lazyload.vim @@ -75,17 +75,10 @@ nn gd Gdiffsplit nn gl Git pull nn gt :GitTagPush nn gC :Git checkout % -au vimrc FileType gh-repos { -nn i execute 'edit!' ['gh:/', getline('.')->matchstr('\S\+'), 'issues']->join('/') -} -au vimrc FileType gh-issues { -nn execute 'new' [expand('%'), getline('.')->matchstr('[0-9]\+'), 'comments']->join('/') -nn r execute 'edit!' expand('%:h:h') .. '/repos' -} -au vimrc FileType gh-issue-comments { -nn execute 'bo vsplit' [expand('%'), getline('.')->matchstr('[0-9]\+')]->join('/')setlocal wrap -} -nn gh tabe gh://utubo/repos +nn gh e gh://utubo/repos +au vimrc FileType gh-repos vimrc#gh#ReposKeymap() +au vimrc FileType gh-issues vimrc#gh#IssuesKeymap() +au vimrc FileType gh-issue-comments vimrc#gh#IssueCommentsKeymap() nn MRUToggle g:MRU_Exclude_Files = has('win32') ? $'{$TEMP}\\.*' : '^/tmp/.*\|^/var/tmp/.*' nn a PortalAim diff --git a/src/.vim/autoload/vimrc/gh.src.vim b/src/.vim/autoload/vimrc/gh.src.vim new file mode 100644 index 0000000..9eb4126 --- /dev/null +++ b/src/.vim/autoload/vimrc/gh.src.vim @@ -0,0 +1,48 @@ +vim9script noclear + +# repos {{{ +def GhRepoListChangePage(op: any) + var p = str2nr($'{b:repo_list.param.page}') + if op ==# '+' + p += 1 + elseif p < 2 + return + else + p -= 1 + endif + b:repo_list.param.page = $'{p}' + + const cmd = printf( + 'e gh://%s/repos?%s', + b:repo_list.owner, + gh#http#encode_param(b:repo_list.param) + ) + gh#gh#delete_buffer(b:, 'gh_repo_list_bufid') + execute(cmd) +enddef +if !exists('*GhRepoListChangePage') + g:GhRepoListChangePage = (op: any) => { + GhRepoListChangePage(op) + } +endif + +export def ReposKeymap() + nnoremap i execute 'edit!' ['gh:/', getline('.')->matchstr('\S\+'), 'issues']->join('/') + gh#map#add('gh-buffer-repo-list', 'nnoremap', '', 'call g:GhRepoListChangePage("-")') + gh#map#add('gh-buffer-repo-list', 'nnoremap', '', 'call g:GhRepoListChangePage("+")') +enddef +# }}} + +# issues {{{ +export def IssuesKeymap() + nnoremap execute 'new' [expand('%'), getline('.')->matchstr('[0-9]\+'), 'comments']->join('/') + nnoremap r execute 'edit!' expand('%:h:h') .. '/repos' +enddef +# }}} + +# issue-comments {{{ +export def IssueCommentsKeymap() + nnoremap execute 'bo vsplit' [expand('%'), getline('.')->matchstr('[0-9]\+')]->join('/')setlocal wrap +enddef +# }}} +# diff --git a/src/.vim/autoload/vimrc/lazyload.src.vim b/src/.vim/autoload/vimrc/lazyload.src.vim index c408af0..05416c3 100644 --- a/src/.vim/autoload/vimrc/lazyload.src.vim +++ b/src/.vim/autoload/vimrc/lazyload.src.vim @@ -118,18 +118,10 @@ nnoremap gC :Git checkout % #}}} # gh {{{ -# ftpluginにすると定義がバラバラになって見通し悪くなるかな -au vimrc FileType gh-repos { - nnoremap i execute 'edit!' ['gh:/', getline('.')->matchstr('\S\+'), 'issues']->join('/') -} -au vimrc FileType gh-issues { - nnoremap execute 'new' [expand('%'), getline('.')->matchstr('[0-9]\+'), 'comments']->join('/') - nnoremap r execute 'edit!' expand('%:h:h') .. '/repos' -} -au vimrc FileType gh-issue-comments { - nnoremap execute 'bo vsplit' [expand('%'), getline('.')->matchstr('[0-9]\+')]->join('/')setlocal wrap -} -nnoremap gh tabe gh://utubo/repos +nnoremap gh e gh://utubo/repos +au vimrc FileType gh-repos vimrc#gh#ReposKeymap() +au vimrc FileType gh-issues vimrc#gh#IssuesKeymap() +au vimrc FileType gh-issue-comments vimrc#gh#IssueCommentsKeymap() # }}} # MRU {{{