diff options
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | doc/sciteco.1.in | 4 | ||||
-rw-r--r-- | doc/sciteco.7.template | 19 | ||||
-rw-r--r-- | src/main.cpp | 15 | ||||
-rw-r--r-- | src/parser.cpp | 23 |
5 files changed, 49 insertions, 14 deletions
@@ -98,8 +98,6 @@ Features: * some missing useful VideoTECO/TECO-11 commands: * EF with buffer id * ER command: read file into current buffer at dot - * ^C: exit from program. Should probably be disallowed - in interactive mode. * nEW to save a buffer by id * use CRTP for RBTrees to avoid unnecessary virtual method calls. This means that like the original BSD headers, implementations diff --git a/doc/sciteco.1.in b/doc/sciteco.1.in index 0a96cab..468c060 100644 --- a/doc/sciteco.1.in +++ b/doc/sciteco.1.in @@ -69,8 +69,8 @@ macro arguments. . .LP If the munged macro does not request program termination using the -\fBEX\fP command, \*(ST will automatically switch into its graphical -\fIinteractive\fP mode. +\fBEX\fP command or exits using \fB^C\fP, \*(ST will automatically +switch into its graphical \fIinteractive\fP mode. \*(ST may be built with different graphical user interfaces, including Curses and GTK+ based ones. Eventually when the user terminates interactive mode by calling diff --git a/doc/sciteco.7.template b/doc/sciteco.7.template index 71bc501..eab26e5 100644 --- a/doc/sciteco.7.template +++ b/doc/sciteco.7.template @@ -523,7 +523,8 @@ pressing \fB^C\fP on the attached console or by explicitly sending it. If \*(ST is not busy, .B ^C -is self-inserting and might be used as a regular command. +is self-inserting and might be typed as part of regular commands. +The \fB^C\fP command itself is disallowed in interactive mode, though. T} .TE . @@ -1034,13 +1035,15 @@ This is \*(ST's equivalent of handlers. The hook is not run when some command fails, but only when \*(ST exits normally. -This is the case when a macro specified via -\fB--eval\fP reaches the end, when a munged -file calls \fBEX\fP or when \fBEX\fP has been -called in interactive mode. -Note however that \fBEX\fP is never executed -immediately, but only requests program termination -(so it can still be rubbed out). +This is the case when control in a macro specified via +\fB--eval\fP reaches the end, or otherwise returns +(using \fB^C\fP or by returning from the top-level +macro via \fB$$\fP). +Similarily the hook is executed when a munged +file calls \fB^C\fP or \fBEX\fP has been called before +the top-level macro returns. +It is also called after the interactive mode has shut down +by calling \fBEX$$\fP. The \fBquit\fP hook will always run in \fIbatch\fP mode (after any user interface has shut down). Errors in the hook's execution will not prevent diff --git a/src/main.cpp b/src/main.cpp index aaedf14..bf25c73 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -419,6 +419,11 @@ main(int argc, char **argv) } catch (Error &error) { error.add_frame(new Error::ToplevelFrame()); throw; /* forward */ + } catch (Quit) { + /* + * ^C invoked, quit hook should still + * be executed. + */ } QRegisters::hook(QRegisters::HOOK_QUIT); exit(EXIT_SUCCESS); @@ -431,9 +436,15 @@ main(int argc, char **argv) if (mung_file && g_file_test(mung_file, G_FILE_TEST_IS_REGULAR)) { - Execute::file(mung_file, false); + try { + Execute::file(mung_file, false); + } catch (Quit) { + /* + * ^C invoked, quit hook should still + * be executed. + */ + } - /* FIXME: make quit immediate in batch/macro mode (non-UNDO)? */ if (quit_requested) { QRegisters::hook(QRegisters::HOOK_QUIT); exit(EXIT_SUCCESS); diff --git a/src/parser.cpp b/src/parser.cpp index 3541db1..85d455c 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1916,6 +1916,29 @@ StateControl::custom(gchar chr) { switch (String::toupper(chr)) { /*$ + * ^C -- Exit program immediately + * + * Lets the top-level macro return immediately + * regardless of the current macro invocation frame. + * This command is only allowed in batch mode, + * so it is not invoked accidentally when using + * the CTRL+C immediate editing command to + * interrupt long running operations. + * When using \fB^C\fP in a munged file, + * interactive mode is never started, so it behaves + * effectively just like \(lq-EX\fB$$\fP\(rq + * (when executed in the top-level macro at least). + * + * The \fBquit\fP hook is still executed. + */ + case 'C': + BEGIN_EXEC(&States::start); + if (undo.enabled) + throw Error("<^C> not allowed in interactive mode"); + quit_requested = true; + throw Quit(); + + /*$ * ^O -- Set radix to 8 (octal) */ case 'O': |