aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar mitchell <70453897+667e-11@users.noreply.github.com>2015-01-15 23:01:19 -0500
committerGravatar mitchell <70453897+667e-11@users.noreply.github.com>2015-01-15 23:01:19 -0500
commit317bca1fd4cdc3fd4b61990a308526358a2fac7d (patch)
tree94ef07a8653c7ac17c72c2a3a53e74377c3fcdaf
parent14ee3e0bf143916f29b2fb05465b9e79707f4611 (diff)
Added events for terminal suspend and resume.
Suspend can be prevented by an error handler, described in a new FAQ entry. New `events.RESUME` replaces `events.FOCUS` for the terminal version. Utilize these events to disable/enable bracketed paste and mouse modes.
-rw-r--r--FAQ.md62
-rw-r--r--core/events.lua14
-rw-r--r--core/ui.lua18
-rw-r--r--modules/textadept/editing.lua17
-rw-r--r--src/termkey.patch18
-rw-r--r--src/textadept.c7
6 files changed, 89 insertions, 47 deletions
diff --git a/FAQ.md b/FAQ.md
index 408dbedf..fddf8979 100644
--- a/FAQ.md
+++ b/FAQ.md
@@ -51,30 +51,6 @@ terminal version.)
- - -
**Q:**
-I'm trying to compile Textadept from one of the download packages, but get some
-obscure errors in the `scintilla/term/`, `gtdialog/`, or `scintillua/`
-directories. What happened?
-
-**A:**
-Prior to Textadept 7.5, some of the dependencies Textadept downloads are the
-latest archives in their respective version control repositories. Occasionally
-there are compile-time incompatibilities with these "bleeding-edge" downloads.
-The solution is to go to the appropriate repository, identify the last revision
-whose date is before the release date of your Textadept version, and download
-the archive for that revision.
-
-For example, if you have Textadept 7.1 and cannot build the terminal version due
-to a file in the `scintilla/term/` directory, go to [scinterm hg][] and look for
-the revision before 11 November 2013 (which happens to be [changeset 60][] from
-23 October 2013), click on it, download the zip from the link near the top of
-the page, and replace the problematic file.
-
-[scinterm hg]: http://foicica.com/hg/scinterm
-[changeset 60]: http://foicica.com/hg/scinterm/rev/ea13ae30cfab
-
-- - -
-
-**Q:**
Why can't Textadept handle HUGE files very well?
**A:**
@@ -107,6 +83,20 @@ Please see the LuaDoc on [compile and run commands][].
- - -
**Q:**
+In Linux, pressing `^Z` suspends Textadept instead of performing an "Undo"
+action. How can I disable suspend and perform "Undo" instead?
+
+**A:**
+Place the following in your `~/.textadept/init.lua` file:
+
+ events.connect(events.SUSPEND, function()
+ buffer:undo()
+ return true
+ end, 1)
+
+- - -
+
+**Q:**
In Linux, middle-clicking in the curses version does not paste the primary
selection and selecting text does copy to the primary selection. All other
terminal apps support this functionality, why not Textadept?
@@ -165,3 +155,27 @@ Your window manager is to blame. Textadept is not responsible for, and should
never attempt to set its window position.
- - -
+
+**Q:**
+I'm trying to compile Textadept from one of the download packages, but get some
+obscure errors in the `scintilla/term/`, `gtdialog/`, or `scintillua/`
+directories. What happened?
+
+**A:**
+Prior to Textadept 7.5, some of the dependencies Textadept downloads are the
+latest archives in their respective version control repositories. Occasionally
+there are compile-time incompatibilities with these "bleeding-edge" downloads.
+The solution is to go to the appropriate repository, identify the last revision
+whose date is before the release date of your Textadept version, and download
+the archive for that revision.
+
+For example, if you have Textadept 7.1 and cannot build the terminal version due
+to a file in the `scintilla/term/` directory, go to [scinterm hg][] and look for
+the revision before 11 November 2013 (which happens to be [changeset 60][] from
+23 October 2013), click on it, download the zip from the link near the top of
+the page, and replace the problematic file.
+
+[scinterm hg]: http://foicica.com/hg/scinterm
+[changeset 60]: http://foicica.com/hg/scinterm/rev/ea13ae30cfab
+
+- - -
diff --git a/core/events.lua b/core/events.lua
index 144917a7..6dedc879 100644
--- a/core/events.lua
+++ b/core/events.lua
@@ -119,8 +119,7 @@ local M = {}
-- * _`next`_: Whether or not to search forward.
-- @field FOCUS (string)
-- Emitted when Textadept receives focus.
--- In the terminal, this event is only emitted after resuming from a suspended
--- state.
+-- This event is never emitted when Textadept is running in the terminal.
-- @field HOTSPOT_CLICK (string)
-- Emitted when clicking on text that is in a style that has the hotspot
-- attribute set.
@@ -230,10 +229,17 @@ local M = {}
-- @field RESET_BEFORE (string)
-- Emitted before resetting the Lua state.
-- Emitted by [`reset()`]().
+-- @field RESUME (string)
+-- Emitted when resuming Textadept from a suspended state.
+-- This event is only emitted by the terminal version.
-- @field SAVE_POINT_LEFT (string)
-- Emitted after leaving a save point.
-- @field SAVE_POINT_REACHED (string)
-- Emitted after reaching a save point.
+-- @field SUSPEND (string)
+-- Emitted when suspending Textadept. If a handler returns `true`, Textadept
+-- does not suspend.
+-- This event is only emitted by the terminal version.
-- @field UPDATE_UI (string)
-- Emitted after the view is visually updated.
-- Arguments:
@@ -383,8 +389,8 @@ local ta_events = {
'appleevent_odoc', 'buffer_after_switch', 'buffer_before_switch',
'buffer_deleted', 'buffer_new', 'csi', 'error', 'find', 'focus',
'initialized', 'keypress', 'menu_clicked', 'mouse', 'quit', 'replace',
- 'replace_all', 'reset_after', 'reset_before', 'view_after_switch',
- 'view_before_switch', 'view_new'
+ 'replace_all', 'reset_after', 'reset_before', 'resume', 'suspend',
+ 'view_after_switch', 'view_before_switch', 'view_new'
}
for _, e in pairs(ta_events) do M[e:upper()] = e end
diff --git a/core/ui.lua b/core/ui.lua
index 46e1c311..6b6e91fc 100644
--- a/core/ui.lua
+++ b/core/ui.lua
@@ -402,8 +402,24 @@ events_connect(events.BUFFER_DELETED, function()
if i and _BUFFERS[buffer] ~= i then view:goto_buffer(i) end
end)
--- Focuses and resizes views based on mouse events in curses.
+-- Enables and disables mouse mode in curses and focuses and resizes views based
+-- on mouse events.
if CURSES then
+ if not WIN32 then
+ local function enable_mouse_mode()
+ io.stdout:write("\x1b[?1002h")
+ io.stdout:flush()
+ end
+ enable_mouse_mode()
+ local function disable_mouse_mode()
+ io.stdout:write("\x1b[?1002l") -- disable mouse mode
+ io.stdout:flush()
+ end
+ events.connect(events.SUSPEND, disable_mouse_mode)
+ events.connect(events.RESUME, enable_mouse_mode)
+ events.connect(events.QUIT, disable_mouse_mode)
+ end
+
-- Retrieves the view or split at the given terminal coordinates.
-- @param view View or split to test for coordinates within.
-- @param y The y terminal coordinate.
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua
index 46db4127..ad010f9f 100644
--- a/modules/textadept/editing.lua
+++ b/modules/textadept/editing.lua
@@ -197,12 +197,19 @@ end)
-- Enables and disables bracketed paste mode in curses and disables auto-pair
-- and auto-indent while pasting.
if CURSES and not WIN32 then
- io.stdout:write('\x1b[?2004h') -- enable bracketed paste mode
- io.stdout:flush()
- events.connect(events.QUIT, function()
- io.stdout:write('\x1b[?2004l') -- disable bracketed paste mode
+ local function enable_bracketed_paste_mode()
+ io.stdout:write('\x1b[?2004h')
io.stdout:flush()
- end)
+ end
+ enable_bracketed_paste_mode()
+ local function disable_bracketed_paste_mode()
+ io.stdout:write('\x1b[?2004l')
+ io.stdout:flush()
+ end
+ events.connect(events.SUSPEND, disable_bracketed_paste_mode)
+ events.connect(events.RESUME, enable_bracketed_paste_mode)
+ events.connect(events.QUIT, disable_bracketed_paste_mode)
+
local reenable_autopair, reenable_autoindent
events.connect('csi', function(cmd, args)
if cmd ~= string.byte('~') then return end
diff --git a/src/termkey.patch b/src/termkey.patch
index c519090e..5a9d4099 100644
--- a/src/termkey.patch
+++ b/src/termkey.patch
@@ -228,28 +228,26 @@ diff -r 49c8684413c0 termkey.c
/* Some OSes have Ctrl-Y==VDSUSP */
#ifdef VDSUSP
termios.c_cc[VDSUSP] = _POSIX_VDISABLE;
-@@ -487,6 +496,8 @@
+@@ -487,6 +496,7 @@
tcsetattr(tk->fd, TCSANOW, &termios);
}
}
-+ printf("\033[?1002h"), fflush(stdout); // enable mouse mode
+#endif
struct TermKeyDriverNode *p;
for(p = tk->drivers; p; p = p->next)
-@@ -512,8 +523,11 @@
+@@ -512,8 +522,10 @@
if(p->driver->stop_driver)
(*p->driver->stop_driver)(tk, p->info);
+#if !_WIN32
if(tk->restore_termios_valid)
tcsetattr(tk->fd, TCSANOW, &tk->restore_termios);
-+ printf("\033[?1002l"), fflush(stdout); // disable mouse mode
+#endif
tk->is_started = 0;
-@@ -525,11 +539,18 @@
+@@ -525,11 +537,18 @@
return tk->is_started;
}
@@ -269,7 +267,7 @@ diff -r 49c8684413c0 termkey.c
int termkey_get_flags(TermKey *tk)
{
return tk->flags;
-@@ -1012,7 +1033,7 @@
+@@ -1012,7 +1031,7 @@
TermKeyResult termkey_waitkey(TermKey *tk, TermKeyKey *key)
{
@@ -278,7 +276,7 @@ diff -r 49c8684413c0 termkey.c
errno = EBADF;
return TERMKEY_RES_ERROR;
}
-@@ -1026,6 +1047,7 @@
+@@ -1026,6 +1045,7 @@
case TERMKEY_RES_ERROR:
return ret;
@@ -286,7 +284,7 @@ diff -r 49c8684413c0 termkey.c
case TERMKEY_RES_NONE:
ret = termkey_advisereadable(tk);
if(ret == TERMKEY_RES_ERROR)
-@@ -1064,6 +1086,7 @@
+@@ -1064,6 +1084,7 @@
return termkey_getkey_force(tk, key);
}
break;
@@ -294,7 +292,7 @@ diff -r 49c8684413c0 termkey.c
}
}
-@@ -1072,6 +1095,7 @@
+@@ -1072,6 +1093,7 @@
TermKeyResult termkey_advisereadable(TermKey *tk)
{
@@ -302,7 +300,7 @@ diff -r 49c8684413c0 termkey.c
ssize_t len;
if(tk->fd == -1) {
-@@ -1109,6 +1133,9 @@
+@@ -1109,6 +1131,9 @@
tk->buffcount += len;
return TERMKEY_RES_AGAIN;
}
diff --git a/src/textadept.c b/src/textadept.c
index 1b1dad0e..37aa95f0 100644
--- a/src/textadept.c
+++ b/src/textadept.c
@@ -2387,10 +2387,11 @@ static void t_signal(int signal) {
resizeterm(w.ws_row, w.ws_col), pane_resize(pane, LINES - 2, COLS, 1, 0);
WINDOW *ce_win = scintilla_get_window(command_entry);
wresize(ce_win, 1, COLS), mvwin(ce_win, LINES - 1 - getmaxy(ce_win), 0);
- if (signal == SIGCONT) lL_event(lua, "focus", -1);
+ if (signal == SIGCONT) lL_event(lua, "resume", -1);
lL_event(lua, "update_ui", -1);
- refresh_all();
- } else endwin(), termkey_stop(ta_tk), kill(0, SIGSTOP);
+ } else if (!lL_event(lua, "suspend", -1))
+ endwin(), termkey_stop(ta_tk), kill(0, SIGSTOP);
+ refresh_all();
}
/** Replacement for `termkey_waitkey()` that handles asynchronous I/O. */