aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2019-07-30 17:19:57 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2019-07-30 17:19:57 -0400
commit2cea55c6e65e4ea7f735655b45d917b76e8b7945 (patch)
treec774bad437062eab22f8ebbea3e22937b15bc136
parente1c41c53c4bb7bf6ef5770dce93e4cda21fb1a8e (diff)
downloadtextadept-2cea55c6e65e4ea7f735655b45d917b76e8b7945.tar.gz
textadept-2cea55c6e65e4ea7f735655b45d917b76e8b7945.zip
Fail more gracefully when attempting to create buffers on init.
-rw-r--r--core/ui.lua4
-rw-r--r--doc/manual.md13
-rw-r--r--src/textadept.c1
3 files changed, 8 insertions, 10 deletions
diff --git a/core/ui.lua b/core/ui.lua
index a5827cef..a19785c9 100644
--- a/core/ui.lua
+++ b/core/ui.lua
@@ -74,13 +74,11 @@ end
-- buffer is already open in a view, the message is printed to that view.
-- Otherwise the view is split (unless `ui.tabs` is `true`) and the message
-- buffer is displayed before being printed to.
--- At this time, `ui.print()` cannot be used until Textadept is fully
--- initialized. (That is, not until `events.INITIALIZED` is emitted.)
-- @param buffer_type String type of message buffer.
-- @param ... Message strings.
-- @usage ui._print(_L['[Message Buffer]'], message)
-- @name _print
-function ui._print(buffer_type, ...) pcall(_print, buffer_type, ...) end
+function ui._print(buffer_type, ...) _print(buffer_type, ...) end
---
-- Prints the given string messages to the message buffer.
diff --git a/doc/manual.md b/doc/manual.md
index c1c6fec4..d49f2b1e 100644
--- a/doc/manual.md
+++ b/doc/manual.md
@@ -941,10 +941,9 @@ mind:
module names that match the name of a lexer in the *lexers/* directory unless
you are creating a language module.
* Do not call any functions that create buffers and views (e.g. `ui.print()`,
- `io.open_file()`, and `buffer.new()`) at file-level scope. This will result in
- hard errors as Textadept initializes. Those types of function calls must occur
- within functions (e.g. in a key binding, menu item, or
- [`events.INITIALIZED`][] event handler).
+ `io.open_file()`, and `buffer.new()`) at file-level scope. Those types of
+ function calls must occur within functions (e.g. in a key binding, menu item,
+ or [`events.INITIALIZED`][] event handler).
* Additional documentation on creating language modules can be found in the
the [language module API documentation][].
@@ -979,9 +978,9 @@ later section.
Note: Do not call any functions that create buffers and views (e.g.
`ui.print()`, `io.open_file()`, and `buffer.new()`) at the file-level scope of
-*~/.textadept/init.lua*. This will result in hard errors as Textadept
-initializes. Those types of function calls must occur within functions (e.g. in
-a key binding, menu item, or [`events.INITIALIZED`][] event handler).
+*~/.textadept/init.lua*. Those types of function calls must occur within
+functions (e.g. in a key binding, menu item, or [`events.INITIALIZED`][] event
+handler).
[`events.INITIALIZED`]: api.html#events.INITIALIZED
diff --git a/src/textadept.c b/src/textadept.c
index 0aef64b8..a8a29c7c 100644
--- a/src/textadept.c
+++ b/src/textadept.c
@@ -1100,6 +1100,7 @@ static int lbuffer_delete(lua_State *L) {
/** `_G.buffer_new()` Lua function. */
static int lbuffer_new(lua_State *L) {
+ if (initing) luaL_error(L, "cannot create buffers during initialization");
new_buffer(0);
lua_getfield(L, LUA_REGISTRYINDEX, "ta_buffers");
return (lua_rawgeti(L, -1, lua_rawlen(L, -1)), 1);