Google
 

Trailing-Edge - PDP-10 Archives - mit_emacs_170_teco_1220 - emacs/tex.emacs
There are no other files named tex.emacs in the archive.
!* -*- TECO -*-		Library maintained by DCB@AI and KMP@MC !

!~Filename~:! !Macros for hacking TEX code!
TeX
!& Setup TeX Library:! !& Set up environment for being able to run TeX macros!

[0[1				    !* Get temp qregs			!
 128*5 fsqvectoru0		    !*   Create a qvector 200 long	!
 0u1				    !*   Init counter			!
 <q1-128; 5*q1:f0AA %1>	    !*   Init qvector with all alpha	!
 5*{+1:f0(			    !*   Give { a syntax of paren	!
 5*}+1:f0)(		    !*   Give } a syntax of paren	!
 5*\+1:f0/			    !*   Give \ a syntax of slash	!
 q0 m.v {TeX}_..D		    !*   Remember this ..D-like thing	!
]1]0				    !* Unbind temps			!


    @:I*/8M(M.M Untabify)	    !* Initialize TeXify Hook 		!
         ZJ
	 I
\par\end
  / M.C TeXify_Hook Macro_that_M-X_Texify_runs_on_buffer_copy'

				    !* Return				!
!Texify:! !C Save preprocessed copy of buffer for submission to TEX.
Runs contents of variable TeXify Hook on copy of buffer and
saves result under FN2 of TEX.  Numeric arg means prompt before
writing copy.  Virtual buffer boundaries are ignored.  TeXify
Hook is run as if from ^R mode with point at top of copied
buffer.  (Default value of TeXify Hook replaces tabs by spaces
and adds an \end command at the end of the buffer.) !

[0 [1 [2 [3 [4			    !* temporaries !

!* hack filenames !
Qbuffer_filenamesF"EW' F[ d file !* bind teco defaults to buffer filenames !
F6TEX FS d fn2		    !* change fn2 to TeX !
FS d file U1			    !* save hacked filename in q1 !

!* move buffer text to temp buffer and hack it !
0FO..Q TeXify_Hook  U0		    !* get hacking macro (or 0) in Q0 !
BU3 W ZU4			    !* save virtual buffer bounds !
0,FSz FS bound		    !* widen virtual bounds !
HX2				    !* grab buffer text !
Q3,Q4 FS bound			    !* restore virtual bounds !
0[..F W F[ b bind		    !* get new buffer !
G2 0J Q0"N @M0'			    !* get text and hack it !

!* write hacked buffer !
FF"N			    !* if arg !
    @M(M.M Write_File)'	    !*     prompt before writing !
"#				    !* otherwise !
    M(M.M Write_File)1'	    !*     just write it !
0 				    !* return !
!TeX Mode:! !S Set up for editing TEX code
Set syntax of $, \, %, {...}, etc appropriately.
<Tab>		 runs Indent Relative
<Rubout>	 deletes backward changing tabs to spaces
<Control-Rubout> deletes backward `normally'
{...}, [...], (...) flash matching delimiters according to
			setting of qDisplay Matching Paren and
			qPermit UnMatched Paren

Unless qInhibit TeX Dollarsign is created with a non-zero value,
     $ runs flashes matching dollarsign
 C-M-$ runs ^R Insert TeX $ Barrier !

m(m.m &_Init_Buffer_Locals)
M.Q..D				    !* Make a local qreg ..D		!
0FO..QTeX_..DF"N U..D'		    !* Dont copy ..D if dont have to	!
"#w :i..D ..D		    !* Copy ..D so we don't side effect	!
    Q..DM.VTeX_..D		    !* Remember this for next time	!
    5* :f..D__		    !* Backspace is whitespace		!
    5*.  :f..D__		    !* . is whitespace			!
    5*,  :f..D__		    !* , is whitespace			!
    5*|  :f..D_A		    !* | is pretty normal		!
    5*/  :f..D_A		    !* / is pretty normal		!
    5*$  :f..D_|		    !* $ is like vertical bars		!
    5*\  :f..D_/		    !* \ is like slash			!
    5*[  :f..D_(		    !* Brackets are like parens		!
    5*]  :f..D_)[		    !* Brackets are like parens		!
    5*{  :f..D_(		    !* Braces are also like parens	!
    5*}  :f..D_){'		    !* Braces are also like parens	!
qPermit_Unmatched_Paren"l	    !* If user hasn't inhibited feature,!
  1,0m.L Permit_Unmatched_Paren'   !*  Inhibit unmatched parens	!
0fo..Q Inhibit_TeX_Dollarsign "e   !* If user hasn't de-selected it	!
  1,(M.M^R_Insert_TeX_$_Barrier)m.Q...$ !* Put $ Barrier on C-M-$   !
  1,(M.M^R_Tex_$)M.Q$'	    !*    Put TeX $ into effect		!
1,(M.M^R_Indent_Relative)M.QI   !* Indent for Paragraph goes on Tab !
1,Q(1,Q.M.QW)M.Q. !* Swap rubout/control-rubout	!
1,(:i*%)M.LComment_Start	    !* Comment starts with %		!
1,(:i*%_)M.LComment_Begin	    !* Comment begins with %<Space>	!
1,55M.LComment_Column		    !* Comment column = 55		!
1m(m.m &_Set_Mode_Line)TeX	    !* Set mode line and return		!
!^R Insert TeX $ Barrier:! !^R Insert marker to restrict TeX $ scan a bit
TeX $'s will not scan behind this point to count $ parity ...!

.:\[1 fn1j :l .,(i	%_{].) !* Insert a barrier and return!
!^R TeX ":! !^R Make " insert appropriate quote marks -- `` or '' !

!* Note that this macro should probably not be turned on by default	!
!*      but may prove useful, so it is included for manual turning-on	!
!*	as desired by user...						!

*2[0				    !* Get arg times 2 in q0		!
-1,0a[1				    !* Get previous chahracter in q1	!
q1"b				    !* If prev char is a delimiter	!
  !"! q1f,.'?;:!:"l oClose' !*    Close if comma,period,quote	!
  q0,`i			    !*    (Else) insert q0 opens	!
  -q0'			    !*    Return affected region	!
!Close!				    !* Come here if close quotes	!
!"!q0<i'>			    !* Insert q0 close quotes		!
-q0				    !* Return affected region		!
!^R TeX $:! !^R Flash under the previous $ like parens do !

[0[1[2[3			    !* Temp qregs			!
q{TeX}_..D[..D		    !* Bind ..D				!
f@m(qA)f			    !* Self-Insert; update display data	!
:"g0'			    !* Handle degenerate case of 0 arg	!
0,-1a-\"e 0'		    !* backslashified $ is boring	!
2-(-@f$)+(@f$)"lfg 0'   !* Beep if too many $'s		!
qDisplay_Matching_Parenu1	    !* Get paren info in q1		!
q1"e0'			    !* Exit if no display requested	!
.:\u0 fn0j .u2		    !* Say to come back here when done	!
1:<-1ful c>"nj'			    !* Try to back up to last {		!
0u0				    !* Init parity count		!
<.-q2;				    !* Exit when we find our $		!
 .-1-(0,-1a-$"e1'"#0')u3	    !* Save point			!
 < s${ 0,-1a-\"n 		    !* Search for non-backslashed $ or {!
    0,0a-{"e r fll'		    !*  Skip tex boxes			!
    "# 0;'' >			    !*  Stop at a $			!
  0,1a-$"e c'			    !* Treat $$ like $			!
  1-q0u0'			    !* Update parity counter		!
>				    !* Loop				!
q0"g 0'			    !* Opens are not interesting	!
q3j				    !* Jump to where the last $ was	!
.-(fswindow)"l q1"l 0''	    !* Abort if limited display wanted	!
0@v 30*(q1):		    !* Display and sleep		!
0				    !* Return				!

!* Code that follows this is what was the TeXmac library *!
!Insert TeXmac Aux Macros:! !S Insert the macros TeXmac needs!

i%_\noflash{...text...}_makes_a_box_as_wide_as_its_arg,_but_which_is_whitespace
 \def\noflash#1{\save0\hbox{#1}\hbox_to_1wd0{\hfill}}

!UnSetup Indented TeX Display:! !S Undo a TeX Display !

q{TeX}_..D[..D		    !* Get TeX brace ..D in effect	!
f[vbw f[vz			    !* Bind virtual buffer		!
:l -:s\vbox"e			    !* Search back for a \vbox		!
  :i* NTD	No_TeX_Display  fserr'
.,( fll .)fsbound		    !* Put bounds around the \vbox	!
h m(m.m &_Save_for_Undo) UnSetup_Indented_TeX_Display 
j .,( s{ .)k zj -d		    !* Delete the \vbox			!
j <:s\hbox{; fkd		    !* Search for next backslashed thing!
   9f~\noflash{"e 9d		    !* Kill start of noflash if exists	!
     < 1a-}"e d 0; ' f_ c >'   !* Loop flushing chars in noflash	!
   ful -d			    !* Flush end of \hbox		!
  >				    !* Come here to iterate		!
j 				    !* Return				!
!Setup Indented TeX Display:! !S Makes an indented display from region !

[0[1 [I				    !* Allocate temp q-reg space	!
				    !*					!
f[vbw f[vz			    !* Bind virtual buffer bounds open	!
ff"e .,(w.)ffsbound'	    !* Maybe Set buffer bounds to region!
      "# j , fsbound'	    !* Set bounds to args if given	!
				    !*					!
h m(m.m &_Save_for_Undo) Setup_Indented_TeX_Display 
				    !*					!
j @f_	l		    !* Move across indentation		!
fsshpos"n			    !* If there is whitespace here,	!
  z:				    !* Set mark at end of buffer	!
  -(fsshpos( j			    !* Top line must not be indented	!
  ))@m(m.m^R_Indent_Rigidly)'	    !* Now pull whole display backward	!
				    !*					!
0uI				    !* Q-reg I for indent-related stuff	!
				    !*					!
j < .-z;			    !* Loop until last line		!
    @f_	l		    !*   Move across whitespace		!
    fsshpos,qIfuI		    !*   Get max of q0 and hpos in qI	!
    l >				    !*   Go down and continue		!
				    !*					!
qI,_:iI			    !* Make a buffer of qI chars in qI	!
				    !*					!
j < !Top! .-z;			    !* Loop until last line		!
"e i1a-ip5pt l oTop' !*   Blank lines just do vskip	!
    .u0 @f_	l	    !*   Move across indentation	!
    fsshposu1			    !*   Save current hpos (twice)	!
    q0,.k			    !*   Kill indentation		!
    0,q1:gIu0			    !*   Get indent-length substr in q0	!
    i\hbox{			    !*   Begin hbox			!
    q1"n i\noflash{ g0 i} '	    !*   Maybe yank filler text		!
    .,(fqI-q1)x0		    !*   Get rest of line (tail) in q0	!
    :l i}			    !*   End hbox			!
    q1:fI0			    !*   Merge new tail into qI		!
    l				    !*   Go down a line			!
  >				    !*   Continue loop			!
				    !*					!
j i\vbox{ zj i}		    !* Set return point			!
j z:				    !* Set point after region altered	!
				    !* Return				!