🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.lisp.mcl
Article #618

Re: view-cursor

#618
From: Bill St. Clair
Date: Wed, 16 Dec 1992 16:08
43 lines
2266 bytes
At 19:11 12/15/92 -0500, Dale J. Skrien wrote:
>I've created a special subclass of view for which I want to continually
>display the mouse position when it is over the view.  I want the mouse
>position to be displayed in the view-window of the view but outside
>of the view.  So I wrote a method of view-cursor for my view as follows:
>
>(defmethod view-cursor ((self my-special-view-class) where)
>  (with-focused-view (view-window self)
>    (#_textmode #$patCopy)
>    (with-pstrs ((horizontal (format nil "~3d" (point-h where)))
>                 (vertical (format nil "~3d" (point-v where))))
>        (#_moveto 10 10)
>        (#_drawstring horizontal)
>        (#_moveto 10 40)
>        (#_drawstring vertical)))
>  *arrow-cursor*   ;return the arrow cursor
>  )
>
>My Question:  Is this the best way to do it (time-wise and
>memory-wise)?  In particular, does this do some cons-ing that
>will rapidly eat up memory while the mouse is over the view?

You're consing two 3-character strings each time your view-cursor
method runs. (format nil ...) conses a string. You'd do better to
FORMAT directly to the window:

(defmethod view-cursor ((self my-special-view-class) where)
  (let ((window (view-window self)))
    (with-focused-view window
      (#_textmode #$patCopy)
      (#_moveto 10 10)
      (format window "~3d" (point-h where))
      (#_moveto 10 40)
      (format window "~3d" (point-v where))))
  *arrow-cursor*   ;return the arrow cursor
  )

Unfortunately, this still conses because MCL's FORMAT ~D code conses if
you specify a MINCOL argument. Two choices: do the numeric conversion
yourself or ask for my patch that eliminates the consing from MCL's
FORMAT ~D code. The patch is called "less-format-consing-patch.lisp".
(This has bothered me for a while. Thanx for giving me the impetus to
spend an hour fixing it) 
Technical Details
Message-ID: <9212161504.AA03390@cambridge.apple.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!apple!cambridge.apple.com!bill@cambridge.apple.com

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!apple!cambridge.apple.com!bill@cambridge.apple.com
From: bill@cambridge.apple.com (Bill St. Clair)
Newsgroups: comp.lang.lisp.mcl
Subject: Re: view-cursor
Message-ID: <9212161504.AA03390@cambridge.apple.com>
Date: 16 Dec 92 16:08:35 GMT
Sender: info-mcl-request@cambridge.apple.com
Lines: 43
Approved: comp.lang.lisp.mcl@Cambridge.Apple.C0M