mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
feat: adds vim.notify
Adds function to notify the user like this: `:lua vim.notify("hello user")` embeds log levels vim.log.levels. you can then reassign vim.notify to for instance ``` function notify_external(msg, log_level, opts) vim.fn.jobstart({"notify-send", msg }) end ```
This commit is contained in:
parent
8950f4e94a
commit
3f81f5c7a4
@ -10,13 +10,7 @@ local log = {}
|
|||||||
-- Can be used to lookup the number from the name or the name from the number.
|
-- Can be used to lookup the number from the name or the name from the number.
|
||||||
-- Levels by name: 'trace', 'debug', 'info', 'warn', 'error'
|
-- Levels by name: 'trace', 'debug', 'info', 'warn', 'error'
|
||||||
-- Level numbers begin with 'trace' at 0
|
-- Level numbers begin with 'trace' at 0
|
||||||
log.levels = {
|
log.levels = vim.log.levels
|
||||||
TRACE = 0;
|
|
||||||
DEBUG = 1;
|
|
||||||
INFO = 2;
|
|
||||||
WARN = 3;
|
|
||||||
ERROR = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Default log level is warn.
|
-- Default log level is warn.
|
||||||
local current_log_level = log.levels.WARN
|
local current_log_level = log.levels.WARN
|
||||||
|
@ -17,10 +17,11 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define DEBUG_LOG_LEVEL 0
|
#define TRACE_LOG_LEVEL 0
|
||||||
#define INFO_LOG_LEVEL 1
|
#define DEBUG_LOG_LEVEL 1
|
||||||
#define WARN_LOG_LEVEL 2
|
#define INFO_LOG_LEVEL 2
|
||||||
#define ERROR_LOG_LEVEL 3
|
#define WARN_LOG_LEVEL 3
|
||||||
|
#define ERROR_LOG_LEVEL 4
|
||||||
|
|
||||||
#define DLOG(...)
|
#define DLOG(...)
|
||||||
#define DLOGN(...)
|
#define DLOGN(...)
|
||||||
|
@ -39,6 +39,16 @@ assert(vim)
|
|||||||
vim.inspect = package.loaded['vim.inspect']
|
vim.inspect = package.loaded['vim.inspect']
|
||||||
assert(vim.inspect)
|
assert(vim.inspect)
|
||||||
|
|
||||||
|
vim.log = {
|
||||||
|
levels = {
|
||||||
|
TRACE = 0;
|
||||||
|
DEBUG = 1;
|
||||||
|
INFO = 2;
|
||||||
|
WARN = 3;
|
||||||
|
ERROR = 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
-- Internal-only until comments in #8107 are addressed.
|
-- Internal-only until comments in #8107 are addressed.
|
||||||
-- Returns:
|
-- Returns:
|
||||||
-- {errcode}, {output}
|
-- {errcode}, {output}
|
||||||
@ -478,6 +488,23 @@ function vim.defer_fn(fn, timeout)
|
|||||||
return timer
|
return timer
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Notification provider
|
||||||
|
--- without a runtime, writes to :Messages
|
||||||
|
-- see :help nvim_notify
|
||||||
|
--@param msg Content of the notification to show to the user
|
||||||
|
--@param log_level Optional log level
|
||||||
|
--@param opts Dictionary with optional options (timeout, etc)
|
||||||
|
function vim.notify(msg, log_level, _opts)
|
||||||
|
|
||||||
|
if log_level == vim.log.levels.ERROR then
|
||||||
|
vim.api.nvim_err_writeln(msg)
|
||||||
|
else
|
||||||
|
vim.api.nvim_echo(msg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local on_keystroke_callbacks = {}
|
local on_keystroke_callbacks = {}
|
||||||
|
|
||||||
--- Register a lua {fn} with an {id} to be run after every keystroke.
|
--- Register a lua {fn} with an {id} to be run after every keystroke.
|
||||||
|
Loading…
Reference in New Issue
Block a user