From a07917a609d8d37a604ba1351cd0dd5816f53c52 Mon Sep 17 00:00:00 2001 From: Michael Paulson Date: Fri, 6 Nov 2020 07:17:56 -0800 Subject: [PATCH] feat(harpoon): The initial PR for harpoon. --- plugin/harpoon.vim | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 plugin/harpoon.vim diff --git a/plugin/harpoon.vim b/plugin/harpoon.vim new file mode 100644 index 0000000..d9271a2 --- /dev/null +++ b/plugin/harpoon.vim @@ -0,0 +1,61 @@ +" TODO: Make this vim compatible. + +" How to do this but much better? +let g:win_ctrl_buf_list = [0, 0, 0, 0] + +fun! GotoBuffer(ctrlId) + if (a:ctrlId > 9) || (a:ctrlId < 0) + echo "CtrlID must be between 0 - 9" + return + end + + let contents = g:win_ctrl_buf_list[a:ctrlId] + if type(l:contents) != v:t_list + " Create the terminal + terminal + call SetBuffer(a:ctrlId) + end + let contents = g:win_ctrl_buf_list[a:ctrlId] + if type(l:contents) != v:t_list + echo "Unable to create a terminal or find the terminal's information." + end + + let bufh = l:contents[1] + call nvim_win_set_buf(0, l:bufh) +endfun + +fun! SetBuffer(ctrlId) + if has_key(b:, "terminal_job_id") == 0 + echo "You must be in a terminal to execute this command" + return + end + if (a:ctrlId > 9) || (a:ctrlId < 0) + echo "CtrlID must be between 0 - 3" + return + end + + let g:win_ctrl_buf_list[a:ctrlId] = [b:terminal_job_id, nvim_win_get_buf(0)] +endfun + +fun! SendTerminalCommand(ctrlId, command) + if (a:ctrlId > 9) || (a:ctrlId < 0) + echo "CtrlID must be between 0 - 9" + return + end + let contents = g:win_ctrl_buf_list[a:ctrlId] + if type(l:contents) != v:t_list + echo "No terminal created, sorry for not creating this in the background..." + call GotoBuffer(a:ctrlId) + end + let contents = g:win_ctrl_buf_list[a:ctrlId] + if type(l:contents) != v:t_list + echo "Unable to send command to terminal" + end + + let job_id = l:contents[0] + call chansend(l:job_id, a:command) +endfun + + + +