diff options
-rw-r--r-- | core/.buffer.luadoc | 8 | ||||
-rw-r--r-- | core/events.lua | 4 | ||||
-rw-r--r-- | core/file_io.lua | 2 | ||||
-rw-r--r-- | core/gui.lua | 2 | ||||
-rw-r--r-- | core/init.lua | 9 | ||||
-rw-r--r-- | core/keys.lua | 2 | ||||
-rw-r--r-- | modules/textadept/keys.lua | 2 | ||||
-rw-r--r-- | modules/textadept/menu.lua | 2 | ||||
-rw-r--r-- | modules/textadept/session.lua | 2 | ||||
-rw-r--r-- | src/textadept.c | 16 |
10 files changed, 24 insertions, 25 deletions
diff --git a/core/.buffer.luadoc b/core/.buffer.luadoc index 248d90b6..6f57ac5b 100644 --- a/core/.buffer.luadoc +++ b/core/.buffer.luadoc @@ -2785,6 +2785,14 @@ function check_global(buffer) end function delete(buffer) end --- +-- Creates and returns a new buffer. +-- Emits a `BUFFER_NEW` event. +-- @return the new buffer. +-- @class function +-- @see events.BUFFER_NEW +function new() end + +--- -- Returns the range of text from *start_pos* to *end_pos* in the buffer. -- @param buffer The global buffer. -- @param start_pos The start position of the range of text to get in *buffer*. diff --git a/core/events.lua b/core/events.lua index 6f755110..ecc35032 100644 --- a/core/events.lua +++ b/core/events.lua @@ -53,7 +53,7 @@ local M = {} -- Emitted by [`buffer:delete()`][]. -- @field BUFFER_NEW (string) -- Called after creating a new buffer. --- Emitted on startup and by [`new_buffer()`][]. +-- Emitted on startup and by [`buffer.new()`][]. -- @field CALL_TIP_CLICK (string) -- Called when clicking on a calltip. -- Arguments: @@ -244,7 +244,7 @@ local M = {} -- -- [`buffer:auto_c_cancel()`]: buffer.html#auto_c_cancel -- [`view:goto_buffer()`]: view.html#goto_buffer --- [`new_buffer()`]: _G.html#new_buffer +-- [`buffer.new()`]: buffer.html#new -- [`buffer:delete()`]: buffer.html#delete -- [dwell period]: buffer.html#mouse_dwell_time -- [`gui.menu()`]: gui.html#menu diff --git a/core/file_io.lua b/core/file_io.lua index 7ccf7605..5314d51d 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -173,7 +173,7 @@ function io.open_file(utf8_filenames) elseif lfs.attributes(filename) then error(err) end - local buffer = new_buffer() + local buffer = buffer.new() -- Tries to detect character encoding and convert text from it to UTF-8. local encoding, encoding_bom = detect_encoding(text) if encoding ~= 'binary' then diff --git a/core/gui.lua b/core/gui.lua index e9aa763b..a69ccbd6 100644 --- a/core/gui.lua +++ b/core/gui.lua @@ -34,7 +34,7 @@ local function _print(buffer_type, ...) if buffer._type == buffer_type then view:goto_buffer(i) break end end if buffer._type ~= buffer_type then - new_buffer()._type = buffer_type + buffer.new()._type = buffer_type events.emit(events.FILE_OPENED) end end diff --git a/core/init.lua b/core/init.lua index 7cb91798..68275835 100644 --- a/core/init.lua +++ b/core/init.lua @@ -104,15 +104,6 @@ local view -- The functions below are Lua C functions. --- --- Creates and returns a new buffer. --- Emits a `BUFFER_NEW` event. --- @return the new buffer. --- @class function --- @see events.BUFFER_NEW --- @name new_buffer -local new_buffer - ---- -- Emits a `QUIT` event, and unless any handler returns `false`, quits -- Textadept. -- @see events.QUIT diff --git a/core/keys.lua b/core/keys.lua index 080ce400..f6373af6 100644 --- a/core/keys.lua +++ b/core/keys.lua @@ -58,7 +58,7 @@ local M = {} -- containing Lua functions with a set of arguments to call the function with. -- Examples are: -- --- keys['cn'] = new_buffer +-- keys['cn'] = buffer.new -- keys['cs'] = buffer.save -- keys['a('] = {_M.textadept.editing.enclose, '(', ')'} -- keys['cu'] = function() io.snapopen(_USERHOME) end diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua index 30076eaf..b2633783 100644 --- a/modules/textadept/keys.lua +++ b/modules/textadept/keys.lua @@ -364,7 +364,7 @@ local utils = M.utils -- Control, Meta, and 'a' = 'cma' -- File. -keys[not OSX and (not CURSES and 'cn' or 'cmn') or 'mn'] = new_buffer +keys[not OSX and (not CURSES and 'cn' or 'cmn') or 'mn'] = buffer.new keys[not OSX and 'co' or 'mo'] = io.open_file keys[not OSX and not CURSES and 'cao' or 'cmo'] = io.open_recent_file keys[not OSX and (not CURSES and 'cO' or 'mo') or 'mO'] = buffer.reload diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index 4416a17c..86bbc5ae 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -38,7 +38,7 @@ local SEPARATOR, c = {''}, _SCINTILLA.constants -- @name menubar M.menubar = { { title = _L['_File'], - {_L['_New'], new_buffer}, + {_L['_New'], buffer.new}, {_L['_Open'], io.open_file}, {_L['Open _Recent...'], io.open_recent_file}, {_L['Re_load'], buffer.reload}, diff --git a/modules/textadept/session.lua b/modules/textadept/session.lua index 9f21a65a..98a5c56c 100644 --- a/modules/textadept/session.lua +++ b/modules/textadept/session.lua @@ -62,7 +62,7 @@ function M.load(filename) not_found[#not_found + 1] = filename end else - new_buffer()._type = filename + buffer.new()._type = filename events.emit(events.FILE_OPENED, filename) end -- Restore saved buffer selection and view. diff --git a/src/textadept.c b/src/textadept.c index f13d4e0d..2495a0df 100644 --- a/src/textadept.c +++ b/src/textadept.c @@ -1121,6 +1121,13 @@ static int lbuffer_delete(lua_State *L) { return 0; } +/** `_G.buffer_new()` Lua function. */ +static int lbuffer_new(lua_State *L) { + new_buffer(0); + lua_getfield(L, LUA_REGISTRYINDEX, "ta_buffers"); + return (lua_rawgeti(L, -1, lua_rawlen(L, -1)), 1); +} + /** `buffer.text_range()` Lua function. */ static int lbuffer_text_range(lua_State *L) { lL_globaldoccheck(L, 1); @@ -1294,6 +1301,7 @@ static void lL_adddoc(lua_State *L, sptr_t doc) { lua_pushvalue(L, -1), lua_setfield(L, -3, "doc_pointer"); l_setcfunction(L, -2, "check_global", lbuffer_check_global); l_setcfunction(L, -2, "delete", lbuffer_delete); + l_setcfunction(L, -2, "new", lbuffer_new); l_setcfunction(L, -2, "text_range", lbuffer_text_range); l_setmetatable(L, -2, "ta_buffer", lbuf_property, lbuf_property); // bs[userdata] = b, bs[#bs + 1] = b, bs[b] = #bs @@ -1325,13 +1333,6 @@ static void new_buffer(sptr_t doc) { lL_event(lua, "buffer_new", -1); } -/** `_G.buffer_new()` Lua function. */ -static int lbuffer_new(lua_State *L) { - new_buffer(0); - lua_getfield(L, LUA_REGISTRYINDEX, "ta_buffers"); - return (lua_rawgeti(L, -1, lua_rawlen(L, -1)), 1); -} - /** `_G.quit()` Lua function. */ static int lquit(lua_State *L) { #if GTK @@ -1519,7 +1520,6 @@ static int lL_init(lua_State *L, int argc, char **argv, int reinit) { lua_setglobal(L, "gui"); lua_getglobal(L, "_G"); - l_setcfunction(L, -1, "new_buffer", lbuffer_new); l_setcfunction(L, -1, "quit", lquit); l_setcfunction(L, -1, "reset", lreset); l_setcfunction(L, -1, "timeout", ltimeout); |