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

with-fore-color problem?

   From: neves@aristotle.ils.nwu.edu (David Neves)

   I looked at the macro expansion.  It doesn't do set-fore-color.  Instead
   it calls rgb-color.  When I replace rgb-color with set-fore-color it
   works correctly. 

You're right, it calls the rgbforecolor trap directly, instead of
calling the set-fore-color function.  This is a very simple
optimization.  There's no reason to introduce the overhead of
the object lisp function call when it's no harder to call the trap.
[the set-fore-color obfun just does some bookkeeping and then calls
this trap.]

The bug/misfeature/misdocumentation in with-fore-color is that you
have to surround it with a call to with-port.  You have to make sure
the port is set before you call with-fore-color, otherwise the color
won't necessarily be set in the right window.

So, you would say

(ask w
  (with-port wptr
    (with-fore-color my-color

One could easily argue that with-fore-color should do this
automatically.  At the very least, it should documented that it

   [example sent by another user]
   (defmacro with-fore-color (color &rest form)
     (let ((old-color (gensym)))
      `(let ((,old-color (get-fore-color)))
	 (set-fore-color ,color)
	 (set-fore-color ,old-color))))

This is a version of the with-fore-color that calls the functions
instead of calling the traps directly.  I just ran some timings, and
it's just under twice as slow as calling with-port and the built in
version of with-fore-color.