diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2016-01-28 05:00:52 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2016-01-28 05:00:52 +0100 |
commit | 131fe7c3431c039825587db0def807fff97b15fc (patch) | |
tree | 142f358fe34b1ed4acfda24687dc7c5029cc1ccb /src | |
parent | f4ac90104f59de06de96692213643e3b80c65e56 (diff) | |
download | sciteco-131fe7c3431c039825587db0def807fff97b15fc.tar.gz |
added :EX (colon-modified EX): exits SciTECO saving all modified buffers
* this allows you to exit and save only those buffers that are modified.
This was not yet possible using macros, since there is currently no way
to query the dirty state of buffers programmatically.
* even if there was, the necessary key presses might be too much for
some users.
* the ability to save all modified buffers has been explicitly requested
by an user in ticket #4.
* the new behaviour is not compatible with classic TECO where EX would
save the current file by default but provides a relatively short way
to do just that.
* updated the documentation: there was also one mistake regarding the
boolean that EX accepts non-colon-modified.
Diffstat (limited to 'src')
-rw-r--r-- | src/parser.cpp | 45 | ||||
-rw-r--r-- | src/ring.cpp | 10 | ||||
-rw-r--r-- | src/ring.h | 1 |
3 files changed, 41 insertions, 15 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index 98eeba8..5d78aaf 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -2245,35 +2245,50 @@ StateECommand::custom(gchar chr) /*$ * [bool]EX -- Exit program * -EX + * :EX * - * Exits \*(ST. - * It is one of the few commands that is not executed - * immediately both in batch and interactive mode. + * Exits \*(ST, or rather requests program termination + * at the end of the top-level macro. + * Therefore instead of exiting immediately which + * could be annoying in interactive mode, EX will + * result in program termination only when the command line + * is terminated. + * This allows EX to be rubbed out and used in macros. + * The usual command to exit \*(ST in interactive mode + * is thus \(lqEX\fB$$\fP\(rq. * In batch mode EX will exit the program if control - * reaches the end of the munged file, preventing - * interactive mode editing. - * In interactive mode, EX will request an exit that - * is performed on command line termination - * (i.e. after \fB$$\fP). + * reaches the end of the munged file \(em instead of + * starting up interactive mode. * * If any buffer is dirty (modified), EX will yield * an error. - * When specifying <bool> as a Failure condition - * boolean, EX will exit unconditionally. + * When specifying <bool> as a success/truth condition + * boolean, EX will not check whether there are modified + * buffers and will always succeed. * If <bool> is omitted, the sign prefix is implied * (1 or -1). - * In other words \(lq-EX\(rq will always succeed. + * In other words \(lq-EX\fB$$\fP\(rq is the usual + * interactive command sequence to discard all unsaved + * changes and exit. + * + * When colon-modified, <bool> is ignored and EX + * will instead immediately save all modified buffers \(em + * this can of course be reversed using rubout. + * \(lq:EX\fB$$\fP\(rq is thus the usual interactive + * command sequence to exit while saving all modified + * buffers. */ /** @bug what if changing file after EX? will currently still exit */ case 'X': BEGIN_EXEC(&States::start); - if (IS_FAILURE(expressions.pop_num_calc()) && - ring.is_any_dirty()) + if (eval_colon()) + ring.save_all_dirty_buffers(); + else if (IS_FAILURE(expressions.pop_num_calc()) && + ring.is_any_dirty()) throw Error("Modified buffers exist"); - undo.push_var<bool>(quit_requested); - quit_requested = true; + undo.push_var(quit_requested) = true; break; default: diff --git a/src/ring.cpp b/src/ring.cpp index fcaea3a..fb10552 100644 --- a/src/ring.cpp +++ b/src/ring.cpp @@ -160,6 +160,16 @@ Ring::is_any_dirty(void) return false; } +void +Ring::save_all_dirty_buffers(void) +{ + Buffer *cur; + + TAILQ_FOREACH(cur, &head, buffers) + if (cur->dirty && cur->filename) + cur->save(); +} + bool Ring::edit(tecoInt id) { @@ -190,6 +190,7 @@ public: void dirtify(void); bool is_any_dirty(void); + void save_all_dirty_buffers(void); bool edit(tecoInt id); void edit(const gchar *filename); |