1










                    CHEF - A programmer's word processor



                          J.E.L.Peck and M.A.Maclean

                        University of British Columbia

                           University of Canterbury



                    This  paper  describes how a programmer's
                editor   has   been   augmented   for    word
                processing.   We  show  that  a  single  text
                justification    command    implementing    a
                well-chosen  set  of rules yields a tool with
                surprising power and utility.


      Introduction



           CHEF is primarily a programmer's editor [1,2].   In  general

      philosophy  and  many  of  its functions it is similar to ED, the

      editor supplied with the UNIX operating system [3], but it has  a

      wider range  of commands and more generality.  CHEF is written in

      BCPL, for portability, and special care has been taken to make it

      adaptable to both large  and  small  machines  and  to  operating

      systems with  differing philosophies.  Machine-dependent code has

      been carefully segregated into one  section,  and  a  conditional

      compilation  feature of the BCPL compiler permits the maintenance

      of a single source code file for all target machines.





                                     - 1 -
1                   CHEF - A programmer's word processor


      Why word processing?



           One may ask why such  an  editor  needs  a  word  processing

      capability.   When we first considered the idea we did not have a

      ready answer.  Now, after two years of use we would  hate  to  be

      without it.



           Consider,  for  instance, the busy programmer who must write

      the  occasional  office  memorandum,  report,  letter,  or  small

      business proposal.      Consider   also  the  fact  that  today's

      programmer spends much time at the keyboard and  so  may  have  a

      typing speed comparable to that of a typist.  Consider, too, that

      a  memorandum  or letter typed by someone else must be proof-read

      and that each such interaction with another  person  takes  extra

      time.   These  considerations  usually lead the programmer to use

      the tools immediately to hand, inadequate though they are, to get

      the job done quickly.  These tools are his computer facility  and

      perhaps his programmer's editor which he knows so well.



      Ragged listings



           Most  of  us  are familiar with the results - we arrive at a

      meeting and are handed a listing fresh from the line printer with

      the remark "I just had a few moments to revise the  proposal  and

      incorporate your comments.    I  hope  you can read it".  What we

      usually see is a set of lines with ragged edges.    The  document

      looks  more  like a FORTRAN program than a business proposal, the



                                     - 2 -
1                   CHEF - A programmer's word processor


      lines vary in length and many are too long to allow the  page  to

      be trimmed  to  fit  properly  into  a  standard  folder.   It is

      unattractive and difficult to evaluate for style and impact.



      Documentation



           The unwillingness of many programmers to document their work

      is legendary:  yet the preparation of good documentation requires

      crafstmanship of a high order - something we would  have  thought

      that programmers  would possess in abundance.  Do programmers not

      want their comment sections to be neatly displayed?  Do they  not

      want others to see how well they have done their job?



           Could  it  be that suitable tools have not been available in

      the past, tools with a simple user interface and enough power  to

      turn drudgery into a self-motivating experience?  We believe that

      this is so.



      Formatting programs



           Not  many will have access to a stand-alone interactive word

      processor.  Another alternative  is  the  specialized  formatting

      utility programs now available on many systems.  These range from

      the  simple  ones  that  do little apart from justifying text, to

      larger programs, available under  many  operating  systems,  that

      have great  power and capability.  These systems are often overly

      elaborate for the casual user.  Why should  the  busy  programmer



                                     - 3 -
1                   CHEF - A programmer's word processor


      have to learn the idiosyncracies of a text formatter, in addition

      to  a text editor, when a well-chosen combination of the two will

      do the job?



           There appear to be two philosophies used by text formatters.

      The first assumes that the text is totally unformatted and relies

      on formatting commands sprinkled throughout the text.  The  other

      uses the present form of the text as the main control, instead of

      explicit formatting commands.



      The CHEF approach



           We decided to pursue the second alternative in attempting to

      incorporate word  processing  in a programmer's editor.  In fact,

      we take  the  principle  to  its  extreme  and  use  no  embedded

      formatting commands at all.



           Another  assumption of most text formatters is that there is

      a "source" file and a "target" file.  Translation of one  to  the

      other  is done as an uninterrupted job, i.e., without interactive

      aid from the user.  With CHEF the target text, after  processing,

      becomes the source text for the next run.  It is not necessary to

      retain  the source file for incorporating further updates as well

      as the target file for running off finished copies.  They are one

      and the same file.



      One system



                                     - 4 -
1                   CHEF - A programmer's word processor




           Another  convenience  of  CHEF,   not   provided   by   text

      formatters,  is  that  the  processor creating and correcting the

      text is the same as that which formats it.   All  these  funcions

      are thus performed by the same editor in the same session.



           To  accomplish  this  the CHEF editor has a single command J

      (for justify).  Like its other commands, the J command accepts  a

      line range  on  the left and possible operands on the right.  For

      example, the command 20,30J will justify lines 20  to  30.    The

      default  assumption  is  that the object text should be justified

      between columns 1 and 65  inclusive,  but  this  can  be  changed

      easily.   For  example,  the  command 20,30J6,70 will justify the

      same lines between 6 and 70.  Subsequent use of J, without  right

      operands,   retains  the  new  column  range,  until  another  is

      explicitly specified.



      Formatting rules



           The rules used by CHEF are based on the paragraph formatting

      rules  of  simple  formatters  like  RUNOFF  [3],  together  with

      additional rules  which,  to  our  knowledge,  are new.  The most

      important are that



                1) a blank line remains blank, and

                2) an indented line  remains  indented,  with  the

           same indentation,



                                     - 5 -
