mailing-list for TeXmacs Users

Text archives Help


Re: [TeXmacs] autosaving time


Chronological Thread 
  • From: David Allouche <address@hidden>
  • To: address@hidden
  • Subject: Re: [TeXmacs] autosaving time
  • Date: Wed, 10 Dec 2003 14:41:07 +0100

On Wed, Dec 10, 2003 at 11:02:48AM +0100, Joris van der Hoeven wrote:
>
> On Wed, 10 Dec 2003, Valery Pipin wrote:
> > Is it possible to change the time option for autosaving the document or
> > session?
>
> No, there is not, but it should not be extremely difficult to hack
> the sources to create such an option (even though several files would
> need to be changed). I have no time for this right now.

Done. Patch attached to this message.

Not what I would call an "easy" patch though.

This will add a Preference->Autosave menu where you can select various
autosave period or disable autosave entirely.

--
-- ddaa
Summary: configurable autosave period
Keywords:

Make the autosave period a preference setting.
Also make it possible to disable autosave entirely.

Since autosave is handled in a delayed event queue and not as a timer,
one has to go through some contorsions to be able to support disabling
and re-enabling of autosave.

Also, the queue handling was fixed to send the delayed message _after_
removing it from the queue, so the handler can safely remove messages
from the queue.

--- TeXmacs/langs/natural/dic/english-french.scm
+++ TeXmacs/langs/natural/dic/english-french.scm
@@ -87,6 +87,7 @@
("automatic" "automatique")
("automatically close brackets" "fermer automatiquement les parenthèses")
("automatically generated content" "génération automatique de contenu")
+("autosave" "sauvegarde automatique")
("axiom" "axiome")
("background" "arrière-plan")
("background color" "couleur de fond")
@@ -259,6 +260,7 @@
("devangari" "dévangari")
("developers guide" "guide du développeur")
("directory" "répertoire")
+("disable" "désactiver")
("disable first indentation" "désactiver première indentation")
("disable first indentation after" "désactiver première indentation après")
("disable first indentation before" "désactiver première indentation avant")
--- TeXmacs/langs/natural/dic/english-new.scm
+++ TeXmacs/langs/natural/dic/english-new.scm
@@ -87,6 +87,7 @@
("automatic" "")
("automatically close brackets" "")
("automatically generated content" "")
+("autosave" "")
("axiom" "")
("background" "")
("background color" "")
@@ -260,6 +261,7 @@
("devangari" "")
("developers guide" "")
("directory" "")
+("disable" "")
("disable first indentation" "")
("disable first indentation after" "")
("disable first indentation before" "")
--- TeXmacs/progs/menus/menu-preferences.scm
+++ TeXmacs/progs/menus/menu-preferences.scm
@@ -140,7 +140,13 @@
(enum ("Security" "security")
("Accept no scripts" "accept no scripts")
("Prompt on scripts" "prompt on scripts")
- ("Accept all scripts" "accept all scripts"))))
+ ("Accept all scripts" "accept all scripts"))
+ (enum ("Autosave" "autosave")
+ ("1 s" "1")
+ ("30 s" "30")
+ ("120 s" "120")
+ ("300 s" "300")
+ ("Disable" "0"))))

(menu-bind page-setup-menu)
(menu-bind preferences-menu)
--- TeXmacs/progs/texmacs/texmacs/tm-server.scm
+++ TeXmacs/progs/texmacs/texmacs/tm-server.scm
@@ -39,11 +39,16 @@
((== val "prompt on scripts") (set-script-status 1))
((== val "accept all scripts") (set-script-status 2))))

+(define (notify-autosave var val)
+ (if (has-view?) ; delayed-autosave would crash at initialization time
+ (delayed-autosave)))
+
(define-preferences
("profile" "beginner" (lambda args (noop)))
("look and feel" "emacs" notify-look-and-feel)
("language" (get-locale-language) notify-language)
- ("security" "prompt on scripts" notify-security))
+ ("security" "prompt on scripts" notify-security)
+ ("autosave" "120" notify-autosave))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Killing buffers, windows and TeXmacs
--- src/Guile/Glue/build-glue-server.scm
+++ src/Guile/Glue/build-glue-server.scm
@@ -77,7 +77,8 @@
(texmacs-load-tree load_tree (texmacs_tree url string))
(texmacs-load-buffer load_buffer (void url string int bool))
(texmacs-save-buffer save_buffer (void url string))
-
+ (delayed-autosave delayed_autosave (void))
+
(color get_color (int string))
(style-clear-cache style_clear_cache (void))
(set-script-status set_script_status (void int))
--- src/Guile/Glue/glue_server.cpp
+++ src/Guile/Glue/glue_server.cpp
@@ -659,6 +659,15 @@
}

