🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.xerox
Article #738

Re: Changing fonts to differentiate comments from code

#738
From: Doug Cutting
Date: Wed, 24 May 1989 21:03
51 lines
2194 bytes
   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
Technical Details
Message-ID: <8905242103.AA00581@bopp.parc.xerox.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!ARISIA.XEROX.COM!cutting

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!ARISIA.XEROX.COM!cutting
From: cutting@ARISIA.XEROX.COM (Doug Cutting)
Newsgroups: comp.sys.xerox
Subject: Re: Changing fonts to differentiate comments from code
Message-ID: <8905242103.AA00581@bopp.parc.xerox.com>
Date: 24 May 89 21:03:17 GMT
Sender: daemon@ucbvax.BERKELEY.EDU
Organization: The Internet
Lines: 51