4 A Programmer's Text Editor
8 Copyright (C) 1991-2007 Jeremy Cowgar, Angel Ortega
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 http://www.triptico.com
28 /* automatically load / save sessions */
29 mp.config.auto_sessions = 0;
32 mp.config.local_sessions = 0;
34 /** session actions **/
36 mp.actions['save_session'] = sub (d) { mp.long_op(mp.save_session); };
37 mp.actions['load_session'] = sub (d) { mp.long_op(mp.load_session); };
39 /** default keybindings **/
41 /** action descriptions **/
43 mp.actdesc['load_session'] = LL("Load session");
44 mp.actdesc['save_session'] = LL("Save session");
49 /* returns the appropriate session saving file */
51 return (mp.config.local_sessions && './' || HOMEDIR) ~ '.mp_session';
56 /* saves currently open files as a session. Returns: -1, nothing to save;
57 -2, error saving; or 0, session correctly saved */
63 /* no named files? exit doing nothing */
64 if (grep(mp.docs, sub (e) { e.name ne L("<unnamed>"); }) == NULL)
67 if ((fh = open(mp.session_file(), "w")) == NULL) {
71 foreach (doc, mp.docs) {
72 if (doc.name ne L("<unnamed>"))
74 sprintf("%s\t%i\t%i\t%s\n",
75 doc.name, doc.txt.x, doc.txt.y,
76 (cmp(doc, mp.active()) == 0 && 'a' || '')
88 /* loads a session. Returns: -1, no session, -2, user cancellation on closing
89 currently open documents and 0, ok */
93 /* check to see if a session file can actually be opened before closing
94 all the editing windows */
95 if ((fh = open(mp.session_file(), "r")) == NULL) {
99 if (!mp.actions.close_all()) {
106 while (l = read(fh)) {
108 data = split (mp.chomp(l), "\t");
110 if (stat(data[0]) != NULL) {
111 doc = mp.open(data[0]);
113 mp.set_y(doc, data[2]);
114 mp.set_x(doc, data[1]);
116 /* if it has the 'a' flag, set as active */
117 if (regex(data[3], '/a/'))
118 active = seek(mp.docs, doc);
123 mp.active_i = active;