[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon May 15 14:47:51 1994 
Subject:Re: Restoring the Poplog Desk Top (ved_mem, ved_gomem) 
From:Aaron Sloman 
Volume-ID:940515.01 

This is a very belated reply to a question from Robin about a month
ago.

pop@cs.umass.edu ( Robin Popplestone ) wrote:

> Date: 18 Apr 1994 13:05:52 GMT
> Organization: CS Dept., Umass-Amherst
>
> One frustration of my life is the fact that if Poplog gets shut down for
> any reason (after all the power sometimes goes off in Western
> Massachusetts....) all the files I had open in XVED are not reopened when I
> start up Poplog again. No doubt I could hack up something to reconstitute
> my desktop automatically, e.g. redefining ved_w so that the files on
> vedbufferlist are recorded, but I was hoping that somebody might have done
> it already. So, has anybody? Ideally the icons would reappear in the same
> places as before. Even better, there might be a more sensible window
> manager which would support grouping icons in a way that reflected their
> role.

I have a tiny step in this direction, which enables you selectively
to remember where you are in a file, and then return to it later.
Roughly you do
    ENTER mem foo
to associate with the 'tag' foo the current file and the current
location. Then later you do
    ENTER gomem foo
to return to that file at that place. Since it depends on line
numbers it is not robust against editing, but it works reasonably
most of the time, at least for me.

You can use two labels to remember two positions in the same file.
E.g.
    ENTER mem foo
    ENTER mem baz
    ENTER gomem foo
    ENTER gomem baz
can be used simultaneously to remember and return to two different
locations in the same file.

It would be easy to write a procedure to use ved_mem to record
current location in all open files every 60 seconds, using
sys_timer.

ved_mem doesn't (at present) attempt to remember the screen
locations of windows, which ones are itemised, etc. etc. In XVED
some (all?) of the desired information can be got by saving the
output of

    xved_value("currentWindow", [x y numRows numColumns iconific])

and updated using

    -> xved_value("currentWindow", [x y numRows numColumns iconic])

Unfortunately the values of "x" and "y" (screen coordinates) may not
be accurate with all window managers, e.g. TWM.

It would be possible to define a procedure that cycles through all
current files recording these values plus vedline vedcolumn and
vedlineoffset, for each file, and writing a file that included code
that re-opened the files and restored their status. The procedure
could be made (using sys_timer) to run every minute or so to record
the current state. Loading the saved file would then reopen all the
original files and restore their windows to the screen, etc.

Normally I would not want this to be done for ALL my files (e.g.
because I have several help or teach files open, or other files
opened for reading only). Thus I would need a way of specifying
which files should have their status recorded.

Anyhow, most of the time the simple mechanism I currently have does
what I want. (It was designed initially with help from Nicola Yuill,
a psychologist at Sussex, who expressed a need for something like
this, whereupon I realised I would also find it useful, and
therefore implemented what she requested.)

Here is the HELP file, followed by the library file, separated by
rows of "=" signs.
Aaron
===================================================================
HELP VEDMEMFILE                       A.Sloman & Nicola Yuill April 1990

<ENTER> MEM <taskname>
<ENTER> GOMEM <taskname>
GOMEM <taskname>

[The <taskname> is optional]

This collection of utilities is designed to facilitate re-starting a
file in VED at a previously recorded line number, even after you have
logged out and logged in again.

-- Overview -----------------------------------------------------------

The general idea is that your work may switch between several tasks each
concerned with several files. For each task you may wish VED to remember
which file you were last working on and on which line of that file. The
commands

    <ENTER> mem
    <ENTER> mem <taskname>

are used to tell ved to remember the current file and its line number.
If you don't specify a <taskname> it just assumes that you wish to
record the file and line number anyway.

Different locations in the same file can be recorded under different
tasknames.

Later, possibly after logging out and logging in again, you can give
one of the following commands to return to a remembered file:

To Pop-11

    gomem
    gomem   <taskname>

To Lisp

    @gomem
    @gomem <taskname>


To VED (using any Poplog language system)

    <ENTER> gomem
    <ENTER> gomem <taskname>

It is possible also to set up your init.p or other initialisation file
so that as soon as you return to Poplog it goes back to the file last
recorded with the '<ENTER> mem' command.


-- How it works -------------------------------------------------------

Each time you give the '<ENTER> mem' command the name of the current VED
file and the line number are stored in a special file, and when you give
a gomem command that file is read to discover which file you were last
editing and which line you were on.

A different memory file is used for each taskname. In order to decide
which file name to use for the memory file the commands look at a global
variable called vedmemfile, whose default value is the string

    '$HOME/.memfile'                      (in Unix)
    '[<YOUR LOGIN DIRECTORY>]MEMFILE'     (in VMS)

You can assign another string to -vedmemfile- if preferred.

If you give a task name as argument to <ENTER> mem, or to gomem, then
that task name is appended to the string -vedmemfile-.

Thus if you are editing a file called 'myfile' and you do
    <ENTER> mem work

then the full pathname for myfile and the current line number will be
stored in a file called

    .memfile.work   (in Unix)
    memfile_work    (in VMS)

in your $HOME directory (unless you have assigned a different string to
vedmemfile).

If you log out and later log in again and type, to Pop-11

    gomem work

or to VED

    <ENTER> gomem work

it will read the file '$HOME/.memfile.work' to find out where to go
(or the corresponding VMS file).

If you don't specify a task name, then the name of the file used as the
memory file is just the value of -vedmemfile-.

[Note added by Aaron May 1994: it would be desirable to add a
utility to purge old memfiles automatically from time to time. I use
    ENTER dired .mem*
to find old files for purging.]

--- $poplocal/local/help/vedmemfile
--- Copyright University of Sussex 1988. All rights reserved. ----------
===================================================================
/* --- Copyright University of Sussex 1990. All rights reserved. ----------
 > File:            $poplocal/local/auto/ved_mem.p
    link this file in the same directory to
        ved_gomem.p
        gomem.p
 > Purpose:         Record or return to file and line number
 > Author:          Aaron Sloman, Dec 22 1988 (see revisions)
 > Documentation:   HELP * VEDMEMFILE
 > Related Files:   ved_gomem.p gomem.p (all linked)
 */

;;; Based in part on an idea suggested by Nicola Yuill

section;

uses sysdefs

global vars vedmemfile;         ;;; Information is stored in files
                                ;;; whose names start with this string


#_IF DEF UNIX
    lconstant memjoiner = '.';  ;;; precedes suffix in memory files.
#_ELSE
    lconstant memjoiner = '_';
#_ENDIF

unless isstring(vedmemfile) then
#_IF DEF UNIX
    '$HOME/.memfile' -> vedmemfile
#_ELSE
    systranslate('SYS$LOGIN') dir_>< 'memfile' -> vedmemfile
#_ENDIF
endunless;

define lconstant memfilename(string) -> string;
    ;;; The argument to ved_mem, or ved_gomem, or gomem is -string-. To
    ;;; get the name of the file where information is stored append it to
    ;;; vedmemfile, unless it is empty.
    lvars string;
    if string = nullstring then
        vedmemfile
    else
        vedmemfile sys_>< memjoiner sys_>< string
    endif -> string
enddefine;

define global ved_mem;
    ;;; Remember current file and line number in the appropriate file
    ;;; for later use by gomem or ved_gomem.
    dlocal pop_pr_quotes = true, pop_file_versions = 1,
        cucharout = discout(memfilename(vedargument));
    printf(vedline,vedpathname,'%p\n%p\n');
    cucharout(termin);
enddefine;

define global ved_gomem;
    ;;; Go to remembered file, of type specified by -vedargument-
    ;;; and go to line number stored there. This also works outside
    ;;; VED if -vedargument- has been set up.
    lvars file, dev = readable(memfilename(vedargument)),
        filename, visible = vedstartwindow >> 1 ;
    if dev then
        incharitem(discin(dev)) -> file;    ;;; create item repeater
        file() -> filename;                 ;;; get the file name
        file() -> vvedgotoplace;            ;;; get the line number
        ;;; subtract -visible- to get some context visible
        max(1, vvedgotoplace - visible) -> vvedgotoplace;
        sysclose(dev);
        vedinput(
            procedure;
                ;;; go to required place
                vedjumpto(vedline + visible, 1);
            endprocedure);
        edit(filename);
    else
        vederror('NO MEMFILE FOR ' sys_>< vedargument)
    endif
enddefine;

define global syntax gomem;
    ;;; For use outside VED. Go to the remembered file and line number
    ;;; stored in the "memfile" corresponding to the argument.
    dlocal popnewline = true;
    sysPUSHQ(rdstringto([; ^termin ^newline]));
    sysPOP("vedargument");
    sysCALL("ved_gomem");
    ";" :: proglist -> proglist;
enddefine;

endsection;

/* --- Revision History ---------------------------------------------------
--- Aaron Sloman, Jul 27 1990
    removed call of vedmidwindow and achieved the same effect better.
--- Aaron Sloman, Apr 17 1990 Changed to use syntax word for "gomem".
    Also tidied up, and generalised for VMS. Updated HELP file.
--- Aaron Sloman, May 31 1989 better error message if file not found
 */
===================================================================
--
Aaron Sloman,
School of Computer Science, The University of Birmingham, B15 2TT, England
EMAIL   A.Sloman@cs.bham.ac.uk  OR A.Sloman@bham.ac.uk
Phone: +44-(0)21-414-3711       Fax:   +44-(0)21-414-4281