aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core-commands.c
diff options
context:
space:
mode:
authorRobin Haberkorn <rhaberkorn@fmsbw.de>2025-12-17 01:17:11 +0100
committerRobin Haberkorn <rhaberkorn@fmsbw.de>2025-12-17 01:17:11 +0100
commitdeed71ac895451041359d7b18e58eca0a0972bc3 (patch)
tree2cce2c266b2f92fca45335c95f0a4b8f4945d31e /src/core-commands.c
parentad0780c7163c9673f89dc584d2a6096f317bec2b (diff)
implemented backup file mechanism
* The backup mechanism is supposed to guard against crashes of SciTECO and unexpected program terminations (e.g. power cycling, etc.) * In a given interval (no matter whether busy or idlying on the prompt) SciTECO saves all modified buffers with the filename~ (like most other editors). As an optimization files are not backed up if they have been backed up previously to avoid pointless and possibly slow file system writes. * While the backup mechanism exists outside of the usual undo-paradigm - backup file creating is not bound to character input and it makes no sense to restore the exact state of backup files - there are some interesting interactions: * When a buffer is dirtyfied or saved that was previously backed up, it must always be reset to the DIRTY state on rubout, so backups are eventually recreated. * When a buffer is dirtyfied first (was clean), the backup file must be removed on rubout as well - we don't expect backup files for clean buffers. * There is currently no automatic way to restore backup files. This could potentially be done by opener.tes and session.tes in the future, although you couldn't currently always get meaningful user feedback (whether he wants to restore the file). Perhaps we should at least log a message when detecting backup files that are newer than the file that is being opened.
Diffstat (limited to 'src/core-commands.c')
-rw-r--r--src/core-commands.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/core-commands.c b/src/core-commands.c
index e0b2f89..47809e2 100644
--- a/src/core-commands.c
+++ b/src/core-commands.c
@@ -2151,6 +2151,11 @@ teco_state_ecommand_flags(teco_machine_main_t *ctx, GError **error)
* .IP 5:
* Height of the command line view in lines.
* Must not be smaller than 1.
+ * .IP 6:
+ * Backup interval in seconds or 0 if backups are disabled.
+ * After changing the interval, the new value may become
+ * active only after the previous interval expires.
+ * Backups are not created in batch mode.
* .
* .IP -1:
* Type of the last mouse event (\fBread-only\fP).
@@ -2204,7 +2209,8 @@ teco_state_ecommand_properties(teco_machine_main_t *ctx, GError **error)
EJ_MEMORY_LIMIT,
EJ_INIT_COLOR,
EJ_CARETX,
- EJ_CMDLINE_HEIGHT
+ EJ_CMDLINE_HEIGHT,
+ EJ_BACKUP_INTERVAL
};
static teco_int_t caret_x = 0;
@@ -2255,6 +2261,17 @@ teco_state_ecommand_properties(teco_machine_main_t *ctx, GError **error)
teco_undo_guint(teco_cmdline.height) = value;
break;
+ case EJ_BACKUP_INTERVAL:
+ if (value < 0 || value > G_MAXUINT) {
+ g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED,
+ "Invalid backup interval %" TECO_INT_FORMAT "s "
+ "for <EJ>", value);
+ return;
+ }
+ teco_undo_guint(teco_ring_backup_interval) = value;
+ /* FIXME: Perhaps signal the interface to reprogram timers */
+ break;
+
default:
g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED,
"Cannot set property %" TECO_INT_FORMAT " "
@@ -2314,6 +2331,10 @@ teco_state_ecommand_properties(teco_machine_main_t *ctx, GError **error)
teco_expressions_push(teco_cmdline.height);
break;
+ case EJ_BACKUP_INTERVAL:
+ teco_expressions_push(teco_ring_backup_interval);
+ break;
+
default:
g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED,
"Invalid property %" TECO_INT_FORMAT " "