ref(libmodal): use `vim.notify` for errors

This allows for integration with `nvim-notify` and others.
pull/14/head
Iron-E 2 years ago
parent 55a0bcca00
commit cf1bca1f8f
No known key found for this signature in database
GPG Key ID: 19B71B7B7B021D22

@ -52,9 +52,10 @@ return setmetatable(
if key ~= 'Layer' then
return rawget(tbl, key)
else
require('libmodal/src/utils/api').nvim_show_err(
require('libmodal/src/globals').DEFAULT_ERROR_TITLE,
'`libmodal.Layer` is deprecated in favor of `libmodal.layer`. It will work FOR NOW, but uncapitalize that `L` please :)'
vim.notify_once(
'`libmodal.Layer` is deprecated in favor of `libmodal.layer`. It will work FOR NOW, but uncapitalize that `L` please :)',
vim.log.levels.WARN,
{title = 'nvim-libmodal'}
)
return require 'libmodal/src/Layer'
end

@ -107,7 +107,7 @@ function Mode:enter()
-- if there were errors, handle them.
if not no_errors then
utils.show_error(mode_result)
utils.notify_error('Error during nvim-libmodal mode', mode_result)
continue_mode = false
else
continue_mode = mode_result

@ -37,7 +37,7 @@ function Prompt:execute_instruction(user_input)
elseif user_input == HELP then -- the user did not define a 'help' command, so use the default.
self.help:show()
else -- show an error.
utils.api.nvim_show_err(globals.DEFAULT_ERROR_TITLE, 'Unknown command')
vim.notify('nvim-libmodal prompt: unkown command', vim.log.levels.ERROR, {title = 'nvim-libmodal'})
end
elseif type(self.instruction) == globals.TYPE_STR then -- the self.instruction is a function.
vim.fn[self.instruction]()
@ -95,7 +95,7 @@ function Prompt:enter()
-- if there were errors.
if not no_errors then
utils.show_error(prompt_result)
utils.notify_error('Error during nvim-libmodal mode', prompt_result)
continue_mode = false
else
continue_mode = prompt_result

@ -2,9 +2,6 @@ local VIM_FALSE = 0
local VIM_TRUE = 1
return {
--- the default error title for `nvim-libmodal` errors.
DEFAULT_ERROR_TITLE = 'nvim-libmodal error',
--- the key-code for the escape character.
ESC_NR = 27,

@ -1,24 +1,21 @@
--[[/* MODULE */]]
local utils =
return
{
api = require 'libmodal/src/utils/api',
classes = require 'libmodal/src/utils/classes',
Indicator = require 'libmodal/src/utils/Indicator',
Help = require 'libmodal/src/utils/Help',
--- `vim.notify` with a `msg` some `error` which has a `vim.v.throwpoint` and `vim.v.exception`.
--- @param msg string
--- @param error string
notify_error = function(msg, error)
vim.notify(
msg .. ': ' .. vim.v.throwpoint .. '\n' .. vim.v.exception .. '\n' .. error,
vim.log.levels.ERROR,
{title = 'nvim-libmodal'}
)
end,
Popup = require 'libmodal/src/utils/Popup',
Vars = require 'libmodal/src/utils/Vars',
}
--- show an error from `pcall()`.
--- @param pcall_err string the error generated by `pcall()`.
function utils.show_error(pcall_err)
utils.api.nvim_bell()
utils.api.nvim_show_err(
require('libmodal/src/globals').DEFAULT_ERROR_TITLE,
vim.v.throwpoint..'\n'..vim.v.exception..'\n'..pcall_err
)
end
return utils

Loading…
Cancel
Save