welch@TUT.CIS.OHIO-STATE.EDU (Arun Welch) (05/12/88)
Before I go reinventing thw wheel, does anyone have a function or collection of functions which will take a string as returned by TEDIT and stick EOLs in it so that other forms of editors/displays can deal with it? I need such a thing for a Lispusers package (sorry, module :-) I'm writing. ...arun
lane@SUMEX-AIM.STANFORD.EDU (Christopher Lane) (05/12/88)
Arun, Here is a routine for breaking the lines in a TEdit window, which we use regularly in a few of our systems (including the mailer in which I'm composing this). It doesn't break at a fixed number of columns (eg. 80) but rather breaks at the edge of the TEdit window, so if your TEdit window was sized to be 80 columns wide (fixed width font is assumed) then this will break at 80 columns. If you size the window to 45 columns this routine will break it at 45, assuming that you want the file to be exactly what you see on the screen. In practice I find it's safer to use a 78 column TEdit window and leave the program some margin for error. This routine is called on a TEXTSTREAM and uses the global TEDIT.TABWIDTH (typically 8 (characters)). To break lines it simulates the user putting carriage returns at the ends of the lines so the TEdit window should be open and the user will actually see the program operate (if there are in fact lines to break). It is not fast as it is programmtically stuffing text into TEdit. This routine works in Koto & Lyric (I've included the Lyric version below so Koto users will have to fix up the BQUOTEs). I would be interested in more elegant solutions (free of unreasonable assumptions), - Christopher PS: If you're interested, there is also a companion inverse routine that (when added as a new command to the TEdit menu) lets you select block of broken text and replace the EOLs with spaces to make it TEdit compatible. It also knows about paragraphs breaks in order to do the right thing. (DEFINEQ (TEDIT.FIXUP [LAMBDA (STREAM) (DECLARE (SPECVARS STREAM)) (RESETLST [RESETSAVE (SETFILEPTR STREAM 0) `(SETFILEPTR ,STREAM ,(GETFILEPTR STREAM] (bind (CHARPTR _ 0) (LINELENGTH _ (QUOTIENT (with REGION (DSPCLIPPINGREGION NIL (\TEDIT.MAINW STREAM)) (* Adjust for TEdit cursor margin) (DIFFERENCE WIDTH 16)) (CHARWIDTH (CHARCODE A) STREAM))) (LINEPTR _ 0) CH declare%: (SPECVARS LINEPTR CH) until (EOFP STREAM) do (SELCHARQ (BIN STREAM) (EOL (SETQ CHARPTR 0) (SETQ LINEPTR (GETFILEPTR STREAM))) (TAB (SETQ CHARPTR (TIMES (ADD1 (QUOTIENT CHARPTR TEDIT.TABWIDTH)) TEDIT.TABWIDTH))) (ADD1VAR CHARPTR)) (if (GREATERP CHARPTR LINELENGTH) then [RESETLST [RESETSAVE NIL `(SETFILEPTR ,STREAM ,(GETFILEPTR STREAM] (if (SETQ CH (for FILEPTR from (SUB1 (GETFILEPTR STREAM)) to LINEPTR by -1 eachtime (SETFILEPTR STREAM FILEPTR) thereis (SELCHARQ (BIN STREAM) (SPACE T) NIL))) then (ADD1VAR CH) (TEDIT.SETSEL STREAM CH 1 NIL T) (TEDIT.INSERT STREAM (CHARACTER (CHARCODE EOL] (if CH then (SETQ LINEPTR CH) (SETQ CHARPTR (DIFFERENCE (GETFILEPTR STREAM) LINEPTR)) else (add LINEPTR CHARPTR]))