gupta@prlhp1.prl.philips.co.uk (gupta) (05/23/89)
I'd like to implement a facility (on an Apollo running Lucid Lisp 2.10) that I've seen on the Xerox Lisp machines, but am having *considerable* trouble ! What I want is for comments to appear in a different font to code. Therefore typing #| or ; must change the font and typing |# or hitting <CR> must reset the font. (Of course hitting <CR> after having typed #| should not reset the font). I've tried to set traces on some low-level read and write routines so as to determine which routines could be advised to set/reset the font. I can change the font but I haven't been able to figure out which routine needs to be advised to do this (and undo it). A few "nasty recursive error in editor" and "fatal stack overflow"s have convinced me that I need to get some clues from*out there*. Any help - from the people at Lucid would be sincerely appreciated. Perhaps the people at Xerox could give me some clues ... Thanks Ashok Gupta
cutting@ARISIA.XEROX.COM (Doug Cutting) (05/25/89)
Date: 23 May 89 09:15:31 GMT
From: gupta%prlhp1.uucp%idec.uucp%stl.uucp%ukc.uucp%mcvax.uucp (gupta)
What I want is for comments to appear in a different font to code.
Therefore typing #| or ; must change the font and typing |# or hitting <CR>
must reset the font. (Of course hitting <CR> after having typed #| should
not reset the font).
I've tried to set traces on some low-level read and write routines so as to
determine which routines could be advised to set/reset the font.
That's the wrong approach. A better approach is to make a readtable
in which ";" is defined to, rather than ignoring the text after it,
reads it in as an object. The print method for these objects can then
do the font changes. E.g.:
(defstruct (comment
(:print-function print-comment))
contents)
(defvar *comment-readtable* (copy-readtable))
(set-macro-character
#\;
#'(lambda (stream char)
(declare (ignore char))
(make-comment :contents (read-line stream)))
*comment-readtable*)
(defun print-comment (comment stream depth)
(declare (ignore depth))
;; need the somehow set the font here
(format stream ";~A" (comment-contents comment)))
(defun pp-file (file &optional (to-stream *standard-output*))
(with-open-file (stream file)
(let ((*readtable* *comment-readtable*)
(eof (list nil)))
(loop
(let ((form (read stream nil eof)))
(when (eq form eof)
(return))
(pprint form to-stream))))))
Of course this is really fairly useless, as you'll not see the font
changes in the editor, where you most often look at code. Perhaps if
you had a structure editor and an interpreter & compiler which knew to
strip comment structures and a database of definitions . . .
Doug