diff --git a/lua/various-textobjs/charwise-textobjs.lua b/lua/various-textobjs/charwise-textobjs.lua index dad3ad9..d929bdf 100644 --- a/lua/various-textobjs/charwise-textobjs.lua +++ b/lua/various-textobjs/charwise-textobjs.lua @@ -296,7 +296,7 @@ function M.diagnostic(wrap) if target then M.setSelection({ target.lnum + 1, target.col }, { target.end_lnum + 1, target.end_col - 1 }) else - u.notify("No diagnostic found.", "notfound") + u.notFoundMsg("No diagnostic found.") end end @@ -369,7 +369,7 @@ function M.lastChange() local changeEndPos = vim.api.nvim_buf_get_mark(0, "]") if changeStartPos[1] == changeEndPos[1] and changeStartPos[2] == changeEndPos[2] then - u.notify("Last change was a deletion operation, aborting.", "warn") + u.warn("Last change was a deletion operation, aborting.") return end diff --git a/lua/various-textobjs/config.lua b/lua/various-textobjs/config.lua index b6db7da..aa8b30e 100644 --- a/lua/various-textobjs/config.lua +++ b/lua/various-textobjs/config.lua @@ -29,24 +29,24 @@ M.config = defaultConfig ---@param userConfig? VariousTextobjs.Config function M.setup(userConfig) M.config = vim.tbl_deep_extend("force", M.config, userConfig or {}) - local notify = require("various-textobjs.utils").notify + local warn = require("various-textobjs.utils").warn -- DEPRECATION (2024-12-03) ---@diagnostic disable: undefined-field if M.config.lookForwardSmall then - notify("The `lookForwardSmall` option is deprecated. Use `forwardLooking.small` instead.") + warn("The `lookForwardSmall` option is deprecated. Use `forwardLooking.small` instead.") end if M.config.lookForwardBig then - notify("The `lookForwardBig` option is deprecated. Use `forwardLooking.big` instead.") + warn("The `lookForwardBig` option is deprecated. Use `forwardLooking.big` instead.") end if M.config.lookForwardBig then - notify("The `lookForwardBig` option is deprecated. Use `forwardLooking.big` instead.") + warn("The `lookForwardBig` option is deprecated. Use `forwardLooking.big` instead.") end if M.config.notificationIcon then - notify("The `notificationIcon` option is deprecated. Use `config.notify.icon` instead.") + warn("The `notificationIcon` option is deprecated. Use `config.notify.icon` instead.") end if M.config.notifyNotFound then - notify( + warn( "The `notifyNotFound` option is deprecated. Use `config.notify.whenObjectNotFound` instead." ) end diff --git a/lua/various-textobjs/linewise-textobjs.lua b/lua/various-textobjs/linewise-textobjs.lua index 6496557..de82e53 100644 --- a/lua/various-textobjs/linewise-textobjs.lua +++ b/lua/various-textobjs/linewise-textobjs.lua @@ -163,7 +163,7 @@ function M.indentation(startBorder, endBorder, blankLines) local lastLine = vim.api.nvim_buf_line_count(0) while isBlankLine(curLnum) do -- when on blank line, use next line if lastLine == curLnum then - u.notify("No indented line found.", "notfound") + u.notFoundMsg("No indented line found.") return end curLnum = curLnum + 1 @@ -171,8 +171,8 @@ function M.indentation(startBorder, endBorder, blankLines) local indentOfStart = vim.fn.indent(curLnum) if indentOfStart == 0 then - u.notify("Current line is not indented.", "notfound") - return false -- return value needed for greedyOuterIndentation textobj + u.warn("Current line is not indented.", "warn") + return false -- return value needed for `greedyOuterIndentation` textobj end local prevLnum = curLnum - 1 @@ -221,7 +221,7 @@ function M.restOfIndentation() local indentOfStart = vim.fn.indent(curLnum) if indentOfStart == 0 then - u.notify("Current line is not indented.", "notfound") + u.warn("Current line is not indented.") return end @@ -260,7 +260,7 @@ end ---@param scope "inner"|"outer" outer includes bottom cell border function M.notebookCell(scope) if vim.bo.commentstring == "" then - u.notify("Buffer has no commentstring set.", "warn") + u.warn("Buffer has no commentstring set.") return end diff --git a/lua/various-textobjs/treesitter-textobjs.lua b/lua/various-textobjs/treesitter-textobjs.lua index c80c4ef..3e2d880 100644 --- a/lua/various-textobjs/treesitter-textobjs.lua +++ b/lua/various-textobjs/treesitter-textobjs.lua @@ -8,12 +8,12 @@ local u = require("various-textobjs.utils") function M.pyTripleQuotes(scope) -- GUARD if vim.treesitter.get_node == nil then - u.notify("This textobj requires least nvim 0.9.", "warn") + u.warn("This textobj requires least nvim 0.9.") return end local node = vim.treesitter.get_node() if not node then - u.notify("No node found.", "notfound") + u.notFoundMsg("No node found.") return end @@ -29,7 +29,7 @@ function M.pyTripleQuotes(scope) then strNode = node:parent():parent() else - u.notify("Not on a triple quoted string.", "warn") + u.warn("Not on a triple quoted string.") return end ---@cast strNode TSNode diff --git a/lua/various-textobjs/utils.lua b/lua/various-textobjs/utils.lua index 78f0774..97464dc 100644 --- a/lua/various-textobjs/utils.lua +++ b/lua/various-textobjs/utils.lua @@ -17,26 +17,27 @@ end ---@return string function M.getline(lnum) return vim.api.nvim_buf_get_lines(0, lnum - 1, lnum, true)[1] end ----send notification ---@param msg string ----@param level? "info"|"trace"|"debug"|"warn"|"error"|"notfound" -function M.notify(msg, level) - if not level then level = "info" end - if level == "notfound" then - if not require("various-textobjs.config").config.notify.whenObjectNotFound then return end - level = "warn" - end +function M.warn(msg) local icon = require("various-textobjs.config").config.notify.icon - vim.notify(msg, vim.log.levels[level:upper()], { title = "nvim-various-textobjs", icon = icon }) + vim.notify(msg, vim.log.levels.WARN, { title = "various-textobjs", icon = icon }) end ---notification when no textobj could be found ----@param lookForwL integer number of lines the plugin tried to look forward -function M.notFoundMsg(lookForwL) - local msg = ("Textobject not found within the next %d lines."):format(lookForwL) - if lookForwL == 1 then msg = msg:gsub("s%.$", ".") end -- remove plural s - if lookForwL == 0 then msg = "Textobject not found within the line." end - M.notify(msg, "notfound") +---@param msg integer|string lines tried to look forward, or custom message +function M.notFoundMsg(msg) + if not require("various-textobjs.config").config.notify.whenObjectNotFound then return end + local notifyText + if type(msg) == "number" then + local lookForwLines = msg + notifyText = ("Textobject not found within the next %d lines."):format(lookForwLines) + if lookForwLines == 1 then notifyText = notifyText:gsub("s%.$", ".") end + if lookForwLines == 0 then notifyText = "Textobject not found within the line." end + elseif type(msg) == "string" then + notifyText = msg + end + local icon = require("various-textobjs.config").config.notify.icon + vim.notify(notifyText, vim.log.levels.WARN, { title = "various-textobjs", icon = icon }) end --------------------------------------------------------------------------------