[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
with-fore-color problem?
- To: neves@aristotle.ils.nwu.edu
- Subject: with-fore-color problem?
- From: Andrew L. M. Shalit <alms>
- Date: Thu, 1 Nov 90 14:59:41 -0500
- Cc: info-macl, lynch@aristotle.ils.nwu.edu
- In-reply-to: David Neves's message of Thu, 1 Nov 90 12:07:32 CST <9011011807.AA10041@aristotle.ils.nwu.edu>
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
doesn't.
[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)
,@form
(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.
-andrew