Google
 

Trailing-Edge - PDP-10 Archives - mit_emacs_170_teco_1220 - emacs/xpage.emacs
There are no other files named xpage.emacs in the archive.
!* -*-TECO-*- library written by David Eppstein <CSD.Kronj at SU-SCORE> !

!~Filename~:! !Macros for narrowing bounds to page!
PAGE
!& Setup PAGE Library:! !S Set environment for paging.
Search macros living on C-S and M-S are replaced with macros that
   execute the search over the whole buffer.
If the variable PAGE Setup Hook exists, it is macroed.
Otherwise, several keys are set:
   C-X ^P gets Page Menu
   C-X P  gets ^R Goto Page
   C-X ]  gets ^R Goto Next Page
   C-X [  gets ^R Goto Previous Page
   C-X W  gets ^R Widen Bounds
   C-M-L  gets ^R Insert Pagemark!

 -1fo..q PAGE_Load_Count+1 f"g uPAGE_Load_Count
    :i* PAGE_library_already_loaded fg 0'
 "# m.v PAGE_Load_Count'

 [0[1[2[3

 0m.c Current_Page !! 1fs Mode Ch
 1m.c PAGE_Flush_CRLF *_1_=>_Expect_a_CRLF_at_the_start_of_each_page

 0fo..q Set_Mode_Line_Hookf"e :i*'m.v PAGE_Old_Set_Mode_Line_Hook
 m.m &_PAGE_Set_Mode_Line_Hook m.v Set_Mode_Line_Hook

 0fo..q Buffer_Selection_Hookf"e :i*'m.v PAGE_Old_Buffer_Selection_Hook
 m.m &_PAGE_Buffer_Selection_Hook m.v Buffer_Selection_Hook

 m.m ^R_Narrow_Bounds_to_Region-q:.X(N)"e
    m.m ^R_Set_Bounds_Narrowu:.X(N)'

 m.m ^R_Incremental_Searchu0
 m.m ^R_String_Searchu1
 m.m ^R_PAGE_I-Searchu2
 m.m ^R_PAGE_String_Searchu3

 q.S-q0"e q2u.S'"# q.S-q1"e q3u.S''
 q..S-q0"e q2u..S'"# q..S-q1"e q3u..S''

 q0m.v PAGE_Old_I-Search
 q1m.v PAGE_Old_String_Search
 q2m.v MM_^R_Incremental_Search
 q3m.v MM_^R_String_Search

 0fo..q PAGE_Setup_Hookf"n u0 m0'
 m.m Page_Menuu:.X()
 m.m ^R_Goto_Pageu:.X(P)
 m.m ^R_Goto_Next_Pageu:.X(])
 m.m ^R_Goto_Previous_Pageu:.X([)
 m.m ^R_Widen_Boundsu:.X(W)
 m.m ^R_Insert_Pagemarku...L

 
!& Kill PAGE Library:! !S Undo definitions and key settings!

 qPAGE_Load_Count-1 :f"l uPAGE_Load_Count 0'

 [0[1[2[3
 m.m Kill_Variable

 mK PAGE_Load_Count

 m.m ^R_Set_Bounds_Narrow-q:.X(N)"e
    m.m ^R_Narrow_Bounds_to_Regionu:.X(N)'

 qPAGE_Old_I-Searchu1
 qPAGE_Old_String_Searchu2
 m.m ^R_PAGE_I-Searchu3
 m.m ^R_PAGE_String_Searchu4

 q.S-q3"e q1u.S'"# q.S-q4"e q2u.S''
 q..S-q3"e q1u..S'"# q..S-q4"e q2u..S''

 mK PAGE_Old_I-Search
 mK PAGE_Old_String_Search
 q1m.v MM_^R_Incremental_Search
 q2m.v MM_^R_String_Search

 m.m Page_Menu-q:.X()"e m.m ^R_Mark_Page u:.X()'
 m.m ^R_Goto_Page-q:.X(P)"e m.m ^R_Narrow_Bounds_to_Page u:.X(P)'
 m.m ^R_Goto_Next_Page-q:.X(])"e m.m ^R_Next_Page u:.X(])'
 m.m ^R_Goto_Previous_Page-q:.X([)"e m.m ^R_Previous_Page u:.X([)'
 m.m ^R_Widen_Bounds-q:.X(W)"e m.m ^R_Set_Bounds_Full u:.X(W)'
 m.m ^R_Insert_Pagemark-q...L"e 700.fs ^R Init u...L'

 qPAGE_Old_Set_Mode_Line_HookuSet_Mode_Line_Hook
 mK PAGE_Old_Set_Mode_Line_Hook

 qPAGE_Old_Buffer_Selection_HookuBuffer_Selection_Hook
 mK PAGE_Old_Buffer_Selection_Hook

 m(m.m ^R_Widen_Bounds)

 
!& PAGE Set Mode Line Hook:! !S Add page number to mode line!

 q:.B(qBuffer_Index+4!*bufbuf!)[..o	    !* look at main buffer!
 fs VZ+bf"e qCurrent_Page"n	    !* if bounds wide and page nonzero!
    0uCurrent_Page''		    !* set page back to zero!
 ]..o				    !* return to modeline buffer!

 qCurrent_Page"n .-z(-:s_Narrow"n fkd')+zj i_Page_ qCurrent_Page\'
				    !* flush "narrow", add page num!

 mPAGE_Old_Set_Mode_Line_Hook    !* call previous hook and return!
!& PAGE Buffer Selection Hook:! !S Make sure page number is a local variable!

 2,m.l Current_Page
 fs VZ+b"e 0uCurrent_Page'
 :mPAGE_Old_Buffer_Selection_Hook
!& Find Pagemark:! !S Look for Page Delimiter after CRLF.
Leaves point after the mark; returns the point before the mark.!

!* argument is like argument to S command
   if fails, leaves point at beginning/end of buffer
   assumes bounds are wide
   preceding crlf is not considered part of the mark!

 "e .'			    !* no arg is no-op!

 qPAGE_Delimiter[0
 0s 0	    !* set up search default!

 "l				    !* if neg arg!
    -<-:s"e j b'		    !* look for delimiter - fail, go to start!
	.-b-1"g -2f=
"n @''> !* check for crlf, continue!
    .[1 fkc'			    !* save point in q1 and move past!

 "# [0[1				    !* else...!
    <:s"e zj z'		    !* pos arg - search!
	.u0 fkc .-b-1"g -2f=
"n @'' (.u1 q0j)>'

 qPAGE_Flush_CRLF"n		    !* if it is expected!
    z-.-1"g			    !* and there is room for it!
	2f=
"e 2c'''	    !* move over crlf!
 q1				    !* return point before marker!
!& PAGE Widen Bounds:! !S Widen, re-narrow when caller exits!

 0uCurrent_Page		    !* clear current page number!
 fs VZ+b"n			    !* are bounds narrow?!
    m(m.m ^R_Widen_Bounds)	    !* yes, widen but prepare to narrow!
    @fn| qCurrent_Page"e m(m.m ^R_Goto_Page)' |'
!^R PAGE I-Search:! !^R Search for character string as you type it.
g(m.m~DOC~ ^R Incremental Search)jk!

 m(m.m &_PAGE_Widen_Bounds) f
 f@mPAGE_Old_I-Search
!^R PAGE String Search:! !^R Search for a character string.
g(m.m~DOC~ ^R String Search)jk!

 m(m.m &_PAGE_Widen_Bounds) f
 f@mPAGE_Old_String_Search
!^R Goto Page:! !^R Set bounds to a specific page.
If no argument, current page, or if already bounded, next page.
If positive argument, that page, numbered starting with 1.
If negative argument, that page counting back from the end.!

 fs Window b[B z[Z .[P	    !* save some parameters!
 [1 ff&1"e 0u1'		    !* 1: argument to ^R Goto Next Page!
 q1"e				    !* no arg or zero?!
    fs VZ+b"n 1u1''		    !* if already bounded, goto next page!
 "# 0,(fs Z)fs Bound		    !* else set bounds full!
    q1"l zj q1+1u1'		    !* neg arg, set to go back to right page!
    "# j q1-1u1''		    !* pos arg, number from one!

 0fs Bound			    !* set bounds narrow for Goto Next Page!
 q1m(m.m ^R_Goto_Next_Page)	    !* do the actual paging!

 qP:j"n qW:"l qW+qB-b :f"l fs Window z,z'''
				    !* try to return to original point!
 qW"l ' .-qB"l ' qZ-."l '	    !* if was out of bounds or no window, exit!

 .uP fn qPj			    !* return to point after window hackery!
 j f[VB f[VZ			    !* go to new start, push bounds!
 qB,qZfsBoundw qWfsWindow	    !* restore old bounds and window!
 fs Top Lineu1 .[0		    !* 1: new ^R V Pos, 0: saved point!
 0,0@fm <qW+b-.; -1,0@fm %1>	    !* count lines to top in q1!
 q0j q1fs ^R VPos		    !* set vpos, point back to new VB!
 0@:f				    !* scroll for redisplay!
 0fs Window			    !* set window!
 0				    !* return!
!^R Goto Next Page:! !^R Find the next page mark.
If bounds were narrow, they will be set narrow again.
An argument says how many page marks to look for.!

!* Pages are delimited by CRLF, qPAGE Delimiter
   followed by an optional CRLF if qPAGE Flush CRLF is set.!

 fs VZ+b"e			    !* if bounds are wide!
    0[PAGE_Flush_CRLF		    !* don't go past ^L!
    "l b'"# z'-."e fg'	    !* beep if nowhere to go!
    f"l(-c)'m(m.m &_Find_Pagemark)''

 0,(fs Z)fs Bound		    !* else widen bounds for search!
 :f"g-1'm(m.m &_Find_Pagemark)   !* go to beginning of page!
 z-."e -m(m.m &_Find_Pagemark)'

 .[1 fn q1j 1[2		    !* save point in 1, page num in 2!
 j <.-q1; %2			    !* stop when we have found where we were!
    1m(m.m &_Find_Pagemark)>	    !* loop going to next page!

 .,(1m(m.m &_Find_Pagemark)) fs Bound	!* set bounds!
 q2uCurrent_Page		    !* and current page!
 0fs Window			    !* and window!
 				    !* return!
!^R Goto Previous Page:! !^R Back up a page marker.
Like ^R Goto Next Page with a negative argument.!

 -:m(m.m ^R_Goto_Next_Page)
!^R Widen Bounds:! !^R Widen bounds to cover whole buffer.
Makes sure there is a CRLF at the end of the page.!

 .[1 fn q1j			    !* save point!

 qCurrent_Page"n		    !* if a page is selected!
    z-b-2"'l f"e z-2,z f=
'"n  !* if page doesn't end with a CRLF!
       zj i
''		    !* insert one (no need for fancy redisp)!
 0uCurrent_Page		    !* reset page number (forces fs ModeCh)!

 fs Window :f"l f( +b fs Window   !* fix window!
    )"e j 0,(fs Z) fs Bound	    !* if beg of page, go to top and bound!
	0@l .-fs Window"n	    !* if window was not start of line,!
	    .fs Window'''	    !* fix window!

 0,(fs Z) fs Bound		    !* widen bounds!
 				    !* return, full redisplay!
!^R Insert Pagemark:! !^R Insert or delete a page break.
With no arguments, inserts a page mark and leaves point on the second
page.  With a zero argument, leave point on the first page.
With a positive argument, delete page mark after point, and
with a negative argument, delete mark before point.!

 m(m.m &_PAGE_Widen_Bounds)	    !* widen but narrow when done!

 ff&1*"e			    !* if no arguments or zero arg!
    .[1 qPAGE_Delimiter	    !* 1: point, D: delimiter!
    .-1"g -2f=
'"# -1'"n	    !* if not already after crlf!
       i
'			    !* insert one!

     f D f"l w'"#, 0f'gD !* insert delimiter, being careful with ^O!

    qPAGE_Flush_CRLF"n	    !* if crlf expected after pagemark!
       z-.-1"g 2f=
'"# -1'"n !* and not one already there!
	  i
''		    !* insert another crlf!
    q1,.(ff&1"n q1j') '	    !* and exit!

 
 "g .[0 fnq0j		    !* pos arg...save point!
    1'"# .-z[0 fnq0+zj		    !* neg arg...!
    -1'm(m.m &_Find_Pagemark)[1    !* find mark, save retval!

 qPAGE_Flush_CRLF"n .-b-1"g	    !* if it can exist!
    -2f=
"e -2c'''	    !* save extra crlf!

 q1+2,.k 0			    !* kill pagemark and return!
!^R Set Bounds Narrow:! !^R Narrow buffer bounds to point and mark.!

 0uCurrent_Page		    !* Clear page number!
 f:m(m.m ^R_Narrow_Bounds_to_Region)	    !* and jump to old macro!
!Page Menu:! !C Display information about pages in buffer.
A recursive edit level is entered on a list of all pages.
On exit the page on the current line is selected.  Point is initially
on line of current page.
   Space exits (like ^R Exit).
     .   searches for the original page (marked with a ".").
     ?   prints this cruft.
     D   marks the current page for deletion.
     N   exits and makes a new page before the current one.
     U   removes a deletion mark.
     W   exits to the given page and sets bounds wide.!

 [0[1[2[3[4[5			    !* Save qregs used!
 fs QP Ptr			    !* Q: stack pointer for unwinding!
 q..ou0 .u1 f[BBind		    !* Save buf, get scratch buf!
 m.m &_Find_Pagemark		    !* P: page finder!
 iPageSizeFirstline
    !* Insert header line!

 1u2 q0[..o			    !* Init count, go back to main buf!
 m(m.m ^R_Widen_Bounds)w j	    !* Carefully widen bounds, go to start!
 < .(1mPu3 .u4)j		    !* Find end of page!
   .,q3fs Bound		    !* and bound to it!
   q1-.:"l q2u5'		    !* Maybe remember as current page!
   :sw 0@L @f	_l !* Go to beginning of first text line!
   @:x3 ]..o i__ g3		    !* Back to menu, add the line!
   q0[..o j			    !* Back to main again!
   0u3 <.-z; @l %3>		    !* Count lines page!
   ]..o 0@L q3\			    !* Back to menu, insert num line!
   5-(fs S HPos (0@L)),_i	    !* Indent to column!
   0@L q2\			    !* Insert page num!
   5-(fs S HPos (0@L)),_i	    !* Indent to column!
   zj fs S HPos-(fs Width)"g	    !* If line is too long!
     <-c fs Width-(fs S HPos);>   !* Move back to end of screen line!
     .,zk'			    !* Kill rest of line!
   i
			    !* Finish with a CRLF!
   q0[..o			    !* Back to main buffer again!
   0,(fs Z)fs Boundw q4j	    !* Go to next page!
   .-z; %2>			    !* Stop if end of buf else loop back!

 q1j				    !* Return to first point in main buf!
 ]..o				    !* Back to menu buffer!
 j q5@L				    !* Find line of current page!
 @f_l .-1f. 0@L		    !* Replace space with dot!

 0fs^R Init f(f[^R Normal) [  !* Insertion chars, del beep!
 m.m #_Page_Help[?		    !* Question mark describes menu!
 m.m #_Page_.[.		    !* Dot finds original page!
 m.m #_Page_D[D		    !* D marks for deletion!
 m.m #_Page_N[N		    !* N exits and makes a new page!
 m.m #_Page_U[U		    !* U clears deletion mark!
 m.m #_Page_W[W		    !* W exits and remains wide!
 fs ^R Init[_		    !* Space exits!

 qBuffer_Filenamesu1		    !* Get buffer filenames!
 fq1:"g qBuffer_Nameu1	    !* If none, use buffer name!
        :i1buffer_1'		    !*    with word buffer prepended!
 :i*Page_Menu_of_1[..J	    !* Mung mode line!
 0[..F				    !* Dont allow funny buffer changes!
 0fs Window			    !* Try to keep entire menu on screen!

 f< !Page_Menu! 0u1 		    !* Enter recursive edit!
    0@L @f_L 0,1a-."e c'	    !* Go to first text on line (ignore dot)!
    \u1 -q1:;			    !* Find number and exit loop if good!
    @fg 0@L>u2			    !* Else beep and go to line start!

 q2f"n-1 f"e-1' u1'		    !* If making new page, set page num!
 -q2f"g u1'			    !* If exiting wide, set page num!

 0[9 m.m &_Kill_Text		    !* Get text kill macro!
 q0[..o j ]..o 1u3		    !* Go back to start of main buf, set pos!

 j< @L @f_L .-z;		    !* Loop on lines in menu buf!
    0,1a-D"e c		    !* If page is marked for deletion!
       0,1a-."e c'		    !* Maybe move over dot!
       \u4 q4"g			    !* Get page num.  If in range!
	  q0[..o q4-q3mPw q4u3	    !* Find appropriate page in main buf!
	  q4-q1"l q1-1u1'	    !* Maybe fix return page number!
	  .,(1mPw .)mK		    !* Kill the text (undoable)!
	  ]..o ''>		    !* Clean up for next iteration!

 qQ fs QP Unwind		    !* Pop pushed buffers etc.!
 -fs Window			    !* Dont scroll when bounding to page!
 q1m(m.m ^R_Goto_Page)		    !* Go to the appropriate page!

 q2f"g-1"e zj'"# 0'm(m.m ^R_Insert_Pagemark)'
				    !* Make new page if appropriate!
 q2"l -fs Window		    !* Else maybe flush window!
      m(m.m ^R_Widen_Bounds)'	    !* ..and widen again!
 -fs ^R Last			    !* Dont leave as kill key command!

!# Page Help:! !S Describe Page Menu.!

 m(m.m Describe) Page_Menu 
!# Page .:! !S Go to page marked with dot.!

 j <@L @f_L .-z;		    !* loop: go to next line!
    0,1a-D"e c'		    !* skip over deletion mark if any!
    0,1a-."e 0@L 0'>	    !* return if next char is a dot!
 @fg 0			    !* else beep and return!
!# Page D:! !S Mark page to be deleted.!

 0@L @f_ f("e @fg 0')L	    !* beg of line, skip at least one space!
 0,1a-D"e :i* Page_already_marked_for_deletion @fg 0'
 .-1fD -(0@L)		    !* change space to D and return!
!# Page N:! !S Make a new page before current page.!

 0@L @f_L			    !* Go to start of line past space!
 0,1a-D"e c' 0,1a-."e c'	    !* Skip over deletion mark, dot!
 .-z"e 1f;Page_Menu'		    !* Maybe make page at end of buf!
    "# \[1 q1:"g @fg 0'	    !* Else find page number!
       q1+1f;Page_Menu'	    !* And make new page before it!
 
!# Page U:! !S Remove deletion mark.!

 0@L @f_L			    !* beg of line, move over spaces!
 0,1a-D"n @fg 0'		    !* make sure there is a D!
 f_ (0@L)		    !* turn D into space and return!
!# Page W:! !S Exit menu with widened bounds.!

 0@L @f_L 0,1a-."e c'	    !* Go to where number should be!
 \[0 q0:"g @fg 0'		    !* Get num, check if in bounds!
 -q0f;Page_Menu		    !* If ok, break loop with it!