[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Dec 13 15:17:28 1993 
Subject:Re: Keyword Completion 
From:Ian Rogers 
Volume-ID:931214.03 

tmr@emotsun.bham.ac.uk (Tim Read) writes:
> 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

I've been slowly building up the following library over a number of
years. I've been reluctant to post it in the past because it has a
number of minor bugs, poor documentation and some of the code is
really old and crufty (I wrote some of it as a 2nd year undergrad -
eeek!)

I'm not trying to offend Tim but it has more features than Tim's
version and it should be easier to extend.

Season to your own tastes, but if you make any major modifications
I'd appreciate a copy, especially if the change included some docs
as I could then put the whole thing in the Pop archive.

Ian.

----- cut --- snip ----


/*	 File:			   VED_AUTO.P
	 Author:		   Ian Rogers
	 Machine:		   tsuna
	 Date:			   10th November 1986
	 Related Files:	   N/A
	 Purpose:		   Sets up all the automatic expansion bits that I know of.
					   I promise to tidy it up... one day...
 */

uses vedmatchbracket;

compile_mode :pop11 +normal;
compile_mode :pop11 +varsch +defpdr;

vars vedwiggling = true;

define macrotable = newmapping([], 8, false, true);
enddefine;

lvars p = newproperty([
		[d {'define' '' 'enddefine;'}]		[ed 'enddefine']
		[ds 'define syntax']
		[dom 'define:method']	[dc 'define:class']
		[dm 'defmethod']	[em 'enddefmethod']
		[fl 'flavour']		[efl 'endflavour']	[iv 'ivars']
		[ex 'external']		[ee 'endexternal']
		[exd 'external declare']	[dec 'declare']
		[exr 'external require']	[req 'require']

		[for {'for' '' 'endfor;'}]
		[For {'For' '' 'endfor;'}]
		[t 'then']			[ei 'endif']		[ef 'endfor']
		[lv 'lvars']		[va 'vars']			[ma 'macro']
		[lc 'lconstant']	[gl 'global']		[co 'constant']

		[r	{'repeat' '' 'endrepeat;'}]		[er 'endrepeat']
		[ul {'unless' '' 'endunless;'}]
		[ut {'until' '' 'enduntil;'}]		[until {'until' '' 'enduntil;'}]
		[wh {'while' '' 'endwhile;'}] 		[while {'while' '' 'endwhile;'}]
		[el 'endunless']	[et 'enduntil']		[ew 'endwhile']

		[if {'if' '' 'endif;'}]
		[l 'else']			[li 'elseif']		[lu 'elseunless']
		[ql 'quitloop']		[qi 'quitif']		[qu 'quitunless']

	[treu 'true']
	[flase 'false']		[fasle 'false']		[fales 'false']

	], 29,false,true);
p -> macrotable('p');
p -> macrotable('ph');
p -> macrotable('icd');

newproperty([
	[f	'fun']
	[t 'then']
	[l 'else']
	[e 'end']
	[or 'orelse']],5,false,true) -> macrotable('ml');

newproperty([
	[c 'cond']
	[d 'defun']
	[l 'lambda']], 5, false, true) -> macrotable('lsp');

newproperty([
	[d 'define']
	[l 'else']], 7, false, true) ->> macrotable('c') -> macrotable('ml');

newproperty([
	[teh the] [hte the] [Teh The]
	[nad and] [adn and] [liek like]
	[htat that] [fro for] [fo of]
	[t then] [l else]
	], 7, false, true) ->> macrotable('') -> macrotable('txt');


define mywiggleproccy(char);
lvars	char bra ket procedure (endtest mvpdr)
	;
dlocal vedwiggletimes = 3;
#_IF (pop_internal_version >= 136000)
	if vedwiggling and not(vedonstatus) and
			not(sysfiletype(vedcurrent) = '') then
		vedpositionpush();
		vedchoosebracket(char) -> endtest -> mvpdr -> bra -> ket;
		if mvpdr == vedcharleft then mvpdr() endif;
		vedfindbracket(bra, ket, endtest, mvpdr);
		vedwiggle(vedline, vedcolumn);
		vedpositionpop();
   endif
#_ENDIF
enddefine;

define indent_to_previous;
	lvars str tstop spstop c
		;
	vedtrimline();
	vedthisline() -> str;
	veddocr();
	returnif(not(vedcompileable) or vedonstatus or str = '');
	-1 -> c;
	for c with_index spstop in_string str do
		quitif(c /== `\s` and c /== `\t`);
	endfor;
	returnif(c == -1 or c == `\t` or c == `\s`);
	spstop - spstop mod vedindentstep -> tstop;
	until vedcolumn >= tstop do vedcharinsert(`\t`) enduntil;
	until vedcolumn >= spstop do vedcharinsert(`\s`) enduntil;
enddefine;

define vedlastword();
	lvars string vedtemp
		;
	lconstant
			alpha = item_chartype(`a`),
		;
	dlocal
			vedline vedcolumn
			%item_chartype(`&`)% = alpha,
			%item_chartype(`#`)% = alpha,
		;
	vedsetlinesize();
	if vedcolumn == 1 or vedcolumn > vvedlinesize + 1
			or (vedthisline() -> string; string(vedcolumn - 1) = ` `) then
		false
	else
		vedcolumn -> vedtemp;
		vedcharleft();
		until vedatitemstart(vedcolumn,string,vvedlinesize + 1) do
			vedcolumn - 1 -> vedcolumn;
		enduntil;
		consword(substring(vedcolumn,vedtemp-vedcolumn,string))
	endif
enddefine;

define vedwordbreak(vedoldthing);
	lvars	vedoldthing vedtemp last_word vedmacros x y
		;                    
	if not(vedonstatus) and
		(macrotable(sysfiletype(vedcurrent)) or macrotable('')) ->> vedmacros
	then
		if (vedmacros(vedlastword() ->> last_word) ->> vedtemp) then
			if vedtemp.isprocedure then
				vedtemp() -> vedtemp;
			endif;
			if isstring(vedtemp) then
				repeat length(last_word) times
					vedchardelete();
				endrepeat;
				vedinsertstring(vedtemp)
			elseif isvector(vedtemp) then
				repeat length(last_word) times
					vedchardelete();
				endrepeat;
				vedinsertstring(vedtemp(1));
				vedcolumn -> x;
				vedline -> y;
				if x >= vvedlinesize then
					vedinsertstring('\s');
					vedinsertstring(vedtemp(2));
					indent_to_previous(); 	
					vedinsertstring(vedtemp(3));
					vedjumpto(y, x);
				endif;
			endif
		endif;
	endif;
	vedoldthing();
enddefine;

define check_define(pdr);
	lvars	pdr, str, item,
			parms, rep;
		;
	vedwordbreak(pdr);
	vedthisline() -> str;
	returnunless(isstartstring('define\s', str));
	returnif(issubstring('/*', 1, str));
	
	[%	incharitem(stringin(str)) -> rep;
		for item from_repeater rep do
			nextunless(item == "(");
			until (rep() ->> item) == ")" do
				item,
				nextif((rep() ->> item) == ")")(2);
				if member(item, [: =]) then
					rep() -> ; rep() -> item;
				endif;
				unless item == "," then
					vederror('badly formed pdr args (no comma)');
				endunless;
			enduntil;
		endfor;
	%] -> parms;
	
	unless parms == [] then
		vedlinebelow();
		vedinsertstring('\tlvars\t');
		for item in parms do
			vedinsertstring(item sys_>< '');
			vedinsertstring(',\s');
		endfor;
		vedlinebelow();
		vedinsertstring('\t\t;');
	endunless;
	
	vedlinebelow();
	vedinsertstring('\t');
enddefine;

define ved_wig();
	not(vedwiggling) -> vedwiggling;
	vedputmessage('Wiggling ' sys_>< if vedwiggling then 'ON'
									 else 'OFF' endif)
enddefine;

define ved_macros();
	;;; sets auto macro stuff (default)
	vedsetkey(' ', vedwordbreak(% vedcharinsert(%` `%)%));
	vedsetkey('\t', vedwordbreak(% vedcharinsert(%`\t`%)%));
	vedsetkey(':', vedwordbreak(% vedcharinsert(%`:`%)%));
	vedsetkey(';', check_define(% vedcharinsert(%`;`%)%));
	vedsetkey(',', vedwordbreak(% vedcharinsert(%`,`%)%));
	vedsetkey('(', vedwordbreak(% vedcharinsert(%`(`%)%));
	vedsetkey(')', vedwordbreak(% vedcharinsert(%`)`%)%)
					pdcomp mywiggleproccy(%`)`%));
	vedsetkey('\^[;', ';;; ');
	vedsetkey('\^[?', ';;; ??? ');
	vedsetkey('\^[/', ';;; ??? ');
	vedsetkey('\^M', indent_to_previous);
enddefine;

define ved_nomacros();
;;; resets auto macro stuff
	vedsetkey(' ', vedinsertvedchar);
	vedsetkey('\t', vedinsertvedchar);
	vedsetkey(':', vedinsertvedchar);
	vedsetkey(';', vedinsertvedchar);
	vedsetkey(',', vedinsertvedchar);
	vedsetkey('(', vedinsertvedchar);
	vedsetkey(')', vedinsertvedchar);
	vedsetkey('\^M', veddocr);
enddefine;


define ved_auto();
	ved_macros();
enddefine;


----- cut ------- snip -----


HELP VED_AUTO                                                 Ian Rogers

This library provides various keyword substitution facilities.


         CONTENTS - (Use <ENTER> g to access required sections)

 -- Features
 -- Commands
 -- Known bugs


-- Features -----------------------------------------------------------

    o The substitution is based on property tables (which are easily
    extended)

    o The tables are associated with file extensions, (so that different
    associations occur for different file types),

    o The substitutions occur at key points of text entry (at: ' ',
    '\t', ':', ';', ',', '(', ')')

    o The return key automatically indents the next line.

    o parameter declarations are inserted automatically.


-- Commands -----------------------------------------------------------

The facilities are switched by the following two Ved commands:

ved_macros                                                   [procedure]
ved_nomacros                                                 [procedure]
        Respectively  switch  on  and   off  the  keyword   substitution
        facilities.

ved_auto                                                     [procedure]
        Identical to ved_macros.


-- Known bugs ---------------------------------------------------------

Indentation should really check the previous line for an opener or
closer and adjust accordingly.

Pop11 procedure output parameters are only discovered if they're inside
parentheses. Ie:

    define foo(a) -> (b, c);

and not:

    define foo(a) -> b -> c;

If you've already had your parameter declarations inserted, but want to
change the formal arguments, be careful not to delete the ; as you'll
get all the parameters reinserted when you type the ; again.


??? ?????/ved_auto
??? Copyright University of Sussex 1993. All rights reserved.