// seshook.e // // Mon, 07/27/1992 22:56:02 // // Purpose: // // The session file defined by Epsilon is a very good way of // storing various state information between editing sessions. // One of the problems with just grabbing the hook and writing a // couple of strings to the file is that this is subject to // errors based on the same routines being hooked by other // extensions and also not paying any attention at all to what // it is writing out (or rather where and how). This file // displays a method to use the save and restore session hooks // to save a buffer specific variable to the session file and to // restore it on startup. This is designed as a template for // use by other extensions. // // Usage: // // Just add these fragments to your extension and replace the // module name with your exension module name. Use the current // code as an example to write out the salient information and // to recall it using the routines get_line, get_string, // get_number, etc. // // This code should normally be a part of the state file on // startup in order to obtain correct session restore (ie. this // code is designed for use with extensions loaded and saved in // the state file as opposed to those loaded dynamically). // // I have ensured that a global replacement of the word MODULE // with your extensions name will create the desired results // (ie. after the replacement this code will cause a section in // the session file to be created delimited by a unique start // sentinel with your extension name as a part of it). You must // still add the code to save your particular variables however. // // Note: This example is specifically tailored to the extension // which requires the storage of a buffer specific variable and // the storage of a single or window specific variable will // require only slightly different bits of code within the main // loops as shown in the code. // // Although this code would probably compile as is, I would not // suggest using it verbatim. The whole point of this example // code is to provide a good unique strategy for many extensions // to share the global session save resource. Using this code // verbatim for an extension would defeat this purpose. // // Details: // // This method avoids collisions with other extensions by // placing all information for this module at the end of the // session at the time the make_session hook is called and by // the use of a unique sentinel before and after the modules // specific pieces. During the restore the restore hook then // looks for the opening sentinel and reads in values until the // closing sentinel (or the end of buffer) is found. To avoid // conflicts with session files without the new information, if // the opening sentinal is not present then the point is // restored and the next hook in line is called. // // // The modifications to this code are dedicated to the public domain // with the caveat that Lugaru is welcome to use this within their // distribution source code which is supplied with Epsilon. Use it // any way you want for whatever purposes. Portions are Copyright // Lugaru Software... // // // John Kercheval // 15563 10th Ave NE // Seattle, WA 98155-6209 // INTERNET: johnk@wrq.com // Compu$erve: 72450,3702 // // // Modification History: // // Fri, 06/12/1992 15:07:19 V1.0 initial release. // // // some amount of Epsilon original code so... // /************************************************************************ * "Epsilon" is a registered trademark licensed to Lugaru Software, Ltd. * * "EEL" and "Lugaru" are trademarks of Lugaru Software, Ltd. * * * * Copyright (C) 1985, 1992 Lugaru Software Ltd. All rights reserved. * * * * Limited permission is hereby granted to reproduce and modify this * * copyrighted material provided that the resulting code is used only in * * conjunction with Lugaru products and that this notice is retained in * * any such reproduction or modification. * ************************************************************************/ #include // // The following two variables are what are stored and retrieved via // the save session mechanism. // buffer char stateVar1[FNAMELEN] = "Default Value State Var 1"; buffer char stateVar2[FNAMELEN] = "Default Value State Var 2"; // // fence post delimiters // #define MODULE_START_DELIM "<>" #define MODULE_END_DELIM "<>" //////////////////////////////////////////////////////////////////////////// // // This hook is called just before the Lugaru session save code is // complete and is among the last code to execute on exit. // new_module_make_session_hook(b) { int i; // looping var save_var bufnum = b; // move to the session buffer // // move to the end of the buffer // point = size(); // // print out the module start in the session buffer // buf_printf(b, "\n%s", MODULE_START_DELIM); // // Loop through all of the current buffers and save the variable // value for each buffer // for (i = buf_list(0, 0); i; i = buf_list(1, 1)) { bufnum = i; // // validate this is a valid buffer by checking that ... // if (i != b && // this is not the session buffer ... *bufname != '-' && // name is not a temp buffer ... !is_dired_buf() && // buffer is not a dired ... size() && // buffer is > 0 length ... *filename && // buffer is associated w/ a file ... strcmp(bufname, PROCBUF)) { // this is not the process buf // // print out each buffer specific state variable // buf_printf(b, "\n%s\n%s\n%s", filename, stateVar1, stateVar2); } } // // Print out one end delimiter for each string in the primary // sequence to avoid restore parsing errors. // buf_printf(b, "\n%s\n%s\n%s\n", MODULE_END_DELIM, MODULE_END_DELIM, MODULE_END_DELIM); // // call the previous hook // module_make_session_hook(b); } // // This is the replacement macro supplied by Lugaru used to hook a // function. // REPLACE_FUNC("module", "make_session_hook") //////////////////////////////////////////////////////////////////////////// // // This hook is called just before the Lugaru session restore code is // complete and is among the last code to execute before user is // passed control. // new_module_restore_session_hook(b) { char fname[FNAMELEN]; // name temporary char tmpVar1[FNAMELEN]; // first state variable to restore char tmpVar2[FNAMELEN]; // second state variable to restore int old_point = point; // save point ... in case ... save_var bufnum = b; // move to session buffer // // start our sentinal search at the beginning of the session file // (even though it is normally going to be at point). // point = 0; if (!search(1, MODULE_START_DELIM)) { // // Can not find the extension sentinal, probably not here. // point = old_point; } else { // // We found it and are currently at the end of the delimiter. // Move beyond the sentinels line so that we may begin // variable parsing. // nl_forward(); // // Loop through the session file until we are out of file or // we find the ending sentinel (we had better find the // sentinel or the restore is probably in *very* bad shape). // do { // // obtain the filename and the state variables // grab_line(b, fname); grab_line(b, tmpVar1); grab_line(b, tmpVar2); // // if the file is currently an attached buffer then // restore the buffer variable. // if (look_file(fname)) { strcpy(stateVar1, tmpVar1); strcpy(stateVar2, tmpVar2); } } while (strcmp(fname, MODULE_END_DELIM) && point < size()); } // // call the previous hook // module_restore_session_hook(b); } // // This is the replacement macro supplied by Lugaru used to hook a // function. // REPLACE_FUNC("module", "restore_session_hook")