SCM
+tmg_delayed_autosave () {
+ // SCM_DEFER_INTS;
+ get_server()->delayed_autosave ();
+ // SCM_ALLOW_INTS;
+
+ return SCM_UNSPECIFIED;
+}
+
+SCM
tmg_color (SCM arg1) {
SCM_ASSERT_STRING (arg1, SCM_ARG1, "color");

@@ -893,6 +902,7 @@
gh_new_procedure ("texmacs-load-tree", (FN) tmg_texmacs_load_tree, 2, 0,
0);
gh_new_procedure ("texmacs-load-buffer", (FN) tmg_texmacs_load_buffer, 4,
0, 0);
gh_new_procedure ("texmacs-save-buffer", (FN) tmg_texmacs_save_buffer, 2,
0, 0);
+ gh_new_procedure ("delayed-autosave", (FN) tmg_delayed_autosave, 0, 0, 0);
gh_new_procedure ("color", (FN) tmg_color, 1, 0, 0);
gh_new_procedure ("style-clear-cache", (FN) tmg_style_clear_cache, 0, 0,
0);
gh_new_procedure ("set-script-status", (FN) tmg_set_script_status, 1, 0,
0);
--- src/Texmacs/Data/tm_file.cpp
+++ src/Texmacs/Data/tm_file.cpp
@@ -224,7 +224,20 @@
}
}
}
- get_display()->delayed_message (get_meta()->get_this(), "auto save",
120000);
+ delayed_autosave();
+}
+
+void
+tm_data_rep::delayed_autosave () {
+ display d= get_display();
+ d->remove_all_delayed_messages (get_meta()->get_this(), "auto save");
+ string s= as_string(eval ("(get-preference \"autosave\")"));
+ int p;
+ if (is_int(s)) p= as_int(s) * 1000;
+ else p= 120000;
+ if (p>0) {
+ d->delayed_message (get_meta()->get_this(), "auto save", p);
+ }
}


/******************************************************************************
--- src/Texmacs/Texmacs/texmacs.cpp
+++ src/Texmacs/Texmacs/texmacs.cpp
@@ -174,7 +174,7 @@
}

if (DEBUG_STD) cout << "TeXmacs] Starting event loop...\n";
- dis->delayed_message (sv->get_meta(), "auto save", 120000);
+ sv->delayed_autosave();
dis->delayed_message (sv->get_meta(), "banner", 100);
dis->event_loop ();

--- src/Texmacs/server.hpp
+++ src/Texmacs/server.hpp
@@ -95,6 +95,7 @@
virtual void load_buffer (url name, string f, int w=0, bool a=false)=0;
virtual void save_buffer (url name, string fm) = 0;
virtual void auto_save () = 0;
+ virtual void delayed_autosave () = 0;
virtual bool buffer_unsaved () = 0;
virtual bool exists_unsaved_buffer () = 0;
virtual void pretend_save_buffer () = 0;
--- src/Texmacs/tm_data.hpp
+++ src/Texmacs/tm_data.hpp
@@ -88,6 +88,7 @@
void load_buffer (url name, string fm, int where= 0, bool asf= false);
void save_buffer (url name, string fm);
void auto_save ();
+ void delayed_autosave ();
bool buffer_unsaved ();
bool exists_unsaved_buffer ();
void pretend_save_buffer ();
--- src/Window/X/x_display.cpp
+++ src/Window/X/x_display.cpp
@@ -272,12 +272,31 @@
return list<message> (l->item, insert_message (l->next, wid, s, cur, t));
}

+static list<message>
+remove_all_messages (list<message> l, widget wid, string s, int& found) {
+ if (nil (l))
+ return l;
+ else if (l->item->wid == wid && l->item->s == s) {
+ found++;
+ return remove_all_messages (l->next, wid, s, found);
+ }
+ else
+ return list<message>(l->item, remove_all_messages(l->next, wid, s,
found));
+};
+
void
x_display_rep::delayed_message (widget wid, string s, time_t delay) {
time_t ct= texmacs_time ();
messages= insert_message (messages, wid, s, ct, ct+ delay);
}

+int
+x_display_rep::remove_all_delayed_messages (widget wid, string s) {
+ int found= 0;
+ messages= remove_all_messages (messages, wid, s, found);
+ return found;
+}
+

/******************************************************************************
* Set the current language

******************************************************************************/
--- src/Window/X/x_display.hpp
+++ src/Window/X/x_display.hpp
@@ -183,6 +183,7 @@
bool set_selection (widget wid, string key, tree t, string s);
void clear_selection (string key);
void delayed_message (widget wid, string s, time_t delay);
+ int remove_all_delayed_messages (widget wid, string s);

/**************************** miscellaneous
********************************/
void set_help_balloon (widget wid, SI x, SI y);
--- src/Window/X/x_loop.cpp
+++ src/Window/X/x_loop.cpp
@@ -357,8 +357,8 @@
time_t ct= texmacs_time ();
message m= messages->item;
if ((m->t - ct) <= 0) {
- m->wid << emit_alarm (m->s, m->t);
messages= messages->next;
+ m->wid << emit_alarm (m->s, m->t);
}
else break;
}
--- src/Window/display.hpp
+++ src/Window/display.hpp
@@ -71,6 +71,7 @@
virtual bool set_selection (widget wid, string k, tree t, string s="") =
0;
virtual void clear_selection (string key) = 0;
virtual void delayed_message (widget wid, string mess, time_t delay) = 0;
+ virtual int remove_all_delayed_messages (widget wid, string s) = 0;

/* miscellaneous */
virtual void set_help_balloon (widget wid, SI x, SI y) = 0;



Archive powered by MHonArc 2.6.19.

Top of page