Skip to content

Instantly share code, notes, and snippets.

@g000001
Created November 5, 2016 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save g000001/040b0036653e7c68646b4d4a32e1b7b8 to your computer and use it in GitHub Desktop.
Save g000001/040b0036653e7c68646b4d4a32e1b7b8 to your computer and use it in GitHub Desktop.
Library for PROLOG Editing System by T.Chikayama
!* -*-TECO-*- Library for PROLOG Editing System by T.Chikayama!
!~FILENAME~:! !Package for programming in PROLOG!
PROLOG
!& Setup PROLOG Library:! !& Set up environment for editing PROLOG codes.
Make *PROLOG* buffer for later use.!
F[D File◊ !* Save Teco Default Filename. !
1,:I**PROLOG*◊M(M.M &_Find_Buffer◊)"L !* If no *PROLOG* buffer yet,!
Q◊Buffer_Name◊[0 !* Save current buffer's name. !
M(M.M Select_Buffer◊) *PROLOG*◊ !* Create *PROLOG* buffer. !
M(M.M PROLOG_Mode◊) !* Put in PROLOG Mode. !
M(M.M Select_Buffer◊) ≥0◊ ' !* restore previous buffer. !
]0 F]D File◊ !* Restore saved Registers. !
≤ !* Return. !
!PROLOG Mode:! !C Set up for editing PROLOG code.
Set syntax of "...", '...', %, [...], {...}, etc appropriately.
{...}, [...], (...) flash matching delimiters according to
setting of q◊Display Matching Paren◊ and q◊Permit UnMatched Paren◊.
Define several PROLOG-oriented command keys.!
m(m.m_&_Init_Buffer_Locals◊) !* Discard locals of old mode, and set: !
M.Q..D◊ !* Make a local qreg ..D !
0FO..QPROLOG_..D◊F"N U..D' !* Dont copy ..D if dont have to !
"#w :i..D ≥..D◊ !* Copy ..D so we dont side effect !
Q..DM.VPROLOG_..D◊ !* Remember this for next time !
5*≡% :f¬..D_;◊ !* % starts comment !
5*≡, :f¬..D__◊ !* , is whitespace !
5*≡; :f¬..D__◊ !* ; is whitespace !
5*≡" :f¬..D_|◊ !* double quotes and !
5*≡' :f¬..D_|◊ !* quotes are like vertical bars !
5*≡| :f¬..D_A◊ !* |s are normal special characters !
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 !
1,(:i*%◊)M.LComment_Start◊ !* Comment starts with % !
1,(:i*%_◊)M.LComment_Begin◊ !* Comment begins with %<Space> !
1,(:i*/8+1*8◊)M.LComment_Rounding◊w !* Comment rounding... !
1,40m.LComment_Column◊w !* Set comment column !
q◊Permit_Unmatched_Paren◊"l !* If user hasn't inhibited feature,!
1,0m.L Permit_Unmatched_Paren◊' !* Inhibit unmatched parens !
M.M ^R_Tab_to_Tab_Stop◊ M.Q≡I◊ !* <Tab> becomes ^R Tab to Tab Stop !
1,Q⋂∫(1,Q.⋂∫ M.Q⋂∫◊W )M.Q .⋂∫◊ !* Exchange rubout flavors.!
!* <Delete> hacks tabs !
M.M ^R_Uppercase_Initial◊ M.Q..⋂c◊w !* M-c is standard M-C !
M.M ^R_Center_Line◊ M.Q..⋂s◊w !* M-s is standard M-S !
M.M ^R_PROLOG_Center_Comment◊ M.Q..⋂C◊w !* M-C !
!* M.M ^R_PROLOG_Beginning_of_Clause◊ M.Q..⋂a◊w M-a !
M.M ^R_PROLOG_End_of_Clause◊ M.Q..⋂e◊w !* M-e !
M.M ^R_PROLOG_Zap_for_Reconsult◊ M.Q..⋂z◊ !* M-z !
M.M ^R_PROLOG_Zap_for_Compile◊ M.Q..⋂Z◊ !* M-Z !
M.M ^R_PROLOG_Save_Region◊ M.Q..⋂S◊ !* M-S !
1M(M.M&_Set_Mode_Line◊)PROLOG◊ !* Set mode!
≤ !* Done. !
!^R PROLOG Save Region:! !^R Store Region between Mark and Point to *PROLOG*.
Contents of *PROLOG* is to be passed to inferior PROLOG later.
Stuff is appended to the contents of the *PROLOG* Buffer.
If given argument (e.g. ≤^R Universal Argument≤), also select the buffer. !
M(M.M &_PROLOG_Save_Region◊)
F←F→"N M(M.M Select_Buffer◊) *PROLOG*◊ '
!& PROLOG Save Region:! !S Store Region between Mark and Point to *PROLOG*.
The Region is appended to the contents of the *PROLOG* Buffer.
A pair of arguments may be given instead of the Mark,
if called from a Teco program. !
F[VB◊ F[VZ◊ !* Save Virtual Bounds. !
F←F→"E :⊗,.' "# F←' F· FS Boundaries◊ !* Bind them to the Region. !
Q..O[3 !* Save Region in Q Register 3. !
Q:.B(:I* *PROLOG* ◊M(M.M &_Find_Buffer◊)◊+4) [..O
!* Select *PROLOG* Buffer. !
ZJ !* Make sure pointer at end of Buffer. !
G3 !* Insert Region into *PROLOG* Buffer. !
0 !* Nothing changed in Buffer. !
≤ !* Restore Everything and Return. !
!& PROLOG Zap to PROLOG:! !& Call inferior PROLOG fork.
String argument is passed to the PROLOG fork.!
[1 :I1≥←◊
:FR◊ !* Clear Mode Line. !
:I*⊂Z◊ FS Echo Display◊ !* Put cursor at bottom of screen. !
0 FS Echo Char◊ !* Dont echo when continued. !
M(M.M^R_Invoke_Inferior◊)PROLOG◊≥1⊃M⊃◊⊃◊◊
≤ !* Return. !
!^R PROLOG Zap for Compile:! !^R Call inferior PROLOG fork
If called with no argument, writes out *PROLOG* buffer
to be passed to PROLOG to be compiled.
If called with argument, just calls PROLOG directly. !
F←F→"N !* If with arg, !
!""!
M(M.M&_PROLOG_Zap_to_PROLOG◊)write('Resuming_PROLOG_...'), nl.◊'
"#
M(M.M&_PROLOG_Write_*PROLOG*_Buffer◊)
!* write out *PROLOG* Buffer. !
!""""""""!
M(M.M&_PROLOG_Zap_to_PROLOG◊)compile('-TEMP-.DEL'),(rename('-TEMP-.DEL',[]);see('-TEMP-.DEL'),see(user),rename('-TEMP-.DEL',[])).◊'
≤ !* Return. !
!^R PROLOG Zap for Reconsult:! !^R Call inferior PROLOG fork
If called with no argument, writes out *PROLOG* buffer
to be passed to PROLOG to be reconsulted.
Also useful for executing a lengthy piece of program.
If called with argument, just calls PROLOG directly. !
F←F→"N !* If with arg, !
!""!
M(M.M&_PROLOG_Zap_to_PROLOG◊)write('Resuming_PROLOG_...'), nl.◊'
"#
M(M.M&_PROLOG_Write_*PROLOG*_Buffer◊)
!* write out *PROLOG* Buffer. !
!""""""""!
M(M.M&_PROLOG_Zap_to_PROLOG◊)reconsult('-TEMP-.DEL'),(rename('-TEMP-.DEL',[]);see('-TEMP-.DEL'),see(user),rename('-TEMP-.DEL',[])).◊'
≤ !* Return. !
!& PROLOG Write *PROLOG* Buffer:! !& Write *PROLOG* to temporary file. !
Q:.B(:I* *PROLOG* ◊M(M.M &_Find_Buffer◊)◊+4) [..O
!* Select *PROLOG* Buffer. !
F[D FILE◊ !* Save Default File Name. !
FS MSName◊FS DSName◊ !* File goes on Current Directory. !
ET -TEMP-.DEL◊ !* Set up Output File Name. !
EI HP EF◊ !* Write Buffer. !
F]D FILE◊ !* Restore Default File Name. !
HK !* Clear Buffer. !
]..O◊ !* Restore Old Buffer. !
!^R PROLOG End of Clause:! !^R Go to the end of a PROLOG clause.
A PROLOG clause ends with a period at the end of the buffer
or followed by either one of blank, tab, CR, LF, or %.
Repeats given arg times. Negative arg is not allowed. !
(F←F→"E 1'"# →') M(M.M&_PROLOG_End_of_Clause◊)
!^R PROLOG Center Comment:! !^R Center comment filling % both sides!
q◊Fill_Column◊[1 !* Fill Column in Q1 !
:l-@fα_%≥⊃ ◊k !* Squeeze trailing blanks, tabs and %s!
0l@fα_%≥⊃ ◊k !* Squeeze leading blanks, tabs and %s!
i__◊ !* Two blanks!
:l !* Go to line end!
i__◊ !* Two blanks!
fsshpos◊[2 !* Horizontal position in Q3!
q1-q2/2-1,≡%i !* Fill %s !
fsshpos◊u2 !* Horizontal position in Q2!
0l !* Goto beginning of line!
q1-q2,≡%i !* Fill %s!
]2]1 !* Restore registers!
≤ !* Return!
!& PROLOG End of Clause:! !S Go to the end of a PROLOG clause.
Repeats number of arg times.
If search fails, returns precomma arg (default -1).
Otherwise, returns 0.!
[1
→< !* Repeat for given arg. !
(:S⋃;∂⋃|∂.◊)U1 !* Search next comment, quote or period !
Q1"E !* If search fails: !
F←F→-1"EFG -1≤' !* With one arg, grumble & return -1. !
"# ←≤'' !* Otherwise, return 1st arg. !
%1"E(:S⋃M◊);!<!@>' !* If comment, find comment ender. !
%1"E0A:I1(:S≥1◊);!<!@>' !* If quote, find another. !
(Z-.)"E !* When end of buffer: !
F←F→-1"FG -1≤' !* With one arg, grumble & return -1. !
"# ←≤'' !* Otherwise, return 1st arg. !
(1A-≡%)"'N&(1A-33)"'G"N!<!@>' !* If next is not % nor a control char !
!* nor a blank, not really end of term. !
-AFα@#$^&*-+=`~<>/\.◊:"L!<!@>' !* If last is an ordinary special char,!
!* not really end either. !
> !* Otherwise, loop counting down. !
0≤ !* Return 0. !
!& PROLOG Beginning of Clause:! !S Go to the beginning of a PROLOG clause.
Repeats given arg times.!
!* to be implemented !
≤ !* Return. !
!& PROLOG Find Meanful Character:! !& Skip blanks and comments.
Skip blanks, tabs, newlines and comments.
Return -1 if a meanful character is found, 0 otherwise.!
< Z-.< 1A-≡_-1; C>
Z-."E 0≤'
1A-≡%"E
:S⋃M◊"E 0≤ '"# !<!>''
"# -1≤'>
!& Collect PROLOG Commands:! !& Collect all commands of some sort.
Collects all the commands in the buffer into a string,
and returns the string. Point is not moved.
The kind of command is specified by the string arg.
Usually "public" or "mode" is expected. General search string is allowed!
.[0 !* Q0 := Saved point!
:I*◊[1 !* Q1 := Result (initially empty)!
[2 :I2≥←◊ !* Q2 := String arg!
M.M &_PROLOG_Find_Meanful_Character◊[3 !* Q3 := Macro def!
M.M&_PROLOG_End_of_Clause◊[4
[5
J !* Go to the top of the buffer!
< M3; !* Skip blanks and comments!
(1A-≡:)↓(2A-≡-)"E !* If :- is found!
.U5 !* Save point!
2C M3; !* Skip blanks and comments!
(.,.+FQ2:FB≥2◊)"E !<!>' !* Check if it is the desired command!
-1,1M4 !* Go to the end of the clause!
Z-.-1"G !* With enough room,!
Q5,.+2 @X1 !* Copy the region + 2 chars and!
FQ1-2 :F¬1 !* Replace last 2 chars by NL!
◊'"# !* Otherwise,!
Q5,.X1 :I1≥1 !* Copy the region and!
◊' !* insert NL!
'"# -1,1M4:;' !* Try next clause!
>
F←F→"N !* With arg!
(Q1 M(M.M &_Sort_String◊)
s≥2$m(m.m&_PROLOG_Find_Meanful_Character$)◊
1m(m.m&_PROLOG_End_of_Clause$)w◊l◊)U1' !* Sort lines in Q1!
Q0J !* Restore point!
Q1≤ !* Return!
!& Sort String:! !& Sort string in the numerical argument and return it.
String arguments are passed to the teco sorter as it is.!
FS Q VECTOR◊[..O !* Make qvector and select it!
→[1 !* Q1 := String to be sorted!
G1 !* Copy the string there!
⊂≥←◊≥←◊≥←◊ !* Do sort!
HX*≤ !* Return sorted string!
!List PROLOG Commands:! !C List all PROLOG commands in the buffer.
The kind of command is specified by the string arg.!
(F← m(m.m &_Collect_PROLOG_Commands◊)≥←◊)[0
FT≥0Done
!Collect PROLOG Commands:! !C Collect all PROLOG commands in the buffer.
Collect all the mode declarations in the buffer into buffer *PROLOG*.
The *PROLOG* buffer is cleared before insertion by default.
With non-zero numerical argument, declarations are appended to the buffer.
The *PROLOG* buffer is selected after the insertion.
With non-zero pre-comma argument, the original buffer is selected.
The kind of command is specified by the string arg.!
(F← m(m.m &_Collect_PROLOG_Commands◊)≥←◊)[0
F[D File◊ !* Save Teco Default Filename!
Q◊Buffer_Name◊[1 !* Save current Buffer's Name!
M(M.M Select_Buffer◊) *PROLOG*◊
!* Select or Create *PROLOG* Buffer!
F←F→"E HK' !* With no arg, clear buffer!
"# →"E HK'' !* With zero arg, clear too!
ZJW !* Goto the end of the buffer!
G0 !* Yank mode declarations!
F←F→-1"G ←"N !* With non-zero precomma argument!
M(M.M Select_Buffer◊) ≥1◊'' !* Return to original buffer!
≤ !* Return!
!List Public Declarations:! !C List all public declarations.
List all the public declarations in the buffer.!
(F← m(m.m List_PROLOG_Commands◊)public◊)
!Collect Public Declarations:! !C Collect all public declarations.
Collect all the public declarations in the buffer into buffer *PROLOG*.
The *PROLOG* buffer is cleared before insertion by default.
With numerical argument, declarations are appended to the buffer.!
(F← m(m.m Collect_PROLOG_Commands◊)public◊
≤ !* Return!
!List Mode Declarations:! !C List all mode declarations.
List all the mode declarations in the buffer.!
(F← m(m.m List_PROLOG_Commands◊)mode◊)
!Collect Mode Declarations:! !C Collect all mode declarations.
Collect all the mode declarations in the buffer into buffer *PROLOG*.
The *PROLOG* buffer is cleared before insertion by default.
With numerical argument, declarations are appended to the buffer.!
(F← m(m.m Collect_PROLOG_Commands◊)mode◊
≤ !* Return!
!List Operator Declarations:! !C List all operator declarations.
List all the operator declarations in the buffer.!
(F← m(m.m List_PROLOG_Commands◊)op◊)
!Collect Operator Declarations:! !C Collect all operator declarations.
Collect all the operator declarations in the buffer into buffer *PROLOG*.
The *PROLOG* buffer is cleared before insertion by default.
With numerical argument, declarations are appended to the buffer.!
(F← m(m.m Collect_PROLOG_Commands◊)op◊
≤ !* Return!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment