From 51b7239577c953c46f7837ddf75aacb98a0c33e1 Mon Sep 17 00:00:00 2001 From: Raigo Jerva Date: Thu, 29 Apr 2021 00:15:01 +0300 Subject: [PATCH] Logging for term commands, fix unknown argument vim.api.nvim_buf_set_option(buf_id, "bufhidden", "hide") happened to work, even though the first argument did not exist, since by default it would set the option on the current buffer which it happens to be. --- lua/harpoon/term.lua | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lua/harpoon/term.lua b/lua/harpoon/term.lua index fd9ded5..0606e55 100644 --- a/lua/harpoon/term.lua +++ b/lua/harpoon/term.lua @@ -1,24 +1,26 @@ -local harpoon = require('harpoon') -local Path = require("plenary.path") +local harpoon = require("harpoon") +local log = require("harpoon.dev").log local M = {} local terminals = {} local function create_terminal() + log.debug("_create_terminal()") local current_id = vim.fn.bufnr() vim.cmd(":terminal") local buf_id = vim.fn.bufnr() - local term_id = vim.b.terminal_job_id + local term_id = vim.b.terminal_job_id if term_id == nil then - -- TODO: Throw an erro? + log.error("_create_terminal(): term_id is nil") + -- TODO: Throw an error? return nil end -- Make sure the term buffer has "hidden" set so it doesn't get thrown -- away and cause an error - vim.api.nvim_buf_set_option(bufh, 'bufhidden', 'hide') + vim.api.nvim_buf_set_option(buf_id, "bufhidden", "hide") -- Resets the buffer back to the old one vim.api.nvim_set_current_buf(current_id) @@ -29,7 +31,8 @@ function getCmd(idx) return end -function find_terminal(idx) +local function find_terminal(idx) + log.debug("_find_terminal(): Terminal:", idx) local term_handle = terminals[idx] if not term_handle or not vim.api.nvim_buf_is_valid(term_handle.buf_id) then local buf_id, term_id = create_terminal() @@ -39,7 +42,7 @@ function find_terminal(idx) term_handle = { buf_id = buf_id, - term_id = term_id + term_id = term_id, } terminals[idx] = term_handle end @@ -47,12 +50,14 @@ function find_terminal(idx) end M.gotoTerminal = function(idx) + log.debug("gotoTerminal(): Terminal:", idx) local term_handle = find_terminal(idx) vim.api.nvim_set_current_buf(term_handle.buf_id) end M.sendCommand = function(idx, cmd, ...) + log.debug("sendCommand(): Terminal:", idx) local term_handle = find_terminal(idx) if type(cmd) == "number" then @@ -60,6 +65,7 @@ M.sendCommand = function(idx, cmd, ...) end if cmd then + log.trace("sendCommand:", cmd) vim.fn.chansend(term_handle.term_id, string.format(cmd, ...)) end end