!* -*- Teco -*- Library created/maintained by KMP@MC *! !~Filename~:! !Macros for hacking text sketches! SKETCH !& Setup Sketch Library:! !S Set up this library after load ! 0 fo..QLast_Sketch_Namem.vLast_Sketch_Name 0 fo..QLast_Sketch_Library_Namem.vLast_Sketch_Library_Name m.m^R_Sketch_Dispatchu...S !* Set up dispatch on c-m-S ! !Insert Sketch:! !C Insert a named text sketch! m.m&_Insert_Sketch,(:i*Insert) :m(m.m&_Sketch_Prompt) !& Insert Sketch:! !S Insert a sketch with a given name (numeric arg)! 1,m(m.m &_Find_Sketch)[0[1 !* q0: Sketch ! !* q1: Position ! .[2 !* Point in q2 ! g0 q2+q1j !* Get text and move point ! q2,fq0 !* Return region changed ! !Edit Sketch:! !C Edit a named text sketch! m.m&_Edit_Sketch,(:i*Edit) :m(m.m&_Sketch_Prompt) !& Edit Sketch:! !S Edit a sketch with a given name (numeric arg)! [0[1 !* Temp qregs ! [..J !* Bind Mode line ! 0[..F !* Disalbe autosave ! u0 !* q0: Sketch name ! !Retry! qLast_Sketch_Library_Nameu1 !* q1: Library name ! q1"e @m(m.mVisit_Sketch_Library) oRetry' !* Force user to visit lib ! e[fne] !* Bind input stream ! e\fne^ !* Bind output stream ! f[dfile !* Bind Teco file defaults ! f[bbind !* Bind a temp buffer ! er1@y j !* Yank input file ! 0f[modifiedw 0f[xmodifiedw !* Bind modified flags ! :s 0î "l !* Find sketch ! :i..J(Editing_Sketch_"0")!''! .,( s  r .)fsbound' !* Set bounds ! "# :s :"l zj i  ' g0 iî  r :i..J(Creating_Sketch_"0")!''! .,(i~.)fsbound' !* Maybe make a place ! [C fsosteco"e :iCC ' "# :iCZ ' :i..J..J__"~"_marks_point,_c-m-C_exits,_c-]_aborts!''!  !* Allow user editing ! et1 !* Assure file defaults ! 0,(fsz)fsbound !* Set bounds back wide ! ew hp ef !* Write out changes ! fsofile :i*CSketch_Library_"O"_Written !''!fsechodisw 0fsechoactive !* Say we won ! 0 !* Return no changes ! !View Sketch:! !C View a named text sketch! m.m&_View_Sketch,(:i*View) :m(m.m&_Sketch_Prompt) !& View Sketch:! !S View a sketch with a given name (numeric arg)! [0[1 !* q0: Temp ! 0f[^RStar !* Kill star in mode line ! u0 :i*(Sketch_"0")!''![..J fr!* Set mode line ! q0m(m.m &_Find_Sketch)u1 !* q1: Sketch ! ft1 !* Display sketch ! :fiw !* Pause ! 0 !* Return no change ! !& Sketch Prompt:! !S Prompt for name and call continuation Continuation (a macro) is arg1; prompt type (a string) is arg2. ! [L[P[N !* Temp qregs ! :f "l !* If interactive, ... ! uP !* P: prompt substring ! qLast_Sketch_NameuL !* L: Last sketch ! :iP P_Sketch !* Build base prompt string ! fqL:"l :iP P_(L)' !* Set up to show default ! 1,m(m.m&_Read_Line)P:_uN' !* N: New input ! "# :iN' !* Non-interactive case ! fqN"e qLast_Sketch_Name uN ' !* If crlf, use default ! "# qN uLast_Sketch_Name' !* else remember input ! qN m() !* Call continuation ! !& Find Sketch:! !S Return a sketch with a given name ! [0[1 !* Bind temp qregs ! u0 !* q0: Sketch name ! qLast_Sketch_Library_Nameu1 !* q1: Library name ! q1 m(m.m &_Prepare_Sketch_Library_Visit) !* Loop ! :i*NST No_such_sketch_"0"_in_"F" fserr !''''! !& Sketch Library Prompt:! !S Prompt for library name and call continuation Continuation (a macro) is arg1; prompt type (a string) is arg2. ! [L[P[N !* Temp qregs ! m(m.m&_Sketch_Set_File_Defaults) !* Set defaults ! qLast_Sketch_Library_NameuL !* L: Last sketch ! qL"n qL fsdfile ' !* Merge with file defaults ! :f "l !* If interactive, ... ! uP !* P: prompt substring ! 5,m(m.m&_Read_Line)P_Sketch_LibraryuN' !* N: New input ! "# :iN' !* Non-interactive case ! fqN"g etN ' !* Merge file defaults ! fsdfile f( uN ) uLast_Sketch_Library_Name !* Pick up default ! qN m() !* Call continuation ! !List Sketch Library:! !C List the contents of the sketch library! [Last_Sketch_Library_Name m.m&_List_Sketch_Library,(:i*List):m(m.m&_Sketch_Library_Prompt) !& List Sketch Library:! !S List a library's contents (name is numeric arg2) ! m(m.m &_Prepare_Sketch_Library_Visit) !* Set up buffer for library visit ! ftSketches_in_file_"F"... !''! < m(m.m&_Find_Next_Sketch) !* Iterate across sketches ! z@; !* Exit if empty ! ft_ t> !* Type name of each sketch ! ft----------  :fiw !* Pause ! 0  !* Return no change to buffer ! !& Prepare Sketch Library Visit:! !S Set up for sketch library perusal Gets a fresh (temp) buffer and opens the library. Calls to & Find Next Sketch will visit successive entries in the library.! f[bbind !* Get temp buffer ! f[dfile !* Bind default filename ! e[ fn e]  !* Bind input channels ! [F !* Get arg as qF ! erF a !* Yank header area ! !* Do NOT pop anything upon return ! !& Find Next Sketch:! !S Visit the next sketch in an open library. The library must have been opened by & Prepare Sketch Library Visit. If no next sketch is found, the buffer is left empty; a sketch will always have at least one char, so this isn't ambiguous.! hk !* Kill existing text ! < a zj 0,0a- "n hk 0; ' !* Empty and exit if no c-L ! 0,-1a-:@; > !* Yank next entry ! j !* Jump to top of entry ! !& Process Sketch:! !S Scan the current sketch removing syntactic markers. Kill the sketch's name, the trailing c-L, hack c-Q's and maybe variables. With a precomma arg, also processes 's, prompting for values in the echo area.! [Last_Sketch_Name [0[1 !* Temp Qregs ! -1u0 !* q0: Impossible buffer position ! j k !* Kill header line ! zj 0a- "n oFormatErr ' !* Assure C-L just in case ! -d j !* Delete it ! <:s~<!>!; !* Search for c-Q, ~, or angle bracket ! 0a-"e -d c ' !* If c-Q, delete and pass quoted char ! "# 0a-~"e !* If ~, ! q0:"l oFormatErr ' !* If one already seen, err ! "# -d .u0 '' !* else remember pos ! "# 0a-!"e "n -d .,( !* If angle bracket, maybe... ! ! -d !* find and kill its match ! .)fx* m(m.m&_Hack_Sketch_Var)''''> !* and insert named text ! q0"l zj ' "# q0j'  !* Jump to marked pos or end ! !FormatErr! !* Come here to handle format errors ! :i*FMT Bad format in sketch entry !& Hack Sketch Var:! !S Prompt for and insert named text (numeric arg2) Uses sticky defaulting on names! [0[1[2[3[C !* Temp qregs ! u0 !* q0: Name ! 0fo..QSketch_0_Varu1 !* q1: Default ! fq1"l :i2 ' "# :i2_(1)' !* q2: Default prompt ! !Prompt! :i*C0_(or_c-R_or_Alt):_fsEchoDis !* Fake prompt ! fi uC !* Get char in qC ! qC-"e !* If c-R ! f[bbind !* Get temp buffer ! [C fsosteco"e :iCC ' "# :iCZ ' :i*(Filler_for_"0")_End_with_c-m-C__!''![..J  ]..J ]C w g(hfx*(f]bbindw)) '!* Edit, yank text ! qC-"e !* If Altmode, ! @m(m.mInsert_Sketch) !* Recurse into Insert Sketch ! ' !* ! qC-?"e ftType_text_to_be_used_for_this_sketch_field_(ended_by_Return) _or_type_Control-R_to_be_able_to_type_this_text_into_an_editor_buffer _or_type_Altmode_to_use_a_sketch_to_fill_this_field. ----------  oPrompt' qC-_"e -1uC' !* Leading space is no-op ! qC fsreread !* Untyi the char ! 1,m(m.m&_Read_Line)02:_u3 !* q3: New value ! !Default! fq3"g q3u1 ' !* Maybe update default ! q1"n q1m.vSketch_0_Var !* Maybe make default permanent ! g1' !* and get value in buffer !  !* Return ! !Visit Sketch Library:! !C Makes a sketch library current ! f[dfile !* Bind default file ! m(m.m&_Sketch_Set_File_Defaults) !* Set defaults ! 5,f Visit_Sketch_Library !* Prompt for library name ! etL !* Set file defaults ! fsdfileuL !* Get fully qualified name ! e?"n !* If file doesnt exist ! @ft Sketch_library_"L"_doesn't_exist.__Create? !'! 1m(m.m &_Yes_or_No)"n m(m.mCreate_Sketch_Library)L '' fsdfile uLast_Sketch_Library_Name!* Update defaults ! 0 !* Return no change ! !Create Sketch Library:! !C Makes a new sketch library! e\fne^ !* Bind output channel ! f[Dfile !* Bind default filenames ! m(m.m&_Sketch_Set_File_Defaults) !* Set defaults ! 5,f Create_Sketch_Library !* Read library name ! qLfsdfile !* Use the library name we saw ! f[bbind !* Get temp buffer ! i -*-_Text_-*-__This_is_an_Emacs_SKETCH_library. Created_ m(m.m Insert_Date) zj i_by_ g(fsuname:f6) i.î  !* Get username, date, etc ! ew hp ef !* Write file ! fsofileuL !* Get name written to ! @ftSketch_Library_"L"_created.  !''! 0fsechoactive !* Display success ! 0 !* Return ! !^R Sketch Dispatch:! !^R Dispatch to appropriate sketch command! fn q..H"n 0u..H @v'  !* Set up to flush typeout ! [0[1 !* Temps ! 60:"e !* Pause awaiting input ! !Prompt! :i*CSketch_Command:_ fsEchoDisplay' !Retry! fi :fc u0 !* q0: Dispatch character ! q0-E"e !* If E, ! f@:m(m.mEdit_Sketch)' !* Edit Sketch ! q0-I"e !* If I, ! f@:m(m.mInsert_Sketch)' !* Insert Sketch ! q0-V"e !* If V, ! f@:m(m.mView_Sketch)' !* View Sketch ! q0- "e !* If c-L, ! f@:m(m.mList_Sketch_Library)' !* List Sketch Library ! q0-"e !* If c-V, ! f@:m(m.mVisit_Sketch_Library)' !* Visit Sketch Library ! q0-Q"e 0' !* If Q, return ! q0-H"e [L ftTo_use_a_sketch,_you_must_visit_a_sketch_library. Currently,_you_are_ qLast_Sketch_Library_NameuL qL"n ft visiting_the_sketch_library_"L".!''! ' "# ft not_visiting_any_sketch_library. ' ft î You_can_visit_ qL"n ft another_ ' "# ft a_ ' ft sketch_library_by_typing_c-V_now. You_can_list_the_contents_of_a_library_by_typing_c-L_now. _  qL"n ft Since_ ' "# ft Once_ ' ft you_have_visited_a_library,_you_can_insert_a_sketch_from that_library_by_typing_I qL"n ft_now ' ft .__To_create_a_new_sketch_or_modify an_existing_one,_you_can_type_E qL"n ft_now ' ft .__Or,_if_you_just_want to_see_an_existing_sketch_without_inserting_it,_you_can_type_V qL"n ft_now ' ft . ----------  ]L oPrompt' (q0-?)*(q0-)"e ftSketch_commands: ___E__Edit_(or_create)_Sketch ___I__Insert_Sketch ___V__View_Sketch _ Sketch_Library_Commands: _c-L__List_Sketch_Library _c-V__Visit_Sketch_Library _ Type_H_for_more_info.__Type_Q_to_exit_this_mode. ----------  oPrompt ' !* Return no change ! fg !* Beep ! :i*CSketch_Command_(E,_I,_V,_c-L,_c-V,_or_?):_fsEchoDisplay oRetry !* Retry ! !& Sketch Set File Defaults:! !S Set file defaults for a Sketch library! qLast_Sketch_Library_Namef"n fsdfile ' !* Sticky defaults ! "#w fshsname fs dsname !* Default dir is homedir ! fsxuname fs dfn1 !* Default fn1 is username ! 0 fs version !* Default version is highest ! f6SKETCH fs dfn2' !* Default fn2 is SKETCH !