[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fred



>I have an application that has defined specialized classes
>of fred windows, and I need to reinitialize  classes of windows
>when they are opened.  If the windows are opened by menu commands,
>this is easy to do, since I have direct control over when it happens.
>But if the application is up and running and the user double clicks
>on a document, the document is opened automatically by a call to
>(fred) over which I have no control.  (At this point I am using the
>standard *top-level-loop* that comes with MCL, and I presume this loop
>opens the file.)   I could (advise fred :after) to reinitialize the
>window, but I don't have a reliable way to find the result the the
>function (fred) returns.  In fact, as a general feature, it would be
>very nice if there were some variable (called, e.g. result) that
>one could use in a piece of after advice that referred to the result
>returned by a function, analogously to the variable 'arglist' that
>refers to the arglist of the function.
>
>There must be many safe ways to solve my problem.  Any suggestions?

There are a couple of ways I can think of. The best one is to define
your own application class, and write an open-application-document
method on it. open-application-document is called in response to
an 'odoc' Apple Event. It was added and documented in patch 1 for
MCL 2.0 and will be built in to MCL 2.1:

--------------------------------------------------------------------

(defclass my-application (application) ())

(setq *application* (make-instance 'my-application))

(defmethod open-application-document ((app my-application) document
                                      &optional startup)
  (declare (ignore startup))
  (let ((w (fred document)))
    (reinitialize-the-window w)))

--------------------------------------------------------------------

Another way to do this would be with :AROUND advice on the FRED function:

(advise fred
         (let ((w (:do-it)))
           (reinitialize-the-window w))
         :when :around
         :name reinitialize-the-window)