aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ring.h
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/ring.h
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/ring.h')
-rw-r--r--src/ring.h19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/ring.h b/src/ring.h
index 6466a69..1b1727e 100644
--- a/src/ring.h
+++ b/src/ring.h
@@ -25,13 +25,26 @@
#include "parser.h"
#include "list.h"
+typedef enum {
+ TECO_BUFFER_CLEAN = 0,
+ /** buffer modified */
+ TECO_BUFFER_DIRTY,
+ /** modified and backup already written */
+ TECO_BUFFER_DIRTY_BACKEDUP
+} teco_buffer_state_t;
+
typedef struct teco_buffer_t {
teco_tailq_entry_t entry;
teco_view_t *view;
gchar *filename;
- gboolean dirty;
+
+ /**
+ * A teco_buffer_state_t.
+ * This is still a guint, so you can call teco_undo_guint().
+ */
+ guint state;
} teco_buffer_t;
/** @memberof teco_buffer_t */
@@ -70,6 +83,10 @@ void teco_ring_dirtify(void);
guint teco_ring_get_first_dirty(void);
gboolean teco_ring_save_all_dirty_buffers(GError **error);
+extern guint teco_ring_backup_interval;
+
+void teco_ring_backup(void);
+
gboolean teco_ring_edit_by_name(const gchar *filename, GError **error);
gboolean teco_ring_edit_by_id(teco_int_t id, GError **error);