Google
 

Trailing-Edge - PDP-10 Archives - steco_19840320_1er_E35 - 10,5676/teco/macros/emacs.tco
There is 1 other file named emacs.tco in the archive. Click here to see a list.
!; TECmacros -- Emacs type macros in TECO %200!
!; To define new command just insert the text to be executed in a 	!
!; Q-register with the name of the following format:			!
!;									!
!;	COMMAND-x		; Normal one character commands		!
!;	META-x			; Meta commands (<ESC>X)		!
!;	CTL-X-x			; Control X commands (^X<char>)		!
!;									!
!; Where:								!
!;	x is the character that is the command.  Control characters are	!
!;	  CTL-x. Example:						!
!;		CTL-A - Control A command				!
!;		B     - Letter B command				!
!;		COMMAND-B - Just letter B defines the command		!
!;		META-B	  - <Escape>B defines the command		!

!; Set up the utility macros in serveral of the q-registers!

!; INPUT-LINE - Input a line and display on the bottom of the screen	!
!;		and store the text so it can be executed for searchs	!
!;		and file I/O						!
	E.(INPUT-LINE)@I\
	    E.(INPUT-TEXT)$HK$
	    !INPUT-LOOP!
		`^TU(CHR)			!; Input the character!
		Q(CHR)-`^O33"E OINPUT-DONE$'	!; Finished ?!
		Q(CHR)-`^O15"E OINPUT-DONE$'	!; ......    !
		Q(CHR)-`^O177"E E.(INPUT-TEXT)$-D$
		    E.(LAST-LINE)$-D$EVUPDATE$OINPUT-LOOP$'
		E.(INPUT-TEXT)Q(CHR)I$		!; Store in the text!
		E.(LAST-LINE)Q(CHR)I$EVUPDATE$	!; And in the last line!
		OINPUT-LOOP$			!; And loop back!
	    !INPUT-DONE!			!; Here if finished!
		E.(INPUT-TEXT)$I^R^R^R$$		!; Store an altmode!
\
!;INPUT-CHAR - This routine will input a single character and append!
!; it to the INPUT-TEXT buffer. It will also handle deletes.!
!;Note that it will return after each character (even deletes) with!
!;the character appended to INPUT-TEXT, and the character still in CHR!

	E.(INPUT-CHAR)@I\
		`^TU(CHR)	!; Get the character!
		Q(CHR)-`^O177"E E.(INPUT-TEXT) Z"N -D
		    E.(LAST-LINE)-D EVUPDATE$' !; Delete the char and the echo!
		    OINPUT-CHAR-DONE$'
		Q(CHR)-`^O33"N
		    E.(INPUT-TEXT) Q(CHR)I$	!; Insert the chracter!
		    E.(LAST-LINE)  Q(CHR)I$	!; And store in echo buffer!
		    EVUPDATE$'		!; Update the screen!
		!INPUT-CHAR-DONE!\

!; UPDATE-INFO-LINE - This will update the text stored in INFO-LINE!
	E.(UPDATE-INFO-LINE)@I\	E.(INFO-LINE)HK
	ITECmacros$`^O11I$:E<(.)"F :E>(.)$'$I
$\

!; NORMAL-DISPATCH - Normal character dispatch macro!
	E.(NORMAL-DISPATCH)$@I\:M(COMMAND-|)"FM(COMMAND-INSERT)'$\
!; META-DISPATCH - Dispatch routine for the meta charcter commands!
	E.(META-DISPATCH)$@I\:M(META-|)"FM(META-INSERT)$'$\
!; CTL-X-DISPATCH - Dispatch routine for the Control X commands!
	E.(CTL-X-DISPATCH)@I\:M(CTL-X-|)"FM(CTL-X-INSERT)$'$\
!; DO-DISPATCH - Macro the will transform a xxxx-DISPATCH into the	!
!;		 dispatch to the correct routine, or the default routine!
	E.(DO-DISPATCH)$@I\JFK|$Q(CHR)U(CHR-TEMP)
		Q(CHR-TEMP)-`^O177"E-1U(CHR-TEMP)'
		Q(CHR-TEMP)-`^O40"LICTL-$Q(CHR-TEMP)+`^O100U(CHR-TEMP)$'
		Q(CHR-TEMP)-`^O140"G Q(CHR-TEMP)-`^O173"L Q(CHR-TEMP)-`^O40U(CHR-TEMP)$''
		Q(CHR-TEMP)-^R^^)"EIR-PARN$E.(.)$W(DISPATCH)$'
		Q(CHR-TEMP)I$E.(.)$W(DISPATCH)$\