1                   CHEF - A programmer's word processor


                3)  a  non-blank,  non-indented  line  forces  the

           justification of the previous lines.



      It is surprising how much can be accomplished  using  these  easy

      rules.  They are certainly sufficient for most memoranda, letters

      or simple documents.



      Tabular displays



           For  more elaborate textual presentations there is sometimes

      the need to display tables in which the columns are aligned.   Of

      course such  displays  are usually indented.  However, if nothing

      else is specified, the well aligned columns will be destroyed  by

      the  removal  of  what  appear,  to the processor, as unnecessary

      blanks.  With CHEF,  we  could  get  over  this  problem  by  not

      justifying  this  range  of lines, since it is so easy to specify

      the range.  However, there is another and safer method using  the

      rule that



                4) any line indented beyond a certain threshold is

           considered  as  "frozen",  i.e.,  no attempt is made to

           modify it.



      The threshold is set initially to  column  6,  but  this  may  be

      changed  in  order to freeze displays that are closer to the left

      margin.





                                     - 6 -
1                   CHEF - A programmer's word processor


      Centering of lines



           For centering of lines we have slightly  deviated  from  the

      rule of "no embedded formatting commands".  The rule here is that



                5)  a line with a colon (:) in the left margin and

           otherwise indented beyond the threshold, is centred and

           the colon is removed.



      Once a line has been centred there is no need  to  do  it  again.

      Hence the  colon is not a permanent part of the source file.  The

      particular character used to specify centering may be changed  by

      the user at any time.



      Sentence separation



           A commonly used rule for finished text is that a sentence is

      separated  from  the  next  one by two or more blanks, contrasted

      with the one or more blanks  used  to  separate  words  within  a

      sentence.   Of course the recognition of the end of a sentence is

      not easy for  an  automatic  processor  that  assumes  that  word

      separators  in  the  source are one or more blanks or a new line.

      CHEF respects sentence separation by the following rule.



                6) A word ending with one of  the  symbols  Å.?]:Ì

           has  the  following  blank frozen (or a frozen blank is

           appended, if it ended a line).



                                     - 7 -
1                   CHEF - A programmer's word processor




      A frozen blank is considered as part of the preceding  word  when

      the  text is being processed prior to justification, so a minimum

      two-blank separation from the following word is retained.    When

      the  text is finally justified, however, a frozen blank appearing

      at the end of a line is removed.



           There is a welcome additional benefit  in  that  a  sequence

      like  "M. I. T." is not padded with additional blanks in order to

      justify the line and  it  will  not  be  broken  in  two,  in  an

      unnatural way,  between  two lines.  If the user wishes to escape

      these effects, then he may simply insert two or more blanks.





      Adjustable parameters



           We have mentioned that the column range of the  object  text

      may  be  changed  by  specifying it explicitly as operands of a J

      command.  These operands set CHEF parameters known  as  the  left

      and right  "verges".    There  is  also  an L command which loads

      parameters and a ? command  to  query  their  values.    Thus  an

      alternative  way  to justify lines 20 to 30 between columns 6 and

      70 is the command sequence LL6; LR65; 20,30J.  The complete  list

      of parameters concerned with word processing is



              parameter        explanation





                                     - 8 -
1                   CHEF - A programmer's word processor


                 Ò             left margin  (of the source text)

                 $             right margin (        "         )

                 L             left verge   (of the object text)

                 R             right verge  (        "         )

                 T             threshold

                 :             centering character



      For example, the command LT2 sets the threshold to 2, the command

      L:- sets the centering character to '-', and so on.



           Text  is  picked up prior to justification from the position

      of the left margin (or the first  nonblank  character,  whichever

      comes first) to the right margin, however indentation is measured

      from the  position  of  the  left margin.  If the source text has

      already been justified between columns  6  and  70  and  must  be

      processed again, unexpected indentation of the justified text may

      occur  unless  the  left  margin  is  also  set  to 6 with an LÒ6

      command.  These parameters therefore allow for the  justification

      of indented text as is done for the rules in this document.



      Other features



           CHEF's  regular  editing  commands  are  available  for  the

      creation and maintenance of the source file.    As  well  as  the

      usual   insertion,  deletion  and  string-substitution  commands,

      blocks of text may be exchanged within the work space or  between

      it and  auxiliary  files in a flexible manner.  The editor has an



                                     - 9 -
1                   CHEF - A programmer's word processor


      automatically  paged  random-access  workspace  of   very   large

      capacity  which gives the user complete freedom to move text from

      one place to another in an arbitrary manner and  to  display  the

      results for verification.



      Conclusion



           We have shown that a text justification command working with

      well-planned   formatting   rules   adds   welcome   power  to  a

      programmer's editor.  The advantages are



              1) one tool instead of two,

              2) one file instead of two,

              3) one editing session instead of two,

              4) no formatting commands to be remembered.



      An editor incorporating these ideas  is  already  in  use  on  an

      Amdahl  470 under MTS, a PDP-11 under UNIX, an ECLIPSE and a NOVA

      under RDOS, on an ECLIPSE under AOS and on an ICL 2900.



      References



           [1]  Maclean,M.A.  and  Peck,J.E.L.,   CHEF:   A   versatile

      portable  text  editor,  Software  Practice  and  Experience - to

      appear.



           [2]  Peck,J.E.L. and Maclean,M.A.,  The  construction  of  a



                                    - 10 -
1                   CHEF - A programmer's word processor


      portable editor, Software Practice and Experience - to appear.



           [3]  Kernighan,B.W.   and   Plauger,P.J.,   Software  Tools,

      Addison-Wesley, Reading, Mass., 1976.

















































                                    - 11 -

