aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthieu Coudron <mcoudron@hotmail.com>2021-01-27 15:09:02 +0100
committerMatthieu Coudron <mcoudron@hotmail.com>2021-01-31 00:18:22 +0100
commit3f81f5c7a451f93a48103af4f1c31fd5f31d687f (patch)
treea9759c653289a1f4f0a7f145ec72b7e95e4219b3 /src
parent8950f4e94af1534852cab5f41066d7c21330bd64 (diff)
downloadrneovim-3f81f5c7a451f93a48103af4f1c31fd5f31d687f.tar.gz
rneovim-3f81f5c7a451f93a48103af4f1c31fd5f31d687f.tar.bz2
rneovim-3f81f5c7a451f93a48103af4f1c31fd5f31d687f.zip
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 ```
Diffstat (limited to 'src')
-rw-r--r--src/nvim/log.h9
-rw-r--r--src/nvim/lua/vim.lua27
2 files changed, 32 insertions, 4 deletions
diff --git a/src/nvim/log.h b/src/nvim/log.h
index f2e74df031..17d754c033 100644
--- a/src/nvim/log.h
+++ b/src/nvim/log.h
@@ -17,10 +17,11 @@
#endif
-#define DEBUG_LOG_LEVEL 0
-#define INFO_LOG_LEVEL 1
-#define WARN_LOG_LEVEL 2
-#define ERROR_LOG_LEVEL 3
+#define TRACE_LOG_LEVEL 0
+#define DEBUG_LOG_LEVEL 1
+#define INFO_LOG_LEVEL 2
+#define WARN_LOG_LEVEL 3
+#define ERROR_LOG_LEVEL 4
#define DLOG(...)
#define DLOGN(...)
diff --git a/src/nvim/lua/vim.lua b/src/nvim/lua/vim.lua
index dbf4f6014c..00a4fe26d3 100644
--- a/src/nvim/lua/vim.lua
+++ b/src/nvim/lua/vim.lua
@@ -39,6 +39,16 @@ assert(vim)
vim.inspect = package.loaded['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.
-- Returns:
-- {errcode}, {output}
@@ -478,6 +488,23 @@ function vim.defer_fn(fn, timeout)
return timer
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 = {}
--- Register a lua {fn} with an {id} to be run after every keystroke.