[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Dec 13 11:27:50 1993 
Subject:Keyword Completion 
From:Tim Read 
Volume-ID:931214.02 

One of the things that irritates me about Pop11 is the need to type closing
keywords for such things as if, repeat, define etc. I have hence written a
little bit of code that does it for you. Simply type in the first two, three
or four letters of a keyword (covered in the header below), press the space
bar, and the closing part will be added automatically. I am sure there are
neater ways to do it that the way I have chosen, but so what, it works for
me... I hope you find it as useful as I do.

/*
 * lazy.p
 *
 * Key word completion, it works for the following keywords:
 *
 * if, unl[ess], rep[eat], for, whi[le], swi[tchon], def[ine],
 * defm[-m,ine :method], defc[-c,ine :class]
 *
 * Type the unbracketed part followed by the SPACE key for completion
 *
 * Loading this library turns the above facility on, to turn if off type ESC 2,
 * to turn it back on type ESC 1
 *
 * Tim Read, Attention & Affect Project, University of Birmingham 1993
 *
 */

vars tim_vedprocesstrap, vedpos, vedleft, vedright, ved_temp_char_count = 0,
     vtcl = []; 

define tim_vedprocesstrap();
  lvars len,vv;
  vtcl <> [^ved_last_char] -> vtcl;
  if ved_last_char = `\r` then
    0 -> ved_temp_char_count;
    [] -> vtcl;
  elseif ved_last_char = `\s` then
    length(vtcl) -> len;
    if len > 2 and vtcl(len-2) = `i` and vtcl(len-1) = `f` then
        vedcolumn -> vv;
        vedchardelete();vedinsertstring('  then\n');
        vedpos(vv-4,'endif;');
        vedleft(3); vedcharup();
    elseif len > 3 and vtcl(len-3) = `u` and vtcl(len-2) = `n` and vtcl(len-1) = `l` then
        vedcolumn -> vv;
        vedchardelete();vedinsertstring('ess  then\n');
        vedpos(vv-5,'endunless;');
        vedleft(3); vedcharup();
    elseif len > 3 and vtcl(len-3) = `r` and vtcl(len-2) = `e` and vtcl(len-1) = `p` then
        vedcolumn -> vv;
        vedchardelete();vedinsertstring('eat  times\n');
        vedpos(vv-5,'endrepeat;');
        vedleft(3); vedcharup();
    elseif len > 3 and vtcl(len-3) = `f` and vtcl(len-2) = `o` and vtcl(len-1) = `r` then
        vedcolumn -> vv;
        vedchardelete();vedinsertstring('  do\n');
        vedpos(vv-5,'endfor;');
        vedleft(3); vedcharup();
    elseif len > 3 and vtcl(len-3) = `w` and vtcl(len-2) = `h` and vtcl(len-1) = `i` then
        vedcolumn -> vv;
        vedchardelete();vedinsertstring('le  do\n');
        vedpos(vv-5,'endwhile;');
        vedleft(3); vedcharup();
    elseif len > 3 and vtcl(len-3) = `s` and vtcl(len-2) = `w` and vtcl(len-1) = `i` then
        vedcolumn -> vv;
        vedchardelete();vedinsertstring('tchon\n');
        vedpos(vv-5,'endswitchon;');
        vedleft(3); vedcharup();
    elseif len > 3 and vtcl(len-3) = `d` and vtcl(len-2) = `e` and vtcl(len-1) = `f` then
        vedcolumn -> vv;
        vedchardelete();vedinsertstring('ine ();\n');
        vedpos(vv-5,'enddefine;');
        vedleft(3); vedcharup();
    elseif len > 3 and vtcl(len-3) = `e` and vtcl(len-2) = `f` and vtcl(len-1) = `m` then
        vedchardelete();vedcolumn -> vv;
        vedchardelete();vedinsertstring('ine :method ();\n');
        vedpos(vv-5,'enddefine;');
        vedright(5);vedcharup();
    elseif len > 3 and vtcl(len-3) = `e` and vtcl(len-2) = `f` and vtcl(len-1) = `c` then
        vedchardelete();vedcolumn -> vv;
        vedchardelete();vedinsertstring('ine :class ;\n');
        vedpos(vv-5,'enddefine;');
        vedright(4);vedcharup();
    endif;
    vedsetcursor();
  endif;
enddefine;

define vedpos(no,str);
  if no > 0 then
    repeat no times
      vedinsertstring(' ');
    endrepeat;
  endif;
  vedinsertstring(str);
enddefine;

define vedleft(no);
  repeat no times
    vedcharleft();
  endrepeat;
enddefine;

define vedright(no);
  repeat no times
    vedcharright();
  endrepeat;
enddefine;

vedsetkey('\^[1', procedure; tim_vedprocesstrap -> vedprocesstrap endprocedure);
vedsetkey('\^[2', procedure; identfn -> vedprocesstrap endprocedure);

;;; turn it on by default
tim_vedprocesstrap -> vedprocesstrap;
--
   ---------------------------------------------------------------------
   Tim Read, Email: tmr@cs.bham.ac.uk, The Attention and Affect Project, 
   Cognitive Science Research Centre, School of Computer Science,
   The University of Birmingham, Edgbaston, Birmingham, B15 2TT, England
   Phone: +44-(0)21-414-4766, Fax: +44-(0)21-414-4281
   ---------------------------------------------------------------------