123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200 |
- (defvar prolog-mode-version "1.22"
- "Prolog mode version number.")
- (eval-when-compile
- (require 'font-lock)
-
- (require 'imenu)
-
- (require 'info)
- (require 'shell)
- )
- (require 'comint)
- (require 'easymenu)
- (require 'align)
- (defgroup prolog nil
- "Major modes for editing and running Prolog and Mercury files."
- :group 'languages)
- (defgroup prolog-faces nil
- "Prolog mode specific faces."
- :group 'font-lock)
- (defgroup prolog-indentation nil
- "Prolog mode indentation configuration."
- :group 'prolog)
- (defgroup prolog-font-lock nil
- "Prolog mode font locking patterns."
- :group 'prolog)
- (defgroup prolog-keyboard nil
- "Prolog mode keyboard flags."
- :group 'prolog)
- (defgroup prolog-inferior nil
- "Inferior Prolog mode options."
- :group 'prolog)
- (defgroup prolog-other nil
- "Other Prolog mode options."
- :group 'prolog)
- (defcustom prolog-system nil
- "Prolog interpreter/compiler used.
- The value of this variable is nil or a symbol.
- If it is a symbol, it determines default values of other configuration
- variables with respect to properties of the specified Prolog
- interpreter/compiler.
- Currently recognized symbol values are:
- eclipse - Eclipse Prolog
- mercury - Mercury
- sicstus - SICStus Prolog
- swi - SWI Prolog
- gnu - GNU Prolog"
- :version "24.1"
- :group 'prolog
- :type '(choice (const :tag "SICStus" :value sicstus)
- (const :tag "SWI Prolog" :value swi)
- (const :tag "GNU Prolog" :value gnu)
- (const :tag "ECLiPSe Prolog" :value eclipse)
-
-
- (const :tag "Default" :value nil)))
- (make-variable-buffer-local 'prolog-system)
- (defcustom prolog-system-version
- '((sicstus (3 . 6))
- (swi (0 . 0))
- (mercury (0 . 0))
- (eclipse (3 . 7))
- (gnu (0 . 0)))
-
- "Alist of Prolog system versions.
- The version numbers are of the format (Major . Minor)."
- :version "24.1"
- :type '(repeat (list (symbol :tag "System")
- (cons :tag "Version numbers" (integer :tag "Major")
- (integer :tag "Minor"))))
- :group 'prolog)
- (defcustom prolog-indent-width 4
- "The indentation width used by the editing buffer."
- :group 'prolog-indentation
- :type 'integer)
- (defcustom prolog-align-comments-flag t
- "Non-nil means automatically align comments when indenting."
- :version "24.1"
- :group 'prolog-indentation
- :type 'boolean)
- (defcustom prolog-indent-mline-comments-flag t
- "Non-nil means indent contents of /* */ comments.
- Otherwise leave such lines as they are."
- :version "24.1"
- :group 'prolog-indentation
- :type 'boolean)
- (defcustom prolog-object-end-to-0-flag t
- "Non-nil means indent closing '}' in SICStus object definitions to level 0.
- Otherwise indent to `prolog-indent-width'."
- :version "24.1"
- :group 'prolog-indentation
- :type 'boolean)
- (defcustom prolog-left-indent-regexp "\\(;\\|\\*?->\\)"
- "Regexp for character sequences after which next line is indented.
- Next line after such a regexp is indented to the opening parenthesis level."
- :version "24.1"
- :group 'prolog-indentation
- :type 'regexp)
- (defcustom prolog-paren-indent-p nil
- "If non-nil, increase indentation for parenthesis expressions.
- The second and subsequent line in a parenthesis expression other than
- a compound term can either be indented `prolog-paren-indent' to the
- right (if this variable is non-nil) or in the same way as for compound
- terms (if this variable is nil, default)."
- :version "24.1"
- :group 'prolog-indentation
- :type 'boolean)
- (defcustom prolog-paren-indent 4
- "The indentation increase for parenthesis expressions.
- Only used in ( If -> Then ; Else) and ( Disj1 ; Disj2 ) style expressions."
- :version "24.1"
- :group 'prolog-indentation
- :type 'integer)
- (defcustom prolog-parse-mode 'beg-of-clause
- "The parse mode used (decides from which point parsing is done).
- Legal values:
- 'beg-of-line - starts parsing at the beginning of a line, unless the
- previous line ends with a backslash. Fast, but has
- problems detecting multiline /* */ comments.
- 'beg-of-clause - starts parsing at the beginning of the current clause.
- Slow, but copes better with /* */ comments."
- :version "24.1"
- :group 'prolog-indentation
- :type '(choice (const :value beg-of-line)
- (const :value beg-of-clause)))
- (defcustom prolog-keywords
- '((eclipse
- ("use_module" "begin_module" "module_interface" "dynamic"
- "external" "export" "dbgcomp" "nodbgcomp" "compile"))
- (mercury
- ("all" "else" "end_module" "equality" "external" "fail" "func" "if"
- "implementation" "import_module" "include_module" "inst" "instance"
- "interface" "mode" "module" "not" "pragma" "pred" "some" "then" "true"
- "type" "typeclass" "use_module" "where"))
- (sicstus
- ("block" "dynamic" "mode" "module" "multifile" "meta_predicate"
- "parallel" "public" "sequential" "volatile"))
- (swi
- ("discontiguous" "dynamic" "ensure_loaded" "export" "export_list" "import"
- "meta_predicate" "module" "module_transparent" "multifile" "require"
- "use_module" "volatile"))
- (gnu
- ("built_in" "char_conversion" "discontiguous" "dynamic" "ensure_linked"
- "ensure_loaded" "foreign" "include" "initialization" "multifile" "op"
- "public" "set_prolog_flag"))
- (t
-
- ("dynamic" "module")))
- "Alist of Prolog keywords which is used for font locking of directives."
- :version "24.1"
- :group 'prolog-font-lock
- :type 'sexp)
- (defcustom prolog-types
- '((mercury
- ("char" "float" "int" "io__state" "string" "univ"))
- (t nil))
- "Alist of Prolog types used by font locking."
- :version "24.1"
- :group 'prolog-font-lock
- :type 'sexp)
- (defcustom prolog-mode-specificators
- '((mercury
- ("bound" "di" "free" "ground" "in" "mdi" "mui" "muo" "out" "ui" "uo"))
- (t nil))
- "Alist of Prolog mode specificators used by font locking."
- :version "24.1"
- :group 'prolog-font-lock
- :type 'sexp)
- (defcustom prolog-determinism-specificators
- '((mercury
- ("cc_multi" "cc_nondet" "det" "erroneous" "failure" "multi" "nondet"
- "semidet"))
- (t nil))
- "Alist of Prolog determinism specificators used by font locking."
- :version "24.1"
- :group 'prolog-font-lock
- :type 'sexp)
- (defcustom prolog-directives
- '((mercury
- ("^#[0-9]+"))
- (t nil))
- "Alist of Prolog source code directives used by font locking."
- :version "24.1"
- :group 'prolog-font-lock
- :type 'sexp)
- (defcustom prolog-electric-newline-flag (not (fboundp 'electric-indent-mode))
- "Non-nil means automatically indent the next line when the user types RET."
- :version "24.1"
- :group 'prolog-keyboard
- :type 'boolean)
- (defcustom prolog-hungry-delete-key-flag nil
- "Non-nil means delete key consumes all preceding spaces."
- :version "24.1"
- :group 'prolog-keyboard
- :type 'boolean)
- (defcustom prolog-electric-dot-flag nil
- "Non-nil means make dot key electric.
- Electric dot appends newline or inserts head of a new clause.
- If dot is pressed at the end of a line where at least one white space
- precedes the point, it inserts a recursive call to the current predicate.
- If dot is pressed at the beginning of an empty line, it inserts the head
- of a new clause for the current predicate. It does not apply in strings
- and comments.
- It does not apply in strings and comments."
- :version "24.1"
- :group 'prolog-keyboard
- :type 'boolean)
- (defcustom prolog-electric-dot-full-predicate-template nil
- "If nil, electric dot inserts only the current predicate's name and `('
- for recursive calls or new clause heads. Non-nil means to also
- insert enough commas to cover the predicate's arity and `)',
- and dot and newline for recursive calls."
- :version "24.1"
- :group 'prolog-keyboard
- :type 'boolean)
- (defcustom prolog-electric-underscore-flag nil
- "Non-nil means make underscore key electric.
- Electric underscore replaces the current variable with underscore.
- If underscore is pressed not on a variable then it behaves as usual."
- :version "24.1"
- :group 'prolog-keyboard
- :type 'boolean)
- (defcustom prolog-electric-tab-flag nil
- "Non-nil means make TAB key electric.
- Electric TAB inserts spaces after parentheses, ->, and ;
- in ( If -> Then ; Else) and ( Disj1 ; Disj2 ) style expressions."
- :version "24.1"
- :group 'prolog-keyboard
- :type 'boolean)
- (defcustom prolog-electric-if-then-else-flag nil
- "Non-nil makes `(', `>' and `;' electric
- to automatically indent if-then-else constructs."
- :version "24.1"
- :group 'prolog-keyboard
- :type 'boolean)
- (defcustom prolog-electric-colon-flag nil
- "Makes `:' electric (inserts `:-' on a new line).
- If non-nil, pressing `:' at the end of a line that starts in
- the first column (i.e., clause heads) inserts ` :-' and newline."
- :version "24.1"
- :group 'prolog-keyboard
- :type 'boolean)
- (defcustom prolog-electric-dash-flag nil
- "Makes `-' electric (inserts a `-->' on a new line).
- If non-nil, pressing `-' at the end of a line that starts in
- the first column (i.e., DCG heads) inserts ` -->' and newline."
- :version "24.1"
- :group 'prolog-keyboard
- :type 'boolean)
- (defcustom prolog-old-sicstus-keys-flag nil
- "Non-nil means old SICStus Prolog mode keybindings are used."
- :version "24.1"
- :group 'prolog-keyboard
- :type 'boolean)
- (defcustom prolog-program-name
- `(((getenv "EPROLOG") (eval (getenv "EPROLOG")))
- (eclipse "eclipse")
- (mercury nil)
- (sicstus "sicstus")
- (swi ,(if (not (executable-find "swipl")) "pl" "swipl"))
- (gnu "gprolog")
- (t ,(let ((names '("prolog" "gprolog" "swipl" "pl")))
- (while (and names
- (not (executable-find (car names))))
- (setq names (cdr names)))
- (or (car names) "prolog"))))
- "Alist of program names for invoking an inferior Prolog with `run-prolog'."
- :group 'prolog-inferior
- :type 'sexp)
- (defun prolog-program-name ()
- (prolog-find-value-by-system prolog-program-name))
- (defcustom prolog-program-switches
- '((sicstus ("-i"))
- (t nil))
- "Alist of switches given to inferior Prolog run with `run-prolog'."
- :version "24.1"
- :group 'prolog-inferior
- :type 'sexp)
- (defun prolog-program-switches ()
- (prolog-find-value-by-system prolog-program-switches))
- (defcustom prolog-consult-string
- '((eclipse "[%f].")
- (mercury nil)
- (sicstus (eval (if (prolog-atleast-version '(3 . 7))
- "prolog:zap_file(%m,%b,consult,%l)."
- "prolog:zap_file(%m,%b,consult).")))
- (swi "[%f].")
- (gnu "[%f].")
- (t "reconsult(%f)."))
- "Alist of strings defining predicate for reconsulting.
- Some parts of the string are replaced:
- `%f' by the name of the consulted file (can be a temporary file)
- `%b' by the file name of the buffer to consult
- `%m' by the module name and name of the consulted file separated by colon
- `%l' by the line offset into the file. This is 0 unless consulting a
- region of a buffer, in which case it is the number of lines before
- the region."
- :group 'prolog-inferior
- :type 'sexp)
- (defun prolog-consult-string ()
- (prolog-find-value-by-system prolog-consult-string))
- (defcustom prolog-compile-string
- '((eclipse "[%f].")
- (mercury "mmake ")
- (sicstus (eval (if (prolog-atleast-version '(3 . 7))
- "prolog:zap_file(%m,%b,compile,%l)."
- "prolog:zap_file(%m,%b,compile).")))
- (swi "[%f].")
- (t "compile(%f)."))
- "Alist of strings and lists defining predicate for recompilation.
- Some parts of the string are replaced:
- `%f' by the name of the compiled file (can be a temporary file)
- `%b' by the file name of the buffer to compile
- `%m' by the module name and name of the compiled file separated by colon
- `%l' by the line offset into the file. This is 0 unless compiling a
- region of a buffer, in which case it is the number of lines before
- the region.
- If `prolog-program-name' is non-nil, it is a string sent to a Prolog process.
- If `prolog-program-name' is nil, it is an argument to the `compile' function."
- :group 'prolog-inferior
- :type 'sexp)
- (defun prolog-compile-string ()
- (prolog-find-value-by-system prolog-compile-string))
- (defcustom prolog-eof-string "end_of_file.\n"
- "Alist of strings that represent end of file for prolog.
- nil means send actual operating system end of file."
- :group 'prolog-inferior
- :type 'sexp)
- (defcustom prolog-prompt-regexp
- '((eclipse "^[a-zA-Z0-9()]* *\\?- \\|^\\[[a-zA-Z]* [0-9]*\\]:")
- (sicstus "| [ ?][- ] *")
- (swi "^\\(\\[[a-zA-Z]*\\] \\)?[1-9]?[0-9]*[ ]?\\?- \\|^| +")
- (gnu "^| \\?-")
- (t "^|? *\\?-"))
- "Alist of prompts of the prolog system command line."
- :version "24.1"
- :group 'prolog-inferior
- :type 'sexp)
- (defun prolog-prompt-regexp ()
- (prolog-find-value-by-system prolog-prompt-regexp))
- (defcustom prolog-debug-on-string "debug.\n"
- "Predicate for enabling debug mode."
- :version "24.1"
- :group 'prolog-inferior
- :type 'string)
- (defcustom prolog-debug-off-string "nodebug.\n"
- "Predicate for disabling debug mode."
- :version "24.1"
- :group 'prolog-inferior
- :type 'string)
- (defcustom prolog-trace-on-string "trace.\n"
- "Predicate for enabling tracing."
- :version "24.1"
- :group 'prolog-inferior
- :type 'string)
- (defcustom prolog-trace-off-string "notrace.\n"
- "Predicate for disabling tracing."
- :version "24.1"
- :group 'prolog-inferior
- :type 'string)
- (defcustom prolog-zip-on-string "zip.\n"
- "Predicate for enabling zip mode for SICStus."
- :version "24.1"
- :group 'prolog-inferior
- :type 'string)
- (defcustom prolog-zip-off-string "nozip.\n"
- "Predicate for disabling zip mode for SICStus."
- :version "24.1"
- :group 'prolog-inferior
- :type 'string)
- (defcustom prolog-use-standard-consult-compile-method-flag t
- "Non-nil means use the standard compilation method.
- Otherwise the new compilation method will be used. This
- utilizes a special compilation buffer with the associated
- features such as parsing of error messages and automatically
- jumping to the source code responsible for the error.
- Warning: the new method is so far only experimental and
- does contain bugs. The recommended setting for the novice user
- is non-nil for this variable."
- :version "24.1"
- :group 'prolog-inferior
- :type 'boolean)
- (defcustom prolog-use-prolog-tokenizer-flag
- (not (fboundp 'syntax-propertize-rules))
- "Non-nil means use the internal prolog tokenizer for indentation etc.
- Otherwise use `parse-partial-sexp' which is faster but sometimes incorrect."
- :version "24.1"
- :group 'prolog-other
- :type 'boolean)
- (defcustom prolog-imenu-flag t
- "Non-nil means add a clause index menu for all prolog files."
- :version "24.1"
- :group 'prolog-other
- :type 'boolean)
- (defcustom prolog-imenu-max-lines 3000
- "The maximum number of lines of the file for imenu to be enabled.
- Relevant only when `prolog-imenu-flag' is non-nil."
- :version "24.1"
- :group 'prolog-other
- :type 'integer)
- (defcustom prolog-info-predicate-index
- "(sicstus)Predicate Index"
- "The info node for the SICStus predicate index."
- :version "24.1"
- :group 'prolog-other
- :type 'string)
- (defcustom prolog-underscore-wordchar-flag nil
- "Non-nil means underscore (_) is a word-constituent character."
- :version "24.1"
- :group 'prolog-other
- :type 'boolean)
- (defcustom prolog-use-sicstus-sd nil
- "If non-nil, use the source level debugger of SICStus 3#7 and later."
- :version "24.1"
- :group 'prolog-other
- :type 'boolean)
- (defcustom prolog-char-quote-workaround nil
- "If non-nil, declare 0 as a quote character to handle 0'<char>.
- This is really kludgy, and unneeded (i.e. obsolete) in Emacs>=24."
- :version "24.1"
- :group 'prolog-other
- :type 'boolean)
- (defvar prolog-mode-syntax-table
-
-
-
-
-
-
-
- (let ((table (make-syntax-table)))
- (if prolog-underscore-wordchar-flag
- (modify-syntax-entry ?_ "w" table)
- (modify-syntax-entry ?_ "_" table))
- (modify-syntax-entry ?+ "." table)
- (modify-syntax-entry ?- "." table)
- (modify-syntax-entry ?= "." table)
- (modify-syntax-entry ?< "." table)
- (modify-syntax-entry ?> "." table)
- (modify-syntax-entry ?| "." table)
- (modify-syntax-entry ?\' "\"" table)
-
- (when prolog-char-quote-workaround
- (modify-syntax-entry ?0 "\\" table))
- (modify-syntax-entry ?% "<" table)
- (modify-syntax-entry ?\n ">" table)
- (if (featurep 'xemacs)
- (progn
- (modify-syntax-entry ?* ". 67" table)
- (modify-syntax-entry ?/ ". 58" table)
- )
-
- (modify-syntax-entry ?* ". 23b" table)
- (modify-syntax-entry ?/ ". 14" table)
- )
- table))
- (defvar prolog-mode-abbrev-table nil)
- (defvar prolog-upper-case-string ""
- "A string containing all upper case characters.
- Set by prolog-build-case-strings.")
- (defvar prolog-lower-case-string ""
- "A string containing all lower case characters.
- Set by prolog-build-case-strings.")
- (defvar prolog-atom-char-regexp ""
- "Set by prolog-set-atom-regexps.")
- (defvar prolog-atom-regexp ""
- "Set by prolog-set-atom-regexps.")
- (defconst prolog-left-paren "[[({]"
- "The characters used as left parentheses for the indentation code.")
- (defconst prolog-right-paren "[])}]"
- "The characters used as right parentheses for the indentation code.")
- (defconst prolog-quoted-atom-regexp
- "\\(^\\|[^0-9]\\)\\('\\([^\n']\\|\\\\'\\)*'\\)"
- "Regexp matching a quoted atom.")
- (defconst prolog-string-regexp
- "\\(\"\\([^\n\"]\\|\\\\\"\\)*\"\\)"
- "Regexp matching a string.")
- (defconst prolog-head-delimiter "\\(:-\\|\\+:\\|-:\\|\\+\\?\\|-\\?\\|-->\\)"
- "A regexp for matching on the end delimiter of a head (e.g. \":-\").")
- (defvar prolog-compilation-buffer "*prolog-compilation*"
- "Name of the output buffer for Prolog compilation/consulting.")
- (defvar prolog-temporary-file-name nil)
- (defvar prolog-keywords-i nil)
- (defvar prolog-types-i nil)
- (defvar prolog-mode-specificators-i nil)
- (defvar prolog-determinism-specificators-i nil)
- (defvar prolog-directives-i nil)
- (defvar prolog-eof-string-i nil)
- (defvar prolog-help-function-i nil)
- (defvar prolog-align-rules
- (eval-when-compile
- (mapcar
- (lambda (x)
- (let ((name (car x))
- (sym (cdr x)))
- `(,(intern (format "prolog-%s" name))
- (regexp . ,(format "\\(\\s-*\\)%s\\(\\s-*\\)" sym))
- (tab-stop . nil)
- (modes . '(prolog-mode))
- (group . (1 2)))))
- '(("dcg" . "-->") ("rule" . ":-") ("simplification" . "<=>")
- ("propagation" . "==>")))))
- (defun prolog-atleast-version (version)
- "Return t if the version of the current prolog system is VERSION or later.
- VERSION is of the format (Major . Minor)"
-
-
- (let* ((thisversion (prolog-find-value-by-system prolog-system-version))
- (thismajor (car thisversion))
- (thisminor (cdr thisversion)))
- (or (< (car version) thismajor)
- (and (= (car version) thismajor)
- (<= (cdr version) thisminor)))
- ))
- (define-abbrev-table 'prolog-mode-abbrev-table ())
- (defun prolog-find-value-by-system (alist)
- "Get value from ALIST according to `prolog-system'."
- (let ((system (or prolog-system
- (let ((infbuf (prolog-inferior-buffer 'dont-run)))
- (when infbuf
- (buffer-local-value 'prolog-system infbuf))))))
- (if (listp alist)
- (let (result
- id)
- (while alist
- (setq id (car (car alist)))
- (if (or (eq id system)
- (eq id t)
- (and (listp id)
- (eval id)))
- (progn
- (setq result (car (cdr (car alist))))
- (if (and (listp result)
- (eq (car result) 'eval))
- (setq result (eval (car (cdr result)))))
- (setq alist nil))
- (setq alist (cdr alist))))
- result)
- alist)))
- (defconst prolog-syntax-propertize-function
- (when (fboundp 'syntax-propertize-rules)
- (syntax-propertize-rules
-
-
- ("\\<0\\(''?\\)"
- (1 (unless (save-excursion (nth 8 (syntax-ppss (match-beginning 0))))
- (string-to-syntax "_"))))
-
-
- ("\\<[1-9][0-9]*\\('\\)[0-9a-zA-Z]" (1 "_"))
-
-
-
- ("\\\\[x0-7][0-9a-fA-F]*\\(\\\\\\)" (1 "_"))
- )))
- (defun prolog-mode-variables ()
- "Set some common variables to Prolog code specific values."
- (setq local-abbrev-table prolog-mode-abbrev-table)
- (set (make-local-variable 'paragraph-start)
- (concat "[ \t]*$\\|" page-delimiter))
- (set (make-local-variable 'paragraph-separate) paragraph-start)
- (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
- (set (make-local-variable 'normal-auto-fill-function) 'prolog-do-auto-fill)
- (set (make-local-variable 'indent-line-function) 'prolog-indent-line)
- (set (make-local-variable 'comment-start) "%")
- (set (make-local-variable 'comment-end) "")
- (set (make-local-variable 'comment-add) 1)
- (set (make-local-variable 'comment-start-skip)
-
-
- (format "^\\(\\(%s\\|%s\\|[^\n\'\"%%]\\)*\\)\\(/\\*+ *\\|%%+ *\\)"
- prolog-quoted-atom-regexp prolog-string-regexp))
- (set (make-local-variable 'comment-indent-function) 'prolog-comment-indent)
- (set (make-local-variable 'parens-require-spaces) nil)
-
- (dolist (var '(prolog-keywords prolog-types prolog-mode-specificators
- prolog-determinism-specificators prolog-directives
- prolog-eof-string
-
- prolog-help-function))
- (set (intern (concat (symbol-name var) "-i"))
- (prolog-find-value-by-system (symbol-value var))))
- (when (null (prolog-program-name))
- (set (make-local-variable 'compile-command) (prolog-compile-string)))
- (set (make-local-variable 'font-lock-defaults)
- '(prolog-font-lock-keywords nil nil ((?_ . "w"))))
- (set (make-local-variable 'syntax-propertize-function)
- prolog-syntax-propertize-function)
- )
- (defun prolog-mode-keybindings-common (map)
- "Define keybindings common to both Prolog modes in MAP."
- (define-key map "\C-c?" 'prolog-help-on-predicate)
- (define-key map "\C-c/" 'prolog-help-apropos)
- (define-key map "\C-c\C-d" 'prolog-debug-on)
- (define-key map "\C-c\C-t" 'prolog-trace-on)
- (define-key map "\C-c\C-z" 'prolog-zip-on)
- (define-key map "\C-c\r" 'run-prolog))
- (defun prolog-mode-keybindings-edit (map)
- "Define keybindings for Prolog mode in MAP."
- (define-key map "\M-a" 'prolog-beginning-of-clause)
- (define-key map "\M-e" 'prolog-end-of-clause)
- (define-key map "\M-q" 'prolog-fill-paragraph)
- (define-key map "\C-c\C-a" 'align)
- (define-key map "\C-\M-a" 'prolog-beginning-of-predicate)
- (define-key map "\C-\M-e" 'prolog-end-of-predicate)
- (define-key map "\M-\C-c" 'prolog-mark-clause)
- (define-key map "\M-\C-h" 'prolog-mark-predicate)
- (define-key map "\M-\C-n" 'prolog-forward-list)
- (define-key map "\M-\C-p" 'prolog-backward-list)
- (define-key map "\C-c\C-n" 'prolog-insert-predicate-template)
- (define-key map "\C-c\C-s" 'prolog-insert-predspec)
- (define-key map "\M-\r" 'prolog-insert-next-clause)
- (define-key map "\C-c\C-va" 'prolog-variables-to-anonymous)
- (define-key map "\C-c\C-v\C-s" 'prolog-view-predspec)
- (define-key map [Backspace] 'prolog-electric-delete)
- (define-key map "." 'prolog-electric-dot)
- (define-key map "_" 'prolog-electric-underscore)
- (define-key map "(" 'prolog-electric-if-then-else)
- (define-key map ";" 'prolog-electric-if-then-else)
- (define-key map ">" 'prolog-electric-if-then-else)
- (define-key map ":" 'prolog-electric-colon)
- (define-key map "-" 'prolog-electric-dash)
- (if prolog-electric-newline-flag
- (define-key map "\r" 'newline-and-indent))
-
-
-
-
-
-
-
-
- (if prolog-old-sicstus-keys-flag
- (progn
- (define-key map "\C-c\C-c" 'prolog-consult-predicate)
- (define-key map "\C-cc" 'prolog-consult-region)
- (define-key map "\C-cC" 'prolog-consult-buffer)
- (define-key map "\C-c\C-k" 'prolog-compile-predicate)
- (define-key map "\C-ck" 'prolog-compile-region)
- (define-key map "\C-cK" 'prolog-compile-buffer))
- (define-key map "\C-c\C-p" 'prolog-consult-predicate)
- (define-key map "\C-c\C-r" 'prolog-consult-region)
- (define-key map "\C-c\C-b" 'prolog-consult-buffer)
- (define-key map "\C-c\C-f" 'prolog-consult-file)
- (define-key map "\C-c\C-cp" 'prolog-compile-predicate)
- (define-key map "\C-c\C-cr" 'prolog-compile-region)
- (define-key map "\C-c\C-cb" 'prolog-compile-buffer)
- (define-key map "\C-c\C-cf" 'prolog-compile-file))
-
- (define-key map "\e\C-x" 'prolog-consult-region)
- (define-key map "\C-c\C-l" 'prolog-consult-file)
- (define-key map "\C-c\C-z" 'switch-to-prolog))
- (defun prolog-mode-keybindings-inferior (_map)
- "Define keybindings for inferior Prolog mode in MAP."
-
- )
- (defvar prolog-mode-map
- (let ((map (make-sparse-keymap)))
- (prolog-mode-keybindings-common map)
- (prolog-mode-keybindings-edit map)
- map))
- (defvar prolog-mode-hook nil
- "List of functions to call after the prolog mode has initialized.")
- (unless (fboundp 'prog-mode)
- (defalias 'prog-mode 'fundamental-mode))
- (define-derived-mode prolog-mode prog-mode "Prolog"
- "Major mode for editing Prolog code.
- Blank lines and `%%...' separate paragraphs. `%'s starts a comment
- line and comments can also be enclosed in /* ... */.
- If an optional argument SYSTEM is non-nil, set up mode for the given system.
- To find out what version of Prolog mode you are running, enter
- `\\[prolog-mode-version]'.
- Commands:
- \\{prolog-mode-map}
- Entry to this mode calls the value of `prolog-mode-hook'
- if that value is non-nil."
- (setq mode-name (concat "Prolog"
- (cond
- ((eq prolog-system 'eclipse) "[ECLiPSe]")
- ((eq prolog-system 'sicstus) "[SICStus]")
- ((eq prolog-system 'swi) "[SWI]")
- ((eq prolog-system 'gnu) "[GNU]")
- (t ""))))
- (prolog-mode-variables)
- (prolog-build-case-strings)
- (prolog-set-atom-regexps)
- (dolist (ar prolog-align-rules) (add-to-list 'align-rules-list ar))
-
-
- (if (and (eq prolog-system 'sicstus)
- (prolog-atleast-version '(3 . 7))
- prolog-use-sicstus-sd)
- (prolog-enable-sicstus-sd))
- (prolog-menu))
- (defvar mercury-mode-map
- (let ((map (make-sparse-keymap)))
- (set-keymap-parent map prolog-mode-map)
- map))
- (define-derived-mode mercury-mode prolog-mode "Prolog[Mercury]"
- "Major mode for editing Mercury programs.
- Actually this is just customized `prolog-mode'."
- (set (make-local-variable 'prolog-system) 'mercury))
- (defvar prolog-inferior-mode-map
- (let ((map (make-sparse-keymap)))
- (prolog-mode-keybindings-common map)
- (prolog-mode-keybindings-inferior map)
- (define-key map [remap self-insert-command]
- 'prolog-inferior-self-insert-command)
- map))
- (defvar prolog-inferior-mode-hook nil
- "List of functions to call after the inferior prolog mode has initialized.")
- (defvar prolog-inferior-error-regexp-alist
- '(
-
-
- ("^\\(?:\\?- *\\)?\\(\\(?:ERROR\\|\\(W\\)arning\\): *\\(.*?\\):\\([1-9][0-9]*\\):\\(?:\\([0-9]*\\):\\)?\\)\\(?:$\\| \\)"
- 3 4 5 (2 . nil) 1)
-
- gnu))
- (defun prolog-inferior-self-insert-command ()
- "Insert the char in the buffer or pass it directly to the process."
- (interactive)
- (let* ((proc (get-buffer-process (current-buffer)))
- (pmark (and proc (marker-position (process-mark proc)))))
-
-
-
- (if (and (eq prolog-system 'gnu)
- pmark
- (null current-prefix-arg)
- (eobp)
- (eq (point) pmark)
- (save-excursion
- (goto-char (- pmark 3))
-
- (looking-at " \\? ")))
-
-
-
-
- (comint-send-string proc (string last-command-event))
- (call-interactively 'self-insert-command))))
- (declare-function 'compilation-shell-minor-mode "compile" (&optional arg))
- (defvar compilation-error-regexp-alist)
- (define-derived-mode prolog-inferior-mode comint-mode "Inferior Prolog"
- "Major mode for interacting with an inferior Prolog process.
- The following commands are available:
- \\{prolog-inferior-mode-map}
- Entry to this mode calls the value of `prolog-mode-hook' with no arguments,
- if that value is non-nil. Likewise with the value of `comint-mode-hook'.
- `prolog-mode-hook' is called after `comint-mode-hook'.
- You can send text to the inferior Prolog from other buffers
- using the commands `send-region', `send-string' and \\[prolog-consult-region].
- Commands:
- Tab indents for Prolog; with argument, shifts rest
- of expression rigidly with the current line.
- Paragraphs are separated only by blank lines and '%%'. '%'s start comments.
- Return at end of buffer sends line as input.
- Return not at end copies rest of line to end and sends it.
- \\[comint-delchar-or-maybe-eof] sends end-of-file as input.
- \\[comint-kill-input] and \\[backward-kill-word] are kill commands,
- imitating normal Unix input editing.
- \\[comint-interrupt-subjob] interrupts the shell or its current subjob if any.
- \\[comint-stop-subjob] stops, likewise.
- \\[comint-quit-subjob] sends quit signal, likewise.
- To find out what version of Prolog mode you are running, enter
- `\\[prolog-mode-version]'."
- (require 'compile)
- (setq comint-input-filter 'prolog-input-filter)
- (setq mode-line-process '(": %s"))
- (prolog-mode-variables)
- (setq comint-prompt-regexp (prolog-prompt-regexp))
- (set (make-local-variable 'shell-dirstack-query) "pwd.")
- (set (make-local-variable 'compilation-error-regexp-alist)
- prolog-inferior-error-regexp-alist)
- (compilation-shell-minor-mode)
- (prolog-inferior-menu))
- (defun prolog-input-filter (str)
- (cond ((string-match "\\`\\s *\\'" str) nil)
- ((not (derived-mode-p 'prolog-inferior-mode)) t)
- ((= (length str) 1) nil)
- ((string-match "\\`[rf] *[0-9]*\\'" str) nil)
- (t t)))
- (defun run-prolog (arg)
- "Run an inferior Prolog process, input and output via buffer *prolog*.
- With prefix argument ARG, restart the Prolog process if running before."
- (interactive "P")
-
-
- (if (and arg (get-process "prolog"))
- (progn
- (process-send-string "prolog" "halt.\n")
- (while (get-process "prolog") (sit-for 0.1))))
- (let ((buff (buffer-name)))
- (if (not (string= buff "*prolog*"))
- (prolog-goto-prolog-process-buffer))
-
- (if (and (eq prolog-system 'sicstus)
- (prolog-atleast-version '(3 . 7))
- prolog-use-sicstus-sd)
- (prolog-enable-sicstus-sd))
- (prolog-mode-variables)
- (prolog-ensure-process)
- ))
- (defun prolog-inferior-guess-flavor (&optional ignored)
- (setq prolog-system
- (when (or (numberp prolog-system) (markerp prolog-system))
- (save-excursion
- (goto-char (1+ prolog-system))
- (cond
- ((looking-at "GNU Prolog") 'gnu)
- ((looking-at "Welcome to SWI-Prolog\\|%.*\\<swi_") 'swi)
- ((looking-at ".*\n") nil)
- (t prolog-system)))))
- (when (symbolp prolog-system)
- (remove-hook 'comint-output-filter-functions
- 'prolog-inferior-guess-flavor t)
- (when prolog-system
- (setq comint-prompt-regexp (prolog-prompt-regexp))
- (if (eq prolog-system 'gnu)
- (set (make-local-variable 'comint-process-echoes) t)))))
- (defun prolog-ensure-process (&optional wait)
- "If Prolog process is not running, run it.
- If the optional argument WAIT is non-nil, wait for Prolog prompt specified by
- the variable `prolog-prompt-regexp'."
- (if (null (prolog-program-name))
- (error "This Prolog system has defined no interpreter."))
- (if (comint-check-proc "*prolog*")
- ()
- (with-current-buffer (get-buffer-create "*prolog*")
- (prolog-inferior-mode)
- (apply 'make-comint-in-buffer "prolog" (current-buffer)
- (prolog-program-name) nil (prolog-program-switches))
- (unless prolog-system
-
- (set (make-local-variable 'prolog-system)
-
- (let* ((proc (get-buffer-process (current-buffer)))
- (pmark (and proc (marker-position (process-mark proc)))))
- (cond
- ((null pmark) (1- (point-min)))
-
-
-
-
-
-
-
- ((> pmark (point-min)) (copy-marker (1- pmark)))
- (t (1- pmark)))))
- (add-hook 'comint-output-filter-functions
- 'prolog-inferior-guess-flavor nil t))
- (if wait
- (progn
- (goto-char (point-max))
- (while
- (save-excursion
- (not
- (re-search-backward
- (concat "\\(" (prolog-prompt-regexp) "\\)" "\\=")
- nil t)))
- (sit-for 0.1)))))))
- (defun prolog-inferior-buffer (&optional dont-run)
- (or (get-buffer "*prolog*")
- (unless dont-run
- (prolog-ensure-process)
- (get-buffer "*prolog*"))))
- (defun prolog-process-insert-string (process string)
- "Insert STRING into inferior Prolog buffer running PROCESS."
-
- (with-current-buffer (process-buffer process)
-
- (let ((moving (= (point) (process-mark process))))
- (save-excursion
-
- (goto-char (process-mark process))
- (insert string)
- (set-marker (process-mark process) (point)))
- (if moving (goto-char (process-mark process))))))
- (declare-function compilation-forget-errors "compile" ())
- (declare-function compilation-fake-loc "compile"
- (marker file &optional line col))
- (defun prolog-old-process-region (compilep start end)
- "Process the region limited by START and END positions.
- If COMPILEP is non-nil then use compilation, otherwise consulting."
- (prolog-ensure-process)
-
- (let ((tmpfile (prolog-temporary-file))
-
- (first-line (1+ (count-lines
- (point-min)
- (save-excursion
- (goto-char start)
- (point))))))
- (write-region start end tmpfile)
- (setq start (copy-marker start))
- (with-current-buffer (prolog-inferior-buffer)
- (compilation-forget-errors)
- (compilation-fake-loc start tmpfile))
- (process-send-string
- "prolog" (prolog-build-prolog-command
- compilep tmpfile (prolog-bsts buffer-file-name)
- first-line))
- (prolog-goto-prolog-process-buffer)))
- (defun prolog-old-process-predicate (compilep)
- "Process the predicate around point.
- If COMPILEP is non-nil then use compilation, otherwise consulting."
- (prolog-old-process-region
- compilep (prolog-pred-start) (prolog-pred-end)))
- (defun prolog-old-process-buffer (compilep)
- "Process the entire buffer.
- If COMPILEP is non-nil then use compilation, otherwise consulting."
- (prolog-old-process-region compilep (point-min) (point-max)))
- (defun prolog-old-process-file (compilep)
- "Process the file of the current buffer.
- If COMPILEP is non-nil then use compilation, otherwise consulting."
- (save-some-buffers)
- (prolog-ensure-process)
- (with-current-buffer (prolog-inferior-buffer)
- (compilation-forget-errors))
- (process-send-string
- "prolog" (prolog-build-prolog-command
- compilep buffer-file-name
- (prolog-bsts buffer-file-name)))
- (prolog-goto-prolog-process-buffer))
- (defun prolog-consult-file ()
- "Consult file of current buffer."
- (interactive)
- (if prolog-use-standard-consult-compile-method-flag
- (prolog-old-process-file nil)
- (prolog-consult-compile-file nil)))
- (defun prolog-consult-buffer ()
- "Consult buffer."
- (interactive)
- (if prolog-use-standard-consult-compile-method-flag
- (prolog-old-process-buffer nil)
- (prolog-consult-compile-buffer nil)))
- (defun prolog-consult-region (beg end)
- "Consult region between BEG and END."
- (interactive "r")
- (if prolog-use-standard-consult-compile-method-flag
- (prolog-old-process-region nil beg end)
- (prolog-consult-compile-region nil beg end)))
- (defun prolog-consult-predicate ()
- "Consult the predicate around current point."
- (interactive)
- (if prolog-use-standard-consult-compile-method-flag
- (prolog-old-process-predicate nil)
- (prolog-consult-compile-predicate nil)))
- (defun prolog-compile-file ()
- "Compile file of current buffer."
- (interactive)
- (if prolog-use-standard-consult-compile-method-flag
- (prolog-old-process-file t)
- (prolog-consult-compile-file t)))
- (defun prolog-compile-buffer ()
- "Compile buffer."
- (interactive)
- (if prolog-use-standard-consult-compile-method-flag
- (prolog-old-process-buffer t)
- (prolog-consult-compile-buffer t)))
- (defun prolog-compile-region (beg end)
- "Compile region between BEG and END."
- (interactive "r")
- (if prolog-use-standard-consult-compile-method-flag
- (prolog-old-process-region t beg end)
- (prolog-consult-compile-region t beg end)))
- (defun prolog-compile-predicate ()
- "Compile the predicate around current point."
- (interactive)
- (if prolog-use-standard-consult-compile-method-flag
- (prolog-old-process-predicate t)
- (prolog-consult-compile-predicate t)))
- (defun prolog-buffer-module ()
- "Select Prolog module name appropriate for current buffer.
- Bases decision on buffer contents (-*- line)."
-
- (let (beg end)
- (save-excursion
- (goto-char (point-min))
- (skip-chars-forward " \t")
- (and (search-forward "-*-" (line-end-position) t)
- (progn
- (skip-chars-forward " \t")
- (setq beg (point))
- (search-forward "-*-" (line-end-position) t))
- (progn
- (forward-char -3)
- (skip-chars-backward " \t")
- (setq end (point))
- (goto-char beg)
- (and (let ((case-fold-search t))
- (search-forward "module:" end t))
- (progn
- (skip-chars-forward " \t")
- (setq beg (point))
- (if (search-forward ";" end t)
- (forward-char -1)
- (goto-char end))
- (skip-chars-backward " \t")
- (buffer-substring beg (point)))))))))
- (defun prolog-build-prolog-command (compilep file buffername
- &optional first-line)
- "Make Prolog command for FILE compilation/consulting.
- If COMPILEP is non-nil, consider compilation, otherwise consulting."
- (let* ((compile-string
-
-
-
- (if compilep (prolog-compile-string) (prolog-consult-string)))
- (module (prolog-buffer-module))
- (file-name (concat "'" (prolog-bsts file) "'"))
- (module-name (if module (concat "'" module "'")))
- (module-file (if module
- (concat module-name ":" file-name)
- file-name))
- strbeg strend
- (lineoffset (if first-line
- (- first-line 1)
- 0)))
-
- (if (not buffername)
- (error "The buffer is not saved"))
- (if (not (string-match "\\`'.*'\\'" buffername))
- (setq buffername (concat "'" buffername "'")))
- (while (string-match "%m" compile-string)
- (setq strbeg (substring compile-string 0 (match-beginning 0)))
- (setq strend (substring compile-string (match-end 0)))
- (setq compile-string (concat strbeg module-file strend)))
-
-
- (while (string-match "%f" compile-string)
- (setq strbeg (substring compile-string 0 (match-beginning 0)))
- (setq strend (substring compile-string (match-end 0)))
- (setq compile-string (concat strbeg file-name strend)))
- (while (string-match "%b" compile-string)
- (setq strbeg (substring compile-string 0 (match-beginning 0)))
- (setq strend (substring compile-string (match-end 0)))
- (setq compile-string (concat strbeg buffername strend)))
- (while (string-match "%l" compile-string)
- (setq strbeg (substring compile-string 0 (match-beginning 0)))
- (setq strend (substring compile-string (match-end 0)))
- (setq compile-string (concat strbeg (format "%d" lineoffset) strend)))
- (concat compile-string "\n")))
- (defvar prolog-process-flag nil
- "Non-nil means that a prolog task (i.e. a consultation or compilation job)
- is running.")
- (defvar prolog-consult-compile-output ""
- "Hold the unprocessed output from the current prolog task.")
- (defvar prolog-consult-compile-first-line 1
- "The number of the first line of the file to consult/compile.
- Used for temporary files.")
- (defvar prolog-consult-compile-file nil
- "The file to compile/consult (can be a temporary file).")
- (defvar prolog-consult-compile-real-file nil
- "The file name of the buffer to compile/consult.")
- (defvar compilation-parse-errors-function)
- (defun prolog-consult-compile (compilep file &optional first-line)
- "Consult/compile FILE.
- If COMPILEP is non-nil, perform compilation, otherwise perform CONSULTING.
- COMMAND is a string described by the variables `prolog-consult-string'
- and `prolog-compile-string'.
- Optional argument FIRST-LINE is the number of the first line in the compiled
- region.
- This function must be called from the source code buffer."
- (if prolog-process-flag
- (error "Another Prolog task is running."))
- (prolog-ensure-process t)
- (let* ((buffer (get-buffer-create prolog-compilation-buffer))
- (real-file buffer-file-name)
- (command-string (prolog-build-prolog-command compilep file
- real-file first-line))
- (process (get-process "prolog"))
- (old-filter (process-filter process)))
- (with-current-buffer buffer
- (delete-region (point-min) (point-max))
-
- (compilation-mode)
-
-
- (set (make-local-variable 'font-lock-defaults)
- '(prolog-font-lock-keywords nil nil ((?_ . "w"))))
- (if (eq prolog-system 'sicstus)
-
-
-
-
-
- (set (make-local-variable 'compilation-parse-errors-function)
- 'prolog-parse-sicstus-compilation-errors))
- (setq buffer-read-only nil)
- (insert command-string "\n"))
- (save-selected-window
- (pop-to-buffer buffer))
- (setq prolog-process-flag t
- prolog-consult-compile-output ""
- prolog-consult-compile-first-line (if first-line (1- first-line) 0)
- prolog-consult-compile-file file
- prolog-consult-compile-real-file (if (string=
- file buffer-file-name)
- nil
- real-file))
- (with-current-buffer buffer
- (goto-char (point-max))
- (set-process-filter process 'prolog-consult-compile-filter)
- (process-send-string "prolog" command-string)
-
- (while (and prolog-process-flag
- (accept-process-output process 10))
- (sit-for 0.1)
- (unless (get-process "prolog")
- (setq prolog-process-flag nil)))
- (insert (if compilep
- "\nCompilation finished.\n"
- "\nConsulted.\n"))
- (set-process-filter process old-filter))))
- (defvar compilation-error-list)
- (defun prolog-parse-sicstus-compilation-errors (limit)
- "Parse the prolog compilation buffer for errors.
- Argument LIMIT is a buffer position limiting searching.
- For use with the `compilation-parse-errors-function' variable."
- (setq compilation-error-list nil)
- (message "Parsing SICStus error messages...")
- (let (filepath dir file errorline)
- (while
- (re-search-backward
- "{\\([a-zA-Z ]* ERROR\\|Warning\\):.* in line[s ]*\\([0-9]+\\)"
- limit t)
- (setq errorline (string-to-number (match-string 2)))
- (save-excursion
- (re-search-backward
- "{\\(consulting\\|compiling\\|processing\\) \\(.*\\)\\.\\.\\.}"
- limit t)
- (setq filepath (match-string 2)))
-
- (if (string-match "\\(.*/\\)\\([^/]*\\)$" filepath)
- (progn
- (setq dir (match-string 1 filepath))
- (setq file (match-string 2 filepath))))
- (setq compilation-error-list
- (cons
- (cons (save-excursion
- (beginning-of-line)
- (point-marker))
- (list (list file dir) errorline))
- compilation-error-list)
- ))
- ))
- (defun prolog-consult-compile-filter (process output)
- "Filter function for Prolog compilation PROCESS.
- Argument OUTPUT is a name of the output file."
-
- (setq prolog-consult-compile-output
- (concat prolog-consult-compile-output output))
-
-
- (let (outputtype)
- (while (and prolog-process-flag
- (or
-
- (progn
- (setq outputtype 'trace)
- (and (eq prolog-system 'sicstus)
- (string-match
- "^[ \t]*[0-9]+[ \t]*[0-9]+[ \t]*Call:.*? "
- prolog-consult-compile-output)))
-
- (progn
- (setq outputtype 'normal)
- (string-match "^.*\n" prolog-consult-compile-output))
- ))
-
- (setq output (match-string 0 prolog-consult-compile-output))
-
- (setq prolog-consult-compile-output
- (substring prolog-consult-compile-output (length output)))
-
-
-
-
- (cond
-
-
- ((and (eq prolog-system 'sicstus)
- (eq outputtype 'trace))
- (let ((input (concat (read-string output) "\n")))
- (process-send-string process input)
- (setq output (concat output input))))
- ((eq prolog-system 'sicstus)
- (if (and prolog-consult-compile-real-file
- (string-match
- "\\({.*:.* in line[s ]*\\)\\([0-9]+\\)-\\([0-9]+\\)" output))
- (setq output (replace-match
-
-
-
-
- (format "Added by Emacs: {processing %s...}\n%s%d-%d"
- prolog-consult-compile-real-file
- (match-string 1 output)
- (+ prolog-consult-compile-first-line
- (string-to-number
- (match-string 2 output)))
- (+ prolog-consult-compile-first-line
- (string-to-number
- (match-string 3 output))))
- t t output)))
- )
- ((eq prolog-system 'swi)
- (if (and prolog-consult-compile-real-file
- (string-match (format
- "%s\\([ \t]*:[ \t]*\\)\\([0-9]+\\)"
- prolog-consult-compile-file)
- output))
- (setq output (replace-match
-
- (format "%s%s%d"
- prolog-consult-compile-real-file
- (match-string 1 output)
- (+ prolog-consult-compile-first-line
- (string-to-number
- (match-string 2 output))))
- t t output)))
- )
- (t ())
- )
-
- (insert output)))
-
- (if (string-match (prolog-prompt-regexp) prolog-consult-compile-output)
- (setq prolog-process-flag nil)))
- (defun prolog-consult-compile-file (compilep)
- "Consult/compile file of current buffer.
- If COMPILEP is non-nil, compile, otherwise consult."
- (let ((file buffer-file-name))
- (if file
- (progn
- (save-some-buffers)
- (prolog-consult-compile compilep file))
- (prolog-consult-compile-region compilep (point-min) (point-max)))))
- (defun prolog-consult-compile-buffer (compilep)
- "Consult/compile current buffer.
- If COMPILEP is non-nil, compile, otherwise consult."
- (prolog-consult-compile-region compilep (point-min) (point-max)))
- (defun prolog-consult-compile-region (compilep beg end)
- "Consult/compile region between BEG and END.
- If COMPILEP is non-nil, compile, otherwise consult."
-
- (let ((file (prolog-bsts (prolog-temporary-file)))
- (lines (count-lines 1 beg)))
- (write-region beg end file nil 'no-message)
- (write-region "\n" nil file t 'no-message)
- (prolog-consult-compile compilep file
- (if (bolp) (1+ lines) lines))
- (delete-file file)))
- (defun prolog-consult-compile-predicate (compilep)
- "Consult/compile the predicate around current point.
- If COMPILEP is non-nil, compile, otherwise consult."
- (prolog-consult-compile-region
- compilep (prolog-pred-start) (prolog-pred-end)))
- (defun prolog-make-keywords-regexp (keywords &optional protect)
- "Create regexp from the list of strings KEYWORDS.
- If PROTECT is non-nil, surround the result regexp by word breaks."
- (let ((regexp
- (if (fboundp 'regexp-opt)
-
-
- (eval '(regexp-opt keywords))
-
- (concat (mapconcat 'regexp-quote keywords "\\|")))
- ))
- (if protect
- (concat "\\<\\(" regexp "\\)\\>")
- regexp)))
- (defun prolog-font-lock-object-matcher (bound)
- "Find SICStus objects method name for font lock.
- Argument BOUND is a buffer position limiting searching."
- (let (point
- (case-fold-search nil))
- (while (and (not point)
- (re-search-forward "\\(::[ \t\n]*{\\|&\\)[ \t]*"
- bound t))
- (while (or (re-search-forward "\\=\n[ \t]*" bound t)
- (re-search-forward "\\=%.*" bound t)
- (and (re-search-forward "\\=/\\*" bound t)
- (re-search-forward "\\*/[ \t]*" bound t))))
- (setq point (re-search-forward
- (format "\\=\\(%s\\)" prolog-atom-regexp)
- bound t)))
- point))
- (defsubst prolog-face-name-p (facename)
-
-
-
-
-
-
- (memq facename (face-list)))
- (defun prolog-font-lock-keywords ()
- "Set up font lock keywords for the current Prolog system."
-
- (require 'font-lock)
-
- (defface prolog-redo-face
- '((((class grayscale)) (:italic t))
- (((class color)) (:foreground "darkorchid"))
- (t (:italic t)))
- "Prolog mode face for highlighting redo trace lines."
- :group 'prolog-faces)
- (defface prolog-exit-face
- '((((class grayscale)) (:underline t))
- (((class color) (background dark)) (:foreground "green"))
- (((class color) (background light)) (:foreground "ForestGreen"))
- (t (:underline t)))
- "Prolog mode face for highlighting exit trace lines."
- :group 'prolog-faces)
- (defface prolog-exception-face
- '((((class grayscale)) (:bold t :italic t :underline t))
- (((class color)) (:bold t :foreground "black" :background "Khaki"))
- (t (:bold t :italic t :underline t)))
- "Prolog mode face for highlighting exception trace lines."
- :group 'prolog-faces)
- (defface prolog-warning-face
- '((((class grayscale)) (:underline t))
- (((class color) (background dark)) (:foreground "blue"))
- (((class color) (background light)) (:foreground "MidnightBlue"))
- (t (:underline t)))
- "Face name to use for compiler warnings."
- :group 'prolog-faces)
- (defface prolog-builtin-face
- '((((class color) (background light)) (:foreground "Purple"))
- (((class color) (background dark)) (:foreground "Cyan"))
- (((class grayscale) (background light)) (:foreground "LightGray" :bold t))
- (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
- (t (:bold t)))
- "Face name to use for compiler warnings."
- :group 'prolog-faces)
- (defvar prolog-warning-face
- (if (prolog-face-name-p 'font-lock-warning-face)
- 'font-lock-warning-face
- 'prolog-warning-face)
- "Face name to use for built in predicates.")
- (defvar prolog-builtin-face
- (if (prolog-face-name-p 'font-lock-builtin-face)
- 'font-lock-builtin-face
- 'prolog-builtin-face)
- "Face name to use for built in predicates.")
- (defvar prolog-redo-face 'prolog-redo-face
- "Face name to use for redo trace lines.")
- (defvar prolog-exit-face 'prolog-exit-face
- "Face name to use for exit trace lines.")
- (defvar prolog-exception-face 'prolog-exception-face
- "Face name to use for exception trace lines.")
-
- (let (
-
- (head-predicates
- (list (format "^\\(%s\\)\\((\\|[ \t]*:-\\)" prolog-atom-regexp)
- 1 font-lock-function-name-face))
-
-
- (head-predicates-1
- (list (format "\\.[ \t]*\\(%s\\)" prolog-atom-regexp)
- 1 font-lock-function-name-face) )
- (variables
- '("\\<\\([_A-Z][a-zA-Z0-9_]*\\)"
- 1 font-lock-variable-name-face))
- (important-elements
- (list (if (eq prolog-system 'mercury)
- "[][}{;|]\\|\\\\[+=]\\|<?=>?"
- "[][}{!;|]\\|\\*->")
- 0 'font-lock-keyword-face))
- (important-elements-1
- '("[^-*]\\(->\\)" 1 font-lock-keyword-face))
- (predspecs
- (list (format "\\<\\(%s:\\|\\)%s/[0-9]+"
- prolog-atom-regexp prolog-atom-regexp)
- 0 font-lock-function-name-face 'prepend))
- (keywords
- (list
- (if (eq prolog-system 'mercury)
- (concat
- "\\<\\("
- (prolog-make-keywords-regexp prolog-keywords-i)
- "\\|"
- (prolog-make-keywords-regexp
- prolog-determinism-specificators-i)
- "\\)\\>")
- (concat
- "^[?:]- *\\("
- (prolog-make-keywords-regexp prolog-keywords-i)
- "\\)\\>"))
- 1 prolog-builtin-face))
- (quoted_atom (list prolog-quoted-atom-regexp
- 2 'font-lock-string-face 'append))
- (string (list prolog-string-regexp
- 1 'font-lock-string-face 'append))
-
- (sicstus-object-methods
- (if (eq prolog-system 'sicstus)
- '(prolog-font-lock-object-matcher
- 1 font-lock-function-name-face)))
-
- (types
- (if (eq prolog-system 'mercury)
- (list
- (prolog-make-keywords-regexp prolog-types-i t)
- 0 'font-lock-type-face)))
- (modes
- (if (eq prolog-system 'mercury)
- (list
- (prolog-make-keywords-regexp prolog-mode-specificators-i t)
- 0 'font-lock-reference-face)))
- (directives
- (if (eq prolog-system 'mercury)
- (list
- (prolog-make-keywords-regexp prolog-directives-i t)
- 0 'prolog-warning-face)))
-
- (prompt
-
- (list (prolog-prompt-regexp) 0 'font-lock-keyword-face))
- (trace-exit
-
- (cond
- ((eq prolog-system 'sicstus)
- '("[ \t]*[0-9]+[ \t]+[0-9]+[ \t]*\\(Exit\\):"
- 1 prolog-exit-face))
- ((eq prolog-system 'swi)
- '("[ \t]*\\(Exit\\):[ \t]*([ \t0-9]*)" 1 prolog-exit-face))
- (t nil)))
- (trace-fail
-
- (cond
- ((eq prolog-system 'sicstus)
- '("[ \t]*[0-9]+[ \t]+[0-9]+[ \t]*\\(Fail\\):"
- 1 prolog-warning-face))
- ((eq prolog-system 'swi)
- '("[ \t]*\\(Fail\\):[ \t]*([ \t0-9]*)" 1 prolog-warning-face))
- (t nil)))
- (trace-redo
-
- (cond
- ((eq prolog-system 'sicstus)
- '("[ \t]*[0-9]+[ \t]+[0-9]+[ \t]*\\(Redo\\):"
- 1 prolog-redo-face))
- ((eq prolog-system 'swi)
- '("[ \t]*\\(Redo\\):[ \t]*([ \t0-9]*)" 1 prolog-redo-face))
- (t nil)))
- (trace-call
-
- (cond
- ((eq prolog-system 'sicstus)
- '("[ \t]*[0-9]+[ \t]+[0-9]+[ \t]*\\(Call\\):"
- 1 font-lock-function-name-face))
- ((eq prolog-system 'swi)
- '("[ \t]*\\(Call\\):[ \t]*([ \t0-9]*)"
- 1 font-lock-function-name-face))
- (t nil)))
- (trace-exception
-
- (cond
- ((eq prolog-system 'sicstus)
- '("[ \t]*[0-9]+[ \t]+[0-9]+[ \t]*\\(Exception\\):"
- 1 prolog-exception-face))
- ((eq prolog-system 'swi)
- '("[ \t]*\\(Exception\\):[ \t]*([ \t0-9]*)"
- 1 prolog-exception-face))
- (t nil)))
- (error-message-identifier
-
- (cond
- ((eq prolog-system 'sicstus)
- '("{\\([A-Z]* ?ERROR:\\)" 1 prolog-exception-face prepend))
- ((eq prolog-system 'swi)
- '("^[[]\\(WARNING:\\)" 1 prolog-builtin-face prepend))
- (t nil)))
- (error-whole-messages
-
- (cond
- ((eq prolog-system 'sicstus)
- '("{\\([A-Z]* ?ERROR:.*\\)}[ \t]*$"
- 1 font-lock-comment-face append))
- ((eq prolog-system 'swi)
- '("^[[]WARNING:[^]]*[]]$" 0 font-lock-comment-face append))
- (t nil)))
- (error-warning-messages
-
-
-
- (cond
- ((eq prolog-system 'sicstus)
- '("^[A-Z ]*[A-Z]+:" 0 prolog-warning-face))
- (t nil)))
- (warning-messages
-
- (cond
- ((eq prolog-system 'sicstus)
- '("\\({ ?\\(Warning\\|WARNING\\) ?:.*}\\)[ \t]*$"
- 2 prolog-warning-face prepend))
- (t nil))))
-
- (delq
- nil
- (cond
- ((eq major-mode 'prolog-mode)
- (list
- head-predicates
- head-predicates-1
- quoted_atom
- string
- variables
- important-elements
- important-elements-1
- predspecs
- keywords
- sicstus-object-methods
- types
- modes
- directives))
- ((eq major-mode 'prolog-inferior-mode)
- (list
- prompt
- error-message-identifier
- error-whole-messages
- error-warning-messages
- warning-messages
- predspecs
- trace-exit
- trace-fail
- trace-redo
- trace-call
- trace-exception))
- ((eq major-mode 'compilation-mode)
- (list
- error-message-identifier
- error-whole-messages
- error-warning-messages
- warning-messages
- predspecs))))
- ))
- (defun prolog-indent-line (&optional _whole-exp)
- "Indent current line as Prolog code.
- With argument, indent any additional lines of the same clause
- rigidly along with this one (not yet)."
- (interactive "p")
- (let ((indent (prolog-indent-level))
- (pos (- (point-max) (point))))
- (beginning-of-line)
- (skip-chars-forward " \t")
- (indent-line-to indent)
- (if (> (- (point-max) pos) (point))
- (goto-char (- (point-max) pos)))
-
- (if (and prolog-align-comments-flag
- (save-excursion
- (line-beginning-position)
-
-
-
-
-
-
- (and (looking-at comment-start-skip)
-
-
- (progn (skip-chars-forward " \t")
- (not (eq (point) (match-end 1)))))))
- (save-excursion
- (prolog-goto-comment-column t)))
-
- (if (or prolog-electric-tab-flag prolog-electric-if-then-else-flag)
- (prolog-insert-spaces-after-paren))
- ))
- (defun prolog-comment-indent ()
- "Compute prolog comment indentation."
-
-
- (cond ((looking-at "%%%") (prolog-indentation-level-of-line))
- ((looking-at "%%") (prolog-indent-level))
- (t
- (save-excursion
- (skip-chars-backward " \t")
-
- (max (+ (current-column) (if (bolp) 0 1))
- comment-column)))
- ))
- (defun prolog-indent-level ()
- "Compute prolog indentation level."
- (save-excursion
- (beginning-of-line)
- (let ((totbal (prolog-region-paren-balance
- (prolog-clause-start t) (point)))
- (oldpoint (point)))
- (skip-chars-forward " \t")
- (cond
- ((looking-at "%%%") (prolog-indentation-level-of-line))
-
- ((looking-at "%[^%]") comment-column)
- ((bobp) 0)
-
-
- ((and (looking-at "}")
- (save-excursion
- (forward-char 1)
-
- (if prolog-use-prolog-tokenizer-flag
- (prolog-backward-list)
- (backward-list))
- (skip-chars-backward " \t")
- (backward-char 2)
- (looking-at "::")))
-
- (if prolog-object-end-to-0-flag
- 0
- prolog-indent-width))
-
- ((looking-at "\\*/")
- (save-excursion
- (prolog-find-start-of-mline-comment)
- (skip-chars-backward " \t")
- (- (current-column) 2)))
-
- ((and (looking-at "[^%/]")
- (eq (prolog-in-string-or-comment) 'cmt))
- (if prolog-indent-mline-comments-flag
- (prolog-find-start-of-mline-comment)
-
- (prolog-indentation-level-of-line)))
- (t
- (let ((empty t) ind linebal)
-
- (while empty
- (forward-line -1)
- (beginning-of-line)
- (if (bobp)
- (setq empty nil)
- (skip-chars-forward " \t")
- (if (not (or (not (member (prolog-in-string-or-comment)
- '(nil txt)))
- (looking-at "%")
- (looking-at "\n")))
- (setq empty nil))))
-
- (setq ind (if (bobp)
- 0
- (current-column)))
-
- (setq linebal (prolog-paren-balance))
-
- (if (< linebal 0)
- (progn
-
- (end-of-line)
- (setq ind (prolog-find-indent-of-matching-paren))))
-
- (beginning-of-line)
-
-
- (cond
-
-
- ((and (eq prolog-system 'sicstus)
- (looking-at ".+&[ \t]*\\(%.*\\|\\)$"))
- (setq ind prolog-indent-width))
-
-
- ((and (looking-at (format ".*%s[^\\.]*[ \t]*\\(%%.*\\|\\)$"
- prolog-head-delimiter))
-
- (save-excursion
- (let ((p (point)))
- (re-search-forward prolog-head-delimiter)
- (>= 0 (prolog-region-paren-balance p (point))))))
- (let ((headindent
- (if (< (prolog-paren-balance) 0)
- (save-excursion
- (end-of-line)
- (prolog-find-indent-of-matching-paren))
- (prolog-indentation-level-of-line))))
- (setq ind (+ headindent prolog-indent-width))))
-
- ((looking-at ".+ *::.*{[ \t]*$")
- (setq ind prolog-indent-width))
-
-
-
- ((and (looking-at "^.+\\.[ \t]*\\(%.*\\|\\)$")
-
- (save-excursion
- (end-of-line)
- (re-search-backward "\\.[ \t]*\\(%.*\\|\\)$" (point-min))
-
-
- (if (eq (prolog-in-string-or-comment) 'cmt)
-
- (let ((here (line-beginning-position)))
- (end-of-line)
- (re-search-backward "\\.[ \t]*%.*$" here t))
- (not (prolog-in-string-or-comment))
- )
- ))
- (setq ind 0))
-
-
-
-
- ((and (looking-at "^.+\\.[ \t]*\\(/\\*.*\\|\\)$")
-
- (save-excursion
- (end-of-line)
- (re-search-backward "\\.[ \t]*\\(/\\*.*\\|\\)$" (point-min))
-
-
- (if (eq (prolog-in-string-or-comment) 'cmt)
-
- (let ((here (line-beginning-position)))
- (end-of-line)
- (re-search-backward "\\.[ \t]*/\\*.*$" here t))
- (not (prolog-in-string-or-comment))
- )
- ))
- (setq ind 0))
- )
-
-
- (if (and
- (> totbal 0)
-
-
-
- (not (and (eq prolog-system 'sicstus)
- (= totbal 1)
- (prolog-in-object))))
- (if (looking-at
- (format "\\(%s\\|%s\\|0'.\\|[0-9]+'[0-9a-zA-Z]+\\|[^\n\'\"%%]\\)*\\(,\\|%s\\|%s\\)\[ \t]*\\(%%.*\\|\\)$"
- prolog-quoted-atom-regexp prolog-string-regexp
- prolog-left-paren prolog-left-indent-regexp))
- (progn
- (goto-char oldpoint)
- (setq ind (prolog-find-unmatched-paren
- (if prolog-paren-indent-p
- 'termdependent
- 'skipwhite)))
-
- )
- (goto-char oldpoint)
- (setq ind (prolog-find-unmatched-paren nil))
- ))
-
- ind
- ))))))
- (defun prolog-find-indent-of-matching-paren ()
- "Find the indentation level based on the matching parenthesis.
- Indentation level is set to the one the point is after when the function is
- called."
- (save-excursion
-
- (if prolog-use-prolog-tokenizer-flag
- (prolog-backward-list)
- (backward-list))
-
-
- (if (prolog-paren-is-the-first-on-line-p)
- (prolog-indentation-level-of-line)
-
- (progn
-
- (prolog-goto-next-paren 0)
-
-
- (if (looking-at prolog-left-paren)
- (+ (current-column) 1)
- (progn
- (forward-char 1)
- (prolog-find-indent-of-matching-paren)))
- ))
- ))
- (defun prolog-indentation-level-of-line ()
- "Return the indentation level of the current line."
- (save-excursion
- (beginning-of-line)
- (skip-chars-forward " \t")
- (current-column)))
- (defun prolog-paren-is-the-first-on-line-p ()
- "Return t if the parenthesis under the point is the first one on the line.
- Return nil otherwise.
- Note: does not check if the point is actually at a parenthesis!"
- (save-excursion
- (let ((begofline (line-beginning-position)))
- (if (= begofline (point))
- t
- (if (prolog-goto-next-paren begofline)
- nil
- t)))))
- (defun prolog-find-unmatched-paren (&optional mode)
- "Return the column of the last unmatched left parenthesis.
- If MODE is `skipwhite' then any white space after the parenthesis is added to
- the answer.
- If MODE is `plusone' then the parenthesis' column +1 is returned.
- If MODE is `termdependent' then if the unmatched parenthesis is part of
- a compound term the function will work as `skipwhite', otherwise
- it will return the column paren plus the value of `prolog-paren-indent'.
- If MODE is nil or not set then the parenthesis' exact column is returned."
- (save-excursion
-
-
- (prolog-goto-next-paren 0)
- (let ((roundparen (looking-at "(")))
- (if (looking-at prolog-left-paren)
- (let ((not-part-of-term
- (save-excursion
- (backward-char 1)
- (looking-at "[ \t]"))))
- (if (eq mode nil)
- (current-column)
- (if (and roundparen
- (eq mode 'termdependent)
- not-part-of-term)
- (+ (current-column)
- (if prolog-electric-tab-flag
-
- prolog-paren-indent
-
- (if (looking-at ".[ \t]*$")
- 2
- prolog-paren-indent))
- )
- (forward-char 1)
- (if (or (eq mode 'skipwhite) (eq mode 'termdependent) )
- (skip-chars-forward " \t"))
- (current-column))))
-
- (progn
- (forward-char 1)
-
-
- (if prolog-use-prolog-tokenizer-flag
- (prolog-backward-list)
- (backward-list))
- (prolog-find-unmatched-paren mode)))
- )))
- (defun prolog-paren-balance ()
- "Return the parenthesis balance of the current line.
- A return value of n means n more left parentheses than right ones."
- (save-excursion
- (end-of-line)
- (prolog-region-paren-balance (line-beginning-position) (point))))
- (defun prolog-region-paren-balance (beg end)
- "Return the summed parenthesis balance in the region.
- The region is limited by BEG and END positions."
- (save-excursion
- (let ((state (if prolog-use-prolog-tokenizer-flag
- (prolog-tokenize beg end)
- (parse-partial-sexp beg end))))
- (nth 0 state))))
- (defun prolog-goto-next-paren (limit-pos)
- "Move the point to the next parenthesis earlier in the buffer.
- Return t if a match was found before LIMIT-POS. Return nil otherwise."
- (let ((retval (re-search-backward
- (concat prolog-left-paren "\\|" prolog-right-paren)
- limit-pos t)))
-
- (if (and retval (prolog-in-string-or-comment))
- (prolog-goto-next-paren limit-pos)
- retval)
- ))
- (defun prolog-in-string-or-comment ()
- "Check whether string, atom, or comment is under current point.
- Return:
- `txt' if the point is in a string, atom, or character code expression
- `cmt' if the point is in a comment
- nil otherwise."
- (save-excursion
- (let* ((start
- (if (eq prolog-parse-mode 'beg-of-line)
-
- (save-excursion
- (let (safepoint)
- (beginning-of-line)
- (setq safepoint (point))
- (while (and (> (point) (point-min))
- (progn
- (forward-line -1)
- (end-of-line)
- (if (not (bobp))
- (backward-char 1))
- (looking-at "\\\\"))
- )
- (beginning-of-line)
- (setq safepoint (point)))
- safepoint))
-
- (prolog-clause-start)))
- (end (point))
- (state (if prolog-use-prolog-tokenizer-flag
- (prolog-tokenize start end)
- (if (fboundp 'syntax-ppss)
- (syntax-ppss)
- (parse-partial-sexp start end)))))
- (cond
- ((nth 3 state) 'txt)
- ((nth 4 state) 'cmt)
- (t
- (cond
- ((looking-at "%") 'cmt)
- ((looking-at "/\\*") 'cmt)
- ((looking-at "\'") 'txt)
- ((looking-at "\"") 'txt)
- (t nil)
- ))))
- ))
- (defun prolog-find-start-of-mline-comment ()
- "Return the start column of a /* */ comment.
- This assumes that the point is inside a comment."
- (re-search-backward "/\\*" (point-min) t)
- (forward-char 2)
- (skip-chars-forward " \t")
- (current-column))
- (defun prolog-insert-spaces-after-paren ()
- "Insert spaces after the opening parenthesis, \"then\" (->) and \"else\" (;) branches.
- Spaces are inserted if all preceding objects on the line are
- whitespace characters, parentheses, or then/else branches."
- (save-excursion
- (let ((regexp (concat "(\\|" prolog-left-indent-regexp))
- level)
- (beginning-of-line)
- (skip-chars-forward " \t")
- (when (looking-at regexp)
-
-
-
-
-
- (while (looking-at regexp)
- (goto-char (match-end 0))
- (setq level (+ (prolog-find-unmatched-paren) prolog-paren-indent))
-
- (let ((start (point)))
- (skip-chars-forward " \t")
- (delete-region start (point)))
- (indent-to level)
- (skip-chars-forward " \t"))
- )))
- (when (save-excursion
- (backward-char 2)
- (looking-at "\\s ;\\|\\s (\\|->"))
- (skip-chars-forward " \t"))
- )
- (defun prolog-comment-limits ()
- "Return the current comment limits plus the comment type (block or line).
- The comment limits are the range of a block comment or the range that
- contains all adjacent line comments (i.e. all comments that starts in
- the same column with no empty lines or non-whitespace characters
- between them)."
- (let ((here (point))
- lit-limits-b lit-limits-e lit-type beg end
- )
- (save-restriction
-
- (widen)
- (setq end (line-end-position)
- beg (line-beginning-position))
- (save-excursion
- (beginning-of-line)
- (setq lit-type (if (search-forward-regexp "%" end t) 'line 'block))
-
-
-
-
-
-
-
-
-
-
- (if (eq lit-type 'block)
- (progn
- (goto-char here)
- (when (looking-at "/\\*") (forward-char 2))
- (when (and (looking-at "\\*") (> (point) (point-min))
- (forward-char -1) (looking-at "/"))
- (forward-char 1))
- (when (save-excursion (search-backward "/*" nil t))
- (list (save-excursion (search-backward "/*") (point))
- (or (search-forward "*/" nil t) (point-max)) lit-type)))
-
- (setq lit-limits-b (- (point) 1)
- lit-limits-e end)
- (condition-case nil
- (if (progn (goto-char lit-limits-b)
- (looking-at "%"))
- (let ((col (current-column)) done)
- (setq beg (point)
- end lit-limits-e)
-
-
- (beginning-of-line)
- (while (and (zerop (setq done (forward-line -1)))
- (search-forward-regexp "^[ \t]*%"
- (line-end-position) t)
- (= (+ 1 col) (current-column)))
- (setq beg (- (point) 1)))
- (when (= done 0)
- (forward-line 1))
-
- (when (and (zerop (setq done (forward-line -1)))
- (search-forward "%" (line-end-position) t)
- (= (+ 1 col) (current-column)))
- (setq beg (- (point) 1)))
- (when (= done 0)
- (forward-line 1))
-
- (goto-char lit-limits-b)
- (beginning-of-line)
- (while (and (zerop (forward-line 1))
- (search-forward-regexp "^[ \t]*%"
- (line-end-position) t)
- (= (+ 1 col) (current-column)))
- (setq end (line-end-position)))
- (list beg end lit-type))
- (list lit-limits-b lit-limits-e lit-type)
- )
- (error (list lit-limits-b lit-limits-e lit-type))))
- ))))
- (defun prolog-guess-fill-prefix ()
-
- (when (save-excursion
- (end-of-line)
- (equal (prolog-in-string-or-comment) 'cmt))
- (let* ((bounds (prolog-comment-limits))
- (cbeg (car bounds))
- (type (nth 2 bounds))
- beg end)
- (save-excursion
- (end-of-line)
- (setq end (point))
- (beginning-of-line)
- (setq beg (point))
- (if (and (eq type 'line)
- (> cbeg beg)
- (save-excursion (not (search-forward-regexp "^[ \t]*%"
- cbeg t))))
- (progn
- (goto-char cbeg)
- (search-forward-regexp "%+[ \t]*" end t)
- (prolog-replace-in-string (buffer-substring beg (point))
- "[^ \t%]" " "))
-
- (if (search-forward-regexp "^[ \t]*\\(%+\\|\\*+\\|/\\*+\\)[ \t]*"
- end t)
- (prolog-replace-in-string (buffer-substring beg (point)) "/" " ")
- (beginning-of-line)
- (when (search-forward-regexp "^[ \t]+" end t)
- (buffer-substring beg (point)))))))))
- (defun prolog-fill-paragraph ()
- "Fill paragraph comment at or after point."
- (interactive)
- (let* ((bounds (prolog-comment-limits))
- (type (nth 2 bounds)))
- (if (eq type 'line)
- (let ((fill-prefix (prolog-guess-fill-prefix)))
- (fill-paragraph nil))
- (save-excursion
- (save-restriction
-
-
-
- (save-excursion
- (backward-paragraph)
- (unless (bobp) (forward-line))
- (if (string-match "^/\\*[^a-zA-Z]*$" (thing-at-point 'line))
- (narrow-to-region (point-at-eol) (point-max))))
- (save-excursion
- (forward-paragraph)
- (forward-line -1)
- (if (string-match "^[^a-zA-Z]*\\*/$" (thing-at-point 'line))
- (narrow-to-region (point-min) (point-at-bol))))
- (let ((fill-prefix (prolog-guess-fill-prefix)))
- (fill-paragraph nil))))
- )))
- (defun prolog-do-auto-fill ()
- "Carry out Auto Fill for Prolog mode.
- In effect it sets the `fill-prefix' when inside comments and then calls
- `do-auto-fill'."
- (let ((fill-prefix (prolog-guess-fill-prefix)))
- (do-auto-fill)
- ))
- (defalias 'prolog-replace-in-string
- (if (fboundp 'replace-in-string)
- #'replace-in-string
- (lambda (str regexp newtext &optional literal)
- (replace-regexp-in-string regexp newtext str nil literal))))
- (defconst prolog-tokenize-searchkey
- (concat "[0-9]+'"
- "\\|"
- "['\"]"
- "\\|"
- prolog-left-paren
- "\\|"
- prolog-right-paren
- "\\|"
- "%"
- "\\|"
- "/\\*"
- ))
- (defun prolog-tokenize (beg end &optional stopcond)
- "Tokenize a region of prolog code between BEG and END.
- STOPCOND decides the stop condition of the parsing. Valid values
- are 'zerodepth which stops the parsing at the first right parenthesis
- where the parenthesis depth is zero, 'skipover which skips over
- the current entity (e.g. a list, a string, etc.) and nil.
- The function returns a list with the following information:
- 0. parenthesis depth
- 3. 'atm if END is inside an atom
- 'str if END is inside a string
- 'chr if END is in a character code expression (0'x)
- nil otherwise
- 4. non-nil if END is inside a comment
- 5. end position (always equal to END if STOPCOND is nil)
- The rest of the elements are undefined."
- (save-excursion
- (let* ((end2 (1+ end))
- oldp
- (depth 0)
- (quoted nil)
- inside_cmt
- (endpos end2)
- skiptype
- )
- (goto-char beg)
- (if (and (eq stopcond 'skipover)
- (looking-at "[^[({'\"]"))
- (setq endpos (point))
- (while (and
- (re-search-forward prolog-tokenize-searchkey end2 t)
- (< (point) end2))
- (progn
- (setq oldp (point))
- (goto-char (match-beginning 0))
- (cond
-
- ((looking-at "'")
-
- (if (re-search-forward "[^\\]'" end2 'limit)
-
- (progn
- (setq oldp end2)
- (if (and (eq stopcond 'skipover)
- (not skiptype))
- (setq endpos (point))
- (setq oldp (point))))
- (setq quoted 'atm)))
- ((looking-at "\"")
-
- (if (re-search-forward "[^\\]\"" end2 'limit)
-
- (progn
- (setq oldp end2)
- (if (and (eq stopcond 'skipover)
- (not skiptype))
- (setq endpos (point))
- (setq oldp (point))))
- (setq quoted 'str)))
-
- ((looking-at prolog-left-paren)
- (setq depth (1+ depth))
- (setq skiptype 'paren))
- ((looking-at prolog-right-paren)
- (setq depth (1- depth))
- (if (and
- (or (eq stopcond 'zerodepth)
- (and (eq stopcond 'skipover)
- (eq skiptype 'paren)))
- (= depth 0))
- (progn
- (setq endpos (1+ (point)))
- (setq oldp end2))))
-
- ((looking-at comment-start)
- (end-of-line)
-
- (if (>= (point) end)
- (progn
- (setq inside_cmt t)
- (setq oldp end2))
- (setq oldp (point))))
- ((looking-at "/\\*")
- (if (re-search-forward "\\*/" end2 'limit)
- (setq oldp (point))
- (setq inside_cmt t)
- (setq oldp end2)))
-
- ((looking-at "0'")
- (setq oldp (1+ (match-end 0)))
- (if (> oldp end)
- (setq quoted 'chr)))
-
- ((looking-at "[0-9]+'")
- (goto-char (match-end 0))
- (skip-chars-forward "0-9a-zA-Z")
- (setq oldp (point)))
- )
- (goto-char oldp)
- ))
- )
-
- (and (prolog-inside-mline-comment end)
- (setq inside_cmt t))
-
- (list depth nil nil quoted inside_cmt endpos)
- )))
- (defun prolog-inside-mline-comment (here)
- (save-excursion
- (goto-char here)
- (let* ((next-close (save-excursion (search-forward "*/" nil t)))
- (next-open (save-excursion (search-forward "/*" nil t)))
- (prev-open (save-excursion (search-backward "/*" nil t)))
- (prev-close (save-excursion (search-backward "*/" nil t)))
- (unmatched-next-close (and next-close
- (or (not next-open)
- (> next-open next-close))))
- (unmatched-prev-open (and prev-open
- (or (not prev-close)
- (> prev-open prev-close))))
- )
- (or unmatched-next-close unmatched-prev-open)
- )))
- (defvar prolog-help-function
- '((mercury nil)
- (eclipse prolog-help-online)
-
- (sicstus prolog-find-documentation)
- (swi prolog-help-online)
- (t prolog-help-online))
- "Alist for the name of the function for finding help on a predicate.")
- (defun prolog-help-on-predicate ()
- "Invoke online help on the atom under cursor."
- (interactive)
- (cond
-
- ((eq prolog-help-function-i 'prolog-find-documentation)
- (prolog-find-documentation))
-
-
- (t
- (let* ((word (prolog-atom-under-point))
- (predicate (read-string
- (format "Help on predicate%s: "
- (if word
- (concat " (default " word ")")
- ""))
- nil nil word))
-
- )
- (if prolog-help-function-i
- (funcall prolog-help-function-i predicate)
- (error "Sorry, no help method defined for this Prolog system."))))
- ))
- (defun prolog-help-info (predicate)
- (let ((buffer (current-buffer))
- oldp
- (str (concat "^\\* " (regexp-quote predicate) " */")))
- (require 'info)
- (pop-to-buffer nil)
- (Info-goto-node prolog-info-predicate-index)
- (if (not (re-search-forward str nil t))
- (error (format "Help on predicate `%s' not found." predicate)))
- (setq oldp (point))
- (if (re-search-forward str nil t)
-
- (let ((max 2)
- n)
-
- (while (re-search-forward str nil t)
- (setq max (1+ max)))
- (goto-char oldp)
- (re-search-backward "[^ /]" nil t)
- (recenter 0)
- (setq n (read-string
- (format "Several matches, choose (1-%d): " max) "1"))
- (forward-line (- (string-to-number n) 1)))
-
- (re-search-backward "[^ /]" nil t))
-
- (prolog-Info-follow-nearest-node)
- (re-search-forward (concat "^`" (regexp-quote predicate)) nil t)
- (beginning-of-line)
- (recenter 0)
- (pop-to-buffer buffer)))
- (defun prolog-Info-follow-nearest-node ()
- (if (featurep 'xemacs)
- (Info-follow-nearest-node (point))
- (Info-follow-nearest-node)))
- (defun prolog-help-online (predicate)
- (prolog-ensure-process)
- (process-send-string "prolog" (concat "help(" predicate ").\n"))
- (display-buffer "*prolog*"))
- (defun prolog-help-apropos (string)
- "Find Prolog apropos on given STRING.
- This function is only available when `prolog-system' is set to `swi'."
- (interactive "sApropos: ")
- (cond
- ((eq prolog-system 'swi)
- (prolog-ensure-process)
- (process-send-string "prolog" (concat "apropos(" string ").\n"))
- (display-buffer "*prolog*"))
- (t
- (error "Sorry, no Prolog apropos available for this Prolog system."))))
- (defun prolog-atom-under-point ()
- "Return the atom under or left to the point."
- (save-excursion
- (let ((nonatom_chars "[](){},\. \t\n")
- start)
- (skip-chars-forward (concat "^" nonatom_chars))
- (skip-chars-backward nonatom_chars)
- (skip-chars-backward (concat "^" nonatom_chars))
- (setq start (point))
- (skip-chars-forward (concat "^" nonatom_chars))
- (buffer-substring-no-properties start (point))
- )))
- (defun prolog-find-documentation ()
- "Go to the Info node for a predicate in the SICStus Info manual."
- (interactive)
- (let ((pred (prolog-read-predicate)))
- (prolog-goto-predicate-info pred)))
- (defvar prolog-info-alist nil
- "Alist with all builtin predicates.
- Only for internal use by `prolog-find-documentation'")
- (defun prolog-goto-predicate-info (predicate)
- "Go to the info page for PREDICATE, which is a PredSpec."
- (interactive)
- (require 'info)
- (string-match "\\(.*\\)/\\([0-9]+\\).*$" predicate)
- (let ((buffer (current-buffer))
- (name (match-string 1 predicate))
- (arity (string-to-number (match-string 2 predicate)))
-
-
- )
- (pop-to-buffer nil)
- (Info-goto-node
- prolog-info-predicate-index)
- (Info-goto-node (car (cdr (assoc predicate prolog-info-alist))))
- (prolog-find-term (regexp-quote name) arity "^`")
- (recenter 0)
- (pop-to-buffer buffer))
- )
- (defun prolog-read-predicate ()
- "Read a PredSpec from the user.
- Returned value is a string \"FUNCTOR/ARITY\".
- Interaction supports completion."
- (let ((default (prolog-atom-under-point)))
-
- (if (not prolog-info-alist)
- (prolog-build-info-alist))
-
-
- (if (eq (try-completion default prolog-info-alist) nil)
- (setq default nil))
-
- (completing-read
- (if (zerop (length default))
- "Help on predicate: "
- (concat "Help on predicate (default " default "): "))
- prolog-info-alist nil t nil nil default)))
- (defun prolog-build-info-alist (&optional verbose)
- "Build an alist of all builtins and library predicates.
- Each element is of the form (\"NAME/ARITY\" . (INFO-NODE1 INFO-NODE2 ...)).
- Typically there is just one Info node associated with each name
- If an optional argument VERBOSE is non-nil, print messages at the beginning
- and end of list building."
- (if verbose
- (message "Building info alist..."))
- (setq prolog-info-alist
- (let ((l ())
- (last-entry (cons "" ())))
- (save-excursion
- (save-window-excursion
-
-
-
- (if (active-minibuffer-window)
- (select-window (next-window)))
-
- (save-window-excursion
- (info))
- (Info-goto-node prolog-info-predicate-index)
- (goto-char (point-min))
- (while (re-search-forward
- "^\\* \\(.+\\)/\\([0-9]+\\)\\([^\n:*]*\\):" nil t)
- (let* ((name (match-string 1))
- (arity (string-to-number (match-string 2)))
- ( (match-string 3))
- (fa (format "%s/%d%s" name arity comment))
- info-node)
- (beginning-of-line)
-
- (setq info-node (progn
- (re-search-forward ":[ \t]*\\([^:]+\\).$")
- (match-string 1)
- ))
-
-
- (if (equal fa (car last-entry))
- (setcdr last-entry (cons info-node (cdr last-entry)))
- (setq last-entry (cons fa (list info-node))
- l (cons last-entry l)))))
- (nreverse l)
- ))))
- (if verbose
- (message "Building info alist... done.")))
- (defun prolog-bsts (string)
- "Change backslashes to slashes in STRING."
- (let ((str1 (copy-sequence string))
- (len (length string))
- (i 0))
- (while (< i len)
- (if (char-equal (aref str1 i) ?\\)
- (aset str1 i ?/))
- (setq i (1+ i)))
- str1))
- (defun prolog-temporary-file ()
- "Make temporary file name for compilation."
- (if prolog-temporary-file-name
-
- (progn
- (write-region "" nil prolog-temporary-file-name nil 'silent)
- prolog-temporary-file-name)
-
-
- (setq prolog-temporary-file-name
- (make-temp-file "prolcomp" nil ".pl"))))
- (defun prolog-goto-prolog-process-buffer ()
- "Switch to the prolog process buffer and go to its end."
- (switch-to-buffer-other-window "*prolog*")
- (goto-char (point-max))
- )
- (defun prolog-enable-sicstus-sd ()
- "Enable the source level debugging facilities of SICStus 3.7 and later."
- (interactive)
- (require 'pltrace)
-
- (add-hook 'prolog-inferior-mode-hook 'pltrace-on)
- (if (not prolog-use-sicstus-sd)
- (progn
-
- (if (get-buffer "*prolog*")
-
- (eval '(pltrace-on)))
- (setq prolog-use-sicstus-sd t)
- )))
- (defun prolog-disable-sicstus-sd ()
- "Disable the source level debugging facilities of SICStus 3.7 and later."
- (interactive)
- (setq prolog-use-sicstus-sd nil)
-
- (remove-hook 'prolog-inferior-mode-hook 'pltrace-on)
-
- (if (get-buffer "*prolog*")
-
- (eval '(pltrace-off))))
- (defun prolog-toggle-sicstus-sd ()
-
- "Toggle the source level debugging facilities of SICStus 3.7 and later."
- (interactive)
- (if prolog-use-sicstus-sd
- (prolog-disable-sicstus-sd)
- (prolog-enable-sicstus-sd)))
- (defun prolog-debug-on (&optional arg)
- "Enable debugging.
- When called with prefix argument ARG, disable debugging instead."
- (interactive "P")
- (if arg
- (prolog-debug-off)
- (prolog-process-insert-string (get-process "prolog")
- prolog-debug-on-string)
- (process-send-string "prolog" prolog-debug-on-string)))
- (defun prolog-debug-off ()
- "Disable debugging."
- (interactive)
- (prolog-process-insert-string (get-process "prolog")
- prolog-debug-off-string)
- (process-send-string "prolog" prolog-debug-off-string))
- (defun prolog-trace-on (&optional arg)
- "Enable tracing.
- When called with prefix argument ARG, disable tracing instead."
- (interactive "P")
- (if arg
- (prolog-trace-off)
- (prolog-process-insert-string (get-process "prolog")
- prolog-trace-on-string)
- (process-send-string "prolog" prolog-trace-on-string)))
- (defun prolog-trace-off ()
- "Disable tracing."
- (interactive)
- (prolog-process-insert-string (get-process "prolog")
- prolog-trace-off-string)
- (process-send-string "prolog" prolog-trace-off-string))
- (defun prolog-zip-on (&optional arg)
- "Enable zipping (for SICStus 3.7 and later).
- When called with prefix argument ARG, disable zipping instead."
- (interactive "P")
- (if (not (and (eq prolog-system 'sicstus)
- (prolog-atleast-version '(3 . 7))))
- (error "Only works for SICStus 3.7 and later"))
- (if arg
- (prolog-zip-off)
- (prolog-process-insert-string (get-process "prolog")
- prolog-zip-on-string)
- (process-send-string "prolog" prolog-zip-on-string)))
- (defun prolog-zip-off ()
- "Disable zipping (for SICStus 3.7 and later)."
- (interactive)
- (prolog-process-insert-string (get-process "prolog")
- prolog-zip-off-string)
- (process-send-string "prolog" prolog-zip-off-string))
- (defun prolog-get-predspec ()
- (save-excursion
- (let ((state (prolog-clause-info))
- (object (prolog-in-object)))
- (if (or (equal (nth 0 state) "") (equal (prolog-in-string-or-comment) 'cmt))
- nil
- (if (and (eq prolog-system 'sicstus)
- object)
- (format "%s::%s/%d"
- object
- (nth 0 state)
- (nth 1 state))
- (format "%s/%d"
- (nth 0 state)
- (nth 1 state)))
- ))))
- (or (fboundp 'match-string)
-
- (defun match-string (num &optional string)
- "Return string of text matched by last search.
- NUM specifies which parenthesized expression in the last regexp.
- Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
- Zero means the entire text matched by the whole regexp or whole string.
- STRING should be given if the last search was by `string-match' on STRING."
- (if (match-beginning num)
- (if string
- (substring string (match-beginning num) (match-end num))
- (buffer-substring (match-beginning num) (match-end num))))))
- (defun prolog-pred-start ()
- "Return the starting point of the first clause of the current predicate."
- (save-excursion
- (goto-char (prolog-clause-start))
-
- (if (and (not (looking-at "[:?]-"))
- (not (looking-at "[ \t]*[%/]"))
- )
- (let* ((pinfo (prolog-clause-info))
- (predname (nth 0 pinfo))
- (arity (nth 1 pinfo))
- (op (point)))
- (while (and (re-search-backward
- (format "^%s\\([(\\.]\\| *%s\\)"
- predname prolog-head-delimiter) nil t)
- (= arity (nth 1 (prolog-clause-info)))
- )
- (setq op (point)))
- (if (eq prolog-system 'mercury)
-
- (progn
- (goto-char (prolog-beginning-of-clause))
- (while (and (not (eq (point) op))
- (looking-at
- (format ":-[ \t]*\\(pred\\|mode\\)[ \t]+%s"
- predname)))
- (setq op (point))
- (goto-char (prolog-beginning-of-clause)))))
- op)
- (point))))
- (defun prolog-pred-end ()
- "Return the position at the end of the last clause of the current predicate."
- (save-excursion
- (goto-char (prolog-clause-end))
- (goto-char (prolog-clause-start))
- (let* ((pinfo (prolog-clause-info))
- (predname (nth 0 pinfo))
- (arity (nth 1 pinfo))
- oldp
- (notdone t)
- (op (point)))
- (if (looking-at "[:?]-")
-
- (progn
- (if (and (eq prolog-system 'mercury)
- (looking-at
- (format ":-[ \t]*\\(pred\\|mode\\)[ \t]+\\(%s+\\)"
- prolog-atom-regexp)))
-
- (progn
- (setq predname (buffer-substring-no-properties
- (match-beginning 2) (match-end 2)))
- (while (re-search-forward
- (format
- "\n*\\(:-[ \t]*\\(pred\\|mode\\)[ \t]+\\)?%s[( \t]"
- predname)
- nil t))))
- (goto-char (prolog-clause-end))
- (setq op (point)))
-
- (while (and notdone
- (re-search-forward
- (format "^%s\\([(\\.]\\| *%s\\)"
- predname prolog-head-delimiter) nil t)
- (= arity (nth 1 (prolog-clause-info))))
- (setq oldp (point))
- (setq op (prolog-clause-end))
- (if (>= oldp op)
-
- (setq notdone nil)
-
- (goto-char op))))
- op)))
- (defun prolog-clause-start (&optional not-allow-methods)
- "Return the position at the start of the head of the current clause.
- If NOTALLOWMETHODS is non-nil then do not match on methods in
- objects (relevant only if 'prolog-system' is set to 'sicstus)."
- (save-excursion
- (let ((notdone t)
- (retval (point-min)))
- (end-of-line)
-
- (if (and (not not-allow-methods)
- (eq prolog-system 'sicstus)
- (prolog-in-object))
- (while (and
- notdone
-
- (re-search-backward
-
-
- "^[ \t]+[a-z$].*\\(:-\\|&\\|:: {\\)"
-
-
-
-
- (point-min) t))
- (if (>= (prolog-paren-balance) 0)
-
- (progn
- (setq retval (point))
- (setq notdone nil)))
- )
-
- (while (and
- notdone
-
-
-
- (let ((case-fold-search nil))
- (re-search-backward
-
-
- (format "^\\([%s$']\\|[:?]-\\)" prolog-lower-case-string)
- nil t)))
- (let ((bal (prolog-paren-balance)))
- (cond
- ((> bal 0)
-
- (progn
- (setq retval (point))
- (setq notdone nil)))
- ((and (= bal 0)
- (looking-at
- (format ".*\\(\\.\\|%s\\|!,\\)[ \t]*\\(%%.*\\|\\)$"
- prolog-head-delimiter)))
-
-
- (progn
- (setq retval (point))
- (setq notdone nil))
- )
- (t nil)
- ))))
- retval)))
- (defun prolog-clause-end (&optional not-allow-methods)
- "Return the position at the end of the current clause.
- If NOTALLOWMETHODS is non-nil then do not match on methods in
- objects (relevant only if 'prolog-system' is set to 'sicstus)."
- (save-excursion
- (beginning-of-line)
- (if (re-search-forward
- (if (and (not not-allow-methods)
- (eq prolog-system 'sicstus)
- (prolog-in-object))
- (format
- "^\\(%s\\|%s\\|[^\n\'\"%%]\\)*&[ \t]*\\(\\|%%.*\\)$\\|[ \t]*}"
- prolog-quoted-atom-regexp prolog-string-regexp)
- (format
- "^\\(%s\\|%s\\|[^\n\'\"%%]\\)*\\.[ \t]*\\(\\|%%.*\\)$"
- prolog-quoted-atom-regexp prolog-string-regexp))
- nil t)
- (if (and (prolog-in-string-or-comment)
- (not (eobp)))
- (progn
- (forward-char)
- (prolog-clause-end))
- (point))
- (point))))
- (defun prolog-clause-info ()
- "Return a (name arity) list for the current clause."
- (save-excursion
- (goto-char (prolog-clause-start))
- (let* ((op (point))
- (predname
- (if (looking-at prolog-atom-char-regexp)
- (progn
- (skip-chars-forward "^ (\\.")
- (buffer-substring op (point)))
- ""))
- (arity 0))
-
- (if (looking-at prolog-left-paren)
- (let ((endp (save-excursion
- (prolog-forward-list) (point))))
- (setq arity 1)
- (forward-char 1)
- (while (progn
- (skip-chars-forward "^[({,'\"")
- (< (point) endp))
- (if (looking-at ",")
- (progn
- (setq arity (1+ arity))
- (forward-char 1)
- )
-
-
-
- (goto-char (nth 5 (prolog-tokenize (point) endp 'skipover))))
- )))
- (list predname arity))))
- (defun prolog-in-object ()
- "Return object name if the point is inside a SICStus object definition."
-
-
- (save-excursion
- (if (save-excursion
- (beginning-of-line)
- (looking-at "\\([^\n ]+\\)[ \t]*::[ \t]*{"))
-
- (match-string 1)
-
- (if (and (re-search-backward "^[a-z$'}]" nil t)
- (looking-at "\\([^\n ]+\\)[ \t]*::[ \t]*{"))
- (match-string 1)
- nil))))
- (defun prolog-forward-list ()
- "Move the point to the matching right parenthesis."
- (interactive)
- (if prolog-use-prolog-tokenizer-flag
- (let ((state (prolog-tokenize (point) (point-max) 'zerodepth)))
- (goto-char (nth 5 state)))
- (forward-list)))
- (defun prolog-backward-list ()
- "Move the point to the matching left parenthesis."
- (interactive)
- (if prolog-use-prolog-tokenizer-flag
- (let ((bal 0)
- (paren-regexp (concat prolog-left-paren "\\|" prolog-right-paren))
- (notdone t))
-
- (while (and notdone (re-search-backward paren-regexp nil t))
- (cond
- ((looking-at prolog-left-paren)
- (if (not (prolog-in-string-or-comment))
- (setq bal (1+ bal)))
- (if (= bal 0)
- (setq notdone nil)))
- ((looking-at prolog-right-paren)
- (if (not (prolog-in-string-or-comment))
- (setq bal (1- bal))))
- )))
- (backward-list)))
- (defun prolog-beginning-of-clause ()
- "Move to the beginning of current clause.
- If already at the beginning of clause, move to previous clause."
- (interactive)
- (let ((point (point))
- (new-point (prolog-clause-start)))
- (if (and (>= new-point point)
- (> point 1))
- (progn
- (goto-char (1- point))
- (goto-char (prolog-clause-start)))
- (goto-char new-point)
- (skip-chars-forward " \t"))))
- (defun prolog-end-of-clause ()
- "Move to the end of clause.
- If already at the end of clause, move to next clause."
- (interactive)
- (let ((point (point))
- (new-point (prolog-clause-end)))
- (if (and (<= new-point point)
- (not (eq new-point (point-max))))
- (progn
- (goto-char (1+ point))
- (goto-char (prolog-clause-end)))
- (goto-char new-point))))
- (defun prolog-beginning-of-predicate ()
- "Go to the nearest beginning of predicate before current point.
- Return the final point or nil if no such a beginning was found."
- (interactive)
- (let ((op (point))
- (pos (prolog-pred-start)))
- (if pos
- (if (= op pos)
- (if (not (bobp))
- (progn
- (goto-char pos)
- (backward-char 1)
- (setq pos (prolog-pred-start))
- (if pos
- (progn
- (goto-char pos)
- (point)))))
- (goto-char pos)
- (point)))))
- (defun prolog-end-of-predicate ()
- "Go to the end of the current predicate."
- (interactive)
- (let ((op (point)))
- (goto-char (prolog-pred-end))
- (if (= op (point))
- (progn
- (forward-line 1)
- (prolog-end-of-predicate)))))
- (defun prolog-insert-predspec ()
- "Insert the predspec for the current predicate."
- (interactive)
- (let* ((pinfo (prolog-clause-info))
- (predname (nth 0 pinfo))
- (arity (nth 1 pinfo)))
- (insert (format "%s/%d" predname arity))))
- (defun prolog-view-predspec ()
- "Insert the predspec for the current predicate."
- (interactive)
- (let* ((pinfo (prolog-clause-info))
- (predname (nth 0 pinfo))
- (arity (nth 1 pinfo)))
- (message (format "%s/%d" predname arity))))
- (defun prolog-insert-predicate-template ()
- "Insert the template for the current clause."
- (interactive)
- (let* ((n 1)
- oldp
- (pinfo (prolog-clause-info))
- (predname (nth 0 pinfo))
- (arity (nth 1 pinfo)))
- (insert predname)
- (if (> arity 0)
- (progn
- (insert "(")
- (when prolog-electric-dot-full-predicate-template
- (setq oldp (point))
- (while (< n arity)
- (insert ",")
- (setq n (1+ n)))
- (insert ")")
- (goto-char oldp))
- ))
- ))
- (defun prolog-insert-next-clause ()
- "Insert newline and the name of the current clause."
- (interactive)
- (insert "\n")
- (prolog-insert-predicate-template))
- (defun prolog-insert-module-modeline ()
- "Insert a modeline for module specification.
- This line should be first in the buffer.
- The module name should be written manually just before the semi-colon."
- (interactive)
- (insert "%%% -*- Module: ; -*-\n")
- (backward-char 6))
- (defalias 'prolog-uncomment-region
- (if (fboundp 'uncomment-region) #'uncomment-region
- (lambda (beg end)
- "Uncomment the region between BEG and END."
- (interactive "r")
- (-region beg end -1))))
- (defun prolog-goto-comment-column (&optional nocreate)
- "Move comments on the current line to the correct position.
- If NOCREATE is nil (or omitted) and there is no comment on the line, then
- a new comment is created."
- (interactive)
- (beginning-of-line)
- (if (or (not nocreate)
- (and
- (re-search-forward
- (format "^\\(\\(%s\\|%s\\|[^\n\'\"%%]\\)*\\)%% *"
- prolog-quoted-atom-regexp prolog-string-regexp)
- (line-end-position) 'limit)
- (progn
- (goto-char (match-beginning 0))
- (not (eq (prolog-in-string-or-comment) 'txt)))))
- (indent-for-comment)))
- (defun prolog-indent-predicate ()
- "*Indent the current predicate."
- (interactive)
- (indent-region (prolog-pred-start) (prolog-pred-end) nil))
- (defun prolog-indent-buffer ()
- "*Indent the entire buffer."
- (interactive)
- (indent-region (point-min) (point-max) nil))
- (defun prolog-mark-clause ()
- "Put mark at the end of this clause and move point to the beginning."
- (interactive)
- (let ((pos (point)))
- (goto-char (prolog-clause-end))
- (forward-line 1)
- (beginning-of-line)
- (set-mark (point))
- (goto-char pos)
- (goto-char (prolog-clause-start))))
- (defun prolog-mark-predicate ()
- "Put mark at the end of this predicate and move point to the beginning."
- (interactive)
- (goto-char (prolog-pred-end))
- (let ((pos (point)))
- (forward-line 1)
- (beginning-of-line)
- (set-mark (point))
- (goto-char pos)
- (goto-char (prolog-pred-start))))
- (defun prolog-electric-delete (arg)
- "Delete preceding character or whitespace.
- If `prolog-hungry-delete-key-flag' is non-nil, then all preceding whitespace is
- consumed. If however an ARG is supplied, or `prolog-hungry-delete-key-flag' is
- nil, or point is inside a literal then the function in the variable
- `backward-delete-char' is called."
- (interactive "P")
- (if (or (not prolog-hungry-delete-key-flag)
- arg
- (prolog-in-string-or-comment))
- (funcall 'backward-delete-char (prefix-numeric-value arg))
- (let ((here (point)))
- (skip-chars-backward " \t\n")
- (if (/= (point) here)
- (delete-region (point) here)
- (funcall 'backward-delete-char 1)
- ))))
- (put 'prolog-electric-delete 'pending-delete 'supersede)
- (defun prolog-electric-if-then-else (arg)
- "If `prolog-electric-if-then-else-flag' is non-nil, indent if-then-else constructs.
- Bound to the >, ; and ( keys."
- (interactive "P")
- (self-insert-command (prefix-numeric-value arg))
- (if prolog-electric-if-then-else-flag (prolog-insert-spaces-after-paren)))
- (defun prolog-electric-colon (arg)
- "If `prolog-electric-colon-flag' is non-nil, insert the electric `:' construct.
- That is, insert space (if appropriate), `:-' and newline if colon is pressed
- at the end of a line that starts in the first column (i.e., clause
- heads)."
- (interactive "P")
- (if (and prolog-electric-colon-flag
- (null arg)
- (eolp)
-
- (not (string-match "^\\(\\s \\|%\\)" (thing-at-point 'line))))
- (progn
- (unless (save-excursion (backward-char 1) (looking-at "\\s "))
- (insert " "))
- (insert ":-\n")
- (prolog-indent-line))
- (self-insert-command (prefix-numeric-value arg))))
- (defun prolog-electric-dash (arg)
- "If `prolog-electric-dash-flag' is non-nil, insert the electric `-' construct.
- that is, insert space (if appropriate), `-->' and newline if dash is pressed
- at the end of a line that starts in the first column (i.e., DCG
- heads)."
- (interactive "P")
- (if (and prolog-electric-dash-flag
- (null arg)
- (eolp)
-
- (not (string-match "^\\(\\s \\|%\\)" (thing-at-point 'line))))
- (progn
- (unless (save-excursion (backward-char 1) (looking-at "\\s "))
- (insert " "))
- (insert "-->\n")
- (prolog-indent-line))
- (self-insert-command (prefix-numeric-value arg))))
- (defun prolog-electric-dot (arg)
- "Insert dot and newline or a head of a new clause.
- If `prolog-electric-dot-flag' is nil, then simply insert dot.
- Otherwise::
- When invoked at the end of nonempty line, insert dot and newline.
- When invoked at the end of an empty line, insert a recursive call to
- the current predicate.
- When invoked at the beginning of line, insert a head of a new clause
- of the current predicate.
- When called with prefix argument ARG, insert just dot."
- (interactive "P")
-
- (if (or (not prolog-electric-dot-flag)
- arg
- (prolog-in-string-or-comment)
-
- (not
- (or
-
-
-
- (save-excursion
- (re-search-backward
-
- "\\(^\\|[])}_!'0-9]+\\)[ \t]*\\="
- nil t))
- (save-excursion
- (re-search-backward
-
- (format "\\(^\\|[])}%s]+\\)[ \t]*\\="
- prolog-lower-case-string)
- nil t))
- (save-excursion
- (re-search-backward
-
- (format "\\(^\\|[])}%s]+\\)[ \t]*\\="
- prolog-upper-case-string)
- nil t))
- )
- )
-
- (not (= (prolog-region-paren-balance (prolog-clause-start) (point))
- 0))
- )
- (funcall 'self-insert-command (prefix-numeric-value arg))
- (cond
-
- ((bolp)
- (prolog-insert-predicate-template))
-
- ((save-excursion
- (beginning-of-line)
- (looking-at "[ \t]+$"))
- (prolog-insert-predicate-template)
- (when prolog-electric-dot-full-predicate-template
- (save-excursion
- (end-of-line)
- (insert ".\n"))))
-
- (t
- (insert ".\n"))
- )))
- (defun prolog-electric-underscore ()
- "Replace variable with an underscore.
- If `prolog-electric-underscore-flag' is non-nil and the point is
- on a variable then replace the variable with underscore and skip
- the following comma and whitespace, if any.
- If the point is not on a variable then insert underscore."
- (interactive)
- (if prolog-electric-underscore-flag
- (let (
- (case-fold-search nil)
- (oldp (point)))
-
-
- (skip-chars-backward
- (format "%s%s_"
-
- prolog-lower-case-string
- prolog-upper-case-string))
-
- (if (and (not (prolog-in-string-or-comment))
-
-
- (looking-at (format "\\<[_%s][%s%s_0-9]*\\>"
-
- prolog-upper-case-string
- prolog-lower-case-string
- prolog-upper-case-string)))
- (progn
- (replace-match "_")
- (skip-chars-forward ", \t\n"))
- (goto-char oldp)
- (self-insert-command 1))
- )
- (self-insert-command 1))
- )
- (defun prolog-find-term (functor arity &optional prefix)
- "Go to the position at the start of the next occurrence of a term.
- The term is specified with FUNCTOR and ARITY. The optional argument
- PREFIX is the prefix of the search regexp."
- (let* (
- (prefix (if (not prefix)
- "\\<"
- prefix))
- (regexp (concat prefix functor))
- (i 1))
-
- (if (= arity 0)
-
-
-
- (setq regexp (concat regexp "\\>"))
-
- (setq regexp (concat regexp "("))
- (while (< i arity)
- (setq regexp (concat regexp ".+,"))
- (setq i (1+ i)))
- (setq regexp (concat regexp ".+)")))
-
- (if (re-search-forward regexp nil t)
- (goto-char (match-beginning 0))
- (error "Term not found"))
- ))
- (defun prolog-variables-to-anonymous (beg end)
- "Replace all variables within a region BEG to END by anonymous variables."
- (interactive "r")
- (save-excursion
- (let ((case-fold-search nil))
- (goto-char end)
- (while (re-search-backward "\\<[A-Z_][a-zA-Z_0-9]*\\>" beg t)
- (progn
- (replace-match "_")
- (backward-char)))
- )))
- (defun prolog-set-atom-regexps ()
- "Set the `prolog-atom-char-regexp' and `prolog-atom-regexp' variables.
- Must be called after `prolog-build-case-strings'."
- (setq prolog-atom-char-regexp
- (format "[%s%s0-9_$]"
-
- prolog-lower-case-string
- prolog-upper-case-string))
- (setq prolog-atom-regexp
- (format "[%s$]%s*"
- prolog-lower-case-string
- prolog-atom-char-regexp))
- )
- (defun prolog-build-case-strings ()
- "Set `prolog-upper-case-string' and `prolog-lower-case-string'.
- Uses the current case-table for extracting the relevant information."
- (let ((up_string "")
- (low_string ""))
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- (let ((key 0))
- (while (< key 256)
- (cond
- ((and
- (eq (prolog-int-to-char key) (downcase key))
- (eq (prolog-int-to-char key) (upcase key)))
-
- )
- ((eq (prolog-int-to-char key) (downcase key))
-
- (setq low_string (format "%s%c" low_string key)))
- ((eq (prolog-int-to-char key) (upcase key))
-
- (setq up_string (format "%s%c" up_string key)))
- )
- (setq key (1+ key))))
-
-
- (setq prolog-upper-case-string (prolog-dash-letters up_string))
- (setq prolog-lower-case-string (prolog-dash-letters low_string))
- ))
- (defun prolog-ints-intervals (ints)
- "Return a list of intervals (from . to) covering INTS."
- (when ints
- (setq ints (sort ints '<))
- (let ((prev (car ints))
- (interval-start (car ints))
- intervals)
- (while ints
- (let ((next (car ints)))
- (when (> next (1+ prev))
- (setq intervals (cons (cons interval-start prev) intervals))
- (setq interval-start next))
- (setq prev next)
- (setq ints (cdr ints))))
- (setq intervals (cons (cons interval-start prev) intervals))
- (reverse intervals))))
- (defun prolog-dash-letters (string)
- "Return a condensed regexp covering all letters in STRING."
- (let ((intervals (prolog-ints-intervals (mapcar #'prolog-char-to-int
- (string-to-list string))))
- codes)
- (while intervals
- (let* ((i (car intervals))
- (from (car i))
- (to (cdr i))
- (c (cond ((= from to) `(,from))
- ((= (1+ from) to) `(,from ,to))
- (t `(,from ?- ,to)))))
- (setq codes (cons c codes)))
- (setq intervals (cdr intervals)))
- (apply 'concat (reverse codes))))
- (defalias 'prolog-int-to-char
- (if (fboundp 'int-to-char) #'int-to-char #'identity))
- (defalias 'prolog-char-to-int
- (if (fboundp 'char-to-int) #'char-to-int #'identity))
- (unless (fboundp 'region-exists-p)
- (defun region-exists-p ()
- "Non-nil iff the mark is set. Lobotomized version for Emacsen that do not provide their own."
- (mark)))
- (easy-menu-define
- prolog-menu-help (list prolog-mode-map prolog-inferior-mode-map)
- "Help menu for the Prolog mode."
-
- `(,(if (featurep 'xemacs) "Help"
-
-
-
- "Prolog-help")
- ["On predicate" prolog-help-on-predicate prolog-help-function-i]
- ["Apropos" prolog-help-apropos (eq prolog-system 'swi)]
- "---"
- ["Describe mode" describe-mode t]))
- (easy-menu-define
- prolog-edit-menu-runtime prolog-mode-map
- "Runtime Prolog commands available from the editing buffer"
-
- `("System"
-
- ,@(unless (featurep 'xemacs)
- '(:label (cond ((eq prolog-system 'eclipse) "ECLiPSe")
- ((eq prolog-system 'mercury) "Mercury")
- (t "System"))))
-
- ["Consult file" prolog-consult-file
- :included (not (eq prolog-system 'mercury))]
- ["Consult buffer" prolog-consult-buffer
- :included (not (eq prolog-system 'mercury))]
- ["Consult region" prolog-consult-region :active (region-exists-p)
- :included (not (eq prolog-system 'mercury))]
- ["Consult predicate" prolog-consult-predicate
- :included (not (eq prolog-system 'mercury))]
-
- ,(if (featurep 'xemacs) "---"
- ["---" nil :included (eq prolog-system 'sicstus)])
- ["Compile file" prolog-compile-file
- :included (eq prolog-system 'sicstus)]
- ["Compile buffer" prolog-compile-buffer
- :included (eq prolog-system 'sicstus)]
- ["Compile region" prolog-compile-region :active (region-exists-p)
- :included (eq prolog-system 'sicstus)]
- ["Compile predicate" prolog-compile-predicate
- :included (eq prolog-system 'sicstus)]
-
- ,(if (featurep 'xemacs) "---"
- ["---" nil :included (not (eq prolog-system 'mercury))])
-
- ["Debug" prolog-debug-on :included (not (eq prolog-system 'mercury))]
- ["Debug off" prolog-debug-off
-
-
- :included (not (memq prolog-system '(mercury sicstus)))]
- ["Trace" prolog-trace-on :included (not (eq prolog-system 'mercury))]
- ["Trace off" prolog-trace-off
- :included (not (memq prolog-system '(mercury sicstus)))]
- ["Zip" prolog-zip-on :included (and (eq prolog-system 'sicstus)
- (prolog-atleast-version '(3 . 7)))]
- ["All debug off" prolog-debug-off
- :included (eq prolog-system 'sicstus)]
- ["Source level debugging"
- prolog-toggle-sicstus-sd
- :included (and (eq prolog-system 'sicstus)
- (prolog-atleast-version '(3 . 7)))
- :style toggle
- :selected prolog-use-sicstus-sd]
- "---"
- ["Run" run-prolog
- :suffix (cond ((eq prolog-system 'eclipse) "ECLiPSe")
- ((eq prolog-system 'mercury) "Mercury")
- (t "Prolog"))]))
- (easy-menu-define
- prolog-edit-menu-insert-move prolog-mode-map
- "Commands for Prolog code manipulation."
- '("Prolog"
- ["Comment region" comment-region (region-exists-p)]
- ["Uncomment region" prolog-uncomment-region (region-exists-p)]
- ["Add comment/move to comment" indent-for-comment t]
- ["Convert variables in region to '_'" prolog-variables-to-anonymous
- :active (region-exists-p) :included (not (eq prolog-system 'mercury))]
- "---"
- ["Insert predicate template" prolog-insert-predicate-template t]
- ["Insert next clause head" prolog-insert-next-clause t]
- ["Insert predicate spec" prolog-insert-predspec t]
- ["Insert module modeline" prolog-insert-module-modeline t]
- "---"
- ["Beginning of clause" prolog-beginning-of-clause t]
- ["End of clause" prolog-end-of-clause t]
- ["Beginning of predicate" prolog-beginning-of-predicate t]
- ["End of predicate" prolog-end-of-predicate t]
- "---"
- ["Indent line" prolog-indent-line t]
- ["Indent region" indent-region (region-exists-p)]
- ["Indent predicate" prolog-indent-predicate t]
- ["Indent buffer" prolog-indent-buffer t]
- ["Align region" align (region-exists-p)]
- "---"
- ["Mark clause" prolog-mark-clause t]
- ["Mark predicate" prolog-mark-predicate t]
- ["Mark paragraph" mark-paragraph t]
-
-
- ))
- (defun prolog-menu ()
- "Add the menus for the Prolog editing buffers."
- (easy-menu-add prolog-edit-menu-insert-move)
- (easy-menu-add prolog-edit-menu-runtime)
-
- (set (make-local-variable 'imenu-create-index-function)
- 'imenu-default-create-index-function)
-
- (setq imenu-prev-index-position-function 'prolog-beginning-of-predicate)
- (setq imenu-extract-index-name-function 'prolog-get-predspec)
- (if (and prolog-imenu-flag
- (< (count-lines (point-min) (point-max)) prolog-imenu-max-lines))
- (imenu-add-to-menubar "Predicates"))
- (easy-menu-add prolog-menu-help))
- (easy-menu-define
- prolog-inferior-menu-all prolog-inferior-mode-map
- "Menu for the inferior Prolog buffer."
- `("Prolog"
-
- ,@(unless (featurep 'xemacs)
- '(:label (cond ((eq prolog-system 'eclipse) "ECLiPSe")
- ((eq prolog-system 'mercury) "Mercury")
- (t "Prolog"))))
-
- ,(if (featurep 'xemacs) "---"
- ["---" nil :included (not (eq prolog-system 'mercury))])
-
- ["Debug" prolog-debug-on :included (not (eq prolog-system 'mercury))]
- ["Debug off" prolog-debug-off
-
-
- :included (not (memq prolog-system '(mercury sicstus)))]
- ["Trace" prolog-trace-on :included (not (eq prolog-system 'mercury))]
- ["Trace off" prolog-trace-off
- :included (not (memq prolog-system '(mercury sicstus)))]
- ["Zip" prolog-zip-on :included (and (eq prolog-system 'sicstus)
- (prolog-atleast-version '(3 . 7)))]
- ["All debug off" prolog-debug-off
- :included (eq prolog-system 'sicstus)]
- ["Source level debugging"
- prolog-toggle-sicstus-sd
- :included (and (eq prolog-system 'sicstus)
- (prolog-atleast-version '(3 . 7)))
- :style toggle
- :selected prolog-use-sicstus-sd]
-
- "---"
- ["Interrupt Prolog" comint-interrupt-subjob t]
- ["Quit Prolog" comint-quit-subjob t]
- ["Kill Prolog" comint-kill-subjob t]))
- (defun prolog-inferior-menu ()
- "Create the menus for the Prolog inferior buffer.
- This menu is dynamically created because one may change systems during
- the life of an Emacs session."
- (easy-menu-add prolog-inferior-menu-all)
- (easy-menu-add prolog-menu-help))
- (defun prolog-mode-version ()
- "Echo the current version of Prolog mode in the minibuffer."
- (interactive)
- (message "Using Prolog mode version %s" prolog-mode-version))
- (provide 'prolog)
|