From c46ae64c0e6325b17fd79cfba5f800abff5c7587 Mon Sep 17 00:00:00 2001 From: kamecha Date: Fri, 5 Jul 2024 21:27:38 +0900 Subject: [PATCH 1/4] create command.vim --- autoload/command.vim | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 autoload/command.vim diff --git a/autoload/command.vim b/autoload/command.vim new file mode 100644 index 0000000..e69de29 From 04fd1829f137dfdf2b4fd76e4d645d6bc317f71c Mon Sep 17 00:00:00 2001 From: kamecha Date: Sun, 7 Jul 2024 17:17:00 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=E6=97=A2=E5=AD=98=E3=82=B3=E3=83=9E?= =?UTF-8?q?=E3=83=B3=E3=83=89=E5=85=A8=E3=81=A6=E3=82=92=E3=82=B5=E3=83=96?= =?UTF-8?q?=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89=E3=81=A7=E4=BB=A3=E7=94=A8?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=AA=E3=82=93?= =?UTF-8?q?=E3=81=A1=E3=82=83=E3=81=A3=E3=81=A6=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- autoload/command.vim | 92 ++++++++++++++++++++++++++++++++++++++++++++ ftplugin/traqvim.vim | 5 --- plugin/traqvim.vim | 35 +++-------------- 3 files changed, 97 insertions(+), 35 deletions(-) diff --git a/autoload/command.vim b/autoload/command.vim index e69de29..b65c982 100644 --- a/autoload/command.vim +++ b/autoload/command.vim @@ -0,0 +1,92 @@ + +let s:completions = #{ + \ token: ['setup', 'delete'], + \ channel: ['open', 'home', 'reload', 'forward', 'back'], + \ activity: ['open', 'reload'], + \ message: ['open', 'send', 'delete', 'edit', 'editApply', 'yankLink', 'yankMarkdown'], + \ pin: ['create', 'remove'], + \} + +function command#token(args) abort + if a:args[0] ==# 'setup' + call denops#request('traqvim', 'setupOAuth', []) + elseif a:args[0] ==# 'delete' + call denops#request('traqvim', 'deleteOAuthToken', []) + endif +endfunction + +function command#channel(args) abort + if a:args[0] ==# 'open' + " TODO:↓これtimeline APIの実装側が間違ってるのでいったんこのまま + call denops#request('traqvim', 'timeline', [a:args[1]]) + elseif a:args[0] ==# 'home' + call denops#request('traqvim', 'home', []) + elseif a:args[0] ==# 'reload' + call denops#request('traqvim', 'reload', [bufnr(), bufname()]) + elseif a:args[0] ==# 'forward' + call denops#request('traqvim', 'messageForwad', [bufnr(), bufname()]) + elseif a:args[0] ==# 'back' + call denops#request('traqvim', 'messageBack', [bufnr(), bufname()]) + endif +endfunction + +function command#activity(args) abort + if a:args[0] ==# 'open' + call denops#request('traqvim', 'activity', []) + elseif a:args[0] ==# 'reload' + call denops#request('traqvim', 'reload', [bufnr(), bufname()]) + endif +endfunction + +function command#message(args) abort + if a:args[0] ==# 'open' + call denops#request('traqvim', 'messageOpen', [bufnr(), bufname()]) + elseif a:args[0] ==# 'send' + call denops#request('traqvim', 'messageSend', [bufnr(), getline(1, '$')]) + elseif a:args[0] ==# 'delete' + call denops#request('traqvim', 'messageDelete', [bufnr(), traqvim#get_message()]) + elseif a:args[0] ==# 'edit' + call denops#request('traqvim', 'messageEditOpen', [bufnr(), traqvim#get_message()]) + elseif a:args[0] ==# 'editApply' + call denops#request('traqvim', 'messageEdit', [getbufvar(bufname("%"), "editSourceBuffer"), getbufvar(bufname("%"), "message"), getline(1, '$')]) + elseif a:args[0] ==# 'yankLink' + call denops#request('traqvim', 'yankMessageLink', [traqvim#get_message()]) + elseif a:args[0] ==# 'yankMarkdown' + call denops#request('traqvim', 'yankMessageMarkdown', [traqvim#get_message()]) + endif +endfunction + +function command#pin(args) abort + if a:args[0] ==# 'create' + call denops#request('traqvim', 'createPin', [bufnr(), traqvim#get_message()]) + elseif a:args[0] ==# 'remove' + call denops#request('traqvim', 'removePin', [bufnr(), traqvim#get_message()]) + endif +endfunction + +function command#complete(arglead, cmdline, cursorpos) abort + let cmdline = matchstr(a:cmdline, '^Traq\s\+\zs.*') + let cmds = split(cmdline) + let comp = s:completions->keys() + " TODO: 引数がネストしても適切に対応できるようにする + if ( a:cmdline[a:cursorpos - 1] == ' ' && len(cmds) == 1 ) + \ || ( a:cmdline[a:cursorpos - 1] != ' ' && len(cmds) == 2 ) + let comp = s:completions[cmds[0]] + elseif len(cmds) >= 2 + let comp = [] + endif + " argleadでフィルタリング + if a:arglead == '' + return comp + else + return filter(copy(comp), {_, v -> v =~? '^' . a:arglead}) + endif +endfunction + +function command#call(rargs) abort + let args = split(a:rargs) + let cmd = args[0] + let FuncRef = function('command#' . cmd) + call FuncRef(args[1:]) +endfunction + diff --git a/ftplugin/traqvim.vim b/ftplugin/traqvim.vim index b3b2904..aec82c2 100644 --- a/ftplugin/traqvim.vim +++ b/ftplugin/traqvim.vim @@ -25,11 +25,6 @@ nnoremap (traqvim-operator-pin-toggle) onoremap (traqvim-motion-message) \ :call traqvim#message_motion() -command! -buffer -nargs=0 TraqYankMessageLink - \ call denops#request('traqvim', 'yankMessageLink', [traqvim#get_message()]) -command! -buffer -nargs=0 TraqYankMessageMarkdown - \ call denops#request('traqvim', 'yankMessageMarkdown', [traqvim#get_message()]) - " filetypeがtraqvimの時かつ、ウィンドウのサイズが変更された時だけ実行 augroup traqvim diff --git a/plugin/traqvim.vim b/plugin/traqvim.vim index 169a161..badec8e 100644 --- a/plugin/traqvim.vim +++ b/plugin/traqvim.vim @@ -3,36 +3,11 @@ " endif " let g:loaded_traq = 1 " -" :Traq setup でdenopsのsetupAPIを叩く -command! TraqSetup call denops#request('traqvim', 'setupOAuth', []) -" :Traq setup でdenopsのsetupAPIを叩く -command! TraqDeleteToken call denops#request('traqvim', 'deleteOAuthToken', []) -" homeChannelを開く -command! TraqHome call denops#request('traqvim', 'home', []) -" :Traq timeline でdenopsのtimelineAPIを叩く -command! -nargs=1 TraqTimeline call denops#request('traqvim', 'timeline', []) -" activity -command! TraqActivity call denops#request('traqvim', 'activity', []) -" reload -command! TraqReload call denops#request('traqvim', 'reload', [bufnr(), bufname()]) -" fetch forward -command! TraqFetchForward call denops#request('traqvim', 'messageForward', [bufnr(), bufname()]) -" fetch backward -command! TraqFetchBack call denops#request('traqvim', 'messageBack', [bufnr(), bufname()]) -" messageバッファの作成 -command! TraqMessageOpen call denops#request('traqvim', 'messageOpen', [bufnr(), bufname()]) -" messageの送信 -command! TraqMessageSend call denops#request('traqvim', 'messageSend', [bufnr(), getline(1, '$')]) -" messageの削除 -command! TraqMessageDelete call denops#request('traqvim', 'messageDelete', [bufnr(), traqvim#get_message()]) -" messageの編集 -command! TraqMessageEdit call denops#request('traqvim', 'messageEditOpen', [bufnr(), traqvim#get_message()]) -" messageの編集を適用 -command! TraqMessageEditApply call denops#request('traqvim', 'messageEdit', [getbufvar(bufname("%"), "editSourceBuffer"), getbufvar(bufname("%"), "message"), getline(1, '$')]) -" pinを作成 -command! TraqCreatePin call denops#request('traqvim', 'createPin', [bufnr(), traqvim#get_message()]) -" pinを削除 -command! TraqRemovePin call denops#request('traqvim', 'removePin', [bufnr(), traqvim#get_message()]) + +command! -nargs=+ + \ -complete=customlist,command#complete + \ Traq + \ call command#call() call helper#define_highlight() From 4987452300ecb85a32401a17f5583ced3ce1d3f6 Mon Sep 17 00:00:00 2001 From: kamecha Date: Mon, 8 Jul 2024 19:46:11 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=E8=A9=B2=E5=BD=93=E9=96=A2=E6=95=B0?= =?UTF-8?q?=E3=81=AE=E5=91=BC=E3=81=B3=E5=87=BA=E3=81=97=E3=82=92=E8=BE=9E?= =?UTF-8?q?=E6=9B=B8=E7=99=BB=E9=8C=B2=E7=B5=8C=E7=94=B1=E3=81=AB=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- autoload/command.vim | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/autoload/command.vim b/autoload/command.vim index b65c982..62766f3 100644 --- a/autoload/command.vim +++ b/autoload/command.vim @@ -7,6 +7,24 @@ let s:completions = #{ \ pin: ['create', 'remove'], \} +let s:subcommands = #{ + \ token: #{ + \ impl: function('command#token'), + \ }, + \ channel: #{ + \ impl: function('command#channel'), + \ }, + \ activity: #{ + \ impl: function('command#activity'), + \ }, + \ message: #{ + \ impl: function('command#message'), + \ }, + \ pin: #{ + \ impl: function('command#pin'), + \ }, + \} + function command#token(args) abort if a:args[0] ==# 'setup' call denops#request('traqvim', 'setupOAuth', []) @@ -85,8 +103,12 @@ endfunction function command#call(rargs) abort let args = split(a:rargs) - let cmd = args[0] - let FuncRef = function('command#' . cmd) - call FuncRef(args[1:]) + let subcommandKey = args[0] + let subcommand = s:subcommands->get(subcommandKey) + if type(subcommand) ==# type(0) && subcommand ==# 0 + echomsg 'subcommand not found: ' . subcommandKey + return + endif + call subcommand.impl(args[1:]) endfunction From c69c7813f0669afb9f9f969237ce9b0e83e89bde Mon Sep 17 00:00:00 2001 From: kamecha Date: Thu, 11 Jul 2024 00:10:22 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=E3=82=B5=E3=83=96=E3=82=B3=E3=83=9E?= =?UTF-8?q?=E3=83=B3=E3=83=89&=E5=BC=95=E6=95=B0=E3=81=AE=E8=A3=9C?= =?UTF-8?q?=E5=AE=8C=E9=96=A2=E6=95=B0=E3=82=82=E8=BE=9E=E6=9B=B8=E7=99=BB?= =?UTF-8?q?=E9=8C=B2=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- autoload/command.vim | 80 ++++++++++++++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 22 deletions(-) diff --git a/autoload/command.vim b/autoload/command.vim index 62766f3..f627a7f 100644 --- a/autoload/command.vim +++ b/autoload/command.vim @@ -1,27 +1,29 @@ -let s:completions = #{ - \ token: ['setup', 'delete'], - \ channel: ['open', 'home', 'reload', 'forward', 'back'], - \ activity: ['open', 'reload'], - \ message: ['open', 'send', 'delete', 'edit', 'editApply', 'yankLink', 'yankMarkdown'], - \ pin: ['create', 'remove'], - \} - let s:subcommands = #{ \ token: #{ + \ args: ['setup', 'delete'], \ impl: function('command#token'), + \ comp: function('command#tokenComplete'), \ }, \ channel: #{ + \ args: ['open', 'home', 'reload', 'forward', 'back'], \ impl: function('command#channel'), + \ comp: function('command#channelComplete'), \ }, \ activity: #{ + \ args: ['open', 'reload'], \ impl: function('command#activity'), + \ comp: function('command#activityComplete'), \ }, \ message: #{ + \ args: ['open', 'send', 'delete', 'edit', 'editApply', 'yankLink', 'yankMarkdown'], \ impl: function('command#message'), + \ comp: function('command#messageComplete'), \ }, \ pin: #{ + \ args: ['create', 'remove'], \ impl: function('command#pin'), + \ comp: function('command#pinComplete'), \ }, \} @@ -33,6 +35,13 @@ function command#token(args) abort endif endfunction +function command#tokenComplete(arglead, cmdline) abort + if a:cmdline[strlen(a:cmdline)-1] ==# ' ' && len(split(a:cmdline)) >= 3 + return [] + endif + return s:subcommands.token.args->copy()->filter({_, v -> v =~? '^' . a:arglead}) +endfunction + function command#channel(args) abort if a:args[0] ==# 'open' " TODO:↓これtimeline APIの実装側が間違ってるのでいったんこのまま @@ -48,6 +57,13 @@ function command#channel(args) abort endif endfunction +function command#channelComplete(arglead, cmdline) abort + if a:cmdline[strlen(a:cmdline)-1] ==# ' ' && len(split(a:cmdline)) >= 3 + return [] + endif + return s:subcommands.channel.args->copy()->filter({_, v -> v =~? '^' . a:arglead}) +endfunction + function command#activity(args) abort if a:args[0] ==# 'open' call denops#request('traqvim', 'activity', []) @@ -56,6 +72,13 @@ function command#activity(args) abort endif endfunction +function command#activityComplete(arglead, cmdline) abort + if a:cmdline[strlen(a:cmdline)-1] ==# ' ' && len(split(a:cmdline)) >= 3 + return [] + endif + return s:subcommands.activity.args->copy()->filter({_, v -> v =~? '^' . a:arglead}) +endfunction + function command#message(args) abort if a:args[0] ==# 'open' call denops#request('traqvim', 'messageOpen', [bufnr(), bufname()]) @@ -74,6 +97,13 @@ function command#message(args) abort endif endfunction +function command#messageComplete(arglead, cmdline) abort + if a:cmdline[strlen(a:cmdline)-1] ==# ' ' && len(split(a:cmdline)) >= 3 + return [] + endif + return s:subcommands.message.args->copy()->filter({_, v -> v =~? '^' . a:arglead}) +endfunction + function command#pin(args) abort if a:args[0] ==# 'create' call denops#request('traqvim', 'createPin', [bufnr(), traqvim#get_message()]) @@ -82,22 +112,28 @@ function command#pin(args) abort endif endfunction +function command#pinComplete(arglead, cmdline) abort + if a:cmdline[strlen(a:cmdline)-1] ==# ' ' && len(split(a:cmdline)) >= 3 + return [] + endif + return s:subcommands.pin.args->copy()->filter({_, v -> v =~? '^' . a:arglead}) +endfunction + function command#complete(arglead, cmdline, cursorpos) abort - let cmdline = matchstr(a:cmdline, '^Traq\s\+\zs.*') - let cmds = split(cmdline) - let comp = s:completions->keys() - " TODO: 引数がネストしても適切に対応できるようにする - if ( a:cmdline[a:cursorpos - 1] == ' ' && len(cmds) == 1 ) - \ || ( a:cmdline[a:cursorpos - 1] != ' ' && len(cmds) == 2 ) - let comp = s:completions[cmds[0]] - elseif len(cmds) >= 2 - let comp = [] + " subcommandを取得 + let subcmd = matchstr(a:cmdline, '^Traq\s\+\zs\w\+') + let subcmdArgLead = matchstr(a:cmdline, '^Traq\s\+\w\+\s\+\zs\w\+') + " subcommandの引数を補完 + if subcmd != '' + \ && has_key(s:subcommands, subcmd) == 1 + \ && has_key(s:subcommands[subcmd], 'comp') == 1 + return s:subcommands[subcmd].comp(a:arglead, a:cmdline) endif - " argleadでフィルタリング - if a:arglead == '' - return comp - else - return filter(copy(comp), {_, v -> v =~? '^' . a:arglead}) + " subcommandを補完 + let cmdline = matchstr(a:cmdline, '^Traq\s\+\w*$') + if cmdline != '' + let subcmdKeys = s:subcommands->keys() + return subcmdKeys->filter({_, v -> v =~? '^' . a:arglead}) endif endfunction