!; Normal commands!
	E.(COMMAND-CTL-A)@I\:0L$\
	E.(COMMAND-CTL-B)@I\:+Q(ARG)R$\
	E.(COMMAND-CTL-C)@I\:-4`^T`^C$\
	E.(COMMAND-CTL-D)@I\:+Q(ARG)D$\
	E.(COMMAND-CTL-E)@I\:+Q(ARG)L2R$\
	E.(COMMAND-CTL-F)@I\:+Q(ARG)C$\
	E.(COMMAND-CTL-G)@I\E.(LAST-LINE)HK\
	E.(COMMAND-CTL-H)@I\:-Q(ARG)D$\
	E.(COMMAND-CTL-J)@I\LI
$\
	E.(COMMAND-CTL-K)@I\:Q(ARG)K$\
	E.(COMMAND-CTL-L)@I\^L\
	E.(COMMAND-CTL-M)@I\I
$\
	E.(COMMAND-CTL-N)@I\:+Q(ARG)^R^D\
	E.(COMMAND-CTL-O)@I\I
$2R\
	E.(COMMAND-CTL-P)@I\:-Q(ARG)^R^D\
	E.(COMMAND-CTL-S)@I\
		.U(SEARCH-START)
		E.(LAST-LINE)HKII-search: $
		EVUPDATE$
		E.(INPUT-TEXT)HK
		M(INPUT-CHAR)
		Q(CHR)-`^O33"EONORMAL-SEARCH$'
		!SEARCH-LOOP!
		    E.(.)Q(SEARCH-START)J
		    :Q(ARG)S^R^G(INPUT-TEXT)$"F
			E.(LAST-LINE)ZJI  Failed$
			OSEARCH-DONE$'
		    EVUPDATE$			!; We found the string, update!
		    !SEARCH-CHAR-LOOP!
		    M(INPUT-CHAR)
		    Q(CHR)-`^O33"EOSEARCH-DONE$'
		    E.(INPUT-TEXT)Z"EOSEARCH-CHAR-LOOP$'
		    OSEARCH-LOOP$
		!NORMAL-SEARCH!
		E.(LAST-LINE)HKISearch: $
		EVUPDATE$
		M(INPUT-CHAR)
		Q(CHR)-`^O33"E
		    E.(INPUT-TEXT)HKG(LAST-SEARCH)
		    ODO-SEARCH$'
		<M(INPUT-CHAR)Q(CHR)-`^O33"E0;'>
		!DO-SEARCH!
		E.(.):Q(ARG)S^R^G(INPUT-TEXT)$"F E.(LAST-LINE)ZJI  Failed$'
		!SEARCH-DONE!
		E.(INPUT-TEXT)HX(LAST-SEARCH)\
	0,0X(LAST-SEARCH)	!; Initialize last searched for thing!

	E.(COMMAND-CTL-T)@I\.U(CUR-POS).,.+1X(TMP)DCG(TMP)Q(CUR-POS)J\
	E.(COMMAND-CTL-U)@I\
	    !CTL-U-TOP!
		E.(LAST-LINE)ICtl-U-$EVUPDATE$
		`^TU(CHR)
		4U(TEMP-ARG)
		Q(CHR)"D 0U(TEMP-ARG) OCTL-U-LP$'
		OCTL-U-DONE$
	    !CTL-U-LP!
		Q(CHR)"D Q(CHR)I$EVUPDATE$
		    Q(TEMP-ARG)*10+(Q(CHR)-`^O60)U(TEMP-ARG)
		    `^TU(CHR) OCTL-U-LP$'
	    !CTL-U-DONE!
		Q(ARG)*Q(TEMP-ARG)U(ARG)
		E.(DISPATCH)HKG(NORMAL-DISPATCH)JW(DO-DISPATCH)$\
	E.(COMMAND-CTL-X)@I\
		E.(LAST-LINE)$ICtl-X-$E.(.)$EVUPDATE$
		`^TU(CHR)E.(DISPATCH)$HKG(CTL-X-DISPATCH)M(DO-DISPATCH)\
	E.(COMMAND-CTL-[)@I\
		E.(LAST-LINE)$IMeta-$E.(.)$EVUPDATE$
		`^TU(CHR)E.(DISPATCH)$HKG(META-DISPATCH)M(DO-DISPATCH)\
	E.(COMMAND-CTL-?)@I\:-Q(ARG)D\
!; Meta commands!
	E.(META-CTL-C)@I\^R$^R$\
	[(COMMAND-CTL-G)](META-CTL-G)
	E.(META-B)@I\:-Q(ARG)S^R^N^R^E[^R^EA,^R^ED]^R^E[^R^EA,^R^ED]$"SR'\
	E.(META-F)@I\:+Q(ARG)S^R^E[^R^EA,^R^ED]^R^N^R^E[^R^EA,^R^ED]$"SR'\
	E.(META->)@I\<^R^N"L 0;'^R^E"L ZJ 12I'A>ZJ\
	E.(META-<)@I\J\
!; Control-X commands!
	[(META-CTL-C)](CTL-X-CTL-C)
	E.(CTL-X-CTL-E)$@I\:-4`^TEG$\
	E.(CTL-X-CTL-F)$@I\:-4`^TEX$$\
	[(COMMAND-CTL-G)](CTL-X-CTL-G)
	E.(CTL-X-CTL-R)@I\E.(LAST-LINE)HKIRead file: $EVUPDATE$
	    M(INPUT-LINE)E.(INPUT-TEXT)JI:ER$ZJI"F0U(FLAG)'$
	    1U(FLAG)
	    E.(.)M(INPUT-TEXT)Q(FLAG)"EE.(LAST-LINE)HKINot found$'
	    [1.U1
	    <^R"L 0;'   ^R"L ZJ 12I'   A>Q1J]1
	    M(UPDATE-INFO-LINE)\
	E.(CTL-X-CTL-W)@I\E.(LAST-LINE)HKIWrite file: $EVUPDATE$
	    M(INPUT-LINE)E.(INPUT-TEXT)JI:EW$ZJI"F0U(FLAG)'$
	    1U(FLAG)
	    E.(.)M(INPUT-TEXT)Q(FLAG)"EE.(LAST-LINE)HKIWrite failed$'
	    HPEF
	    M(UPDATE-INFO-LINE)\
	[(COMMAND-CTL-S)](CTL-X-S)
!; Insert commands!
	E.(COMMAND-INSERT)$@I\Q(ARG)<Q(CHR)I$>\
	E.(META-INSERT)$@I\I^R^R^R$$Q(CHR)I$\
	E.(CTL-X-INSERT)$@I\I^R^R^R^X$Q(CHR)I$\

!; Initialize the main q-register with the driver code!
	E.(EMACS)@I\
!; First turn off the echo!
	:-1^R^T$
!; Put the terminal into packed image mode!
	:-3^R^T$
!; Set up different screen areas!
	1,21E`$(.)$
	M(UPDATE-INFO-LINE)
	22,22E`$(INFO-LINE)$
	0,0X(LAST-LINE)$24,24E`$(LAST-LINE)$
	23,23E`$(COMMAND-BUFFER)$
!; Set to the normal editing buffer!
	E.(.)				!; Normal editing is in .!
!; Execute the initialization file!
	:EI(INIT-FILE)TMACS.INI$
	0U(INIT-FILE)$-1EC		!; Reclaim the space!
!; Main driving loop!
	!MAIN-LOOP!
		E.(.)			!; Back to the default edting buffer!
		EVUPDATE$		!; Update the screen!
		+1U(ARG)		!; Reset the argument counter!
		^R^TU(CHR)		!; Input the character!
		E.(LAST-LINE)$HK$	!; Clear any previous text!
		Q(CHR)-^R^^?"E?OMAIN-LOOP$' !; Allow for tracing on and off!
		E.(DISPATCH)$HK$G(NORMAL-DISPATCH)$
		M(DO-DISPATCH)		!; Dispatch on the item!
		OMAIN-LOOP$		!; Go get the next command!
\E.(.)
!; Now get rid of the EI'ed copy of the macro, do a garbage collection!
!; and start up the main loop of the macro!

0U*-1ECEEEMACS$W(EMACS)