aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/events.lua7
-rw-r--r--core/ui.lua7
-rw-r--r--modules/textadept/editing.lua2
-rw-r--r--src/textadept.c10
4 files changed, 15 insertions, 11 deletions
diff --git a/core/events.lua b/core/events.lua
index c63e98a8..afa851f9 100644
--- a/core/events.lua
+++ b/core/events.lua
@@ -206,8 +206,11 @@ local M = {}
-- * _`alt`_: The "Alt"/"Option" modifier key is held down.
-- @field QUIT (string)
-- Emitted when quitting Textadept.
--- When connecting to this event, connect with an index of 1 or the handler
--- will be ignored.
+-- When connecting to this event, connect with an index of 1 if the handler
+-- needs to run before Textadept closes all open buffers. If a handler returns
+-- `true`, Textadept does not quit. It is not recommended to return `false`
+-- from a quit handler, as that may interfere with Textadept's normal shutdown
+-- procedure.
-- Emitted by [`quit()`]().
-- @field REPLACE (string)
-- Emitted to replace selected (found) text.
diff --git a/core/ui.lua b/core/ui.lua
index bb6f7e4f..f90c5626 100644
--- a/core/ui.lua
+++ b/core/ui.lua
@@ -386,12 +386,13 @@ events_connect(events.QUIT, function()
list[#list + 1] = filename:iconv('UTF-8', _CHARSET)
end
end
- return #list < 1 or ui.dialogs.msgbox{
+ local cancel = #list > 0 and ui.dialogs.msgbox{
title = _L['Quit without saving?'],
text = _L['The following buffers are unsaved:'],
informative_text = table.concat(list, '\n'), icon = 'gtk-dialog-question',
button1 = _L['_Cancel'], button2 = _L['Quit _without saving']
- } == 2
+ } ~= 2
+ if cancel then return true end -- prevent quit
end)
-- Keeps track of and switches back to the previous buffer after buffer close.
@@ -412,7 +413,7 @@ if CURSES then
events.connect(events.QUIT, function()
io.stdout:write("\x1b[?1002l") -- disable mouse mode
io.stdout:flush()
- end, 1)
+ end)
end
-- Retrieves the view or split at the given terminal coordinates.
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua
index cd5f0a92..13503111 100644
--- a/modules/textadept/editing.lua
+++ b/modules/textadept/editing.lua
@@ -202,7 +202,7 @@ if CURSES and not WIN32 then
events.connect(events.QUIT, function()
io.stdout:write('\x1b[?2004l') -- disable bracketed paste mode
io.stdout:flush()
- end, 1)
+ end)
local reenable_autopair, reenable_autoindent
events.connect('csi', function(cmd, args)
if cmd ~= string.byte('~') then return end
diff --git a/src/textadept.c b/src/textadept.c
index 29e37bb9..9466aed9 100644
--- a/src/textadept.c
+++ b/src/textadept.c
@@ -151,7 +151,7 @@ TermKey *ta_tk; // global for CDK use
(focused_view ? SS(focused_view, SCI_SETFOCUS, 0, 0) : 0, \
SS(view, SCI_SETFOCUS, 1, 0))
/** Callback for refreshing a single Scintilla view. */
-static void r_cb(void *view, void*_) { scintilla_refresh((Scintilla *)view); }
+static void r_cb(void *view, void*_) {scintilla_refresh((Scintilla *)view);}
#define refresh_all() { \
wman_walk(wm, r_cb, NULL), wman_refresh(wm); \
if (command_entry_focused) scintilla_refresh(command_entry); \
@@ -1189,7 +1189,7 @@ static int lbuf_closure(lua_State *L) {
int result = l_globaldoccompare(L, 1);
if (result != 0) view = (result > 0) ? dummy_view : command_entry;
}
- // Interface table is of the form { msg, rtype, wtype, ltype }.
+ // Interface table is of the form {msg, rtype, wtype, ltype}.
return l_callscintilla(L, view, l_rawgetiint(L, lua_upvalueindex(1), 1),
l_rawgetiint(L, lua_upvalueindex(1), 3),
l_rawgetiint(L, lua_upvalueindex(1), 4),
@@ -1734,7 +1734,7 @@ static void l_close(lua_State *L) {
* @see l_close
*/
static int w_exit(GtkWidget*_, GdkEventAny*__, void*___) {
- if (!lL_event(lua, "quit", -1)) return TRUE;
+ if (lL_event(lua, "quit", -1)) return TRUE;
l_close(lua);
scintilla_release_resources();
gtk_main_quit();
@@ -1755,7 +1755,7 @@ static int w_open_osx(GtkosxApplication*_, char *path, void*__) {
* Generates a 'quit' event.
*/
static int w_exit_osx(GtkosxApplication*_, void*__) {
- return !lL_event(lua, "quit", -1);
+ return lL_event(lua, "quit", -1);
}
/**
@@ -2420,7 +2420,7 @@ int main(int argc, char **argv) {
lL_event(lua, "mouse", LUA_TNUMBER, event, LUA_TNUMBER, button,
LUA_TNUMBER, y, LUA_TNUMBER, x, LUA_TBOOLEAN, shift,
LUA_TBOOLEAN, ctrl, LUA_TBOOLEAN, alt, -1);
- if (quit && lL_event(lua, "quit", -1)) {
+ if (quit && !lL_event(lua, "quit", -1)) {
l_close(lua);
// Free some memory.
free(flabel), free(rlabel);