info.el 192 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013
  1. ;; info.el --- info package for Emacs
  2. ;; Copyright (C) 1985-1986, 1992-2012 Free Software Foundation, Inc.
  3. ;; Maintainer: FSF
  4. ;; Keywords: help
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;; Note that nowadays we expect Info files to be made using makeinfo.
  18. ;; In particular we make these assumptions:
  19. ;; - a menu item MAY contain colons but not colon-space ": "
  20. ;; - a menu item ending with ": " (but not ":: ") is an index entry
  21. ;; - a node name MAY NOT contain a colon
  22. ;; This distinction is to support indexing of computer programming
  23. ;; language terms that may contain ":" but not ": ".
  24. ;;; Code:
  25. (eval-when-compile (require 'cl))
  26. (defgroup info nil
  27. "Info subsystem."
  28. :group 'help
  29. :group 'docs)
  30. (defvar Info-history nil
  31. "Stack of Info nodes user has visited.
  32. Each element of the stack is a list (FILENAME NODENAME BUFFERPOS).")
  33. (defvar Info-history-forward nil
  34. "Stack of Info nodes user has visited with `Info-history-back' command.
  35. Each element of the stack is a list (FILENAME NODENAME BUFFERPOS).")
  36. (defvar Info-history-list nil
  37. "List of all Info nodes user has visited.
  38. Each element of the list is a list (FILENAME NODENAME).")
  39. (defcustom Info-history-skip-intermediate-nodes t
  40. "Non-nil means don't record intermediate Info nodes to the history.
  41. Intermediate Info nodes are nodes visited by Info internally in the process of
  42. searching the node to display. Intermediate nodes are not presented
  43. to the user."
  44. :type 'boolean
  45. :group 'info
  46. :version "24.1")
  47. (defcustom Info-enable-edit nil
  48. "Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
  49. This is convenient if you want to write Info files by hand.
  50. However, we recommend that you not do this.
  51. It is better to write a Texinfo file and generate the Info file from that,
  52. because that gives you a printed manual as well."
  53. :type 'boolean
  54. :group 'info)
  55. (defvar Info-enable-active-nodes nil
  56. "Non-nil allows Info to execute Lisp code associated with nodes.
  57. The Lisp code is executed when the node is selected.")
  58. (put 'Info-enable-active-nodes 'risky-local-variable t)
  59. (defface info-node
  60. '((((class color) (background light)) :foreground "brown" :weight bold :slant italic)
  61. (((class color) (background dark)) :foreground "white" :weight bold :slant italic)
  62. (t :weight bold :slant italic))
  63. "Face for Info node names."
  64. :group 'info)
  65. (defface info-title-1
  66. '((((type tty pc) (class color) (background light))
  67. :foreground "green" :weight bold)
  68. (((type tty pc) (class color) (background dark))
  69. :foreground "yellow" :weight bold)
  70. (t :height 1.2 :inherit info-title-2))
  71. "Face for info titles at level 1."
  72. :group 'info)
  73. (define-obsolete-face-alias 'Info-title-1-face 'info-title-1 "22.1")
  74. (defface info-title-2
  75. '((((type tty pc) (class color)) :foreground "lightblue" :weight bold)
  76. (t :height 1.2 :inherit info-title-3))
  77. "Face for info titles at level 2."
  78. :group 'info)
  79. (define-obsolete-face-alias 'Info-title-2-face 'info-title-2 "22.1")
  80. (defface info-title-3
  81. '((((type tty pc) (class color)) :weight bold)
  82. (t :height 1.2 :inherit info-title-4))
  83. "Face for info titles at level 3."
  84. :group 'info)
  85. (define-obsolete-face-alias 'Info-title-3-face 'info-title-3 "22.1")
  86. (defface info-title-4
  87. '((((type tty pc) (class color)) :weight bold)
  88. (t :weight bold :inherit variable-pitch))
  89. "Face for info titles at level 4."
  90. :group 'info)
  91. (define-obsolete-face-alias 'Info-title-4-face 'info-title-4 "22.1")
  92. (defface info-menu-header
  93. '((((type tty pc))
  94. :underline t
  95. :weight bold)
  96. (t
  97. :inherit variable-pitch
  98. :weight bold))
  99. "Face for headers in Info menus."
  100. :group 'info)
  101. (defface info-menu-star
  102. '((((class color)) :foreground "red1")
  103. (t :underline t))
  104. "Face for every third `*' in an Info menu."
  105. :group 'info)
  106. (define-obsolete-face-alias 'info-menu-5 'info-menu-star "22.1")
  107. (defface info-xref
  108. '((t :inherit link))
  109. "Face for unvisited Info cross-references."
  110. :group 'info)
  111. (defface info-xref-visited
  112. '((t :inherit (link-visited info-xref)))
  113. "Face for visited Info cross-references."
  114. :version "22.1"
  115. :group 'info)
  116. (defcustom Info-fontify-visited-nodes t
  117. "Non-nil to fontify references to visited nodes in `info-xref-visited' face."
  118. :version "22.1"
  119. :type 'boolean
  120. :group 'info)
  121. (defcustom Info-fontify-maximum-menu-size 100000
  122. "Maximum size of menu to fontify if `font-lock-mode' is non-nil.
  123. Set to nil to disable node fontification."
  124. :type 'integer
  125. :group 'info)
  126. (defcustom Info-use-header-line t
  127. "Non-nil means to put the beginning-of-node links in an Emacs header-line.
  128. A header-line does not scroll with the rest of the buffer."
  129. :type 'boolean
  130. :group 'info)
  131. (defface info-header-xref
  132. '((t :inherit info-xref))
  133. "Face for Info cross-references in a node header."
  134. :group 'info)
  135. (defface info-header-node
  136. '((t :inherit info-node))
  137. "Face for Info nodes in a node header."
  138. :group 'info)
  139. (defvar Info-directory-list nil
  140. "List of directories to search for Info documentation files.
  141. If nil, meaning not yet initialized, Info uses the environment
  142. variable INFOPATH to initialize it, or `Info-default-directory-list'
  143. if there is no INFOPATH variable in the environment, or the
  144. concatenation of the two if INFOPATH ends with a `path-separator'.
  145. When `Info-directory-list' is initialized from the value of
  146. `Info-default-directory-list', and Emacs is installed in one of the
  147. standard directories, the directory of Info files that come with Emacs
  148. is put last (so that local Info files override standard ones).
  149. When `Info-directory-list' is initialized from the value of
  150. `Info-default-directory-list', and Emacs is not installed in one
  151. of the standard directories, the first element of the resulting
  152. list is the directory where Emacs installs the Info files that
  153. come with it. This is so that Emacs's own manual, which suits the
  154. version of Emacs you are using, will always be found first. This
  155. is useful when you install an experimental version of Emacs without
  156. removing the standard installation.
  157. If you want to override the order of directories in
  158. `Info-default-directory-list', set INFOPATH in the environment.
  159. If you run the Emacs executable from the `src' directory in the Emacs
  160. source tree, and INFOPATH is not defined, the `info' directory in the
  161. source tree is used as the first element of `Info-directory-list', in
  162. place of the installation Info directory. This is useful when you run
  163. a version of Emacs without installing it.")
  164. (defcustom Info-additional-directory-list nil
  165. "List of additional directories to search for Info documentation files.
  166. These directories are searched after those in `Info-directory-list'."
  167. :type '(repeat directory)
  168. :group 'info)
  169. (defcustom Info-scroll-prefer-subnodes nil
  170. "If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
  171. If this is non-nil, and you scroll far enough in a node that its menu
  172. appears on the screen, the next \\<Info-mode-map>\\[Info-scroll-up]
  173. moves to a subnode indicated by the following menu item. This means
  174. that you visit a subnode before getting to the end of the menu.
  175. Setting this option to nil results in behavior similar to the stand-alone
  176. Info reader program, which visits the first subnode from the menu only
  177. when you hit the end of the current node."
  178. :version "22.1"
  179. :type 'boolean
  180. :group 'info)
  181. (defcustom Info-hide-note-references t
  182. "If non-nil, hide the tag and section reference in *note and * menu items.
  183. If value is non-nil but not `hide', also replaces the \"*note\" with \"see\".
  184. If value is non-nil but not t or `hide', the reference section is still shown.
  185. `nil' completely disables this feature. If this is non-nil, you might
  186. want to set `Info-refill-paragraphs'."
  187. :version "22.1"
  188. :type '(choice (const :tag "No hiding" nil)
  189. (const :tag "Replace tag and hide reference" t)
  190. (const :tag "Hide tag and reference" hide)
  191. (other :tag "Only replace tag" tag))
  192. :set (lambda (sym val)
  193. (set sym val)
  194. (dolist (buffer (buffer-list))
  195. (with-current-buffer buffer
  196. (when (eq major-mode 'Info-mode)
  197. (revert-buffer t t)))))
  198. :group 'info)
  199. (defcustom Info-refill-paragraphs nil
  200. "If non-nil, attempt to refill paragraphs with hidden references.
  201. This refilling may accidentally remove explicit line breaks in the Info
  202. file, so be prepared for a few surprises if you enable this feature.
  203. This only has an effect if `Info-hide-note-references' is non-nil."
  204. :version "22.1"
  205. :type 'boolean
  206. :group 'info)
  207. (defcustom Info-breadcrumbs-depth 4
  208. "Depth of breadcrumbs to display.
  209. 0 means do not display breadcrumbs."
  210. :version "23.1"
  211. :type 'integer
  212. :group 'info)
  213. (defcustom Info-search-whitespace-regexp "\\s-+"
  214. "If non-nil, regular expression to match a sequence of whitespace chars.
  215. This applies to Info search for regular expressions.
  216. You might want to use something like \"[ \\t\\r\\n]+\" instead.
  217. In the Customization buffer, that is `[' followed by a space,
  218. a tab, a carriage return (control-M), a newline, and `]+'."
  219. :type 'regexp
  220. :group 'info)
  221. (defcustom Info-isearch-search t
  222. "If non-nil, isearch in Info searches through multiple nodes.
  223. Before leaving the initial Info node, where isearch was started,
  224. it fails once with the error message [initial node], and with
  225. subsequent C-s/C-r continues through other nodes without failing
  226. with this error message in other nodes. When isearch fails for
  227. the rest of the manual, it wraps around the whole manual and
  228. restarts the search from the top/final node depending on
  229. search direction.
  230. Setting this option to nil restores the default isearch behavior
  231. with wrapping around the current Info node."
  232. :version "22.1"
  233. :type 'boolean
  234. :group 'info)
  235. (defvar Info-isearch-initial-node nil)
  236. (defvar Info-isearch-initial-history nil)
  237. (defvar Info-isearch-initial-history-list nil)
  238. (defcustom Info-mode-hook
  239. ;; Try to obey obsolete Info-fontify settings.
  240. (unless (and (boundp 'Info-fontify) (null Info-fontify))
  241. '(turn-on-font-lock))
  242. "Hooks run when `Info-mode' is called."
  243. :type 'hook
  244. :group 'info)
  245. (defcustom Info-selection-hook nil
  246. "Hooks run when `Info-select-node' is called."
  247. :type 'hook
  248. :group 'info)
  249. (defvar Info-edit-mode-hook nil
  250. "Hooks run when `Info-edit-mode' is called.")
  251. (defvar Info-current-file nil
  252. "Info file that Info is now looking at, or nil.
  253. This is the name that was specified in Info, not the actual file name.
  254. It doesn't contain directory names or file name extensions added by Info.")
  255. (defvar Info-current-subfile nil
  256. "Info subfile that is actually in the *info* buffer now.
  257. It is nil if current Info file is not split into subfiles.")
  258. (defvar Info-current-node nil
  259. "Name of node that Info is now looking at, or nil.")
  260. (defvar Info-tag-table-marker nil
  261. "Marker pointing at beginning of current Info file's tag table.
  262. Marker points nowhere if file has no tag table.")
  263. (defvar Info-tag-table-buffer nil
  264. "Buffer used for indirect tag tables.")
  265. (defvar Info-current-file-completions nil
  266. "Cached completion list for current Info file.")
  267. (defvar Info-file-supports-index-cookies nil
  268. "Non-nil if current Info file supports index cookies.")
  269. (defvar Info-file-supports-index-cookies-list nil
  270. "List of Info files with information about index cookies support.
  271. Each element of the list is a list (FILENAME SUPPORTS-INDEX-COOKIES)
  272. where SUPPORTS-INDEX-COOKIES can be either t or nil.")
  273. (defvar Info-index-alternatives nil
  274. "List of possible matches for last `Info-index' command.")
  275. (defvar Info-point-loc nil
  276. "Point location within a selected node.
  277. If string, the point is moved to the proper occurrence of the
  278. name of the followed cross reference within a selected node.
  279. If number, the point is moved to the corresponding line.")
  280. (defvar Info-standalone nil
  281. "Non-nil if Emacs was started solely as an Info browser.")
  282. (defvar Info-virtual-files nil
  283. "List of definitions of virtual Info files.
  284. Each element of the list has the format (FILENAME (OPERATION . HANDLER) ...)
  285. where FILENAME is a regexp that matches a class of virtual Info file names.
  286. It should be carefully chosen to not cause file name clashes with
  287. existing file names. OPERATION is one of the following operation
  288. symbols `find-file', `find-node', `toc-nodes' that define what HANDLER
  289. function to call instead of calling the default corresponding function
  290. to override it.")
  291. (defvar Info-virtual-nodes nil
  292. "List of definitions of virtual Info nodes.
  293. Each element of the list has the format (NODENAME (OPERATION . HANDLER) ...)
  294. where NODENAME is a regexp that matches a class of virtual Info node names.
  295. It should be carefully chosen to not cause node name clashes with
  296. existing node names. OPERATION is one of the following operation
  297. symbols `find-node' that define what HANDLER function to call instead
  298. of calling the default corresponding function to override it.")
  299. (defvar Info-current-node-virtual nil
  300. "Non-nil if the current Info node is virtual.")
  301. (defun Info-virtual-file-p (filename)
  302. "Check if Info file FILENAME is virtual."
  303. (Info-virtual-fun 'find-file filename nil))
  304. (defun Info-virtual-fun (op filename nodename)
  305. "Find a function that handles operations on virtual manuals.
  306. OP is an operation symbol (`find-file', `find-node' or `toc-nodes'),
  307. FILENAME is a virtual Info file name, NODENAME is a virtual Info
  308. node name. Return a function found either in `Info-virtual-files'
  309. or `Info-virtual-nodes'."
  310. (or (and (stringp filename) ; some legacy code can still use a symbol
  311. (cdr-safe (assoc op (assoc-default filename
  312. Info-virtual-files
  313. 'string-match))))
  314. (and (stringp nodename) ; some legacy code can still use a symbol
  315. (cdr-safe (assoc op (assoc-default nodename
  316. Info-virtual-nodes
  317. 'string-match))))))
  318. (defun Info-virtual-call (virtual-fun &rest args)
  319. "Call a function that handles operations on virtual manuals."
  320. (when (functionp virtual-fun)
  321. (or (apply virtual-fun args) t)))
  322. (defvar Info-suffix-list
  323. ;; The MS-DOS list should work both when long file names are
  324. ;; supported (Windows 9X), and when only 8+3 file names are available.
  325. (if (eq system-type 'ms-dos)
  326. '( (".gz" . "gunzip")
  327. (".z" . "gunzip")
  328. (".bz2" . ("bzip2" "-dc"))
  329. (".inz" . "gunzip")
  330. (".igz" . "gunzip")
  331. (".info.Z" . "gunzip")
  332. (".info.gz" . "gunzip")
  333. ("-info.Z" . "gunzip")
  334. ("-info.gz" . "gunzip")
  335. ("/index.gz" . "gunzip")
  336. ("/index.z" . "gunzip")
  337. (".inf" . nil)
  338. (".info" . nil)
  339. ("-info" . nil)
  340. ("/index" . nil)
  341. ("" . nil))
  342. '( (".info.Z" . "uncompress")
  343. (".info.Y" . "unyabba")
  344. (".info.gz" . "gunzip")
  345. (".info.z" . "gunzip")
  346. (".info.bz2" . ("bzip2" "-dc"))
  347. (".info.xz" . "unxz")
  348. (".info" . nil)
  349. ("-info.Z" . "uncompress")
  350. ("-info.Y" . "unyabba")
  351. ("-info.gz" . "gunzip")
  352. ("-info.bz2" . ("bzip2" "-dc"))
  353. ("-info.z" . "gunzip")
  354. ("-info.xz" . "unxz")
  355. ("-info" . nil)
  356. ("/index.Z" . "uncompress")
  357. ("/index.Y" . "unyabba")
  358. ("/index.gz" . "gunzip")
  359. ("/index.z" . "gunzip")
  360. ("/index.bz2" . ("bzip2" "-dc"))
  361. ("/index.xz" . "unxz")
  362. ("/index" . nil)
  363. (".Z" . "uncompress")
  364. (".Y" . "unyabba")
  365. (".gz" . "gunzip")
  366. (".z" . "gunzip")
  367. (".bz2" . ("bzip2" "-dc"))
  368. (".xz" . "unxz")
  369. ("" . nil)))
  370. "List of file name suffixes and associated decoding commands.
  371. Each entry should be (SUFFIX . STRING); the file is given to
  372. the command as standard input.
  373. STRING may be a list of strings. In that case, the first element is
  374. the command name, and the rest are arguments to that command.
  375. If STRING is nil, no decoding is done.
  376. Because the SUFFIXes are tried in order, the empty string should
  377. be last in the list.")
  378. ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
  379. ;; First, on MS-DOS with no long file names support, delete some of
  380. ;; the extension in FILENAME to make room.
  381. (defun info-insert-file-contents-1 (filename suffix lfn)
  382. (if lfn ; long file names are supported
  383. (concat filename suffix)
  384. (let* ((sans-exts (file-name-sans-extension filename))
  385. ;; How long is the extension in FILENAME (not counting the dot).
  386. (ext-len (max 0 (- (length filename) (length sans-exts) 1)))
  387. ext-left)
  388. ;; SUFFIX starts with a dot. If FILENAME already has one,
  389. ;; get rid of the one in SUFFIX (unless suffix is empty).
  390. (or (and (<= ext-len 0)
  391. (not (eq (aref filename (1- (length filename))) ?.)))
  392. (= (length suffix) 0)
  393. (setq suffix (substring suffix 1)))
  394. ;; How many chars of that extension should we keep?
  395. (setq ext-left (min ext-len (max 0 (- 3 (length suffix)))))
  396. ;; Get rid of the rest of the extension, and add SUFFIX.
  397. (concat (substring filename 0 (- (length filename)
  398. (- ext-len ext-left)))
  399. suffix))))
  400. (defun info-file-exists-p (filename)
  401. (and (file-exists-p filename)
  402. (not (file-directory-p filename))))
  403. (defun info-insert-file-contents (filename &optional visit)
  404. "Insert the contents of an Info file in the current buffer.
  405. Do the right thing if the file has been compressed or zipped."
  406. (let* ((tail Info-suffix-list)
  407. (jka-compr-verbose nil)
  408. (lfn (if (fboundp 'msdos-long-file-names)
  409. (msdos-long-file-names)
  410. t))
  411. (check-short (and (fboundp 'msdos-long-file-names)
  412. lfn))
  413. fullname decoder done)
  414. (if (info-file-exists-p filename)
  415. ;; FILENAME exists--see if that name contains a suffix.
  416. ;; If so, set DECODE accordingly.
  417. (progn
  418. (while (and tail
  419. (not (string-match
  420. (concat (regexp-quote (car (car tail))) "$")
  421. filename)))
  422. (setq tail (cdr tail)))
  423. (setq fullname filename
  424. decoder (cdr (car tail))))
  425. ;; Try adding suffixes to FILENAME and see if we can find something.
  426. (while (and tail (not done))
  427. (setq fullname (info-insert-file-contents-1 filename
  428. (car (car tail)) lfn))
  429. (if (info-file-exists-p fullname)
  430. (setq done t
  431. ;; If we found a file with a suffix, set DECODER
  432. ;; according to the suffix.
  433. decoder (cdr (car tail)))
  434. ;; When the MS-DOS port runs on Windows, we need to check
  435. ;; the short variant of a long file name as well.
  436. (when check-short
  437. (setq fullname (info-insert-file-contents-1 filename
  438. (car (car tail)) nil))
  439. (if (info-file-exists-p fullname)
  440. (setq done t
  441. decoder (cdr (car tail))))))
  442. (setq tail (cdr tail)))
  443. (or tail
  444. (error "Can't find %s or any compressed version of it" filename)))
  445. ;; check for conflict with jka-compr
  446. (if (and (jka-compr-installed-p)
  447. (jka-compr-get-compression-info fullname))
  448. (setq decoder nil))
  449. (if decoder
  450. (progn
  451. (insert-file-contents-literally fullname visit)
  452. (let ((inhibit-read-only t)
  453. (coding-system-for-write 'no-conversion)
  454. (inhibit-null-byte-detection t) ; Index nodes include null bytes
  455. (default-directory (or (file-name-directory fullname)
  456. default-directory)))
  457. (or (consp decoder)
  458. (setq decoder (list decoder)))
  459. (apply 'call-process-region (point-min) (point-max)
  460. (car decoder) t t nil (cdr decoder))))
  461. (let ((inhibit-null-byte-detection t)) ; Index nodes include null bytes
  462. (insert-file-contents fullname visit)))))
  463. (defun Info-file-supports-index-cookies (&optional file)
  464. "Return non-nil value if FILE supports Info index cookies.
  465. Info index cookies were first introduced in 4.7, and all later
  466. makeinfo versions output them in index nodes, so we can rely
  467. solely on the makeinfo version. This function caches the information
  468. in `Info-file-supports-index-cookies-list'."
  469. (or file (setq file Info-current-file))
  470. (or (assoc file Info-file-supports-index-cookies-list)
  471. ;; Skip virtual Info files
  472. (and (or (not (stringp file))
  473. (Info-virtual-file-p file))
  474. (setq Info-file-supports-index-cookies-list
  475. (cons (cons file nil) Info-file-supports-index-cookies-list)))
  476. (save-excursion
  477. (let ((found nil))
  478. (goto-char (point-min))
  479. (condition-case ()
  480. (if (and (re-search-forward
  481. "makeinfo[ \n]version[ \n]\\([0-9]+.[0-9]+\\)"
  482. (line-beginning-position 4) t)
  483. (not (version< (match-string 1) "4.7")))
  484. (setq found t))
  485. (error nil))
  486. (setq Info-file-supports-index-cookies-list
  487. (cons (cons file found) Info-file-supports-index-cookies-list)))))
  488. (cdr (assoc file Info-file-supports-index-cookies-list)))
  489. (defun Info-default-dirs ()
  490. (let ((source (expand-file-name "info/" source-directory))
  491. (sibling (if installation-directory
  492. (expand-file-name "info/" installation-directory)
  493. (if invocation-directory
  494. (let ((infodir (expand-file-name
  495. "../share/info/"
  496. invocation-directory)))
  497. (if (file-exists-p infodir)
  498. infodir
  499. (setq infodir (expand-file-name
  500. "../../../share/info/"
  501. invocation-directory))
  502. (and (file-exists-p infodir)
  503. infodir))))))
  504. alternative)
  505. (setq alternative
  506. (if (and sibling (file-exists-p sibling))
  507. ;; Uninstalled, Emacs builddir != srcdir.
  508. sibling
  509. ;; Uninstalled, builddir == srcdir
  510. source))
  511. (if (or (member alternative Info-default-directory-list)
  512. ;; On DOS/NT, we use movable executables always,
  513. ;; and we must always find the Info dir at run time.
  514. (if (memq system-type '(ms-dos windows-nt))
  515. nil
  516. ;; Use invocation-directory for Info
  517. ;; only if we used it for exec-directory also.
  518. (not (string= exec-directory
  519. (expand-file-name "lib-src/"
  520. installation-directory))))
  521. (not (file-exists-p alternative)))
  522. Info-default-directory-list
  523. ;; `alternative' contains the Info files that came with this
  524. ;; version, so we should look there first. `Info-insert-dir'
  525. ;; currently expects to find `alternative' first on the list.
  526. (cons alternative
  527. ;; Don't drop the last part, it might contain non-Emacs stuff.
  528. ;; (reverse (cdr (reverse
  529. Info-default-directory-list)))) ;; )))
  530. (defun info-initialize ()
  531. "Initialize `Info-directory-list', if that hasn't been done yet."
  532. (unless Info-directory-list
  533. (let ((path (getenv "INFOPATH"))
  534. (sep (regexp-quote path-separator)))
  535. (setq Info-directory-list
  536. (prune-directory-list
  537. (if path
  538. (if (string-match-p (concat sep "\\'") path)
  539. (append (split-string (substring path 0 -1) sep)
  540. (Info-default-dirs))
  541. (split-string path sep))
  542. (Info-default-dirs))))
  543. ;; For a self-contained (ie relocatable) NS build, AFAICS we
  544. ;; always want the included info directory to be at the head of
  545. ;; the search path, unless it's already in INFOPATH somewhere.
  546. ;; It's at the head of Info-default-directory-list,
  547. ;; but there's no way to get it at the head of Info-directory-list
  548. ;; except by doing it here.
  549. (and path
  550. (featurep 'ns)
  551. (let ((dir (expand-file-name "../info" data-directory)))
  552. (and (file-directory-p dir)
  553. (not (member dir (split-string path ":" t)))
  554. (push dir Info-directory-list)))))))
  555. ;;;###autoload
  556. (defun info-other-window (&optional file-or-node)
  557. "Like `info' but show the Info buffer in another window."
  558. (interactive (if current-prefix-arg
  559. (list (read-file-name "Info file name: " nil nil t))))
  560. (info-setup file-or-node (switch-to-buffer-other-window "*info*")))
  561. ;;;###autoload (put 'info 'info-file (purecopy "emacs"))
  562. ;;;###autoload
  563. (defun info (&optional file-or-node buffer)
  564. "Enter Info, the documentation browser.
  565. Optional argument FILE-OR-NODE specifies the file to examine;
  566. the default is the top-level directory of Info.
  567. Called from a program, FILE-OR-NODE may specify an Info node of the form
  568. \"(FILENAME)NODENAME\".
  569. Optional argument BUFFER specifies the Info buffer name;
  570. the default buffer name is *info*. If BUFFER exists,
  571. just switch to BUFFER. Otherwise, create a new buffer
  572. with the top-level Info directory.
  573. In interactive use, a non-numeric prefix argument directs
  574. this command to read a file name from the minibuffer.
  575. A numeric prefix argument selects an Info buffer with the prefix number
  576. appended to the Info buffer name.
  577. The search path for Info files is in the variable `Info-directory-list'.
  578. The top-level Info directory is made by combining all the files named `dir'
  579. in all the directories in that path.
  580. See a list of available Info commands in `Info-mode'."
  581. (interactive (list
  582. (if (and current-prefix-arg (not (numberp current-prefix-arg)))
  583. (read-file-name "Info file name: " nil nil t))
  584. (if (numberp current-prefix-arg)
  585. (format "*info*<%s>" current-prefix-arg))))
  586. (info-setup file-or-node
  587. (pop-to-buffer-same-window (or buffer "*info*"))))
  588. (defun info-setup (file-or-node buffer)
  589. "Display Info node FILE-OR-NODE in BUFFER."
  590. (if (and buffer (not (eq major-mode 'Info-mode)))
  591. (Info-mode))
  592. (if file-or-node
  593. ;; If argument already contains parentheses, don't add another set
  594. ;; since the argument will then be parsed improperly. This also
  595. ;; has the added benefit of allowing node names to be included
  596. ;; following the parenthesized filename.
  597. (Info-goto-node
  598. (if (and (stringp file-or-node) (string-match "(.*)" file-or-node))
  599. file-or-node
  600. (concat "(" file-or-node ")")))
  601. (if (and (zerop (buffer-size))
  602. (null Info-history))
  603. ;; If we just created the Info buffer, go to the directory.
  604. (Info-directory))))
  605. ;;;###autoload
  606. (defun info-emacs-manual ()
  607. "Display the Emacs manual in Info mode."
  608. (interactive)
  609. (info "emacs"))
  610. ;;;###autoload
  611. (defun info-emacs-bug ()
  612. "Display the \"Reporting Bugs\" section of the Emacs manual in Info mode."
  613. (interactive)
  614. (info "(emacs)Bugs"))
  615. ;;;###autoload
  616. (defun info-standalone ()
  617. "Run Emacs as a standalone Info reader.
  618. Usage: emacs -f info-standalone [filename]
  619. In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
  620. (setq Info-standalone t)
  621. (if (and command-line-args-left
  622. (not (string-match "^-" (car command-line-args-left))))
  623. (condition-case err
  624. (progn
  625. (info (car command-line-args-left))
  626. (setq command-line-args-left (cdr command-line-args-left)))
  627. (error (send-string-to-terminal
  628. (format "%s\n" (if (eq (car-safe err) 'error)
  629. (nth 1 err) err)))
  630. (save-buffers-kill-emacs)))
  631. (info)))
  632. ;; See if the accessible portion of the buffer begins with a node
  633. ;; delimiter, and the node header line which follows matches REGEXP.
  634. ;; Typically, this test will be followed by a loop that examines the
  635. ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
  636. ;; to have the overhead of this special test inside the loop.
  637. ;; This function changes match-data, but supposedly the caller might
  638. ;; want to use the results of re-search-backward.
  639. ;; The return value is the value of point at the beginning of matching
  640. ;; REGEXP, if the function succeeds, nil otherwise.
  641. (defun Info-node-at-bob-matching (regexp)
  642. (and (bobp) ; are we at beginning of buffer?
  643. (looking-at "\^_") ; does it begin with node delimiter?
  644. (let (beg)
  645. (forward-line 1)
  646. (setq beg (point))
  647. (forward-line 1) ; does the line after delimiter match REGEXP?
  648. (re-search-backward regexp beg t))))
  649. (defun Info-find-file (filename &optional noerror)
  650. "Return expanded FILENAME, or t if FILENAME is \"dir\".
  651. Optional second argument NOERROR, if t, means if file is not found
  652. just return nil (no error)."
  653. ;; Convert filename to lower case if not found as specified.
  654. ;; Expand it.
  655. (cond
  656. ((Info-virtual-call
  657. (Info-virtual-fun 'find-file filename nil)
  658. filename noerror))
  659. ((stringp filename)
  660. (let (temp temp-downcase found)
  661. (setq filename (substitute-in-file-name filename))
  662. (let ((dirs (if (string-match "^\\./" filename)
  663. ;; If specified name starts with `./'
  664. ;; then just try current directory.
  665. '("./")
  666. (if (file-name-absolute-p filename)
  667. ;; No point in searching for an
  668. ;; absolute file name
  669. '(nil)
  670. (if Info-additional-directory-list
  671. (append Info-directory-list
  672. Info-additional-directory-list)
  673. Info-directory-list)))))
  674. ;; Fall back on the installation directory if we can't find
  675. ;; the info node anywhere else.
  676. (when installation-directory
  677. (setq dirs (append dirs (list (expand-file-name
  678. "info" installation-directory)))))
  679. ;; Search the directory list for file FILENAME.
  680. (while (and dirs (not found))
  681. (setq temp (expand-file-name filename (car dirs)))
  682. (setq temp-downcase
  683. (expand-file-name (downcase filename) (car dirs)))
  684. ;; Try several variants of specified name.
  685. (let ((suffix-list Info-suffix-list)
  686. (lfn (if (fboundp 'msdos-long-file-names)
  687. (msdos-long-file-names)
  688. t)))
  689. (while (and suffix-list (not found))
  690. (cond ((info-file-exists-p
  691. (info-insert-file-contents-1
  692. temp (car (car suffix-list)) lfn))
  693. (setq found temp))
  694. ((info-file-exists-p
  695. (info-insert-file-contents-1
  696. temp-downcase (car (car suffix-list)) lfn))
  697. (setq found temp-downcase))
  698. ((and (fboundp 'msdos-long-file-names)
  699. lfn
  700. (info-file-exists-p
  701. (info-insert-file-contents-1
  702. temp (car (car suffix-list)) nil)))
  703. (setq found temp)))
  704. (setq suffix-list (cdr suffix-list))))
  705. (setq dirs (cdr dirs))))
  706. (if found
  707. (setq filename found)
  708. (if noerror
  709. (setq filename nil)
  710. (error "Info file %s does not exist" filename)))
  711. filename))))
  712. (defun Info-find-node (filename nodename &optional no-going-back)
  713. "Go to an Info node specified as separate FILENAME and NODENAME.
  714. NO-GOING-BACK is non-nil if recovering from an error in this function;
  715. it says do not attempt further (recursive) error recovery."
  716. (info-initialize)
  717. (setq filename (Info-find-file filename))
  718. ;; Go into Info buffer.
  719. (or (eq major-mode 'Info-mode) (switch-to-buffer "*info*"))
  720. ;; Record the node we are leaving, if we were in one.
  721. (and (not no-going-back)
  722. Info-current-file
  723. (push (list Info-current-file Info-current-node (point))
  724. Info-history))
  725. (Info-find-node-2 filename nodename no-going-back))
  726. ;;;###autoload
  727. (defun Info-on-current-buffer (&optional nodename)
  728. "Use Info mode to browse the current Info buffer.
  729. With a prefix arg, this queries for the node name to visit first;
  730. otherwise, that defaults to `Top'."
  731. (interactive
  732. (list (if current-prefix-arg
  733. (completing-read "Node name: " (Info-build-node-completions)
  734. nil t "Top"))))
  735. (unless nodename (setq nodename "Top"))
  736. (info-initialize)
  737. (Info-mode)
  738. (set (make-local-variable 'Info-current-file)
  739. (or buffer-file-name
  740. ;; If called on a non-file buffer, make a fake file name.
  741. (concat default-directory (buffer-name))))
  742. (Info-find-node-2 nil nodename))
  743. (defun Info-revert-find-node (filename nodename)
  744. "Go to an Info node FILENAME and NODENAME, re-reading disk contents.
  745. When *info* is already displaying FILENAME and NODENAME, the window position
  746. is preserved, if possible."
  747. (or (eq major-mode 'Info-mode) (switch-to-buffer "*info*"))
  748. (let ((old-filename Info-current-file)
  749. (old-nodename Info-current-node)
  750. (window-selected (eq (selected-window) (get-buffer-window)))
  751. (pcolumn (current-column))
  752. (pline (count-lines (point-min) (line-beginning-position)))
  753. (wline (count-lines (point-min) (window-start)))
  754. (new-history (and Info-current-file
  755. (list Info-current-file Info-current-node (point)))))
  756. ;; When `Info-current-file' is nil, `Info-find-node-2' rereads the file.
  757. (setq Info-current-file nil)
  758. (Info-find-node filename nodename)
  759. (if (and (equal old-filename Info-current-file)
  760. (equal old-nodename Info-current-node))
  761. (progn
  762. ;; note goto-line is no good, we want to measure from point-min
  763. (when window-selected
  764. (goto-char (point-min))
  765. (forward-line wline)
  766. (set-window-start (selected-window) (point)))
  767. (goto-char (point-min))
  768. (forward-line pline)
  769. (move-to-column pcolumn))
  770. ;; only add to the history when coming from a different file+node
  771. (if new-history
  772. (setq Info-history (cons new-history Info-history))))))
  773. (defun Info-revert-buffer-function (_ignore-auto noconfirm)
  774. (when (or noconfirm (y-or-n-p "Revert info buffer? "))
  775. (Info-revert-find-node Info-current-file Info-current-node)
  776. (message "Reverted %s" Info-current-file)))
  777. (defun Info-find-in-tag-table-1 (marker regexp case-fold)
  778. "Find a node in a tag table.
  779. MARKER specifies the buffer and position to start searching at.
  780. REGEXP is a regular expression matching nodes or references. Its first
  781. group should match `Node:' or `Ref:'.
  782. CASE-FOLD t means search for a case-insensitive match.
  783. If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
  784. FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
  785. where the match was found, and MODE is `major-mode' of the buffer in
  786. which the match was found."
  787. (let ((case-fold-search case-fold))
  788. (with-current-buffer (marker-buffer marker)
  789. (goto-char marker)
  790. ;; Search tag table
  791. (beginning-of-line)
  792. (when (re-search-forward regexp nil t)
  793. (list (string-equal "Ref:" (match-string 1))
  794. (+ (point-min) (read (current-buffer)))
  795. major-mode)))))
  796. (defun Info-find-in-tag-table (marker regexp)
  797. "Find a node in a tag table.
  798. MARKER specifies the buffer and position to start searching at.
  799. REGEXP is a regular expression matching nodes or references. Its first
  800. group should match `Node:' or `Ref:'.
  801. If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
  802. FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
  803. where the match was found, and MODE is `major-mode' of the buffer in
  804. which the match was found.
  805. This function tries to find a case-sensitive match first, then a
  806. case-insensitive match is tried."
  807. (let ((result (Info-find-in-tag-table-1 marker regexp nil)))
  808. (when (null (car result))
  809. (setq result (Info-find-in-tag-table-1 marker regexp t)))
  810. result))
  811. (defun Info-find-node-in-buffer-1 (regexp case-fold)
  812. "Find a node or anchor in the current buffer.
  813. REGEXP is a regular expression matching nodes or references. Its first
  814. group should match `Node:' or `Ref:'.
  815. CASE-FOLD t means search for a case-insensitive match.
  816. Value is the position at which a match was found, or nil if not found."
  817. (let ((case-fold-search case-fold)
  818. found)
  819. (save-excursion
  820. (if (Info-node-at-bob-matching regexp)
  821. (setq found (point))
  822. (while (and (not found)
  823. (search-forward "\n\^_" nil t))
  824. (forward-line 1)
  825. (let ((beg (point)))
  826. (forward-line 1)
  827. (if (re-search-backward regexp beg t)
  828. (setq found (line-beginning-position)))))))
  829. found))
  830. (defun Info-find-node-in-buffer (regexp)
  831. "Find a node or anchor in the current buffer.
  832. REGEXP is a regular expression matching nodes or references. Its first
  833. group should match `Node:' or `Ref:'.
  834. Value is the position at which a match was found, or nil if not found.
  835. This function looks for a case-sensitive match first. If none is found,
  836. a case-insensitive match is tried."
  837. (or (Info-find-node-in-buffer-1 regexp nil)
  838. (Info-find-node-in-buffer-1 regexp t)))
  839. (defun Info-find-node-2 (filename nodename &optional no-going-back)
  840. (buffer-disable-undo (current-buffer))
  841. (or (eq major-mode 'Info-mode)
  842. (Info-mode))
  843. (widen)
  844. (setq Info-current-node nil)
  845. (unwind-protect
  846. (let ((case-fold-search t)
  847. (virtual-fun (Info-virtual-fun 'find-node
  848. (or filename Info-current-file)
  849. nodename))
  850. anchorpos)
  851. (cond
  852. ((functionp virtual-fun)
  853. (let ((filename (or filename Info-current-file)))
  854. (setq buffer-read-only nil)
  855. (setq Info-current-file filename
  856. Info-current-subfile nil
  857. Info-current-file-completions nil
  858. buffer-file-name nil)
  859. (erase-buffer)
  860. (Info-virtual-call virtual-fun filename nodename no-going-back)
  861. (set-marker Info-tag-table-marker nil)
  862. (setq buffer-read-only t)
  863. (set-buffer-modified-p nil)
  864. (set (make-local-variable 'Info-current-node-virtual) t)))
  865. ((not (and
  866. ;; Reread a file when moving from a virtual node.
  867. (not Info-current-node-virtual)
  868. (or (null filename)
  869. (equal Info-current-file filename))))
  870. ;; Switch files if necessary
  871. (let ((inhibit-read-only t))
  872. (when Info-current-node-virtual
  873. ;; When moving from a virtual node.
  874. (set (make-local-variable 'Info-current-node-virtual) nil)
  875. (if (null filename)
  876. (setq filename Info-current-file)))
  877. (setq Info-current-file nil
  878. Info-current-subfile nil
  879. Info-current-file-completions nil
  880. buffer-file-name nil)
  881. (erase-buffer)
  882. (info-insert-file-contents filename nil)
  883. (setq default-directory (file-name-directory filename))
  884. (set-buffer-modified-p nil)
  885. (set (make-local-variable 'Info-file-supports-index-cookies)
  886. (Info-file-supports-index-cookies filename))
  887. ;; See whether file has a tag table. Record the location if yes.
  888. (goto-char (point-max))
  889. (forward-line -8)
  890. ;; Use string-equal, not equal, to ignore text props.
  891. (if (not (or (string-equal nodename "*")
  892. (not
  893. (search-forward "\^_\nEnd tag table\n" nil t))))
  894. (let (pos)
  895. ;; We have a tag table. Find its beginning.
  896. ;; Is this an indirect file?
  897. (search-backward "\nTag table:\n")
  898. (setq pos (point))
  899. (if (save-excursion
  900. (forward-line 2)
  901. (looking-at "(Indirect)\n"))
  902. ;; It is indirect. Copy it to another buffer
  903. ;; and record that the tag table is in that buffer.
  904. (let ((buf (current-buffer))
  905. (tagbuf
  906. (or Info-tag-table-buffer
  907. (generate-new-buffer " *info tag table*"))))
  908. (setq Info-tag-table-buffer tagbuf)
  909. (with-current-buffer tagbuf
  910. (buffer-disable-undo (current-buffer))
  911. (setq case-fold-search t)
  912. (erase-buffer)
  913. (insert-buffer-substring buf))
  914. (set-marker Info-tag-table-marker
  915. (match-end 0) tagbuf))
  916. (set-marker Info-tag-table-marker pos)))
  917. (set-marker Info-tag-table-marker nil))
  918. (setq Info-current-file filename)
  919. )))
  920. ;; Use string-equal, not equal, to ignore text props.
  921. (if (string-equal nodename "*")
  922. (progn (setq Info-current-node nodename)
  923. (Info-set-mode-line))
  924. ;; Possibilities:
  925. ;;
  926. ;; 1. Anchor found in tag table
  927. ;; 2. Anchor *not* in tag table
  928. ;;
  929. ;; 3. Node found in tag table
  930. ;; 4. Node *not* found in tag table, but found in file
  931. ;; 5. Node *not* in tag table, and *not* in file
  932. ;;
  933. ;; *Or* the same, but in an indirect subfile.
  934. ;; Search file for a suitable node.
  935. (let ((guesspos (point-min))
  936. (regexp (concat "\\(Node:\\|Ref:\\) *\\("
  937. (if (stringp nodename)
  938. (regexp-quote nodename)
  939. "")
  940. "\\) *[,\t\n\177]")))
  941. (catch 'foo
  942. ;; First, search a tag table, if any
  943. (when (marker-position Info-tag-table-marker)
  944. (let* ((m Info-tag-table-marker)
  945. (found (Info-find-in-tag-table m regexp)))
  946. (when found
  947. ;; FOUND is (ANCHOR POS MODE).
  948. (setq guesspos (nth 1 found))
  949. ;; If this is an indirect file, determine which
  950. ;; file really holds this node and read it in.
  951. (unless (eq (nth 2 found) 'Info-mode)
  952. ;; Note that the current buffer must be the
  953. ;; *info* buffer on entry to
  954. ;; Info-read-subfile. Thus the hackery above.
  955. (setq guesspos (Info-read-subfile guesspos)))
  956. ;; Handle anchor
  957. (when (nth 0 found)
  958. (goto-char (setq anchorpos guesspos))
  959. (throw 'foo t)))))
  960. ;; Else we may have a node, which we search for:
  961. (goto-char (max (point-min)
  962. (- (byte-to-position guesspos) 1000)))
  963. ;; Now search from our advised position (or from beg of
  964. ;; buffer) to find the actual node. First, check
  965. ;; whether the node is right where we are, in case the
  966. ;; buffer begins with a node.
  967. (let ((pos (Info-find-node-in-buffer regexp)))
  968. (when pos
  969. (goto-char pos)
  970. (throw 'foo t)))
  971. (when (string-match "\\([^.]+\\)\\." nodename)
  972. (let (Info-point-loc)
  973. (Info-find-node-2
  974. filename (match-string 1 nodename) no-going-back))
  975. (widen)
  976. (throw 'foo t))
  977. ;; No such anchor in tag table or node in tag table or file
  978. (user-error "No such node or anchor: %s" nodename))
  979. (Info-select-node)
  980. (goto-char (point-min))
  981. (forward-line 1) ; skip header line
  982. ;; (when (> Info-breadcrumbs-depth 0) ; skip breadcrumbs line
  983. ;; (forward-line 1))
  984. (cond (anchorpos
  985. (let ((new-history (list Info-current-file
  986. (substring-no-properties nodename))))
  987. ;; Add anchors to the history too
  988. (setq Info-history-list
  989. (cons new-history
  990. (remove new-history Info-history-list))))
  991. (goto-char anchorpos))
  992. ((numberp Info-point-loc)
  993. (forward-line (- Info-point-loc 2))
  994. (setq Info-point-loc nil))
  995. ((stringp Info-point-loc)
  996. (Info-find-index-name Info-point-loc)
  997. (setq Info-point-loc nil))))))
  998. ;; If we did not finish finding the specified node,
  999. ;; go back to the previous one.
  1000. (or Info-current-node no-going-back (null Info-history)
  1001. (let ((hist (car Info-history)))
  1002. (setq Info-history (cdr Info-history))
  1003. (Info-find-node (nth 0 hist) (nth 1 hist) t)
  1004. (goto-char (nth 2 hist))))))
  1005. ;; Cache the contents of the (virtual) dir file, once we have merged
  1006. ;; it for the first time, so we can save time subsequently.
  1007. (defvar Info-dir-contents nil)
  1008. ;; Cache for the directory we decided to use for the default-directory
  1009. ;; of the merged dir text.
  1010. (defvar Info-dir-contents-directory nil)
  1011. ;; Record the file attributes of all the files from which we
  1012. ;; constructed Info-dir-contents.
  1013. (defvar Info-dir-file-attributes nil)
  1014. (defvar Info-dir-file-name nil)
  1015. ;; Construct the Info directory node by merging the files named `dir'
  1016. ;; from various directories. Set the *info* buffer's
  1017. ;; default-directory to the first directory we actually get any text
  1018. ;; from.
  1019. (defun Info-insert-dir ()
  1020. (if (and Info-dir-contents Info-dir-file-attributes
  1021. ;; Verify that none of the files we used has changed
  1022. ;; since we used it.
  1023. (eval (cons 'and
  1024. (mapcar (lambda (elt)
  1025. (let ((curr (file-attributes
  1026. ;; Handle symlinks
  1027. (file-truename (car elt)))))
  1028. ;; Don't compare the access time.
  1029. (if curr (setcar (nthcdr 4 curr) 0))
  1030. (setcar (nthcdr 4 (cdr elt)) 0)
  1031. (equal (cdr elt) curr)))
  1032. Info-dir-file-attributes))))
  1033. (progn
  1034. (insert Info-dir-contents)
  1035. (goto-char (point-min)))
  1036. (let ((dirs (if Info-additional-directory-list
  1037. (append Info-directory-list
  1038. Info-additional-directory-list)
  1039. Info-directory-list))
  1040. (dir-file-attrs nil)
  1041. ;; Bind this in case the user sets it to nil.
  1042. (case-fold-search t)
  1043. ;; This is set non-nil if we find a problem in some input files.
  1044. problems
  1045. buffers buffer others nodes dirs-done)
  1046. ;; Search the directory list for the directory file.
  1047. (while dirs
  1048. (let ((truename (file-truename (expand-file-name (car dirs)))))
  1049. (or (member truename dirs-done)
  1050. (member (directory-file-name truename) dirs-done)
  1051. ;; Try several variants of specified name.
  1052. ;; Try upcasing, appending `.info', or both.
  1053. (let* (file
  1054. (attrs
  1055. (or
  1056. (progn (setq file (expand-file-name "dir" truename))
  1057. (file-attributes file))
  1058. (progn (setq file (expand-file-name "DIR" truename))
  1059. (file-attributes file))
  1060. (progn (setq file (expand-file-name "dir.info" truename))
  1061. (file-attributes file))
  1062. (progn (setq file (expand-file-name "DIR.INFO" truename))
  1063. (file-attributes file))
  1064. ;; Shouldn't really happen, but sometimes does,
  1065. ;; eg on Debian systems with buggy packages;
  1066. ;; so may as well try it.
  1067. ;; http://lists.gnu.org/archive/html/emacs-devel/2012-03/msg00005.html
  1068. (progn (setq file (expand-file-name "dir.gz" truename))
  1069. (file-attributes file)))))
  1070. (setq dirs-done
  1071. (cons truename
  1072. (cons (directory-file-name truename)
  1073. dirs-done)))
  1074. (if attrs
  1075. (with-current-buffer (generate-new-buffer " info dir")
  1076. (or buffers
  1077. (message "Composing main Info directory..."))
  1078. (condition-case nil
  1079. ;; Index nodes include null bytes. DIR
  1080. ;; files should not have indices, but who
  1081. ;; knows...
  1082. (let ((inhibit-null-byte-detection t))
  1083. (insert-file-contents file)
  1084. (set (make-local-variable 'Info-dir-file-name)
  1085. file)
  1086. (push (current-buffer) buffers)
  1087. (push (cons file attrs) dir-file-attrs))
  1088. (error (kill-buffer (current-buffer))))))))
  1089. (unless (cdr dirs)
  1090. (set (make-local-variable 'Info-dir-contents-directory)
  1091. (file-name-as-directory (car dirs))))
  1092. (setq dirs (cdr dirs))))
  1093. (or buffers
  1094. (error "Can't find the Info directory node"))
  1095. ;; Distinguish the dir file that comes with Emacs from all the
  1096. ;; others. Yes, that is really what this is supposed to do.
  1097. ;; The definition of `Info-directory-list' puts it first on that
  1098. ;; list and so last in `buffers' at this point.
  1099. (setq buffer (car (last buffers))
  1100. others (delq buffer buffers))
  1101. ;; Insert the entire original dir file as a start; note that we've
  1102. ;; already saved its default directory to use as the default
  1103. ;; directory for the whole concatenation.
  1104. (save-excursion (insert-buffer-substring buffer))
  1105. ;; Look at each of the other buffers one by one.
  1106. (dolist (other others)
  1107. (let (this-buffer-nodes)
  1108. ;; In each, find all the menus.
  1109. (with-current-buffer other
  1110. (goto-char (point-min))
  1111. ;; Find each menu, and add an elt to NODES for it.
  1112. (while (re-search-forward "^\\* Menu:" nil t)
  1113. (while (and (zerop (forward-line 1)) (eolp)))
  1114. (let ((beg (point))
  1115. nodename end)
  1116. (re-search-backward "^\^_")
  1117. (search-forward "Node: ")
  1118. (setq nodename (Info-following-node-name))
  1119. (search-forward "\n\^_" nil 'move)
  1120. (beginning-of-line)
  1121. (setq end (point))
  1122. (push (list nodename other beg end) this-buffer-nodes)))
  1123. (if (assoc-string "top" this-buffer-nodes t)
  1124. (setq nodes (nconc this-buffer-nodes nodes))
  1125. (setq problems t)
  1126. (message "No `top' node in %s" Info-dir-file-name)))))
  1127. ;; Add to the main menu a menu item for each other node.
  1128. (re-search-forward "^\\* Menu:")
  1129. (forward-line 1)
  1130. (let ((menu-items '("top"))
  1131. (end (save-excursion (search-forward "\^_" nil t) (point))))
  1132. (dolist (node nodes)
  1133. (let ((nodename (car node)))
  1134. (save-excursion
  1135. (or (member (downcase nodename) menu-items)
  1136. (re-search-forward (concat "^\\* +"
  1137. (regexp-quote nodename)
  1138. "::")
  1139. end t)
  1140. (progn
  1141. (insert "* " nodename "::" "\n")
  1142. (push nodename menu-items)))))))
  1143. ;; Now take each node of each of the other buffers
  1144. ;; and merge it into the main buffer.
  1145. (dolist (node nodes)
  1146. (let ((case-fold-search t)
  1147. (nodename (car node)))
  1148. (goto-char (point-min))
  1149. ;; Find the like-named node in the main buffer.
  1150. (if (re-search-forward (concat "^\^_.*\n.*Node: "
  1151. (regexp-quote nodename)
  1152. "[,\n\t]")
  1153. nil t)
  1154. (progn
  1155. (search-forward "\n\^_" nil 'move)
  1156. (beginning-of-line)
  1157. (insert "\n"))
  1158. ;; If none exists, add one.
  1159. (goto-char (point-max))
  1160. (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
  1161. ;; Merge the text from the other buffer's menu
  1162. ;; into the menu in the like-named node in the main buffer.
  1163. (apply 'insert-buffer-substring (cdr node))))
  1164. (Info-dir-remove-duplicates)
  1165. ;; Kill all the buffers we just made, including the special one excised.
  1166. (mapc 'kill-buffer (cons buffer buffers))
  1167. (goto-char (point-min))
  1168. (if problems
  1169. (message "Composing main Info directory...problems encountered, see `*Messages*'")
  1170. (message "Composing main Info directory...done"))
  1171. (set (make-local-variable 'Info-dir-contents) (buffer-string))
  1172. (set (make-local-variable 'Info-dir-file-attributes) dir-file-attrs)))
  1173. (setq default-directory Info-dir-contents-directory))
  1174. (defvar Info-streamline-headings
  1175. '(("Emacs" . "Emacs")
  1176. ("Programming" . "Programming")
  1177. ("Libraries" . "Libraries")
  1178. ("World Wide Web\\|Net Utilities" . "Net Utilities"))
  1179. "List of elements (RE . NAME) to merge headings matching RE to NAME.")
  1180. (defun Info-dir-remove-duplicates ()
  1181. (let (limit)
  1182. (goto-char (point-min))
  1183. ;; Remove duplicate headings in the same menu.
  1184. (while (search-forward "\n* Menu:" nil t)
  1185. (setq limit (save-excursion (search-forward "\n\^_" nil t)))
  1186. ;; Look for the next heading to unify.
  1187. (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t)
  1188. (let ((name (match-string 1))
  1189. (start (match-beginning 0))
  1190. (entries nil) re)
  1191. ;; Check whether this heading should be streamlined.
  1192. (save-match-data
  1193. (dolist (x Info-streamline-headings)
  1194. (when (string-match (car x) name)
  1195. (setq name (cdr x))
  1196. (setq re (car x)))))
  1197. (if re (replace-match name t t nil 1))
  1198. (goto-char (if (re-search-forward "^[^* \n\t]" limit t)
  1199. (match-beginning 0)
  1200. (or limit (point-max))))
  1201. ;; Look for other headings of the same category and merge them.
  1202. (save-excursion
  1203. (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t)
  1204. (when (if re (save-match-data (string-match re (match-string 1)))
  1205. (equal name (match-string 1)))
  1206. (forward-line 0)
  1207. ;; Delete redundant heading.
  1208. (delete-region (match-beginning 0) (point))
  1209. ;; Push the entries onto `text'.
  1210. (push
  1211. (delete-and-extract-region
  1212. (point)
  1213. (if (re-search-forward "^[^* \n\t]" nil t)
  1214. (match-beginning 0)
  1215. (or limit (point-max))))
  1216. entries)
  1217. (forward-line 0))))
  1218. ;; Insert the entries just found.
  1219. (while (= (line-beginning-position 0) (1- (point)))
  1220. (backward-char))
  1221. (dolist (entry (nreverse entries))
  1222. (insert entry)
  1223. (while (= (line-beginning-position 0) (1- (point)))
  1224. (delete-region (1- (point)) (point))))
  1225. ;; Now remove duplicate entries under the same heading.
  1226. (let (seen)
  1227. (save-restriction
  1228. (narrow-to-region start (point))
  1229. (goto-char (point-min))
  1230. (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)" nil 'move)
  1231. ;; Fold case straight away; `member-ignore-case' here wasteful.
  1232. (let ((x (downcase (match-string 1))))
  1233. (if (member x seen)
  1234. (delete-region
  1235. (match-beginning 0)
  1236. (if (re-search-forward "^[^ \t]" nil 'move)
  1237. (goto-char (match-beginning 0))
  1238. (point-max)))
  1239. (push x seen)))))))))))
  1240. ;; Note that on entry to this function the current-buffer must be the
  1241. ;; *info* buffer; not the info tags buffer.
  1242. (defun Info-read-subfile (nodepos)
  1243. ;; NODEPOS is either a position (in the Info file as a whole,
  1244. ;; not relative to a subfile) or the name of a subfile.
  1245. (let (lastfilepos
  1246. lastfilename)
  1247. (if (numberp nodepos)
  1248. (with-current-buffer (marker-buffer Info-tag-table-marker)
  1249. (goto-char (point-min))
  1250. (or (looking-at "\^_")
  1251. (search-forward "\n\^_"))
  1252. (forward-line 2)
  1253. (catch 'foo
  1254. (while (not (looking-at "\^_"))
  1255. (if (not (eolp))
  1256. (let ((beg (point))
  1257. thisfilepos thisfilename)
  1258. (search-forward ": ")
  1259. (setq thisfilename (buffer-substring beg (- (point) 2)))
  1260. (setq thisfilepos (+ (point-min) (read (current-buffer))))
  1261. ;; read in version 19 stops at the end of number.
  1262. ;; Advance to the next line.
  1263. (forward-line 1)
  1264. (if (> thisfilepos nodepos)
  1265. (throw 'foo t))
  1266. (setq lastfilename thisfilename)
  1267. (setq lastfilepos thisfilepos))
  1268. (forward-line 1)))))
  1269. (setq lastfilename nodepos)
  1270. (setq lastfilepos 0))
  1271. ;; Assume previous buffer is in Info-mode.
  1272. ;; (set-buffer (get-buffer "*info*"))
  1273. (or (equal Info-current-subfile lastfilename)
  1274. (let ((inhibit-read-only t))
  1275. (setq buffer-file-name nil)
  1276. (widen)
  1277. (erase-buffer)
  1278. (info-insert-file-contents lastfilename)
  1279. (set-buffer-modified-p nil)
  1280. (setq Info-current-subfile lastfilename)))
  1281. ;; Widen in case we are in the same subfile as before.
  1282. (widen)
  1283. (goto-char (point-min))
  1284. (if (looking-at "\^_")
  1285. (forward-char 1)
  1286. (search-forward "\n\^_"))
  1287. (if (numberp nodepos)
  1288. (+ (- nodepos lastfilepos) (point)))))
  1289. (defun Info-unescape-quotes (value)
  1290. "Unescape double quotes and backslashes in VALUE."
  1291. (let ((start 0)
  1292. (unquote value))
  1293. (while (string-match "[^\\\"]*\\(\\\\\\)[\\\\\"]" unquote start)
  1294. (setq unquote (replace-match "" t t unquote 1))
  1295. (setq start (- (match-end 0) 1)))
  1296. unquote))
  1297. ;; As of Texinfo 4.6, makeinfo writes constructs like
  1298. ;; \0\h[image param=value ...\h\0]
  1299. ;; into the Info file for handling images.
  1300. (defun Info-split-parameter-string (parameter-string)
  1301. "Return alist of (\"KEY\" . \"VALUE\") from PARAMETER-STRING.
  1302. PARAMETER-STRING is a whitespace separated list of KEY=VALUE pairs.
  1303. If VALUE contains whitespace or double quotes, it must be quoted
  1304. in double quotes and any double quotes or backslashes must be
  1305. escaped (\\\",\\\\)."
  1306. (let ((start 0)
  1307. (parameter-alist))
  1308. (while (string-match
  1309. "\\s *\\([^=]+\\)=\\(?:\\([^\\s \"]+\\)\\|\\(?:\"\\(\\(?:[^\\\"]\\|\\\\[\\\\\"]\\)*\\)\"\\)\\)"
  1310. parameter-string start)
  1311. (setq start (match-end 0))
  1312. (push (cons (match-string 1 parameter-string)
  1313. (or (match-string 2 parameter-string)
  1314. (Info-unescape-quotes
  1315. (match-string 3 parameter-string))))
  1316. parameter-alist))
  1317. parameter-alist))
  1318. (defun Info-display-images-node ()
  1319. "Display images in current node."
  1320. (save-excursion
  1321. (let ((inhibit-read-only t)
  1322. (case-fold-search t))
  1323. (goto-char (point-min))
  1324. (while (re-search-forward
  1325. "\\(\0\b[[]image\\(\\(?:[^\b]\\|[^\0]+\b\\)*\\)\0\b[]]\\)"
  1326. nil t)
  1327. (let* ((start (match-beginning 1))
  1328. (parameter-alist (Info-split-parameter-string (match-string 2)))
  1329. (src (cdr (assoc-string "src" parameter-alist))))
  1330. (if (display-images-p)
  1331. (let* ((image-file (if src (if (file-name-absolute-p src) src
  1332. (concat default-directory src))
  1333. ""))
  1334. (image (if (file-exists-p image-file)
  1335. (create-image image-file)
  1336. "[broken image]")))
  1337. (if (not (get-text-property start 'display))
  1338. (add-text-properties
  1339. start (point) `(display ,image rear-nonsticky (display)))))
  1340. ;; text-only display, show alternative text if provided, or
  1341. ;; otherwise a clue that there's meant to be a picture
  1342. (delete-region start (point))
  1343. (insert (or (cdr (assoc-string "text" parameter-alist))
  1344. (cdr (assoc-string "alt" parameter-alist))
  1345. (and src
  1346. (concat "[image:" src "]"))
  1347. "[image]"))))))
  1348. (set-buffer-modified-p nil)))
  1349. ;; Texinfo 4.7 adds cookies of the form ^@^H[NAME CONTENTS ^@^H].
  1350. ;; Hide any construct of the general form ^@[^@-^_][ ... ^@[^@-^_]],
  1351. ;; including one optional trailing newline.
  1352. (defun Info-hide-cookies-node ()
  1353. "Hide unrecognized cookies in current node."
  1354. (save-excursion
  1355. (let ((inhibit-read-only t)
  1356. (case-fold-search t))
  1357. (goto-char (point-min))
  1358. (while (re-search-forward
  1359. "\\(\0[\0-\37][[][^\0]*\0[\0-\37][]]\n?\\)"
  1360. nil t)
  1361. (let* ((start (match-beginning 1)))
  1362. (if (and (not (get-text-property start 'invisible))
  1363. (not (get-text-property start 'display)))
  1364. (put-text-property start (point) 'invisible t)))))
  1365. (set-buffer-modified-p nil)))
  1366. (defun Info-select-node ()
  1367. "Select the Info node that point is in."
  1368. ;; Bind this in case the user sets it to nil.
  1369. (let ((case-fold-search t))
  1370. (save-excursion
  1371. ;; Find beginning of node.
  1372. (if (search-backward "\n\^_" nil 'move)
  1373. (forward-line 2)
  1374. (if (looking-at "\^_")
  1375. (forward-line 1)
  1376. (signal 'search-failed (list "\n\^_"))))
  1377. ;; Get nodename spelled as it is in the node.
  1378. (re-search-forward "Node:[ \t]*")
  1379. (setq Info-current-node
  1380. (buffer-substring-no-properties (point)
  1381. (progn
  1382. (skip-chars-forward "^,\t\n")
  1383. (point))))
  1384. (Info-set-mode-line)
  1385. ;; Find the end of it, and narrow.
  1386. (beginning-of-line)
  1387. (let (active-expression)
  1388. ;; Narrow to the node contents
  1389. (narrow-to-region (point)
  1390. (if (re-search-forward "\n[\^_\f]" nil t)
  1391. (prog1
  1392. (1- (point))
  1393. (if (looking-at "[\n\^_\f]*execute: ")
  1394. (progn
  1395. (goto-char (match-end 0))
  1396. (setq active-expression
  1397. (read (current-buffer))))))
  1398. (point-max)))
  1399. (if Info-enable-active-nodes (eval active-expression))
  1400. ;; Add a new unique history item to full history list
  1401. (let ((new-history (list Info-current-file Info-current-node)))
  1402. (setq Info-history-list
  1403. (cons new-history (remove new-history Info-history-list)))
  1404. (setq Info-history-forward nil))
  1405. (if (not (eq Info-fontify-maximum-menu-size nil))
  1406. (Info-fontify-node))
  1407. (Info-display-images-node)
  1408. (Info-hide-cookies-node)
  1409. (run-hooks 'Info-selection-hook)))))
  1410. (defvar Info-mode-line-node-keymap
  1411. (let ((map (make-sparse-keymap)))
  1412. (define-key map [mode-line mouse-1] 'Info-mouse-scroll-up)
  1413. (define-key map [mode-line mouse-3] 'Info-mouse-scroll-down)
  1414. map)
  1415. "Keymap to put on the Info node name in the mode line.")
  1416. (defun Info-set-mode-line ()
  1417. (setq mode-line-buffer-identification
  1418. (nconc (propertized-buffer-identification "%b")
  1419. (list
  1420. (concat
  1421. " ("
  1422. (if (stringp Info-current-file)
  1423. (replace-regexp-in-string
  1424. "%" "%%" (file-name-nondirectory Info-current-file))
  1425. (format "*%S*" Info-current-file))
  1426. ") "
  1427. (if Info-current-node
  1428. (propertize (replace-regexp-in-string
  1429. "%" "%%" Info-current-node)
  1430. 'face 'mode-line-buffer-id
  1431. 'help-echo
  1432. "mouse-1: scroll forward, mouse-3: scroll back"
  1433. 'mouse-face 'mode-line-highlight
  1434. 'local-map Info-mode-line-node-keymap)
  1435. ""))))))
  1436. ;; Go to an Info node specified with a filename-and-nodename string
  1437. ;; of the sort that is found in pointers in nodes.
  1438. ;; Don't autoload this function: the correct entry point for other packages
  1439. ;; to use is `info'. --Stef
  1440. ;; ;;;###autoload
  1441. (defun Info-goto-node (nodename &optional fork)
  1442. "Go to Info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
  1443. If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
  1444. FILENAME; otherwise, NODENAME should be in the current Info file (or one of
  1445. its sub-files).
  1446. Completion is available, but only for node names in the current Info file.
  1447. If FORK is non-nil (interactively with a prefix arg), show the node in
  1448. a new Info buffer.
  1449. If FORK is a string, it is the name to use for the new buffer."
  1450. (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg))
  1451. (info-initialize)
  1452. (if fork
  1453. (set-buffer
  1454. (clone-buffer (concat "*info-" (if (stringp fork) fork nodename) "*") t)))
  1455. (let (filename)
  1456. (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
  1457. nodename)
  1458. (setq filename (if (= (match-beginning 1) (match-end 1))
  1459. ""
  1460. (match-string 2 nodename))
  1461. nodename (match-string 3 nodename))
  1462. (let ((trim (string-match "\\s +\\'" filename)))
  1463. (if trim (setq filename (substring filename 0 trim))))
  1464. (let ((trim (string-match "\\s +\\'" nodename)))
  1465. (if trim (setq nodename (substring nodename 0 trim))))
  1466. (if transient-mark-mode (deactivate-mark))
  1467. (Info-find-node (if (equal filename "") nil filename)
  1468. (if (equal nodename "") "Top" nodename))))
  1469. (defvar Info-read-node-completion-table)
  1470. (defun Info-read-node-name-2 (dirs suffixes string pred action)
  1471. "Internal function used to complete Info node names.
  1472. Return a completion table for Info files---the FILENAME part of a
  1473. node named \"(FILENAME)NODENAME\". DIRS is a list of Info
  1474. directories to search if FILENAME is not absolute; SUFFIXES is a
  1475. list of valid filename suffixes for Info files. See
  1476. `try-completion' for a description of the remaining arguments."
  1477. (setq suffixes (remove "" suffixes))
  1478. (when (file-name-absolute-p string)
  1479. (setq dirs (list (file-name-directory string))))
  1480. (let ((names nil)
  1481. (suffix (concat (regexp-opt suffixes t) "\\'"))
  1482. (string-dir (file-name-directory string)))
  1483. (dolist (dir dirs)
  1484. (unless dir
  1485. (setq dir default-directory))
  1486. (if string-dir (setq dir (expand-file-name string-dir dir)))
  1487. (when (file-directory-p dir)
  1488. (dolist (file (file-name-all-completions
  1489. (file-name-nondirectory string) dir))
  1490. ;; If the file name has no suffix or a standard suffix,
  1491. ;; include it.
  1492. (and (or (null (file-name-extension file))
  1493. (string-match suffix file))
  1494. ;; But exclude subfiles of split Info files.
  1495. (not (string-match "-[0-9]+\\'" file))
  1496. ;; And exclude backup files.
  1497. (not (string-match "~\\'" file))
  1498. (push (if string-dir (concat string-dir file) file) names))
  1499. ;; If the file name ends in a standard suffix,
  1500. ;; add the unsuffixed name as a completion option.
  1501. (when (string-match suffix file)
  1502. (setq file (substring file 0 (match-beginning 0)))
  1503. (push (if string-dir (concat string-dir file) file) names)))))
  1504. (complete-with-action action names string pred)))
  1505. (defun Info-read-node-name-1 (string predicate code)
  1506. "Internal function used by `Info-read-node-name'.
  1507. See `completing-read' for a description of arguments and usage."
  1508. (cond
  1509. ;; First complete embedded file names.
  1510. ((string-match "\\`([^)]*\\'" string)
  1511. (completion-table-with-context
  1512. "("
  1513. (apply-partially 'completion-table-with-terminator ")"
  1514. (apply-partially 'Info-read-node-name-2
  1515. Info-directory-list
  1516. (mapcar 'car Info-suffix-list)))
  1517. (substring string 1)
  1518. predicate
  1519. code))
  1520. ;; If a file name was given, then any node is fair game.
  1521. ((string-match "\\`(" string)
  1522. (cond
  1523. ((eq code nil) string)
  1524. ((eq code t) nil)
  1525. (t t)))
  1526. ;; Otherwise use Info-read-node-completion-table.
  1527. (t (complete-with-action
  1528. code Info-read-node-completion-table string predicate))))
  1529. ;; Arrange to highlight the proper letters in the completion list buffer.
  1530. (defun Info-read-node-name (prompt)
  1531. "Read an Info node name with completion, prompting with PROMPT.
  1532. A node name can have the form \"NODENAME\", referring to a node
  1533. in the current Info file, or \"(FILENAME)NODENAME\"."
  1534. (let* ((completion-ignore-case t)
  1535. (Info-read-node-completion-table (Info-build-node-completions))
  1536. (nodename (completing-read prompt 'Info-read-node-name-1 nil t)))
  1537. (if (equal nodename "")
  1538. (Info-read-node-name prompt)
  1539. nodename)))
  1540. (defun Info-build-node-completions ()
  1541. (or Info-current-file-completions
  1542. (let ((compl nil)
  1543. ;; Bind this in case the user sets it to nil.
  1544. (case-fold-search t)
  1545. (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
  1546. (save-excursion
  1547. (save-restriction
  1548. (or Info-tag-table-marker
  1549. (error "No Info tags found"))
  1550. (if (marker-buffer Info-tag-table-marker)
  1551. (let ((marker Info-tag-table-marker))
  1552. (set-buffer (marker-buffer marker))
  1553. (widen)
  1554. (goto-char marker)
  1555. (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t)
  1556. (setq compl
  1557. (cons (list (match-string-no-properties 2))
  1558. compl))))
  1559. (widen)
  1560. (goto-char (point-min))
  1561. ;; If the buffer begins with a node header, process that first.
  1562. (if (Info-node-at-bob-matching node-regexp)
  1563. (setq compl (list (match-string-no-properties 1))))
  1564. ;; Now for the rest of the nodes.
  1565. (while (search-forward "\n\^_" nil t)
  1566. (forward-line 1)
  1567. (let ((beg (point)))
  1568. (forward-line 1)
  1569. (if (re-search-backward node-regexp beg t)
  1570. (setq compl
  1571. (cons (list (match-string-no-properties 1))
  1572. compl))))))))
  1573. (setq compl (cons '("*") compl))
  1574. (set (make-local-variable 'Info-current-file-completions) compl))))
  1575. (defun Info-restore-point (hl)
  1576. "If this node has been visited, restore the point value when we left."
  1577. (while hl
  1578. (if (and (equal (nth 0 (car hl)) Info-current-file)
  1579. ;; Use string-equal, not equal, to ignore text props.
  1580. (string-equal (nth 1 (car hl)) Info-current-node))
  1581. (progn
  1582. (goto-char (nth 2 (car hl)))
  1583. (setq hl nil)) ;terminate the while at next iter
  1584. (setq hl (cdr hl)))))
  1585. (defvar Info-search-history nil
  1586. "The history list for `Info-search'.")
  1587. (defvar Info-search-case-fold nil
  1588. "The value of `case-fold-search' from previous `Info-search' command.")
  1589. (defun Info-search (regexp &optional bound _noerror _count direction)
  1590. "Search for REGEXP, starting from point, and select node it's found in.
  1591. If DIRECTION is `backward', search in the reverse direction."
  1592. (interactive (list (read-string
  1593. (if Info-search-history
  1594. (format "Regexp search%s (default %s): "
  1595. (if case-fold-search "" " case-sensitively")
  1596. (car Info-search-history))
  1597. (format "Regexp search%s: "
  1598. (if case-fold-search "" " case-sensitively")))
  1599. nil 'Info-search-history)))
  1600. (deactivate-mark)
  1601. (when (equal regexp "")
  1602. (setq regexp (car Info-search-history)))
  1603. (when regexp
  1604. (let (found beg-found give-up
  1605. (backward (eq direction 'backward))
  1606. (onode Info-current-node)
  1607. (ofile Info-current-file)
  1608. (opoint (point))
  1609. (opoint-min (point-min))
  1610. (opoint-max (point-max))
  1611. (ostart (window-start))
  1612. (osubfile Info-current-subfile))
  1613. (setq Info-search-case-fold case-fold-search)
  1614. (save-excursion
  1615. (save-restriction
  1616. (widen)
  1617. (when backward
  1618. ;; Hide Info file header for backward search
  1619. (narrow-to-region (save-excursion
  1620. (goto-char (point-min))
  1621. (search-forward "\n\^_")
  1622. (1- (point)))
  1623. (point-max)))
  1624. (while (and (not give-up)
  1625. (or (null found)
  1626. (not (funcall isearch-filter-predicate beg-found found))))
  1627. (let ((search-spaces-regexp
  1628. (if (or (not isearch-mode) isearch-regexp)
  1629. Info-search-whitespace-regexp)))
  1630. (if (if backward
  1631. (re-search-backward regexp bound t)
  1632. (re-search-forward regexp bound t))
  1633. (setq found (point) beg-found (if backward (match-end 0)
  1634. (match-beginning 0)))
  1635. (setq give-up t))))))
  1636. (when (and isearch-mode Info-isearch-search
  1637. (not Info-isearch-initial-node)
  1638. (not bound)
  1639. (or give-up (and found (not (and (> found opoint-min)
  1640. (< found opoint-max))))))
  1641. (signal 'search-failed (list regexp "initial node")))
  1642. ;; If no subfiles, give error now.
  1643. (if give-up
  1644. (if (null Info-current-subfile)
  1645. (if isearch-mode
  1646. (signal 'search-failed (list regexp "end of manual"))
  1647. (let ((search-spaces-regexp
  1648. (if (or (not isearch-mode) isearch-regexp)
  1649. Info-search-whitespace-regexp)))
  1650. (if backward
  1651. (re-search-backward regexp)
  1652. (re-search-forward regexp))))
  1653. (setq found nil)))
  1654. (if (and bound (not found))
  1655. (signal 'search-failed (list regexp)))
  1656. (unless (or found bound)
  1657. (unwind-protect
  1658. ;; Try other subfiles.
  1659. (let ((list ()))
  1660. (with-current-buffer (marker-buffer Info-tag-table-marker)
  1661. (goto-char (point-min))
  1662. (search-forward "\n\^_\nIndirect:")
  1663. (save-restriction
  1664. (narrow-to-region (point)
  1665. (progn (search-forward "\n\^_")
  1666. (1- (point))))
  1667. (goto-char (point-min))
  1668. ;; Find the subfile we just searched.
  1669. (search-forward (concat "\n" osubfile ": "))
  1670. ;; Skip that one.
  1671. (forward-line (if backward 0 1))
  1672. (if backward (forward-char -1))
  1673. ;; Make a list of all following subfiles.
  1674. ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
  1675. (while (not (if backward (bobp) (eobp)))
  1676. (if backward
  1677. (re-search-backward "\\(^.*\\): [0-9]+$")
  1678. (re-search-forward "\\(^.*\\): [0-9]+$"))
  1679. (goto-char (+ (match-end 1) 2))
  1680. (setq list (cons (cons (+ (point-min)
  1681. (read (current-buffer)))
  1682. (match-string-no-properties 1))
  1683. list))
  1684. (goto-char (if backward
  1685. (1- (match-beginning 0))
  1686. (1+ (match-end 0)))))
  1687. ;; Put in forward order
  1688. (setq list (nreverse list))))
  1689. (while list
  1690. (message "Searching subfile %s..." (cdr (car list)))
  1691. (Info-read-subfile (car (car list)))
  1692. (when backward
  1693. ;; Hide Info file header for backward search
  1694. (narrow-to-region (save-excursion
  1695. (goto-char (point-min))
  1696. (search-forward "\n\^_")
  1697. (1- (point)))
  1698. (point-max))
  1699. (goto-char (point-max)))
  1700. (setq list (cdr list))
  1701. (setq give-up nil found nil)
  1702. (while (and (not give-up)
  1703. (or (null found)
  1704. (not (funcall isearch-filter-predicate beg-found found))))
  1705. (let ((search-spaces-regexp
  1706. (if (or (not isearch-mode) isearch-regexp)
  1707. Info-search-whitespace-regexp)))
  1708. (if (if backward
  1709. (re-search-backward regexp nil t)
  1710. (re-search-forward regexp nil t))
  1711. (setq found (point) beg-found (if backward (match-end 0)
  1712. (match-beginning 0)))
  1713. (setq give-up t))))
  1714. (if give-up
  1715. (setq found nil))
  1716. (if found
  1717. (setq list nil)))
  1718. (if found
  1719. (message "")
  1720. (signal 'search-failed (if isearch-mode
  1721. (list regexp "end of manual")
  1722. (list regexp)))))
  1723. (if (not found)
  1724. (progn (Info-read-subfile osubfile)
  1725. (goto-char opoint)
  1726. (Info-select-node)
  1727. (set-window-start (selected-window) ostart)))))
  1728. (if (and (string= osubfile Info-current-subfile)
  1729. (> found opoint-min)
  1730. (< found opoint-max))
  1731. ;; Search landed in the same node
  1732. (goto-char found)
  1733. (widen)
  1734. (goto-char found)
  1735. (save-match-data (Info-select-node)))
  1736. ;; Use string-equal, not equal, to ignore text props.
  1737. (or (and (string-equal onode Info-current-node)
  1738. (equal ofile Info-current-file))
  1739. (and isearch-mode isearch-wrapped
  1740. (eq opoint (if isearch-forward opoint-min opoint-max)))
  1741. (setq Info-history (cons (list ofile onode opoint)
  1742. Info-history))))))
  1743. (defun Info-search-case-sensitively ()
  1744. "Search for a regexp case-sensitively."
  1745. (interactive)
  1746. (let ((case-fold-search nil))
  1747. (call-interactively 'Info-search)))
  1748. (defun Info-search-next ()
  1749. "Search for next regexp from a previous `Info-search' command."
  1750. (interactive)
  1751. (let ((case-fold-search Info-search-case-fold))
  1752. (if Info-search-history
  1753. (Info-search (car Info-search-history))
  1754. (call-interactively 'Info-search))))
  1755. (defun Info-search-backward (regexp &optional bound noerror count)
  1756. "Search for REGEXP in the reverse direction."
  1757. (interactive (list (read-string
  1758. (if Info-search-history
  1759. (format "Regexp search%s backward (default %s): "
  1760. (if case-fold-search "" " case-sensitively")
  1761. (car Info-search-history))
  1762. (format "Regexp search%s backward: "
  1763. (if case-fold-search "" " case-sensitively")))
  1764. nil 'Info-search-history)))
  1765. (Info-search regexp bound noerror count 'backward))
  1766. (defun Info-isearch-search ()
  1767. (if Info-isearch-search
  1768. (lambda (string &optional bound noerror count)
  1769. (Info-search
  1770. (cond
  1771. (isearch-word
  1772. ;; Lax version of word search
  1773. (let ((lax (not (or isearch-nonincremental
  1774. (eq (length string)
  1775. (length (isearch-string-state
  1776. (car isearch-cmds))))))))
  1777. (if (functionp isearch-word)
  1778. (funcall isearch-word string lax)
  1779. (word-search-regexp string lax))))
  1780. (isearch-regexp string)
  1781. (t (regexp-quote string)))
  1782. bound noerror count
  1783. (unless isearch-forward 'backward))
  1784. (point))
  1785. (isearch-search-fun-default)))
  1786. (defun Info-isearch-wrap ()
  1787. (if Info-isearch-search
  1788. (if Info-isearch-initial-node
  1789. (progn
  1790. (if isearch-forward (Info-top-node) (Info-final-node))
  1791. (goto-char (if isearch-forward (point-min) (point-max))))
  1792. (setq Info-isearch-initial-node Info-current-node)
  1793. (setq isearch-wrapped nil))
  1794. (goto-char (if isearch-forward (point-min) (point-max)))))
  1795. (defun Info-isearch-push-state ()
  1796. `(lambda (cmd)
  1797. (Info-isearch-pop-state cmd ',Info-current-file ',Info-current-node)))
  1798. (defun Info-isearch-pop-state (_cmd file node)
  1799. (or (and (equal Info-current-file file)
  1800. (equal Info-current-node node))
  1801. (progn (Info-find-node file node) (sit-for 0))))
  1802. (defun Info-isearch-start ()
  1803. (setq Info-isearch-initial-node
  1804. ;; Don't stop at initial node for nonincremental search.
  1805. ;; Otherwise this variable is set after first search failure.
  1806. (and isearch-nonincremental Info-current-node))
  1807. (setq Info-isearch-initial-history Info-history
  1808. Info-isearch-initial-history-list Info-history-list)
  1809. (add-hook 'isearch-mode-end-hook 'Info-isearch-end nil t))
  1810. (defun Info-isearch-end ()
  1811. ;; Remove intermediate nodes (visited while searching)
  1812. ;; from the history. Add only the last node (where Isearch ended).
  1813. (if (> (length Info-history)
  1814. (length Info-isearch-initial-history))
  1815. (setq Info-history
  1816. (nthcdr (- (length Info-history)
  1817. (length Info-isearch-initial-history)
  1818. 1)
  1819. Info-history)))
  1820. (if (> (length Info-history-list)
  1821. (length Info-isearch-initial-history-list))
  1822. (setq Info-history-list
  1823. (cons (car Info-history-list)
  1824. Info-isearch-initial-history-list)))
  1825. (remove-hook 'isearch-mode-end-hook 'Info-isearch-end t))
  1826. (defun Info-isearch-filter (beg-found found)
  1827. "Test whether the current search hit is a visible useful text.
  1828. Return non-nil if the text from BEG-FOUND to FOUND is visible
  1829. and is not in the header line or a tag table."
  1830. (save-match-data
  1831. (let ((backward (< found beg-found)))
  1832. (not
  1833. (or
  1834. (and (not (eq search-invisible t))
  1835. (if backward
  1836. (or (text-property-not-all found beg-found 'invisible nil)
  1837. (text-property-not-all found beg-found 'display nil))
  1838. (or (text-property-not-all beg-found found 'invisible nil)
  1839. (text-property-not-all beg-found found 'display nil))))
  1840. ;; Skip node header line
  1841. (and (save-excursion (forward-line -1)
  1842. (looking-at "\^_"))
  1843. (forward-line (if backward -1 1)))
  1844. ;; Skip Tag Table node
  1845. (save-excursion
  1846. (and (search-backward "\^_" nil t)
  1847. (looking-at
  1848. "\^_\n\\(Tag Table\\|Local Variables\\)"))))))))
  1849. (defun Info-extract-pointer (name &optional errorname)
  1850. "Extract the value of the node-pointer named NAME.
  1851. If there is none, use ERRORNAME in the error message;
  1852. if ERRORNAME is nil, just return nil."
  1853. ;; Bind this in case the user sets it to nil.
  1854. (let ((case-fold-search t))
  1855. (save-excursion
  1856. (goto-char (point-min))
  1857. (let ((bound (point)))
  1858. (forward-line 1)
  1859. (cond ((re-search-backward
  1860. (concat name ":" (Info-following-node-name-re)) bound t)
  1861. (match-string-no-properties 1))
  1862. ((not (eq errorname t))
  1863. (user-error "Node has no %s"
  1864. (capitalize (or errorname name)))))))))
  1865. (defun Info-following-node-name-re (&optional allowedchars)
  1866. "Return a regexp matching a node name.
  1867. ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
  1868. saying which chars may appear in the node name.
  1869. Submatch 1 is the complete node name.
  1870. Submatch 2 if non-nil is the parenthesized file name part of the node name.
  1871. Submatch 3 is the local part of the node name.
  1872. End of submatch 0, 1, and 3 are the same, so you can safely concat."
  1873. (concat "[ \t\n]*" ;Skip leading space.
  1874. "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
  1875. "\\([" (or allowedchars "^,\t\n") "]*" ;Any number of allowed chars.
  1876. "[" (or allowedchars "^,\t\n") " ]" ;The last char can't be a space.
  1877. "\\|\\)\\)")) ;Allow empty node names.
  1878. ;;; For compatibility; other files have used this name.
  1879. (defun Info-following-node-name ()
  1880. (and (looking-at (Info-following-node-name-re))
  1881. (match-string-no-properties 1)))
  1882. (defun Info-next ()
  1883. "Go to the next node of this node."
  1884. (interactive)
  1885. ;; In case another window is currently selected
  1886. (save-window-excursion
  1887. (or (eq major-mode 'Info-mode) (switch-to-buffer "*info*"))
  1888. (Info-goto-node (Info-extract-pointer "next"))))
  1889. (defun Info-prev ()
  1890. "Go to the previous node of this node."
  1891. (interactive)
  1892. ;; In case another window is currently selected
  1893. (save-window-excursion
  1894. (or (eq major-mode 'Info-mode) (switch-to-buffer "*info*"))
  1895. (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous"))))
  1896. (defun Info-up (&optional same-file)
  1897. "Go to the superior node of this node.
  1898. If SAME-FILE is non-nil, do not move to a different Info file."
  1899. (interactive)
  1900. ;; In case another window is currently selected
  1901. (save-window-excursion
  1902. (or (eq major-mode 'Info-mode) (switch-to-buffer "*info*"))
  1903. (let ((old-node Info-current-node)
  1904. (old-file Info-current-file)
  1905. (node (Info-extract-pointer "up")) p)
  1906. (and same-file
  1907. (string-match "^(" node)
  1908. (error "Up node is in another Info file"))
  1909. (Info-goto-node node)
  1910. (setq p (point))
  1911. (goto-char (point-min))
  1912. (if (and (stringp old-file)
  1913. (search-forward "\n* Menu:" nil t)
  1914. (re-search-forward
  1915. (if (string-equal old-node "Top")
  1916. (concat "\n\\*[^:]+: +(" (file-name-nondirectory old-file) ")")
  1917. (concat "\n\\* +\\(" (regexp-quote old-node)
  1918. ":\\|[^:]+: +" (regexp-quote old-node) "\\)"))
  1919. nil t))
  1920. (progn (beginning-of-line) (if (looking-at "^\\* ") (forward-char 2)))
  1921. (goto-char p)
  1922. (Info-restore-point Info-history)))))
  1923. (defun Info-history-back ()
  1924. "Go back in the history to the last node visited."
  1925. (interactive)
  1926. (or Info-history
  1927. (user-error "This is the first Info node you looked at"))
  1928. (let ((history-forward
  1929. (cons (list Info-current-file Info-current-node (point))
  1930. Info-history-forward))
  1931. filename nodename opoint)
  1932. (setq filename (car (car Info-history)))
  1933. (setq nodename (car (cdr (car Info-history))))
  1934. (setq opoint (car (cdr (cdr (car Info-history)))))
  1935. (setq Info-history (cdr Info-history))
  1936. (Info-find-node filename nodename)
  1937. (setq Info-history (cdr Info-history))
  1938. (setq Info-history-forward history-forward)
  1939. (goto-char opoint)))
  1940. (defalias 'Info-last 'Info-history-back)
  1941. (defun Info-history-forward ()
  1942. "Go forward in the history of visited nodes."
  1943. (interactive)
  1944. (or Info-history-forward
  1945. (user-error "This is the last Info node you looked at"))
  1946. (let ((history-forward (cdr Info-history-forward))
  1947. filename nodename opoint)
  1948. (setq filename (car (car Info-history-forward)))
  1949. (setq nodename (car (cdr (car Info-history-forward))))
  1950. (setq opoint (car (cdr (cdr (car Info-history-forward)))))
  1951. (Info-find-node filename nodename)
  1952. (setq Info-history-forward history-forward)
  1953. (goto-char opoint)))
  1954. (add-to-list 'Info-virtual-files
  1955. '("\\`dir\\'"
  1956. (toc-nodes . Info-directory-toc-nodes)
  1957. (find-file . Info-directory-find-file)
  1958. (find-node . Info-directory-find-node)
  1959. ))
  1960. (defun Info-directory-toc-nodes (filename)
  1961. "Directory-specific implementation of `Info-toc-nodes'."
  1962. `(,filename
  1963. ("Top" nil nil nil)))
  1964. (defun Info-directory-find-file (filename &optional _noerror)
  1965. "Directory-specific implementation of `Info-find-file'."
  1966. filename)
  1967. (defun Info-directory-find-node (_filename _nodename &optional _no-going-back)
  1968. "Directory-specific implementation of `Info-find-node-2'."
  1969. (Info-insert-dir))
  1970. ;;;###autoload
  1971. (defun Info-directory ()
  1972. "Go to the Info directory node."
  1973. (interactive)
  1974. (Info-find-node "dir" "top"))
  1975. (add-to-list 'Info-virtual-files
  1976. '("\\`\\*History\\*\\'"
  1977. (toc-nodes . Info-history-toc-nodes)
  1978. (find-file . Info-history-find-file)
  1979. (find-node . Info-history-find-node)
  1980. ))
  1981. (defun Info-history-toc-nodes (filename)
  1982. "History-specific implementation of `Info-toc-nodes'."
  1983. `(,filename
  1984. ("Top" nil nil nil)))
  1985. (defun Info-history-find-file (filename &optional _noerror)
  1986. "History-specific implementation of `Info-find-file'."
  1987. filename)
  1988. (defun Info-history-find-node (filename nodename &optional _no-going-back)
  1989. "History-specific implementation of `Info-find-node-2'."
  1990. (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
  1991. (or filename Info-current-file) nodename))
  1992. (insert "Recently Visited Nodes\n")
  1993. (insert "**********************\n\n")
  1994. (insert "* Menu:\n\n")
  1995. (let ((hl (remove '("*History*" "Top") Info-history-list)))
  1996. (while hl
  1997. (let ((file (nth 0 (car hl)))
  1998. (node (nth 1 (car hl))))
  1999. (if (stringp file)
  2000. (insert "* " node ": ("
  2001. (propertize (or (file-name-directory file) "") 'invisible t)
  2002. (file-name-nondirectory file)
  2003. ")" node ".\n")))
  2004. (setq hl (cdr hl)))))
  2005. (defun Info-history ()
  2006. "Go to a node with a menu of visited nodes."
  2007. (interactive)
  2008. (Info-find-node "*History*" "Top")
  2009. (Info-next-reference)
  2010. (Info-next-reference))
  2011. (add-to-list 'Info-virtual-nodes
  2012. '("\\`\\*TOC\\*\\'"
  2013. (find-node . Info-toc-find-node)
  2014. ))
  2015. (defun Info-toc-find-node (filename nodename &optional _no-going-back)
  2016. "Toc-specific implementation of `Info-find-node-2'."
  2017. (let* ((curr-file (substring-no-properties (or filename Info-current-file)))
  2018. (curr-node (substring-no-properties (or nodename Info-current-node)))
  2019. (node-list (Info-toc-nodes curr-file)))
  2020. (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
  2021. curr-file curr-node))
  2022. (insert "Table of Contents\n")
  2023. (insert "*****************\n\n")
  2024. (insert "*Note Top::\n")
  2025. (Info-toc-insert
  2026. (nth 3 (assoc "Top" node-list)) ; get Top nodes
  2027. node-list 0 curr-file)
  2028. (unless (bobp)
  2029. (let ((Info-hide-note-references 'hide)
  2030. (Info-fontify-visited-nodes nil))
  2031. (setq Info-current-file filename Info-current-node "*TOC*")
  2032. (goto-char (point-min))
  2033. (narrow-to-region (or (re-search-forward "\n[\^_\f]\n" nil t)
  2034. (point-min))
  2035. (point-max))
  2036. (Info-fontify-node)
  2037. (widen)))))
  2038. (defun Info-toc ()
  2039. "Go to a node with table of contents of the current Info file.
  2040. Table of contents is created from the tree structure of menus."
  2041. (interactive)
  2042. (Info-find-node Info-current-file "*TOC*")
  2043. (let ((prev-node (nth 1 (car Info-history))) p)
  2044. (goto-char (point-min))
  2045. (if (setq p (search-forward (concat "*Note " prev-node ":") nil t))
  2046. (setq p (- p (length prev-node) 2)))
  2047. (goto-char (or p (point-min)))))
  2048. (defun Info-toc-insert (nodes node-list level curr-file)
  2049. "Insert table of contents with references to nodes."
  2050. (let ((section "Top"))
  2051. (while nodes
  2052. (let ((node (assoc (car nodes) node-list)))
  2053. (unless (member (nth 2 node) (list nil section))
  2054. (insert (setq section (nth 2 node)) "\n"))
  2055. (insert (make-string level ?\t))
  2056. (insert "*Note " (car nodes) ":: \n")
  2057. (Info-toc-insert (nth 3 node) node-list (1+ level) curr-file)
  2058. (setq nodes (cdr nodes))))))
  2059. (defun Info-toc-build (file)
  2060. "Build table of contents from menus of Info FILE and its subfiles."
  2061. (with-temp-buffer
  2062. (let* ((file (and (stringp file) (Info-find-file file)))
  2063. (default-directory (or (and (stringp file)
  2064. (file-name-directory file))
  2065. default-directory))
  2066. (main-file (and (stringp file) file))
  2067. (sections '(("Top" "Top")))
  2068. nodes subfiles)
  2069. (while (or main-file subfiles)
  2070. ;; (or main-file (message "Searching subfile %s..." (car subfiles)))
  2071. (erase-buffer)
  2072. (info-insert-file-contents (or main-file (car subfiles)))
  2073. (goto-char (point-min))
  2074. (while (and (search-forward "\n\^_\nFile:" nil 'move)
  2075. (search-forward "Node: " nil 'move))
  2076. (let* ((nodename (substring-no-properties (Info-following-node-name)))
  2077. (bound (- (or (save-excursion (search-forward "\n\^_" nil t))
  2078. (point-max)) 2))
  2079. (upnode (and (re-search-forward
  2080. (concat "Up:" (Info-following-node-name-re))
  2081. bound t)
  2082. (match-string-no-properties 1)))
  2083. (section "Top")
  2084. menu-items)
  2085. (when (and upnode (string-match "(" upnode)) (setq upnode nil))
  2086. (when (and (not (Info-index-node nodename file))
  2087. (re-search-forward "^\\* Menu:" bound t))
  2088. (forward-line 1)
  2089. (beginning-of-line)
  2090. (setq bound (or (and (equal nodename "Top")
  2091. (save-excursion
  2092. (re-search-forward
  2093. "^[ \t-]*The Detailed Node Listing" nil t)))
  2094. bound))
  2095. (while (< (point) bound)
  2096. (cond
  2097. ;; Menu item line
  2098. ((looking-at "^\\* +[^:]+:")
  2099. (beginning-of-line)
  2100. (forward-char 2)
  2101. (let ((menu-node-name (substring-no-properties
  2102. (Info-extract-menu-node-name))))
  2103. (setq menu-items (cons menu-node-name menu-items))
  2104. (if (equal nodename "Top")
  2105. (setq sections
  2106. (cons (list menu-node-name section) sections)))))
  2107. ;; Other non-empty strings in the Top node are section names
  2108. ((and (equal nodename "Top")
  2109. (looking-at "^\\([^ \t\n*=.-][^:\n]*\\)"))
  2110. (setq section (match-string-no-properties 1))))
  2111. (forward-line 1)
  2112. (beginning-of-line)))
  2113. (setq nodes (cons (list nodename upnode
  2114. (cadr (assoc nodename sections))
  2115. (nreverse menu-items))
  2116. nodes))
  2117. (goto-char bound)))
  2118. (if main-file
  2119. (save-excursion
  2120. (goto-char (point-min))
  2121. (if (search-forward "\n\^_\nIndirect:" nil t)
  2122. (let ((bound (save-excursion (search-forward "\n\^_" nil t))))
  2123. (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t)
  2124. (setq subfiles (cons (match-string-no-properties 1)
  2125. subfiles)))))
  2126. (setq subfiles (nreverse subfiles)
  2127. main-file nil))
  2128. (setq subfiles (cdr subfiles))))
  2129. (message "")
  2130. (nreverse nodes))))
  2131. (defvar Info-toc-nodes nil
  2132. "Alist of cached parent-children node information in visited Info files.
  2133. Each element is (FILE (NODE-NAME PARENT SECTION CHILDREN) ...)
  2134. where PARENT is the parent node extracted from the Up pointer,
  2135. SECTION is the section name in the Top node where this node is placed,
  2136. CHILDREN is a list of child nodes extracted from the node menu.")
  2137. (defun Info-toc-nodes (filename)
  2138. "Return a node list of Info FILENAME with parent-children information.
  2139. This information is cached in the variable `Info-toc-nodes' with the help
  2140. of the function `Info-toc-build'."
  2141. (cond
  2142. ((Info-virtual-call
  2143. (Info-virtual-fun 'toc-nodes (or filename Info-current-file) nil)
  2144. filename))
  2145. (t
  2146. (or filename (setq filename Info-current-file))
  2147. (or (assoc filename Info-toc-nodes)
  2148. ;; Skip virtual Info files
  2149. (and (or (not (stringp filename))
  2150. (Info-virtual-file-p filename))
  2151. (push (cons filename nil) Info-toc-nodes))
  2152. ;; Scan the entire manual and cache the result in Info-toc-nodes
  2153. (let ((nodes (Info-toc-build filename)))
  2154. (push (cons filename nodes) Info-toc-nodes)
  2155. nodes)
  2156. ;; If there is an error, still add nil to the cache
  2157. (push (cons filename nil) Info-toc-nodes))
  2158. (cdr (assoc filename Info-toc-nodes)))))
  2159. (defun Info-follow-reference (footnotename &optional fork)
  2160. "Follow cross reference named FOOTNOTENAME to the node it refers to.
  2161. FOOTNOTENAME may be an abbreviation of the reference name.
  2162. If FORK is non-nil (interactively with a prefix arg), show the node in
  2163. a new Info buffer. If FORK is a string, it is the name to use for the
  2164. new buffer."
  2165. (interactive
  2166. (let ((completion-ignore-case t)
  2167. (case-fold-search t)
  2168. completions default alt-default (start-point (point)) str i bol eol)
  2169. (save-excursion
  2170. ;; Store end and beginning of line.
  2171. (setq eol (line-end-position)
  2172. bol (line-beginning-position))
  2173. (goto-char (point-min))
  2174. (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
  2175. (setq str (match-string-no-properties 1))
  2176. ;; See if this one should be the default.
  2177. (and (null default)
  2178. (<= (match-beginning 0) start-point)
  2179. (<= start-point (point))
  2180. (setq default t))
  2181. ;; See if this one should be the alternate default.
  2182. (and (null alt-default)
  2183. (and (<= bol (match-beginning 0))
  2184. (<= (point) eol))
  2185. (setq alt-default t))
  2186. (setq i 0)
  2187. (while (setq i (string-match "[ \n\t]+" str i))
  2188. (setq str (concat (substring str 0 i) " "
  2189. (substring str (match-end 0))))
  2190. (setq i (1+ i)))
  2191. ;; Record as a completion and perhaps as default.
  2192. (if (eq default t) (setq default str))
  2193. (if (eq alt-default t) (setq alt-default str))
  2194. ;; Don't add this string if it's a duplicate.
  2195. (or (assoc-string str completions t)
  2196. (push str completions))))
  2197. ;; If no good default was found, try an alternate.
  2198. (or default
  2199. (setq default alt-default))
  2200. ;; If only one cross-reference found, then make it default.
  2201. (if (eq (length completions) 1)
  2202. (setq default (car completions)))
  2203. (if completions
  2204. (let ((input (completing-read (if default
  2205. (concat
  2206. "Follow reference named (default "
  2207. default "): ")
  2208. "Follow reference named: ")
  2209. completions nil t)))
  2210. (list (if (equal input "")
  2211. default input) current-prefix-arg))
  2212. (user-error "No cross-references in this node"))))
  2213. (unless footnotename
  2214. (error "No reference was specified"))
  2215. (let (target i (str (concat "\\*note " (regexp-quote footnotename)))
  2216. (case-fold-search t))
  2217. (while (setq i (string-match " " str i))
  2218. (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
  2219. (setq i (+ i 6)))
  2220. (save-excursion
  2221. ;; Move point to the beginning of reference if point is on reference
  2222. (or (looking-at "\\*note[ \n\t]+")
  2223. (and (looking-back "\\*note[ \n\t]+")
  2224. (goto-char (match-beginning 0)))
  2225. (if (and (save-excursion
  2226. (goto-char (+ (point) 5)) ; skip a possible *note
  2227. (re-search-backward "\\*note[ \n\t]+" nil t)
  2228. (looking-at str))
  2229. (<= (point) (match-end 0)))
  2230. (goto-char (match-beginning 0))))
  2231. ;; Go to the reference closest to point
  2232. (let ((next-ref (save-excursion (and (re-search-forward str nil t)
  2233. (+ (match-beginning 0) 5))))
  2234. (prev-ref (save-excursion (and (re-search-backward str nil t)
  2235. (+ (match-beginning 0) 5)))))
  2236. (goto-char (cond ((and next-ref prev-ref)
  2237. (if (< (abs (- next-ref (point)))
  2238. (abs (- prev-ref (point))))
  2239. next-ref prev-ref))
  2240. ((or next-ref prev-ref))
  2241. ((user-error "No cross-reference named %s"
  2242. footnotename))))
  2243. (setq target (Info-extract-menu-node-name t))))
  2244. (while (setq i (string-match "[ \t\n]+" target i))
  2245. (setq target (concat (substring target 0 i) " "
  2246. (substring target (match-end 0))))
  2247. (setq i (+ i 1)))
  2248. (Info-goto-node target fork)))
  2249. (defconst Info-menu-entry-name-re "\\(?:[^:]\\|:[^:,.;() \t\n]\\)*"
  2250. ;; We allow newline because this is also used in Info-follow-reference,
  2251. ;; where the xref name might be wrapped over two lines.
  2252. "Regexp that matches a menu entry name upto but not including the colon.
  2253. Because of ambiguities, this should be concatenated with something like
  2254. `:' and `Info-following-node-name-re'.")
  2255. (defun Info-extract-menu-node-name (&optional multi-line index-node)
  2256. (skip-chars-forward " \t\n")
  2257. (when (looking-at (concat Info-menu-entry-name-re ":\\(:\\|"
  2258. (Info-following-node-name-re
  2259. (cond
  2260. (index-node "^,\t\n")
  2261. (multi-line "^.,\t")
  2262. (t "^.,\t\n")))
  2263. "\\)"
  2264. (if index-node
  2265. "\\.\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"
  2266. "")))
  2267. (if index-node
  2268. (setq Info-point-loc
  2269. (if (match-beginning 5)
  2270. (string-to-number (match-string 5))
  2271. (buffer-substring-no-properties
  2272. (match-beginning 0) (1- (match-beginning 1)))))
  2273. ;;; Uncomment next line to use names of cross-references in non-index nodes:
  2274. ;;; (setq Info-point-loc
  2275. ;;; (buffer-substring (match-beginning 0) (1- (match-beginning 1))))
  2276. )
  2277. (replace-regexp-in-string
  2278. "[ \n]+" " "
  2279. (or (and (not (equal (match-string-no-properties 2) ""))
  2280. (match-string-no-properties 2))
  2281. ;; If the node name is the menu entry name (using `entry::').
  2282. (buffer-substring-no-properties
  2283. (match-beginning 0) (1- (match-beginning 1)))))))
  2284. ;; No one calls this.
  2285. ;;(defun Info-menu-item-sequence (list)
  2286. ;; (while list
  2287. ;; (Info-menu (car list))
  2288. ;; (setq list (cdr list))))
  2289. (defvar Info-complete-menu-buffer)
  2290. (defvar Info-complete-next-re nil)
  2291. (defvar Info-complete-nodes nil)
  2292. (defvar Info-complete-cache nil)
  2293. (defconst Info-node-spec-re
  2294. (concat (Info-following-node-name-re "^.,:") "[,:.]")
  2295. "Regexp to match the text after a : until the terminating `.'.")
  2296. (defun Info-complete-menu-item (string predicate action)
  2297. ;; This uses two dynamically bound variables:
  2298. ;; - `Info-complete-menu-buffer' which contains the buffer in which
  2299. ;; is the menu of items we're trying to complete.
  2300. ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
  2301. ;; also look for menu items in subsequent nodes as long as those
  2302. ;; nodes' names match `Info-complete-next-re'. This feature is currently
  2303. ;; not used.
  2304. ;; - `Info-complete-nodes' which, if non-nil, indicates that we should
  2305. ;; also look for menu items in these nodes. This feature is currently
  2306. ;; only used for completion in Info-index.
  2307. ;; Note that `Info-complete-menu-buffer' could be current already,
  2308. ;; so we want to save point.
  2309. (with-current-buffer Info-complete-menu-buffer
  2310. (save-excursion
  2311. (let ((completion-ignore-case t)
  2312. (case-fold-search t)
  2313. (orignode Info-current-node)
  2314. nextnode)
  2315. (goto-char (point-min))
  2316. (search-forward "\n* Menu:")
  2317. (cond
  2318. ((eq (car-safe action) 'boundaries) nil)
  2319. ((eq action 'lambda)
  2320. (re-search-forward
  2321. (concat "\n\\* +" (regexp-quote string) ":") nil t))
  2322. (t
  2323. (let ((pattern (concat "\n\\* +\\("
  2324. (regexp-quote string)
  2325. Info-menu-entry-name-re "\\):"
  2326. Info-node-spec-re))
  2327. completions
  2328. (complete-nodes Info-complete-nodes))
  2329. ;; Check the cache.
  2330. (if (and (equal (nth 0 Info-complete-cache) Info-current-file)
  2331. (equal (nth 1 Info-complete-cache) Info-current-node)
  2332. (equal (nth 2 Info-complete-cache) Info-complete-next-re)
  2333. (equal (nth 5 Info-complete-cache) Info-complete-nodes)
  2334. (let ((prev (nth 3 Info-complete-cache)))
  2335. (eq t (compare-strings string 0 (length prev)
  2336. prev 0 nil t))))
  2337. ;; We can reuse the previous list.
  2338. (setq completions (nth 4 Info-complete-cache))
  2339. ;; The cache can't be used.
  2340. (while
  2341. (progn
  2342. (while (re-search-forward pattern nil t)
  2343. (push (match-string-no-properties 1)
  2344. completions))
  2345. ;; Check subsequent nodes if applicable.
  2346. (or (and Info-complete-next-re
  2347. (setq nextnode (Info-extract-pointer "next" t))
  2348. (string-match Info-complete-next-re nextnode))
  2349. (and complete-nodes
  2350. (setq complete-nodes (cdr complete-nodes)
  2351. nextnode (car complete-nodes)))))
  2352. (Info-goto-node nextnode))
  2353. ;; Go back to the start node (for the next completion).
  2354. (unless (equal Info-current-node orignode)
  2355. (Info-goto-node orignode))
  2356. ;; Update the cache.
  2357. (set (make-local-variable 'Info-complete-cache)
  2358. (list Info-current-file Info-current-node
  2359. Info-complete-next-re string completions
  2360. Info-complete-nodes)))
  2361. (complete-with-action action completions string predicate))))))))
  2362. (defun Info-menu (menu-item &optional fork)
  2363. "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
  2364. The menu item should one of those listed in the current node's menu.
  2365. Completion is allowed, and the default menu item is the one point is on.
  2366. If FORK is non-nil (interactively with a prefix arg), show the node in
  2367. a new Info buffer. If FORK is a string, it is the name to use for the
  2368. new buffer."
  2369. (interactive
  2370. (let (;; If point is within a menu item, use that item as the default
  2371. (default nil)
  2372. (p (point))
  2373. beg
  2374. (case-fold-search t))
  2375. (save-excursion
  2376. (goto-char (point-min))
  2377. (if (not (search-forward "\n* menu:" nil t))
  2378. (user-error "No menu in this node"))
  2379. (setq beg (point))
  2380. (and (< (point) p)
  2381. (save-excursion
  2382. (goto-char p)
  2383. (end-of-line)
  2384. (if (re-search-backward (concat "\n\\* +\\("
  2385. Info-menu-entry-name-re
  2386. "\\):") beg t)
  2387. (setq default (match-string-no-properties 1))))))
  2388. (let ((item nil))
  2389. (while (null item)
  2390. (setq item (let ((completion-ignore-case t)
  2391. (Info-complete-menu-buffer (current-buffer)))
  2392. (completing-read (if default
  2393. (format "Menu item (default %s): "
  2394. default)
  2395. "Menu item: ")
  2396. 'Info-complete-menu-item nil t)))
  2397. ;; we rely on the fact that completing-read accepts an input
  2398. ;; of "" even when the require-match argument is true and ""
  2399. ;; is not a valid possibility
  2400. (if (string= item "")
  2401. (if default
  2402. (setq item default)
  2403. ;; ask again
  2404. (setq item nil))))
  2405. (list item current-prefix-arg))))
  2406. ;; there is a problem here in that if several menu items have the same
  2407. ;; name you can only go to the node of the first with this command.
  2408. (Info-goto-node (Info-extract-menu-item menu-item)
  2409. (and fork
  2410. (if (stringp fork) fork menu-item))))
  2411. (defun Info-extract-menu-item (menu-item)
  2412. (setq menu-item (regexp-quote menu-item))
  2413. (let ((case-fold-search t))
  2414. (save-excursion
  2415. (let ((case-fold-search t))
  2416. (goto-char (point-min))
  2417. (or (search-forward "\n* menu:" nil t)
  2418. (user-error "No menu in this node"))
  2419. (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
  2420. (re-search-forward (concat "\n\\* +" menu-item) nil t)
  2421. (user-error "No such item in menu"))
  2422. (beginning-of-line)
  2423. (forward-char 2)
  2424. (Info-extract-menu-node-name nil (Info-index-node))))))
  2425. ;; If COUNT is nil, use the last item in the menu.
  2426. (defun Info-extract-menu-counting (count &optional no-detail)
  2427. (let ((case-fold-search t))
  2428. (save-excursion
  2429. (let ((case-fold-search t)
  2430. (bound (when (and no-detail
  2431. (re-search-forward
  2432. "^[ \t-]*The Detailed Node Listing" nil t))
  2433. (match-beginning 0))))
  2434. (goto-char (point-min))
  2435. (or (search-forward "\n* menu:" bound t)
  2436. (user-error "No menu in this node"))
  2437. (if count
  2438. (or (search-forward "\n* " bound t count)
  2439. (error "Too few items in menu"))
  2440. (while (search-forward "\n* " bound t)
  2441. nil))
  2442. (Info-extract-menu-node-name nil (Info-index-node))))))
  2443. (defun Info-nth-menu-item ()
  2444. "Go to the node of the Nth menu item.
  2445. N is the digit argument used to invoke this command."
  2446. (interactive)
  2447. (Info-goto-node
  2448. (Info-extract-menu-counting
  2449. (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
  2450. (defun Info-top-node ()
  2451. "Go to the Top node of this file."
  2452. (interactive)
  2453. (Info-goto-node "Top"))
  2454. (defun Info-final-node ()
  2455. "Go to the final node in this file."
  2456. (interactive)
  2457. (Info-goto-node "Top")
  2458. (let ((Info-history nil)
  2459. (case-fold-search t))
  2460. ;; Go to the last node in the menu of Top. But don't delve into
  2461. ;; detailed node listings.
  2462. (Info-goto-node (Info-extract-menu-counting nil t))
  2463. ;; If the last node in the menu is not last in pointer structure,
  2464. ;; move forward (but not down- or upward - see bug#1116) until we
  2465. ;; can't go any farther.
  2466. (while (Info-forward-node t t t) nil)
  2467. ;; Then keep moving down to last subnode, unless we reach an index.
  2468. (while (and (not (Info-index-node))
  2469. (save-excursion (search-forward "\n* Menu:" nil t)))
  2470. (Info-goto-node (Info-extract-menu-counting nil)))))
  2471. (defun Info-forward-node (&optional not-down not-up no-error)
  2472. "Go forward one node, considering all nodes as forming one sequence."
  2473. (interactive)
  2474. (goto-char (point-min))
  2475. (forward-line 1)
  2476. (let ((case-fold-search t))
  2477. ;; three possibilities, in order of priority:
  2478. ;; 1. next node is in a menu in this node (but not in an index)
  2479. ;; 2. next node is next at same level
  2480. ;; 3. next node is up and next
  2481. (cond ((and (not not-down)
  2482. (save-excursion (search-forward "\n* menu:" nil t))
  2483. (not (Info-index-node)))
  2484. (Info-goto-node (Info-extract-menu-counting 1))
  2485. t)
  2486. ((save-excursion (search-backward "next:" nil t))
  2487. (Info-next)
  2488. t)
  2489. ((and (not not-up)
  2490. (save-excursion (search-backward "up:" nil t))
  2491. ;; Use string-equal, not equal, to ignore text props.
  2492. (not (string-equal (downcase (Info-extract-pointer "up"))
  2493. "top")))
  2494. (let ((old-node Info-current-node))
  2495. (Info-up)
  2496. (let ((old-history Info-history)
  2497. success)
  2498. (unwind-protect
  2499. (setq success (Info-forward-node t nil no-error))
  2500. (or success (Info-goto-node old-node)))
  2501. (if Info-history-skip-intermediate-nodes
  2502. (setq Info-history old-history)))))
  2503. (no-error nil)
  2504. (t (user-error "No pointer forward from this node")))))
  2505. (defun Info-backward-node ()
  2506. "Go backward one node, considering all nodes as forming one sequence."
  2507. (interactive)
  2508. (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
  2509. (upnode (Info-extract-pointer "up" t))
  2510. (case-fold-search t))
  2511. (cond ((and upnode (string-match "(" upnode))
  2512. (user-error "First node in file"))
  2513. ((and upnode (or (null prevnode)
  2514. ;; Use string-equal, not equal,
  2515. ;; to ignore text properties.
  2516. (string-equal (downcase prevnode)
  2517. (downcase upnode))))
  2518. (Info-up))
  2519. (prevnode
  2520. ;; If we move back at the same level,
  2521. ;; go down to find the last subnode*.
  2522. (Info-prev)
  2523. (let ((old-history Info-history))
  2524. (while (and (not (Info-index-node))
  2525. (save-excursion (search-forward "\n* Menu:" nil t)))
  2526. (Info-goto-node (Info-extract-menu-counting nil)))
  2527. (if Info-history-skip-intermediate-nodes
  2528. (setq Info-history old-history))))
  2529. (t
  2530. (user-error "No pointer backward from this node")))))
  2531. (defun Info-exit ()
  2532. "Exit Info by selecting some other buffer."
  2533. (interactive)
  2534. (if Info-standalone
  2535. (save-buffers-kill-emacs)
  2536. (quit-window)))
  2537. (defun Info-next-menu-item ()
  2538. "Go to the node of the next menu item."
  2539. (interactive)
  2540. ;; Bind this in case the user sets it to nil.
  2541. (let* ((case-fold-search t)
  2542. (node
  2543. (save-excursion
  2544. (forward-line -1)
  2545. (search-forward "\n* menu:" nil t)
  2546. (and (search-forward "\n* " nil t)
  2547. (Info-extract-menu-node-name)))))
  2548. (if node (Info-goto-node node)
  2549. (user-error "No more items in menu"))))
  2550. (defun Info-last-menu-item ()
  2551. "Go to the node of the previous menu item."
  2552. (interactive)
  2553. (save-excursion
  2554. (forward-line 1)
  2555. ;; Bind this in case the user sets it to nil.
  2556. (let* ((case-fold-search t)
  2557. (beg (save-excursion
  2558. (and (search-backward "\n* menu:" nil t)
  2559. (point)))))
  2560. (or (and beg (search-backward "\n* " beg t))
  2561. (user-error "No previous items in menu")))
  2562. (Info-goto-node (save-excursion
  2563. (goto-char (match-end 0))
  2564. (Info-extract-menu-node-name)))))
  2565. (defmacro Info-no-error (&rest body)
  2566. (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
  2567. (defun Info-next-preorder ()
  2568. "Go to the next subnode or the next node, or go up a level."
  2569. (interactive)
  2570. (cond ((Info-no-error (Info-next-menu-item)))
  2571. ((Info-no-error (Info-next)))
  2572. ((Info-no-error (Info-up t))
  2573. ;; Since we have already gone thru all the items in this menu,
  2574. ;; go up to the end of this node.
  2575. (goto-char (point-max))
  2576. ;; Since logically we are done with the node with that menu,
  2577. ;; move on from it. But don't add intermediate nodes
  2578. ;; to the history on recursive calls.
  2579. (let ((old-history Info-history))
  2580. (Info-next-preorder)
  2581. (if Info-history-skip-intermediate-nodes
  2582. (setq Info-history old-history))))
  2583. (t
  2584. (user-error "No more nodes"))))
  2585. (defun Info-last-preorder ()
  2586. "Go to the last node, popping up a level if there is none."
  2587. (interactive)
  2588. (cond ((and Info-scroll-prefer-subnodes
  2589. (Info-no-error
  2590. (Info-last-menu-item)
  2591. ;; If we go down a menu item, go to the end of the node
  2592. ;; so we can scroll back through it.
  2593. (goto-char (point-max))))
  2594. ;; Keep going down, as long as there are nested menu nodes.
  2595. (let ((old-history Info-history))
  2596. (while (Info-no-error
  2597. (Info-last-menu-item)
  2598. ;; If we go down a menu item, go to the end of the node
  2599. ;; so we can scroll back through it.
  2600. (goto-char (point-max))))
  2601. (if Info-history-skip-intermediate-nodes
  2602. (setq Info-history old-history)))
  2603. (recenter -1))
  2604. ((and (Info-no-error (Info-extract-pointer "prev"))
  2605. (not (equal (Info-extract-pointer "up")
  2606. (Info-extract-pointer "prev"))))
  2607. (Info-no-error (Info-prev))
  2608. (goto-char (point-max))
  2609. (let ((old-history Info-history))
  2610. (while (Info-no-error
  2611. (Info-last-menu-item)
  2612. ;; If we go down a menu item, go to the end of the node
  2613. ;; so we can scroll back through it.
  2614. (goto-char (point-max))))
  2615. (if Info-history-skip-intermediate-nodes
  2616. (setq Info-history old-history)))
  2617. (recenter -1))
  2618. ((Info-no-error (Info-up t))
  2619. (goto-char (point-min))
  2620. (let ((case-fold-search t))
  2621. (or (search-forward "\n* Menu:" nil t)
  2622. (goto-char (point-max)))))
  2623. (t (user-error "No previous nodes"))))
  2624. (defun Info-scroll-up ()
  2625. "Scroll one screenful forward in Info, considering all nodes as one sequence.
  2626. Once you scroll far enough in a node that its menu appears on the screen
  2627. but after point, the next scroll moves into its first subnode, unless
  2628. `Info-scroll-prefer-subnodes' is nil.
  2629. When you scroll past the end of a node, that goes to the next node if
  2630. `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
  2631. if this node has no successor, it moves to the parent node's successor,
  2632. and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
  2633. the menu of a node, it moves to subnode indicated by the following menu
  2634. item. (That case won't normally result from this command, but can happen
  2635. in other ways.)"
  2636. (interactive)
  2637. (if (or (< (window-start) (point-min))
  2638. (> (window-start) (point-max)))
  2639. (set-window-start (selected-window) (point)))
  2640. (let* ((case-fold-search t)
  2641. (virtual-end (save-excursion
  2642. (goto-char (point-min))
  2643. (if (and Info-scroll-prefer-subnodes
  2644. (search-forward "\n* Menu:" nil t))
  2645. (point)
  2646. (point-max)))))
  2647. (if (or (< virtual-end (window-start))
  2648. (pos-visible-in-window-p virtual-end))
  2649. (cond
  2650. (Info-scroll-prefer-subnodes (Info-next-preorder))
  2651. ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
  2652. (t (Info-next-preorder)))
  2653. (scroll-up))))
  2654. (defun Info-mouse-scroll-up (e)
  2655. "Scroll one screenful forward in Info, using the mouse.
  2656. See `Info-scroll-up'."
  2657. (interactive "e")
  2658. (save-selected-window
  2659. (if (eventp e)
  2660. (select-window (posn-window (event-start e))))
  2661. (Info-scroll-up)))
  2662. (defun Info-scroll-down ()
  2663. "Scroll one screenful back in Info, considering all nodes as one sequence.
  2664. If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
  2665. is non-nil, this goes to its last subnode. When you scroll past the
  2666. beginning of a node, that goes to the previous node or back up to the
  2667. parent node."
  2668. (interactive)
  2669. (if (or (< (window-start) (point-min))
  2670. (> (window-start) (point-max)))
  2671. (set-window-start (selected-window) (point)))
  2672. (let* ((case-fold-search t)
  2673. (current-point (point))
  2674. (virtual-end
  2675. (and Info-scroll-prefer-subnodes
  2676. (save-excursion
  2677. (setq current-point (line-beginning-position))
  2678. (goto-char (point-min))
  2679. (search-forward "\n* Menu:" current-point t)))))
  2680. (if (or virtual-end
  2681. (pos-visible-in-window-p (point-min) nil t))
  2682. (Info-last-preorder)
  2683. (scroll-down))))
  2684. (defun Info-mouse-scroll-down (e)
  2685. "Scroll one screenful backward in Info, using the mouse.
  2686. See `Info-scroll-down'."
  2687. (interactive "e")
  2688. (save-selected-window
  2689. (if (eventp e)
  2690. (select-window (posn-window (event-start e))))
  2691. (Info-scroll-down)))
  2692. (defun Info-next-reference (&optional recur)
  2693. "Move cursor to the next cross-reference or menu item in the node."
  2694. (interactive)
  2695. (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
  2696. (old-pt (point))
  2697. (case-fold-search t))
  2698. (or (eobp) (forward-char 1))
  2699. (or (re-search-forward pat nil t)
  2700. (progn
  2701. (goto-char (point-min))
  2702. (or (re-search-forward pat nil t)
  2703. (progn
  2704. (goto-char old-pt)
  2705. (user-error "No cross references in this node")))))
  2706. (goto-char (or (match-beginning 1) (match-beginning 0)))
  2707. (if (looking-at "\\* Menu:")
  2708. (if recur
  2709. (user-error "No cross references in this node")
  2710. (Info-next-reference t))
  2711. (if (looking-at "^\\* ")
  2712. (forward-char 2)))))
  2713. (defun Info-prev-reference (&optional recur)
  2714. "Move cursor to the previous cross-reference or menu item in the node."
  2715. (interactive)
  2716. (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
  2717. (old-pt (point))
  2718. (case-fold-search t))
  2719. (or (re-search-backward pat nil t)
  2720. (progn
  2721. (goto-char (point-max))
  2722. (or (re-search-backward pat nil t)
  2723. (progn
  2724. (goto-char old-pt)
  2725. (user-error "No cross references in this node")))))
  2726. (goto-char (or (match-beginning 1) (match-beginning 0)))
  2727. (if (looking-at "\\* Menu:")
  2728. (if recur
  2729. (user-error "No cross references in this node")
  2730. (Info-prev-reference t))
  2731. (if (looking-at "^\\* ")
  2732. (forward-char 2)))))
  2733. (defvar Info-index-nodes nil
  2734. "Alist of cached index node names of visited Info files.
  2735. Each element has the form (INFO-FILE INDEX-NODE-NAMES-LIST).")
  2736. (defun Info-index-nodes (&optional file)
  2737. "Return a list of names of all index nodes in Info FILE.
  2738. If FILE is omitted, it defaults to the current Info file.
  2739. First look in a list of cached index node names. Then scan Info
  2740. file and its subfiles for nodes with the index cookie. Then try
  2741. to find index nodes starting from the first node in the top level
  2742. menu whose name contains the word \"Index\", plus any immediately
  2743. following nodes whose names also contain the word \"Index\"."
  2744. (or file (setq file Info-current-file))
  2745. (or (assoc file Info-index-nodes)
  2746. ;; Skip virtual Info files
  2747. (and (or (not (stringp file))
  2748. (Info-virtual-file-p file))
  2749. (setq Info-index-nodes (cons (cons file nil) Info-index-nodes)))
  2750. (if (Info-file-supports-index-cookies file)
  2751. ;; Find nodes with index cookie
  2752. (let* ((default-directory (or (and (stringp file)
  2753. (file-name-directory
  2754. (setq file (Info-find-file file))))
  2755. default-directory))
  2756. Info-history Info-history-list Info-fontify-maximum-menu-size
  2757. (main-file file) subfiles nodes)
  2758. (condition-case nil
  2759. (with-temp-buffer
  2760. (while (or main-file subfiles)
  2761. (erase-buffer)
  2762. (info-insert-file-contents (or main-file (car subfiles)))
  2763. (goto-char (point-min))
  2764. (while (search-forward "\0\b[index\0\b]" nil 'move)
  2765. (save-excursion
  2766. (re-search-backward "^\^_")
  2767. (search-forward "Node: ")
  2768. (setq nodes (cons (Info-following-node-name) nodes))))
  2769. (if main-file
  2770. (save-excursion
  2771. (goto-char (point-min))
  2772. (if (search-forward "\n\^_\nIndirect:" nil t)
  2773. (let ((bound (save-excursion (search-forward "\n\^_" nil t))))
  2774. (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t)
  2775. (setq subfiles (cons (match-string-no-properties 1)
  2776. subfiles)))))
  2777. (setq subfiles (nreverse subfiles)
  2778. main-file nil))
  2779. (setq subfiles (cdr subfiles)))))
  2780. (error nil))
  2781. (if nodes
  2782. (setq nodes (nreverse nodes)
  2783. Info-index-nodes (cons (cons file nodes) Info-index-nodes)))
  2784. nodes)
  2785. ;; Else find nodes with the word "Index" in the node name
  2786. (let ((case-fold-search t)
  2787. Info-history Info-history-list Info-fontify-maximum-menu-size Info-point-loc
  2788. nodes node)
  2789. (condition-case nil
  2790. (with-temp-buffer
  2791. (Info-mode)
  2792. (Info-find-node file "Top")
  2793. (when (and (search-forward "\n* menu:" nil t)
  2794. (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
  2795. (goto-char (match-beginning 1))
  2796. (setq nodes (list (Info-extract-menu-node-name)))
  2797. (Info-goto-node (car nodes))
  2798. (while (and (setq node (Info-extract-pointer "next" t))
  2799. (string-match "\\<Index\\>" node))
  2800. (push node nodes)
  2801. (Info-goto-node node))))
  2802. (error nil))
  2803. (if nodes
  2804. (setq nodes (nreverse nodes)
  2805. Info-index-nodes (cons (cons file nodes) Info-index-nodes)))
  2806. nodes))
  2807. ;; If file has no index nodes, still add it to the cache
  2808. (setq Info-index-nodes (cons (cons file nil) Info-index-nodes)))
  2809. (cdr (assoc file Info-index-nodes)))
  2810. (defun Info-index-node (&optional node file)
  2811. "Return non-nil value if NODE is an index node.
  2812. If NODE is nil, check the current Info node.
  2813. If FILE is nil, check the current Info file."
  2814. (or file (setq file Info-current-file))
  2815. (if (and (or (and node (not (equal node Info-current-node)))
  2816. (assoc file Info-index-nodes))
  2817. (not Info-current-node-virtual))
  2818. (member (or node Info-current-node) (Info-index-nodes file))
  2819. ;; Don't search all index nodes if request is only for the current node
  2820. ;; and file is not in the cache of index nodes
  2821. (save-match-data
  2822. (if (Info-file-supports-index-cookies file)
  2823. (save-excursion
  2824. (goto-char (+ (or (save-excursion
  2825. (search-backward "\n\^_" nil t))
  2826. (point-min)) 2))
  2827. (search-forward "\0\b[index\0\b]"
  2828. (or (save-excursion
  2829. (search-forward "\n\^_" nil t))
  2830. (point-max)) t))
  2831. (string-match "\\<Index\\>" (or node Info-current-node ""))))))
  2832. (defun Info-goto-index ()
  2833. "Go to the first index node."
  2834. (let ((node (car (Info-index-nodes))))
  2835. (or node (error "No index"))
  2836. (Info-goto-node node)))
  2837. ;;;###autoload
  2838. (defun Info-index (topic)
  2839. "Look up a string TOPIC in the index for this manual and go to that entry.
  2840. If there are no exact matches to the specified topic, this chooses
  2841. the first match which is a case-insensitive substring of a topic.
  2842. Use the \\<Info-mode-map>\\[Info-index-next] command to see the other matches.
  2843. Give an empty topic name to go to the Index node itself."
  2844. (interactive
  2845. (list
  2846. (let ((completion-ignore-case t)
  2847. (Info-complete-menu-buffer (clone-buffer))
  2848. (Info-complete-nodes (Info-index-nodes))
  2849. (Info-history-list nil))
  2850. (if (equal Info-current-file "dir")
  2851. (error "The Info directory node has no index; use m to select a manual"))
  2852. (unwind-protect
  2853. (with-current-buffer Info-complete-menu-buffer
  2854. (Info-goto-index)
  2855. (completing-read "Index topic: " 'Info-complete-menu-item))
  2856. (kill-buffer Info-complete-menu-buffer)))))
  2857. (if (equal Info-current-file "dir")
  2858. (error "The Info directory node has no index; use m to select a manual"))
  2859. ;; Strip leading colon in topic; index format does not allow them.
  2860. (if (and (stringp topic)
  2861. (> (length topic) 0)
  2862. (= (aref topic 0) ?:))
  2863. (setq topic (substring topic 1)))
  2864. (let ((orignode Info-current-node)
  2865. (pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
  2866. (regexp-quote topic)))
  2867. node (nodes (Info-index-nodes))
  2868. (ohist-list Info-history-list)
  2869. (case-fold-search t))
  2870. (Info-goto-index)
  2871. (or (equal topic "")
  2872. (let ((matches nil)
  2873. (exact nil)
  2874. ;; We bind Info-history to nil for internal node-switches so
  2875. ;; that we don't put junk in the history. In the first
  2876. ;; Info-goto-index call, above, we do update the history
  2877. ;; because that is what the user's previous node choice into it.
  2878. (Info-history nil)
  2879. found)
  2880. (while
  2881. (progn
  2882. (goto-char (point-min))
  2883. (while (re-search-forward pattern nil t)
  2884. (push (list (match-string-no-properties 1)
  2885. (match-string-no-properties 2)
  2886. Info-current-node
  2887. (string-to-number (concat "0"
  2888. (match-string 3))))
  2889. matches))
  2890. (setq nodes (cdr nodes) node (car nodes)))
  2891. (Info-goto-node node))
  2892. (or matches
  2893. (progn
  2894. (Info-goto-node orignode)
  2895. (user-error "No `%s' in index" topic)))
  2896. ;; Here it is a feature that assoc is case-sensitive.
  2897. (while (setq found (assoc topic matches))
  2898. (setq exact (cons found exact)
  2899. matches (delq found matches)))
  2900. (setq Info-history-list ohist-list)
  2901. (setq Info-index-alternatives (nconc exact (nreverse matches)))
  2902. (Info-index-next 0)))))
  2903. (defun Info-index-next (num)
  2904. "Go to the next matching index item from the last \\<Info-mode-map>\\[Info-index] command."
  2905. (interactive "p")
  2906. (or Info-index-alternatives
  2907. (user-error "No previous `i' command"))
  2908. (while (< num 0)
  2909. (setq num (+ num (length Info-index-alternatives))))
  2910. (while (> num 0)
  2911. (setq Info-index-alternatives
  2912. (nconc (cdr Info-index-alternatives)
  2913. (list (car Info-index-alternatives)))
  2914. num (1- num)))
  2915. (Info-goto-node (nth 1 (car Info-index-alternatives)))
  2916. (if (> (nth 3 (car Info-index-alternatives)) 0)
  2917. ;; Forward 2 lines less because `Info-find-node-2' initially
  2918. ;; puts point to the 2nd line.
  2919. (forward-line (- (nth 3 (car Info-index-alternatives)) 2))
  2920. (forward-line 3) ; don't search in headers
  2921. (let ((name (car (car Info-index-alternatives))))
  2922. (Info-find-index-name name)))
  2923. (message "Found `%s' in %s. %s"
  2924. (car (car Info-index-alternatives))
  2925. (nth 2 (car Info-index-alternatives))
  2926. (if (cdr Info-index-alternatives)
  2927. (format "(%s total; use `%s' for next)"
  2928. (length Info-index-alternatives)
  2929. (key-description (where-is-internal
  2930. 'Info-index-next overriding-local-map
  2931. t)))
  2932. "(Only match)")))
  2933. (defun Info-find-index-name (name)
  2934. "Move point to the place within the current node where NAME is defined."
  2935. (let ((case-fold-search t))
  2936. (if (or (re-search-forward (format
  2937. "[a-zA-Z]+: %s\\( \\|$\\)"
  2938. (regexp-quote name)) nil t)
  2939. ;; Find a function definition with a return type.
  2940. (re-search-forward (format
  2941. "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
  2942. (regexp-quote name)) nil t)
  2943. (search-forward (format "`%s'" name) nil t)
  2944. (and (string-match "\\`.*\\( (.*)\\)\\'" name)
  2945. (search-forward
  2946. (format "`%s'" (substring name 0 (match-beginning 1)))
  2947. nil t))
  2948. (search-forward name nil t)
  2949. ;; Try again without the " <1>" makeinfo can append
  2950. (and (string-match "\\`\\(.*\\) <[0-9]+>\\'" name)
  2951. (Info-find-index-name (match-string 1 name))))
  2952. (progn (beginning-of-line) t) ;; non-nil for recursive call
  2953. (goto-char (point-min)))))
  2954. (add-to-list 'Info-virtual-nodes
  2955. '("\\`\\*Index.*\\*\\'"
  2956. (find-node . Info-virtual-index-find-node)
  2957. (slow . t)
  2958. ))
  2959. (defvar Info-virtual-index-nodes nil
  2960. "Alist of cached matched index search nodes.
  2961. Each element is ((FILENAME . TOPIC) MATCHES) where
  2962. FILENAME is the file name of the manual,
  2963. TOPIC is the search string given as an argument to `Info-virtual-index',
  2964. MATCHES is a list of index matches found by `Info-index'.")
  2965. (defun Info-virtual-index-find-node (filename nodename &optional _no-going-back)
  2966. "Index-specific implementation of `Info-find-node-2'."
  2967. ;; Generate Index-like menu of matches
  2968. (if (string-match "^\\*Index for `\\(.+\\)'\\*$" nodename)
  2969. ;; Generate Index-like menu of matches
  2970. (let* ((topic (match-string 1 nodename))
  2971. (matches (cdr (assoc (cons (or filename Info-current-file) topic)
  2972. Info-virtual-index-nodes))))
  2973. (insert (format "\n\^_\nFile: %s, Node: %s, Up: *Index*\n\n"
  2974. (or filename Info-current-file) nodename))
  2975. (insert "Info Virtual Index\n")
  2976. (insert "******************\n\n")
  2977. (insert "Index entries that match `" topic "':\n\n")
  2978. (insert "\0\b[index\0\b]\n")
  2979. (if (null matches)
  2980. (insert "No matches found.\n")
  2981. (insert "* Menu:\n\n")
  2982. (dolist (entry matches)
  2983. (insert (format "* %-38s %s.%s\n"
  2984. (format "%s [%s]:" (nth 0 entry) (nth 2 entry))
  2985. (nth 1 entry)
  2986. (if (nth 3 entry)
  2987. (format " (line %s)" (nth 3 entry))
  2988. ""))))))
  2989. ;; Else, Generate a list of previous search results
  2990. (let ((nodes (reverse Info-virtual-index-nodes)))
  2991. (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
  2992. (or filename Info-current-file) nodename))
  2993. (insert "Info Virtual Index\n")
  2994. (insert "******************\n\n")
  2995. (insert "This is a list of search results produced by\n"
  2996. "`Info-virtual-index' for the current manual.\n\n")
  2997. (insert "* Menu:\n\n")
  2998. (dolist (nodeinfo nodes)
  2999. (when (equal (car (nth 0 nodeinfo)) (or filename Info-current-file))
  3000. (insert
  3001. (format "* %-20s %s.\n"
  3002. (format "*Index for `%s'*::" (cdr (nth 0 nodeinfo)))
  3003. (cdr (nth 0 nodeinfo)))))))))
  3004. (defun Info-virtual-index (topic)
  3005. "Show a node with all lines in the index containing a string TOPIC.
  3006. Like `Info-index' but displays a node with index search results.
  3007. Give an empty topic name to go to the node with links to previous
  3008. search results."
  3009. ;; `interactive' is a copy from `Info-index'
  3010. (interactive
  3011. (list
  3012. (let ((completion-ignore-case t)
  3013. (Info-complete-menu-buffer (clone-buffer))
  3014. (Info-complete-nodes (Info-index-nodes))
  3015. (Info-history-list nil))
  3016. (if (equal Info-current-file "dir")
  3017. (error "The Info directory node has no index; use m to select a manual"))
  3018. (unwind-protect
  3019. (with-current-buffer Info-complete-menu-buffer
  3020. (Info-goto-index)
  3021. (completing-read "Index topic: " 'Info-complete-menu-item))
  3022. (kill-buffer Info-complete-menu-buffer)))))
  3023. (if (equal topic "")
  3024. (Info-find-node Info-current-file "*Index*")
  3025. (unless (assoc (cons Info-current-file topic) Info-virtual-index-nodes)
  3026. (let ((orignode Info-current-node)
  3027. (ohist-list Info-history-list))
  3028. ;; Reuse `Info-index' to set `Info-index-alternatives'.
  3029. (Info-index topic)
  3030. (push (cons (cons Info-current-file topic) Info-index-alternatives)
  3031. Info-virtual-index-nodes)
  3032. ;; Clean up unnecessary side-effects of `Info-index'.
  3033. (setq Info-history-list ohist-list)
  3034. (Info-goto-node orignode)
  3035. (message "")))
  3036. (Info-find-node Info-current-file (format "*Index for `%s'*" topic))))
  3037. (add-to-list 'Info-virtual-files
  3038. '("\\`\\*Apropos\\*\\'"
  3039. (toc-nodes . Info-apropos-toc-nodes)
  3040. (find-file . Info-apropos-find-file)
  3041. (find-node . Info-apropos-find-node)
  3042. (slow . t)
  3043. ))
  3044. (defvar Info-apropos-file "*Apropos*"
  3045. "Info file name of the virtual manual for matches of `info-apropos'.")
  3046. (defvar Info-apropos-nodes nil
  3047. "Alist of cached apropos matched nodes.
  3048. Each element is (NODENAME STRING MATCHES) where
  3049. NODENAME is the name of the node that holds the search result,
  3050. STRING is the search string given as an argument to `info-apropos',
  3051. MATCHES is a list of index matches found by `Info-apropos-matches'.")
  3052. (defun Info-apropos-toc-nodes (filename)
  3053. "Apropos-specific implementation of `Info-toc-nodes'."
  3054. (let ((nodes (mapcar 'car (reverse Info-apropos-nodes))))
  3055. `(,filename
  3056. ("Top" nil nil ,nodes)
  3057. ,@(mapcar (lambda (node) `(,node "Top" nil nil)) nodes))))
  3058. (defun Info-apropos-find-file (filename &optional _noerror)
  3059. "Apropos-specific implementation of `Info-find-file'."
  3060. filename)
  3061. (defun Info-apropos-find-node (_filename nodename &optional _no-going-back)
  3062. "Apropos-specific implementation of `Info-find-node-2'."
  3063. (if (equal nodename "Top")
  3064. ;; Generate Top menu
  3065. (let ((nodes (reverse Info-apropos-nodes)))
  3066. (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
  3067. Info-apropos-file nodename))
  3068. (insert "Apropos Index\n")
  3069. (insert "*************\n\n")
  3070. (insert "This is a list of search results produced by `info-apropos'.\n\n")
  3071. (insert "* Menu:\n\n")
  3072. (dolist (nodeinfo nodes)
  3073. (insert (format "* %-20s %s.\n"
  3074. (format "%s::" (nth 0 nodeinfo))
  3075. (nth 1 nodeinfo)))))
  3076. ;; Else, Generate Index-like menu of matches
  3077. (let* ((nodeinfo (assoc nodename Info-apropos-nodes))
  3078. (matches (nth 2 nodeinfo)))
  3079. (when matches
  3080. (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
  3081. Info-apropos-file nodename))
  3082. (insert "Apropos Index\n")
  3083. (insert "*************\n\n")
  3084. (insert "Index entries that match `" (nth 1 nodeinfo) "':\n\n")
  3085. (insert "\0\b[index\0\b]\n")
  3086. (if (eq matches t)
  3087. (insert "No matches found.\n")
  3088. (insert "* Menu:\n\n")
  3089. (dolist (entry matches)
  3090. (insert (format "* %-38s (%s)%s.%s\n"
  3091. (format "%s [%s]:" (nth 1 entry) (nth 0 entry))
  3092. (nth 0 entry)
  3093. (nth 2 entry)
  3094. (if (nth 3 entry)
  3095. (format " (line %s)" (nth 3 entry))
  3096. "")))))))))
  3097. (defun Info-apropos-matches (string)
  3098. "Collect STRING matches from all known Info files on your system.
  3099. Return a list of matches where each element is in the format
  3100. \((FILENAME INDEXTEXT NODENAME LINENUMBER))."
  3101. (unless (string= string "")
  3102. (let ((pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]+\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
  3103. (regexp-quote string)))
  3104. (ohist Info-history)
  3105. (ohist-list Info-history-list)
  3106. (current-node Info-current-node)
  3107. (current-file Info-current-file)
  3108. manuals matches node nodes)
  3109. (let ((Info-fontify-maximum-menu-size nil))
  3110. (Info-directory)
  3111. ;; current-node and current-file are nil when they invoke info-apropos
  3112. ;; as the first Info command, i.e. info-apropos loads info.el. In that
  3113. ;; case, we use (DIR)Top instead, to avoid signaling an error after
  3114. ;; the search is complete.
  3115. (when (null current-node)
  3116. (setq current-file Info-current-file)
  3117. (setq current-node Info-current-node))
  3118. (message "Searching indices...")
  3119. (goto-char (point-min))
  3120. (re-search-forward "\\* Menu: *\n" nil t)
  3121. (while (re-search-forward "\\*.*: *(\\([^)]+\\))" nil t)
  3122. ;; add-to-list makes sure we don't have duplicates in `manuals',
  3123. ;; so that the following dolist loop runs faster.
  3124. (add-to-list 'manuals (match-string 1)))
  3125. (dolist (manual (nreverse manuals))
  3126. (message "Searching %s" manual)
  3127. (condition-case err
  3128. (if (setq nodes (Info-index-nodes (Info-find-file manual)))
  3129. (save-excursion
  3130. (Info-find-node manual (car nodes))
  3131. (while
  3132. (progn
  3133. (goto-char (point-min))
  3134. (while (re-search-forward pattern nil t)
  3135. (setq matches
  3136. (cons (list manual
  3137. (match-string-no-properties 1)
  3138. (match-string-no-properties 2)
  3139. (match-string-no-properties 3))
  3140. matches)))
  3141. (setq nodes (cdr nodes) node (car nodes)))
  3142. (Info-goto-node node))))
  3143. (error
  3144. (message "%s" (if (eq (car-safe err) 'error)
  3145. (nth 1 err) err))
  3146. (sit-for 1 t)))))
  3147. (Info-find-node current-file current-node)
  3148. (setq Info-history ohist
  3149. Info-history-list ohist-list)
  3150. (message "Searching indices...done")
  3151. (or (nreverse matches) t))))
  3152. ;;;###autoload
  3153. (defun info-apropos (string)
  3154. "Grovel indices of all known Info files on your system for STRING.
  3155. Build a menu of the possible matches."
  3156. (interactive "sIndex apropos: ")
  3157. (if (equal string "")
  3158. (Info-find-node Info-apropos-file "Top")
  3159. (let* ((nodes Info-apropos-nodes) nodename)
  3160. (while (and nodes (not (equal string (nth 1 (car nodes)))))
  3161. (setq nodes (cdr nodes)))
  3162. (if nodes
  3163. (Info-find-node Info-apropos-file (car (car nodes)))
  3164. (setq nodename (format "Index for `%s'" string))
  3165. (push (list nodename string (Info-apropos-matches string))
  3166. Info-apropos-nodes)
  3167. (Info-find-node Info-apropos-file nodename)))))
  3168. (add-to-list 'Info-virtual-files
  3169. '("\\`\\*Finder.*\\*\\'"
  3170. (find-file . Info-finder-find-file)
  3171. (find-node . Info-finder-find-node)
  3172. ))
  3173. (defvar Info-finder-file "*Finder*"
  3174. "Info file name of the virtual Info keyword finder manual.")
  3175. (defun Info-finder-find-file (filename &optional _noerror)
  3176. "Finder-specific implementation of `Info-find-file'."
  3177. filename)
  3178. (defvar finder-known-keywords)
  3179. (declare-function find-library-name "find-func" (library))
  3180. (declare-function finder-unknown-keywords "finder" ())
  3181. (declare-function lm-commentary "lisp-mnt" (&optional file))
  3182. (defvar finder-keywords-hash)
  3183. (defvar package--builtins) ; finder requires package
  3184. (defun Info-finder-find-node (_filename nodename &optional _no-going-back)
  3185. "Finder-specific implementation of `Info-find-node-2'."
  3186. (require 'finder)
  3187. (cond
  3188. ((equal nodename "Top")
  3189. ;; Display Top menu with descriptions of the keywords
  3190. (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
  3191. Info-finder-file nodename))
  3192. (insert "Finder Keywords\n")
  3193. (insert "***************\n\n")
  3194. (insert "* Menu:\n\n")
  3195. (dolist (assoc (append '((all . "All package info")
  3196. (unknown . "Unknown keywords"))
  3197. finder-known-keywords))
  3198. (let ((keyword (car assoc)))
  3199. (insert (format "* %s %s.\n"
  3200. (concat (symbol-name keyword) ": "
  3201. "Keyword " (symbol-name keyword) ".")
  3202. (cdr assoc))))))
  3203. ((equal nodename "Keyword unknown")
  3204. ;; Display unknown keywords
  3205. (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
  3206. Info-finder-file nodename))
  3207. (insert "Finder Unknown Keywords\n")
  3208. (insert "***********************\n\n")
  3209. (insert "* Menu:\n\n")
  3210. (mapc
  3211. (lambda (assoc)
  3212. (insert (format "* %-14s %s.\n"
  3213. (concat (symbol-name (car assoc)) ": "
  3214. "Keyword " (symbol-name (car assoc)) ".")
  3215. (cdr assoc))))
  3216. (finder-unknown-keywords)))
  3217. ((equal nodename "Keyword all")
  3218. ;; Display all package info.
  3219. (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
  3220. Info-finder-file nodename))
  3221. (insert "Finder Package Info\n")
  3222. (insert "*******************\n\n")
  3223. (insert "* Menu:\n\n")
  3224. (let (desc)
  3225. (dolist (package package--builtins)
  3226. (setq desc (cdr-safe package))
  3227. (when (vectorp desc)
  3228. (insert (format "* %-16s %s.\n"
  3229. (concat (symbol-name (car package)) "::")
  3230. (aref desc 2)))))))
  3231. ((string-match "\\`Keyword " nodename)
  3232. (setq nodename (substring nodename (match-end 0)))
  3233. ;; Display packages that match the keyword
  3234. ;; or the list of keywords separated by comma.
  3235. (insert (format "\n\^_\nFile: %s, Node: Keyword %s, Up: Top\n\n"
  3236. Info-finder-file nodename))
  3237. (insert "Finder Packages\n")
  3238. (insert "***************\n\n")
  3239. (insert
  3240. "The following packages match the keyword `" nodename "':\n\n")
  3241. (insert "* Menu:\n\n")
  3242. (let ((keywords
  3243. (mapcar 'intern (if (string-match-p "," nodename)
  3244. (split-string nodename ",[ \t\n]*" t)
  3245. (list nodename))))
  3246. hits desc)
  3247. (dolist (keyword keywords)
  3248. (push (copy-tree (gethash keyword finder-keywords-hash)) hits))
  3249. (setq hits (delete-dups (apply 'append hits)))
  3250. (dolist (package hits)
  3251. (setq desc (cdr-safe (assq package package--builtins)))
  3252. (when (vectorp desc)
  3253. (insert (format "* %-16s %s.\n"
  3254. (concat (symbol-name package) "::")
  3255. (aref desc 2)))))))
  3256. (t
  3257. ;; Display commentary section
  3258. (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
  3259. Info-finder-file nodename))
  3260. (insert "Finder Commentary\n")
  3261. (insert "*****************\n\n")
  3262. (insert
  3263. "Commentary section of the package `" nodename "':\n\n")
  3264. (let ((str (lm-commentary (find-library-name nodename))))
  3265. (if (null str)
  3266. (insert "Can't find any Commentary section\n\n")
  3267. (insert
  3268. (with-temp-buffer
  3269. (insert str)
  3270. (goto-char (point-min))
  3271. (delete-blank-lines)
  3272. (goto-char (point-max))
  3273. (delete-blank-lines)
  3274. (goto-char (point-min))
  3275. (while (re-search-forward "^;+ ?" nil t)
  3276. (replace-match "" nil nil))
  3277. (buffer-string))))))))
  3278. ;;;###autoload
  3279. (defun info-finder (&optional keywords)
  3280. "Display descriptions of the keywords in the Finder virtual manual.
  3281. In interactive use, a prefix argument directs this command to read
  3282. a list of keywords separated by comma. After that, it displays a node
  3283. with a list of packages that contain all specified keywords."
  3284. (interactive
  3285. (when current-prefix-arg
  3286. (require 'finder)
  3287. (list
  3288. (completing-read-multiple
  3289. "Keywords (separated by comma): "
  3290. (mapcar 'symbol-name (mapcar 'car (append finder-known-keywords
  3291. (finder-unknown-keywords))))
  3292. nil t))))
  3293. (require 'finder)
  3294. (if keywords
  3295. (Info-find-node Info-finder-file (mapconcat 'identity keywords ", "))
  3296. (Info-find-node Info-finder-file "Top")))
  3297. (defun Info-undefined ()
  3298. "Make command be undefined in Info."
  3299. (interactive)
  3300. (ding))
  3301. (defun Info-help ()
  3302. "Enter the Info tutorial."
  3303. (interactive)
  3304. (delete-other-windows)
  3305. (Info-find-node "info"
  3306. (if (< (window-height) 23)
  3307. "Help-Small-Screen"
  3308. "Help")))
  3309. (defun Info-summary ()
  3310. "Display a brief summary of all Info commands."
  3311. (interactive)
  3312. (save-window-excursion
  3313. (switch-to-buffer "*Help*")
  3314. (setq buffer-read-only nil)
  3315. (erase-buffer)
  3316. (insert (documentation 'Info-mode))
  3317. (help-mode)
  3318. (goto-char (point-min))
  3319. (let (ch flag)
  3320. (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
  3321. (message (if flag "Type Space to see more"
  3322. "Type Space to return to Info"))
  3323. (if (not (eq ?\s (setq ch (read-event))))
  3324. (progn (setq unread-command-events (list ch)) nil)
  3325. flag))
  3326. (scroll-up)))
  3327. (bury-buffer "*Help*")))
  3328. (defun Info-get-token (pos start all &optional errorstring)
  3329. "Return the token around POS.
  3330. POS must be somewhere inside the token.
  3331. START is a regular expression which will match the
  3332. beginning of the tokens delimited string.
  3333. ALL is a regular expression with a single
  3334. parenthesized subpattern which is the token to be
  3335. returned. E.g. '{\(.*\)}' would return any string
  3336. enclosed in braces around POS.
  3337. ERRORSTRING optional fourth argument, controls action on no match:
  3338. nil: return nil
  3339. t: beep
  3340. a string: signal an error, using that string."
  3341. (let ((case-fold-search t))
  3342. (save-excursion
  3343. (goto-char pos)
  3344. ;; First look for a match for START that goes across POS.
  3345. (while (and (not (bobp)) (> (point) (- pos (length start)))
  3346. (not (looking-at start)))
  3347. (forward-char -1))
  3348. ;; If we did not find one, search back for START
  3349. ;; (this finds only matches that end at or before POS).
  3350. (or (looking-at start)
  3351. (progn
  3352. (goto-char pos)
  3353. (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
  3354. (let (found)
  3355. (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
  3356. (not (setq found (and (<= (match-beginning 0) pos)
  3357. (> (match-end 0) pos))))))
  3358. (if (and found (<= (match-beginning 0) pos)
  3359. (> (match-end 0) pos))
  3360. (match-string-no-properties 1)
  3361. (cond ((null errorstring)
  3362. nil)
  3363. ((eq errorstring t)
  3364. (beep)
  3365. nil)
  3366. (t
  3367. (error "No %s around position %d" errorstring pos))))))))
  3368. (defun Info-mouse-follow-nearest-node (click)
  3369. "\\<Info-mode-map>Follow a node reference near point.
  3370. Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
  3371. At end of the node's text, moves to the next node, or up if none."
  3372. (interactive "e")
  3373. (mouse-set-point click)
  3374. (and (not (Info-follow-nearest-node))
  3375. (save-excursion (forward-line 1) (eobp))
  3376. (Info-next-preorder)))
  3377. (defun Info-follow-nearest-node (&optional fork)
  3378. "Follow a node reference near point.
  3379. If point is on a reference, follow that reference. Otherwise,
  3380. if point is in a menu item description, follow that menu item.
  3381. If FORK is non-nil (interactively with a prefix arg), show the node in
  3382. a new Info buffer.
  3383. If FORK is a string, it is the name to use for the new buffer."
  3384. (interactive "P")
  3385. (or (Info-try-follow-nearest-node fork)
  3386. (when (save-excursion
  3387. (search-backward "\n* menu:" nil t))
  3388. (save-excursion
  3389. (beginning-of-line)
  3390. (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
  3391. (beginning-of-line 0))
  3392. (when (looking-at "\\* +\\([^\t\n]*\\):")
  3393. (Info-goto-node
  3394. (Info-extract-menu-item (match-string-no-properties 1)) fork)
  3395. t)))
  3396. (and (eq this-command 'Info-mouse-follow-nearest-node)
  3397. ;; Don't raise an error when mouse-1 is bound to this - it's
  3398. ;; often used to simply select the window or frame.
  3399. (eq 'mouse-1 (event-basic-type last-input-event)))
  3400. (user-error "Point neither on reference nor in menu item description")))
  3401. ;; Common subroutine.
  3402. (defun Info-try-follow-nearest-node (&optional fork)
  3403. "Follow a node reference near point. Return non-nil if successful.
  3404. If FORK is non-nil, it is passed to `Info-goto-node'."
  3405. (let (node)
  3406. (cond
  3407. ((setq node (Info-get-token (point) "[hf]t?tps?://"
  3408. "\\([hf]t?tps?://[^ \t\n\"`({<>})']+\\)"))
  3409. (browse-url node)
  3410. (setq node t))
  3411. ((setq node (Info-get-token (point) "\\*note[ \n\t]+"
  3412. "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))
  3413. (Info-follow-reference node fork))
  3414. ;; menu item: node name
  3415. ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
  3416. (Info-goto-node node fork))
  3417. ;; menu item: node name or index entry
  3418. ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
  3419. (beginning-of-line)
  3420. (forward-char 2)
  3421. (setq node (Info-extract-menu-node-name nil (Info-index-node)))
  3422. (Info-goto-node node fork))
  3423. ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
  3424. (Info-goto-node node fork))
  3425. ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
  3426. (Info-goto-node node fork))
  3427. ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
  3428. (Info-goto-node "Top" fork))
  3429. ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
  3430. (Info-goto-node node fork)))
  3431. node))
  3432. (defun Info-mouse-follow-link (click)
  3433. "Follow a link where you click."
  3434. (interactive "e")
  3435. (let* ((position (event-start click))
  3436. (posn-string (and position (posn-string position)))
  3437. (string (car-safe posn-string))
  3438. (string-pos (cdr-safe posn-string))
  3439. (link-args (and string string-pos
  3440. (get-text-property string-pos 'link-args string))))
  3441. (when link-args
  3442. (Info-goto-node link-args))))
  3443. (defvar Info-mode-map
  3444. (let ((map (make-keymap)))
  3445. (suppress-keymap map)
  3446. (define-key map "." 'beginning-of-buffer)
  3447. (define-key map " " 'Info-scroll-up)
  3448. (define-key map "\C-m" 'Info-follow-nearest-node)
  3449. (define-key map "\t" 'Info-next-reference)
  3450. (define-key map "\e\t" 'Info-prev-reference)
  3451. (define-key map [backtab] 'Info-prev-reference)
  3452. (define-key map "1" 'Info-nth-menu-item)
  3453. (define-key map "2" 'Info-nth-menu-item)
  3454. (define-key map "3" 'Info-nth-menu-item)
  3455. (define-key map "4" 'Info-nth-menu-item)
  3456. (define-key map "5" 'Info-nth-menu-item)
  3457. (define-key map "6" 'Info-nth-menu-item)
  3458. (define-key map "7" 'Info-nth-menu-item)
  3459. (define-key map "8" 'Info-nth-menu-item)
  3460. (define-key map "9" 'Info-nth-menu-item)
  3461. (define-key map "0" 'undefined)
  3462. (define-key map "?" 'Info-summary)
  3463. (define-key map "]" 'Info-forward-node)
  3464. (define-key map "[" 'Info-backward-node)
  3465. (define-key map "<" 'Info-top-node)
  3466. (define-key map ">" 'Info-final-node)
  3467. (define-key map "b" 'beginning-of-buffer)
  3468. (put 'beginning-of-buffer :advertised-binding "b")
  3469. (define-key map "d" 'Info-directory)
  3470. (define-key map "e" 'end-of-buffer)
  3471. (define-key map "f" 'Info-follow-reference)
  3472. (define-key map "g" 'Info-goto-node)
  3473. (define-key map "h" 'Info-help)
  3474. (define-key map "i" 'Info-index)
  3475. (define-key map "I" 'Info-virtual-index)
  3476. (define-key map "l" 'Info-history-back)
  3477. (define-key map "L" 'Info-history)
  3478. (define-key map "m" 'Info-menu)
  3479. (define-key map "n" 'Info-next)
  3480. (define-key map "p" 'Info-prev)
  3481. (define-key map "q" 'Info-exit)
  3482. (define-key map "r" 'Info-history-forward)
  3483. (define-key map "s" 'Info-search)
  3484. (define-key map "S" 'Info-search-case-sensitively)
  3485. (define-key map "\M-n" 'clone-buffer)
  3486. (define-key map "t" 'Info-top-node)
  3487. (define-key map "T" 'Info-toc)
  3488. (define-key map "u" 'Info-up)
  3489. ;; `w' for consistency with `dired-copy-filename-as-kill'.
  3490. (define-key map "w" 'Info-copy-current-node-name)
  3491. (define-key map "c" 'Info-copy-current-node-name)
  3492. ;; `^' for consistency with `dired-up-directory'.
  3493. (define-key map "^" 'Info-up)
  3494. (define-key map "," 'Info-index-next)
  3495. (define-key map "\177" 'Info-scroll-down)
  3496. (define-key map [mouse-2] 'Info-mouse-follow-nearest-node)
  3497. (define-key map [follow-link] 'mouse-face)
  3498. (define-key map [XF86Back] 'Info-history-back)
  3499. (define-key map [XF86Forward] 'Info-history-forward)
  3500. map)
  3501. "Keymap containing Info commands.")
  3502. (defun Info-check-pointer (item)
  3503. "Non-nil if ITEM is present in this node."
  3504. (condition-case nil
  3505. (Info-extract-pointer item)
  3506. (error nil)))
  3507. (easy-menu-define
  3508. Info-mode-menu Info-mode-map
  3509. "Menu for Info files."
  3510. '("Info"
  3511. ["Up" Info-up :active (Info-check-pointer "up")
  3512. :help "Go up in the Info tree"]
  3513. ["Next" Info-next :active (Info-check-pointer "next")
  3514. :help "Go to the next node"]
  3515. ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
  3516. :help "Go to the previous node"]
  3517. ["Backward" Info-backward-node
  3518. :help "Go backward one node, considering all as a sequence"]
  3519. ["Forward" Info-forward-node
  3520. :help "Go forward one node, considering all as a sequence"]
  3521. ["Beginning" beginning-of-buffer
  3522. :help "Go to beginning of this node"]
  3523. ["Top" Info-top-node
  3524. :help "Go to top node of file"]
  3525. ["Final Node" Info-final-node
  3526. :help "Go to final node in this file"]
  3527. ("Menu Item" ["You should never see this" report-emacs-bug t])
  3528. ("Reference" ["You should never see this" report-emacs-bug t])
  3529. ["Search..." Info-search
  3530. :help "Search for regular expression in this Info file"]
  3531. ["Search Next" Info-search-next
  3532. :help "Search for another occurrence of regular expression"]
  3533. ["Go to Node..." Info-goto-node
  3534. :help "Go to a named node"]
  3535. ["Back in history" Info-history-back :active Info-history
  3536. :help "Go back in history to the last node you were at"]
  3537. ["Forward in history" Info-history-forward :active Info-history-forward
  3538. :help "Go forward in history"]
  3539. ["History" Info-history :active Info-history-list
  3540. :help "Go to menu of visited nodes"]
  3541. ["Table of Contents" Info-toc
  3542. :help "Go to table of contents"]
  3543. ("Index"
  3544. ["Lookup a String..." Info-index
  3545. :help "Look for a string in the index items"]
  3546. ["Next Matching Item" Info-index-next :active Info-index-alternatives
  3547. :help "Look for another occurrence of previous item"]
  3548. ["Lookup a string and display index of results..." Info-virtual-index
  3549. :help "Look for a string in the index items and display node with results"]
  3550. ["Lookup a string in all indices..." info-apropos
  3551. :help "Look for a string in the indices of all manuals"])
  3552. ["Copy Node Name" Info-copy-current-node-name
  3553. :help "Copy the name of the current node into the kill ring"]
  3554. ["Clone Info buffer" clone-buffer
  3555. :help "Create a twin copy of the current Info buffer."]
  3556. ["Exit" Info-exit :help "Stop reading Info"]))
  3557. (defvar info-tool-bar-map
  3558. (let ((map (make-sparse-keymap)))
  3559. (tool-bar-local-item-from-menu 'Info-history-back "left-arrow" map Info-mode-map
  3560. :rtl "right-arrow"
  3561. :label "Back"
  3562. :vert-only t)
  3563. (tool-bar-local-item-from-menu 'Info-history-forward "right-arrow" map Info-mode-map
  3564. :rtl "left-arrow"
  3565. :label "Forward"
  3566. :vert-only t)
  3567. (define-key-after map [separator-1] menu-bar-separator)
  3568. (tool-bar-local-item-from-menu 'Info-prev "prev-node" map Info-mode-map
  3569. :rtl "next-node")
  3570. (tool-bar-local-item-from-menu 'Info-next "next-node" map Info-mode-map
  3571. :rtl "prev-node")
  3572. (tool-bar-local-item-from-menu 'Info-up "up-node" map Info-mode-map
  3573. :vert-only t)
  3574. (define-key-after map [separator-2] menu-bar-separator)
  3575. (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map
  3576. :vert-only t)
  3577. (tool-bar-local-item-from-menu 'Info-goto-node "jump-to" map Info-mode-map)
  3578. (define-key-after map [separator-3] menu-bar-separator)
  3579. (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map
  3580. :label "Index")
  3581. (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map
  3582. :vert-only t)
  3583. (tool-bar-local-item-from-menu 'Info-exit "exit" map Info-mode-map
  3584. :vert-only t)
  3585. map))
  3586. (defvar Info-menu-last-node nil)
  3587. ;; Last node the menu was created for.
  3588. ;; Value is a list, (FILE-NAME NODE-NAME).
  3589. (defun Info-menu-update ()
  3590. "Update the Info menu for the current node."
  3591. (condition-case nil
  3592. (if (or (not (eq major-mode 'Info-mode))
  3593. (equal (list Info-current-file Info-current-node)
  3594. Info-menu-last-node))
  3595. ()
  3596. ;; Update menu menu.
  3597. (let* ((Info-complete-menu-buffer (current-buffer))
  3598. (items (nreverse (condition-case nil
  3599. (Info-complete-menu-item "" nil t)
  3600. (error nil))))
  3601. entries current
  3602. (number 0))
  3603. (while (and items (< number 9))
  3604. (setq current (car items)
  3605. items (cdr items)
  3606. number (1+ number))
  3607. (setq entries (cons `[,current
  3608. (Info-menu ,current)
  3609. :keys ,(format "%d" number)]
  3610. entries)))
  3611. (if items
  3612. (setq entries (cons ["Other..." Info-menu t] entries)))
  3613. (or entries
  3614. (setq entries (list ["No menu" nil nil] nil :active)))
  3615. (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
  3616. ;; Update reference menu. Code stolen from `Info-follow-reference'.
  3617. (let ((items nil)
  3618. str i entries current
  3619. (number 0)
  3620. (case-fold-search t))
  3621. (save-excursion
  3622. (goto-char (point-min))
  3623. (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
  3624. (setq str (match-string 1))
  3625. (setq i 0)
  3626. (while (setq i (string-match "[ \n\t]+" str i))
  3627. (setq str (concat (substring str 0 i) " "
  3628. (substring str (match-end 0))))
  3629. (setq i (1+ i)))
  3630. (setq items
  3631. (cons str items))))
  3632. (while (and items (< number 9))
  3633. (setq current (car items)
  3634. items (cdr items)
  3635. number (1+ number))
  3636. (setq entries (cons `[,current
  3637. (Info-follow-reference ,current)
  3638. t]
  3639. entries)))
  3640. (if items
  3641. (setq entries (cons ["Other..." Info-follow-reference t]
  3642. entries)))
  3643. (or entries
  3644. (setq entries (list ["No references" nil nil] nil :active)))
  3645. (easy-menu-change '("Info") "Reference" (nreverse entries)))
  3646. ;; Update last seen node.
  3647. (setq Info-menu-last-node (list Info-current-file Info-current-node)))
  3648. ;; Try to avoid entering infinite beep mode in case of errors.
  3649. (error (ding))))
  3650. (defun Info-copy-current-node-name (&optional arg)
  3651. "Put the name of the current Info node into the kill ring.
  3652. The name of the Info file is prepended to the node name in parentheses.
  3653. With a zero prefix arg, put the name inside a function call to `info'."
  3654. (interactive "P")
  3655. (unless Info-current-node
  3656. (user-error "No current Info node"))
  3657. (let ((node (if (stringp Info-current-file)
  3658. (concat "(" (file-name-nondirectory Info-current-file) ") "
  3659. Info-current-node))))
  3660. (if (zerop (prefix-numeric-value arg))
  3661. (setq node (concat "(info \"" node "\")")))
  3662. (unless (stringp Info-current-file)
  3663. (setq node (format "(Info-find-node '%S '%S)"
  3664. Info-current-file Info-current-node)))
  3665. (kill-new node)
  3666. (message "%s" node)))
  3667. ;; Info mode is suitable only for specially formatted data.
  3668. (put 'Info-mode 'mode-class 'special)
  3669. (put 'Info-mode 'no-clone-indirect t)
  3670. (defvar tool-bar-map)
  3671. (defvar bookmark-make-record-function)
  3672. (defvar Info-mode-syntax-table
  3673. (let ((st (copy-syntax-table text-mode-syntax-table)))
  3674. ;; Use punctuation syntax for apostrophe because of
  3675. ;; extensive use of quotes like `this' in Info manuals.
  3676. (modify-syntax-entry ?' "." st)
  3677. st)
  3678. "Syntax table used in `Info-mode'.")
  3679. ;; Autoload cookie needed by desktop.el
  3680. ;;;###autoload
  3681. (define-derived-mode Info-mode nil "Info"
  3682. "Info mode provides commands for browsing through the Info documentation tree.
  3683. Documentation in Info is divided into \"nodes\", each of which discusses
  3684. one topic and contains references to other nodes which discuss related
  3685. topics. Info has commands to follow the references and show you other nodes.
  3686. \\<Info-mode-map>\
  3687. \\[Info-help] Invoke the Info tutorial.
  3688. \\[Info-exit] Quit Info: reselect previously selected buffer.
  3689. Selecting other nodes:
  3690. \\[Info-mouse-follow-nearest-node]
  3691. Follow a node reference you click on.
  3692. This works with menu items, cross references, and
  3693. the \"next\", \"previous\" and \"up\", depending on where you click.
  3694. \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
  3695. \\[Info-next] Move to the \"next\" node of this node.
  3696. \\[Info-prev] Move to the \"previous\" node of this node.
  3697. \\[Info-up] Move \"up\" from this node.
  3698. \\[Info-menu] Pick menu item specified by name (or abbreviation).
  3699. Picking a menu item causes another node to be selected.
  3700. \\[Info-directory] Go to the Info directory node.
  3701. \\[Info-top-node] Go to the Top node of this file.
  3702. \\[Info-final-node] Go to the final node in this file.
  3703. \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
  3704. \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
  3705. \\[Info-next-reference] Move cursor to next cross-reference or menu item.
  3706. \\[Info-prev-reference] Move cursor to previous cross-reference or menu item.
  3707. \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
  3708. \\[Info-history-back] Move back in history to the last node you were at.
  3709. \\[Info-history-forward] Move forward in history to the node you returned from after using \\[Info-history-back].
  3710. \\[Info-history] Go to menu of visited nodes.
  3711. \\[Info-toc] Go to table of contents of the current Info file.
  3712. Moving within a node:
  3713. \\[Info-scroll-up] Normally, scroll forward a full screen.
  3714. Once you scroll far enough in a node that its menu appears on the
  3715. screen but after point, the next scroll moves into its first
  3716. subnode. When after all menu items (or if there is no menu),
  3717. move up to the parent node.
  3718. \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
  3719. already visible, try to go to the previous menu entry, or up
  3720. if there is none.
  3721. \\[beginning-of-buffer] Go to beginning of node.
  3722. Advanced commands:
  3723. \\[Info-search] Search through this Info file for specified regexp,
  3724. and select the node in which the next occurrence is found.
  3725. \\[Info-search-case-sensitively] Search through this Info file for specified regexp case-sensitively.
  3726. \\[isearch-forward], \\[isearch-forward-regexp] Use Isearch to search through multiple Info nodes.
  3727. \\[Info-index] Search for a topic in this manual's Index and go to index entry.
  3728. \\[Info-index-next] (comma) Move to the next match from a previous \\<Info-mode-map>\\[Info-index] command.
  3729. \\[Info-virtual-index] Look for a string and display the index node with results.
  3730. \\[info-apropos] Look for a string in the indices of all manuals.
  3731. \\[Info-goto-node] Move to node specified by name.
  3732. You may include a filename as well, as (FILENAME)NODENAME.
  3733. 1 .. 9 Pick first ... ninth item in node's menu.
  3734. Every third `*' is highlighted to help pick the right number.
  3735. \\[Info-copy-current-node-name] Put name of current Info node in the kill ring.
  3736. \\[clone-buffer] Select a new cloned Info buffer in another window.
  3737. \\[universal-argument] \\[info] Move to new Info file with completion.
  3738. \\[universal-argument] N \\[info] Select Info buffer with prefix number in the name *info*<N>."
  3739. :syntax-table Info-mode-syntax-table
  3740. :abbrev-table text-mode-abbrev-table
  3741. (setq tab-width 8)
  3742. (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
  3743. (setq case-fold-search t)
  3744. (setq buffer-read-only t)
  3745. (make-local-variable 'Info-current-file)
  3746. (make-local-variable 'Info-current-subfile)
  3747. (make-local-variable 'Info-current-node)
  3748. (set (make-local-variable 'Info-tag-table-marker) (make-marker))
  3749. (set (make-local-variable 'Info-tag-table-buffer) nil)
  3750. (make-local-variable 'Info-history)
  3751. (make-local-variable 'Info-history-forward)
  3752. (make-local-variable 'Info-index-alternatives)
  3753. (if Info-use-header-line ; do not override global header lines
  3754. (setq header-line-format
  3755. '(:eval (get-text-property (point-min) 'header-line))))
  3756. (set (make-local-variable 'tool-bar-map) info-tool-bar-map)
  3757. ;; This is for the sake of the invisible text we use handling titles.
  3758. (set (make-local-variable 'line-move-ignore-invisible) t)
  3759. (set (make-local-variable 'desktop-save-buffer)
  3760. 'Info-desktop-buffer-misc-data)
  3761. (set (make-local-variable 'widen-automatically) nil)
  3762. (add-hook 'kill-buffer-hook 'Info-kill-buffer nil t)
  3763. (add-hook 'clone-buffer-hook 'Info-clone-buffer nil t)
  3764. (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
  3765. (add-hook 'isearch-mode-hook 'Info-isearch-start nil t)
  3766. (set (make-local-variable 'isearch-search-fun-function)
  3767. 'Info-isearch-search)
  3768. (set (make-local-variable 'isearch-wrap-function)
  3769. 'Info-isearch-wrap)
  3770. (set (make-local-variable 'isearch-push-state-function)
  3771. 'Info-isearch-push-state)
  3772. (set (make-local-variable 'isearch-filter-predicate)
  3773. 'Info-isearch-filter)
  3774. (set (make-local-variable 'search-whitespace-regexp)
  3775. Info-search-whitespace-regexp)
  3776. (set (make-local-variable 'revert-buffer-function)
  3777. 'Info-revert-buffer-function)
  3778. (Info-set-mode-line)
  3779. (set (make-local-variable 'bookmark-make-record-function)
  3780. 'Info-bookmark-make-record))
  3781. ;; When an Info buffer is killed, make sure the associated tags buffer
  3782. ;; is killed too.
  3783. (defun Info-kill-buffer ()
  3784. (and (eq major-mode 'Info-mode)
  3785. Info-tag-table-buffer
  3786. (kill-buffer Info-tag-table-buffer)))
  3787. ;; Placed on `clone-buffer-hook'.
  3788. (defun Info-clone-buffer ()
  3789. (when (bufferp Info-tag-table-buffer)
  3790. (setq Info-tag-table-buffer
  3791. (with-current-buffer Info-tag-table-buffer (clone-buffer))))
  3792. (let ((m Info-tag-table-marker))
  3793. (when (markerp m)
  3794. (setq Info-tag-table-marker
  3795. (if (and (marker-position m) (bufferp Info-tag-table-buffer))
  3796. (with-current-buffer Info-tag-table-buffer
  3797. (copy-marker (marker-position m)))
  3798. (make-marker))))))
  3799. (defvar Info-edit-map (let ((map (make-sparse-keymap)))
  3800. (set-keymap-parent map text-mode-map)
  3801. (define-key map "\C-c\C-c" 'Info-cease-edit)
  3802. map)
  3803. "Local keymap used within `e' command of Info.")
  3804. ;; Info-edit mode is suitable only for specially formatted data.
  3805. (put 'Info-edit-mode 'mode-class 'special)
  3806. (defun Info-edit-mode ()
  3807. "Major mode for editing the contents of an Info node.
  3808. Like text mode with the addition of `Info-cease-edit'
  3809. which returns to Info mode for browsing.
  3810. \\{Info-edit-map}"
  3811. (use-local-map Info-edit-map)
  3812. (setq major-mode 'Info-edit-mode)
  3813. (setq mode-name "Info Edit")
  3814. (kill-local-variable 'mode-line-buffer-identification)
  3815. (setq buffer-read-only nil)
  3816. (force-mode-line-update)
  3817. (buffer-enable-undo (current-buffer))
  3818. (run-mode-hooks 'Info-edit-mode-hook))
  3819. (defun Info-edit ()
  3820. "Edit the contents of this Info node.
  3821. Allowed only if variable `Info-enable-edit' is non-nil."
  3822. (interactive)
  3823. (or Info-enable-edit
  3824. (error "Editing Info nodes is not enabled"))
  3825. (Info-edit-mode)
  3826. (message "%s" (substitute-command-keys
  3827. "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
  3828. (defun Info-cease-edit ()
  3829. "Finish editing Info node; switch back to Info proper."
  3830. (interactive)
  3831. ;; Do this first, so nothing has changed if user C-g's at query.
  3832. (and (buffer-modified-p)
  3833. (y-or-n-p "Save the file? ")
  3834. (save-buffer))
  3835. (use-local-map Info-mode-map)
  3836. (setq major-mode 'Info-mode)
  3837. (setq mode-name "Info")
  3838. (Info-set-mode-line)
  3839. (setq buffer-read-only t)
  3840. (force-mode-line-update)
  3841. (and (marker-position Info-tag-table-marker)
  3842. (buffer-modified-p)
  3843. (message "Tags may have changed. Use Info-tagify if necessary")))
  3844. (defvar Info-file-list-for-emacs
  3845. '("ediff" "eudc" "forms" "gnus" "info" ("Info" . "info") ("mh" . "mh-e")
  3846. "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
  3847. ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
  3848. ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
  3849. ("skeleton" . "autotype") ("auto-insert" . "autotype")
  3850. ("copyright" . "autotype") ("executable" . "autotype")
  3851. ("time-stamp" . "autotype") ("quickurl" . "autotype")
  3852. ("tempo" . "autotype") ("hippie-expand" . "autotype")
  3853. ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
  3854. ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
  3855. "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
  3856. ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
  3857. ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
  3858. ("rfc2045" . "emacs-mime")
  3859. ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
  3860. ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
  3861. ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
  3862. ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
  3863. ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
  3864. ("mml" . "emacs-mime"))
  3865. "List of Info files that describe Emacs commands.
  3866. An element can be a file name, or a list of the form (PREFIX . FILE)
  3867. where PREFIX is a name prefix and FILE is the file to look in.
  3868. If the element is just a file name, the file name also serves as the prefix.")
  3869. (defun Info-find-emacs-command-nodes (command)
  3870. "Return a list of locations documenting COMMAND.
  3871. The `info-file' property of COMMAND says which Info manual to search.
  3872. If COMMAND has no property, the variable `Info-file-list-for-emacs'
  3873. defines heuristics for which Info manual to try.
  3874. The locations are of the format used in `Info-history', i.e.
  3875. \(FILENAME NODENAME BUFFERPOS), where BUFFERPOS is the line number
  3876. in the first element of the returned list (which is treated specially in
  3877. `Info-goto-emacs-command-node'), and 0 for the rest elements of a list."
  3878. (let ((where '()) line-number
  3879. (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
  3880. "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\."
  3881. "\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"))
  3882. (info-file "emacs")) ;default
  3883. ;; Determine which Info file this command is documented in.
  3884. (if (get command 'info-file)
  3885. (setq info-file (get command 'info-file))
  3886. ;; If it doesn't say explicitly, test its name against
  3887. ;; various prefixes that we know.
  3888. (let ((file-list Info-file-list-for-emacs))
  3889. (while file-list
  3890. (let* ((elt (car file-list))
  3891. (name (if (consp elt)
  3892. (car elt)
  3893. elt))
  3894. (file (if (consp elt) (cdr elt) elt))
  3895. (case-fold-search nil)
  3896. (regexp (concat "\\`" (regexp-quote name)
  3897. "\\(\\'\\|-\\)")))
  3898. (if (string-match regexp (symbol-name command))
  3899. (setq info-file file file-list nil))
  3900. (setq file-list (cdr file-list))))))
  3901. (Info-find-node info-file "Top")
  3902. ;; Bind Info-history to nil, to prevent the index nodes from
  3903. ;; getting into the node history.
  3904. (let ((Info-history nil)
  3905. (Info-history-list nil)
  3906. node (nodes (Info-index-nodes)))
  3907. (Info-goto-node (car nodes))
  3908. (while
  3909. (progn
  3910. (goto-char (point-min))
  3911. (while (re-search-forward cmd-desc nil t)
  3912. (setq where
  3913. (cons (list Info-current-file
  3914. (match-string-no-properties 2)
  3915. 0)
  3916. where))
  3917. (setq line-number (and (match-beginning 3)
  3918. (string-to-number (match-string 3)))))
  3919. (and (setq nodes (cdr nodes) node (car nodes))))
  3920. (Info-goto-node node)))
  3921. (if (and line-number where)
  3922. (cons (list (nth 0 (car where)) (nth 1 (car where)) line-number)
  3923. (cdr where))
  3924. where)))
  3925. ;;;###autoload (put 'Info-goto-emacs-command-node 'info-file (purecopy "emacs"))
  3926. ;;;###autoload
  3927. (defun Info-goto-emacs-command-node (command)
  3928. "Go to the Info node in the Emacs manual for command COMMAND.
  3929. The command is found by looking up in Emacs manual's indices
  3930. or in another manual found via COMMAND's `info-file' property or
  3931. the variable `Info-file-list-for-emacs'.
  3932. COMMAND must be a symbol or string."
  3933. (interactive "CFind documentation for command: ")
  3934. ;; If command is given as a string, convert it to a symbol.
  3935. (if (stringp command)
  3936. (setq command (intern command)))
  3937. (or (commandp command)
  3938. (signal 'wrong-type-argument (list 'commandp command)))
  3939. (let ((where (Info-find-emacs-command-nodes command)))
  3940. (if where
  3941. (let ((num-matches (length where)))
  3942. ;; Get Info running, and pop to it in another window.
  3943. (save-window-excursion
  3944. (info))
  3945. (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
  3946. ;; Bind Info-history to nil, to prevent the last Index node
  3947. ;; visited by Info-find-emacs-command-nodes from being
  3948. ;; pushed onto the history.
  3949. (let ((Info-history nil) (Info-history-list nil)
  3950. (line-number (nth 2 (car where))))
  3951. (Info-find-node (nth 0 (car where)) (nth 1 (car where)))
  3952. (if (and (integerp line-number) (> line-number 0))
  3953. (forward-line (1- line-number))))
  3954. (if (> num-matches 1)
  3955. (progn
  3956. ;; (car where) will be pushed onto Info-history
  3957. ;; when/if they go to another node. Put the other
  3958. ;; nodes that were found on the history.
  3959. (setq Info-history (nconc (cdr where) Info-history))
  3960. (message "Found %d other entr%s. Use %s to see %s."
  3961. (1- num-matches)
  3962. (if (> num-matches 2) "ies" "y")
  3963. (substitute-command-keys "\\[Info-history-back]")
  3964. (if (> num-matches 2) "them" "it")))))
  3965. (error "Couldn't find documentation for %s" command))))
  3966. ;;;###autoload (put 'Info-goto-emacs-key-command-node 'info-file (purecopy "emacs"))
  3967. ;;;###autoload
  3968. (defun Info-goto-emacs-key-command-node (key)
  3969. "Go to the node in the Emacs manual which describes the command bound to KEY.
  3970. KEY is a string.
  3971. Interactively, if the binding is `execute-extended-command', a command is read.
  3972. The command is found by looking up in Emacs manual's indices
  3973. or in another manual found via COMMAND's `info-file' property or
  3974. the variable `Info-file-list-for-emacs'."
  3975. (interactive "kFind documentation for key: ")
  3976. (let ((command (key-binding key)))
  3977. (cond ((null command)
  3978. (message "%s is undefined" (key-description key)))
  3979. ((and (called-interactively-p 'interactive)
  3980. (eq command 'execute-extended-command))
  3981. (Info-goto-emacs-command-node
  3982. (read-command "Find documentation for command: ")))
  3983. (t
  3984. (Info-goto-emacs-command-node command)))))
  3985. (defvar Info-next-link-keymap
  3986. (let ((keymap (make-sparse-keymap)))
  3987. (define-key keymap [header-line mouse-1] 'Info-next)
  3988. (define-key keymap [header-line mouse-2] 'Info-next)
  3989. (define-key keymap [header-line down-mouse-1] 'ignore)
  3990. (define-key keymap [mouse-2] 'Info-next)
  3991. (define-key keymap [follow-link] 'mouse-face)
  3992. keymap)
  3993. "Keymap to put on the Next link in the text or the header line.")
  3994. (defvar Info-prev-link-keymap
  3995. (let ((keymap (make-sparse-keymap)))
  3996. (define-key keymap [header-line mouse-1] 'Info-prev)
  3997. (define-key keymap [header-line mouse-2] 'Info-prev)
  3998. (define-key keymap [header-line down-mouse-1] 'ignore)
  3999. (define-key keymap [mouse-2] 'Info-prev)
  4000. (define-key keymap [follow-link] 'mouse-face)
  4001. keymap)
  4002. "Keymap to put on the Prev link in the text or the header line.")
  4003. (defvar Info-up-link-keymap
  4004. (let ((keymap (make-sparse-keymap)))
  4005. (define-key keymap [header-line mouse-1] 'Info-up)
  4006. (define-key keymap [header-line mouse-2] 'Info-up)
  4007. (define-key keymap [header-line down-mouse-1] 'ignore)
  4008. (define-key keymap [mouse-2] 'Info-up)
  4009. (define-key keymap [follow-link] 'mouse-face)
  4010. keymap)
  4011. "Keymap to put on the Up link in the text or the header line.")
  4012. (defvar Info-link-keymap
  4013. (let ((keymap (make-sparse-keymap)))
  4014. (define-key keymap [header-line mouse-1] 'Info-mouse-follow-link)
  4015. (define-key keymap [header-line mouse-2] 'Info-mouse-follow-link)
  4016. (define-key keymap [header-line down-mouse-1] 'ignore)
  4017. (define-key keymap [mouse-2] 'Info-mouse-follow-link)
  4018. (define-key keymap [follow-link] 'mouse-face)
  4019. keymap)
  4020. "Keymap to put on the link in the text or the header line.")
  4021. (defun Info-breadcrumbs ()
  4022. (let ((nodes (Info-toc-nodes Info-current-file))
  4023. (node Info-current-node)
  4024. (crumbs ())
  4025. (depth Info-breadcrumbs-depth)
  4026. line)
  4027. ;; Get ancestors from the cached parent-children node info
  4028. (while (and (not (equal "Top" node)) (> depth 0))
  4029. (setq node (nth 1 (assoc node nodes)))
  4030. (if node (push node crumbs))
  4031. (setq depth (1- depth)))
  4032. ;; Add bottom node.
  4033. (when Info-use-header-line
  4034. ;; Let it disappear if crumbs is nil.
  4035. (nconc crumbs (list Info-current-node)))
  4036. (when (or Info-use-header-line crumbs)
  4037. ;; Add top node (and continuation if needed).
  4038. (setq crumbs
  4039. (cons "Top" (if (member (pop crumbs) '(nil "Top"))
  4040. crumbs (cons nil crumbs))))
  4041. ;; Eliminate duplicate.
  4042. (forward-line 1)
  4043. (dolist (node crumbs)
  4044. (let ((text
  4045. (if (not (equal node "Top")) node
  4046. (format "(%s)Top"
  4047. (if (stringp Info-current-file)
  4048. (file-name-nondirectory Info-current-file)
  4049. ;; Some legacy code can still use a symbol.
  4050. Info-current-file)))))
  4051. (setq line (concat
  4052. line
  4053. (if (null line) "" " > ")
  4054. (cond
  4055. ((null node) "...")
  4056. ((equal node Info-current-node)
  4057. ;; No point linking to ourselves.
  4058. (propertize text 'font-lock-face 'info-header-node))
  4059. (t
  4060. (propertize text
  4061. 'mouse-face 'highlight
  4062. 'font-lock-face 'info-header-xref
  4063. 'help-echo "mouse-2: Go to node"
  4064. 'keymap Info-link-keymap
  4065. 'link-args text)))))))
  4066. (setq line (concat line "\n")))
  4067. ;; (font-lock-append-text-property 0 (length line)
  4068. ;; 'font-lock-face 'header-line line)
  4069. line))
  4070. (defun Info-fontify-node ()
  4071. "Fontify the node."
  4072. (save-excursion
  4073. (let* ((inhibit-read-only t)
  4074. (case-fold-search t)
  4075. paragraph-markers
  4076. (not-fontified-p ; the node hasn't already been fontified
  4077. (not (let ((where (next-single-property-change (point-min)
  4078. 'font-lock-face)))
  4079. (and where (not (= where (point-max)))))))
  4080. (fontify-visited-p ; visited nodes need to be re-fontified
  4081. (and Info-fontify-visited-nodes
  4082. ;; Don't take time to refontify visited nodes in huge nodes
  4083. Info-fontify-maximum-menu-size
  4084. (< (- (point-max) (point-min)) Info-fontify-maximum-menu-size)))
  4085. rbeg rend)
  4086. ;; Fontify header line
  4087. (goto-char (point-min))
  4088. (when (and not-fontified-p (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?"))
  4089. (goto-char (match-end 0))
  4090. (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
  4091. (goto-char (match-end 0))
  4092. (let* ((nbeg (match-beginning 2))
  4093. (nend (match-end 2))
  4094. (tbeg (match-beginning 1))
  4095. (tag (match-string 1)))
  4096. (if (string-equal (downcase tag) "node")
  4097. (put-text-property nbeg nend 'font-lock-face 'info-header-node)
  4098. (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
  4099. (put-text-property tbeg nend 'mouse-face 'highlight)
  4100. (put-text-property tbeg nend
  4101. 'help-echo
  4102. (concat "mouse-2: Go to node "
  4103. (buffer-substring nbeg nend)))
  4104. ;; Always set up the text property keymap.
  4105. ;; It will either be used in the buffer
  4106. ;; or copied in the header line.
  4107. (put-text-property
  4108. tbeg nend 'keymap
  4109. (cond
  4110. ((string-equal (downcase tag) "prev") Info-prev-link-keymap)
  4111. ((string-equal (downcase tag) "next") Info-next-link-keymap)
  4112. ((string-equal (downcase tag) "up" ) Info-up-link-keymap))))))
  4113. ;; (when (> Info-breadcrumbs-depth 0)
  4114. ;; (insert (Info-breadcrumbs)))
  4115. ;; Treat header line.
  4116. (when Info-use-header-line
  4117. (goto-char (point-min))
  4118. (let* ((header-end (line-end-position))
  4119. (header
  4120. ;; If we find neither Next: nor Prev: link, show the entire
  4121. ;; node header. Otherwise, don't show the File: and Node:
  4122. ;; parts, to avoid wasting precious space on information that
  4123. ;; is available in the mode line.
  4124. (if (re-search-forward
  4125. "\\(next\\|up\\|prev[ious]*\\): "
  4126. header-end t)
  4127. (progn
  4128. (goto-char (match-beginning 1))
  4129. (buffer-substring (point) header-end))
  4130. (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*"
  4131. header-end t)
  4132. (concat "No next, prev or up links -- "
  4133. (buffer-substring (point) header-end))
  4134. (buffer-substring (point) header-end)))))
  4135. (put-text-property (point-min) (1+ (point-min))
  4136. 'header-line
  4137. (replace-regexp-in-string
  4138. "%"
  4139. ;; Preserve text properties on duplicated `%'.
  4140. (lambda (s) (concat s s)) header))
  4141. ;; Hide the part of the first line
  4142. ;; that is in the header, if it is just part.
  4143. (cond
  4144. ((> Info-breadcrumbs-depth 0)
  4145. (let ((ov (make-overlay (point-min) (1+ header-end))))
  4146. (overlay-put ov 'display (Info-breadcrumbs))
  4147. (overlay-put ov 'evaporate t)))
  4148. ((not (bobp))
  4149. ;; Hide the punctuation at the end, too.
  4150. (skip-chars-backward " \t,")
  4151. (put-text-property (point) header-end 'invisible t))))))
  4152. ;; Fontify titles
  4153. (goto-char (point-min))
  4154. (when (and font-lock-mode not-fontified-p)
  4155. (while (and (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*\\*+\\|==+\\|--+\\|\\.\\.+\\)$"
  4156. nil t)
  4157. ;; Only consider it as an underlined title if the ASCII
  4158. ;; underline has the same size as the text. A typical
  4159. ;; counter example is when a continuation "..." is alone
  4160. ;; on a line.
  4161. (= (string-width (match-string 1))
  4162. (string-width (match-string 2))))
  4163. (let* ((c (preceding-char))
  4164. (face
  4165. (cond ((= c ?*) 'info-title-1)
  4166. ((= c ?=) 'info-title-2)
  4167. ((= c ?-) 'info-title-3)
  4168. (t 'info-title-4))))
  4169. (put-text-property (match-beginning 1) (match-end 1)
  4170. 'font-lock-face face))
  4171. ;; This is a serious problem for trying to handle multiple
  4172. ;; frame types at once. We want this text to be invisible
  4173. ;; on frames that can display the font above.
  4174. (when (memq (framep (selected-frame)) '(x pc w32 ns))
  4175. (add-text-properties (1- (match-beginning 2)) (match-end 2)
  4176. '(invisible t front-sticky nil rear-nonsticky t)))))
  4177. ;; Fontify cross references
  4178. (goto-char (point-min))
  4179. (when (or not-fontified-p fontify-visited-p)
  4180. (while (re-search-forward "\\(\\*Note[ \n\t]+\\)\\([^:]*\\)\\(:[ \t]*\\([^.,:(]*\\)\\(\\(([^)]*)\\)[^.,:]*\\)?[,:]?\n?\\)" nil t)
  4181. (let ((start (match-beginning 0))
  4182. (next (point))
  4183. other-tag)
  4184. (when not-fontified-p
  4185. (when Info-hide-note-references
  4186. (when (and (not (eq Info-hide-note-references 'hide))
  4187. (> (line-number-at-pos) 4)) ; Skip breadcrumbs
  4188. ;; *Note is often used where *note should have been
  4189. (goto-char start)
  4190. (skip-syntax-backward " ")
  4191. (when (memq (char-before) '(?\( ?\[ ?\{))
  4192. ;; Check whether the paren is preceded by
  4193. ;; an end of sentence
  4194. (skip-syntax-backward " ("))
  4195. (setq other-tag
  4196. (cond ((save-match-data (looking-back "\\<see"))
  4197. "")
  4198. ((save-match-data (looking-back "\\<in"))
  4199. "")
  4200. ((memq (char-before) '(nil ?\. ?! ??))
  4201. "See ")
  4202. ((save-match-data
  4203. (save-excursion
  4204. (search-forward "\n\n" start t)))
  4205. "See ")
  4206. (t "see "))))
  4207. (goto-char next)
  4208. (add-text-properties
  4209. (match-beginning 1)
  4210. (or (save-match-data
  4211. ;; Don't hide \n after *Note
  4212. (let ((start1 (match-beginning 1)))
  4213. (if (string-match "\n" (match-string 1))
  4214. (+ start1 (match-beginning 0)))))
  4215. (match-end 1))
  4216. (if other-tag
  4217. `(display ,other-tag front-sticky nil rear-nonsticky t)
  4218. '(invisible t front-sticky nil rear-nonsticky t))))
  4219. (add-text-properties
  4220. (match-beginning 2) (match-end 2)
  4221. (list
  4222. 'help-echo (if (or (match-end 5)
  4223. (not (equal (match-string 4) "")))
  4224. (concat "mouse-2: go to " (or (match-string 5)
  4225. (match-string 4)))
  4226. "mouse-2: go to this node")
  4227. 'mouse-face 'highlight)))
  4228. (when (or not-fontified-p fontify-visited-p)
  4229. (setq rbeg (match-beginning 2)
  4230. rend (match-end 2))
  4231. (put-text-property
  4232. rbeg rend
  4233. 'font-lock-face
  4234. ;; Display visited nodes in a different face
  4235. (if (and Info-fontify-visited-nodes
  4236. (save-match-data
  4237. (let* ((node (replace-regexp-in-string
  4238. "^[ \t]+" ""
  4239. (replace-regexp-in-string
  4240. "[ \t\n]+" " "
  4241. (or (match-string-no-properties 5)
  4242. (and (not (equal (match-string 4) ""))
  4243. (match-string-no-properties 4))
  4244. (match-string-no-properties 2)))))
  4245. (external-link-p
  4246. (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
  4247. (file (if external-link-p
  4248. (file-name-nondirectory
  4249. (match-string-no-properties 1 node))
  4250. Info-current-file))
  4251. (hl Info-history-list)
  4252. res)
  4253. (if external-link-p
  4254. (setq node (if (equal (match-string 2 node) "")
  4255. "Top"
  4256. (match-string-no-properties 2 node))))
  4257. (while hl
  4258. (if (and (string-equal node (nth 1 (car hl)))
  4259. (equal file
  4260. (if (and external-link-p
  4261. (stringp (caar hl)))
  4262. (file-name-nondirectory
  4263. (caar hl))
  4264. (caar hl))))
  4265. (setq res (car hl) hl nil)
  4266. (setq hl (cdr hl))))
  4267. res))) 'info-xref-visited 'info-xref))
  4268. ;; For multiline ref, unfontify newline and surrounding whitespace
  4269. (save-excursion
  4270. (goto-char rbeg)
  4271. (save-match-data
  4272. (while (re-search-forward "\\s-*\n\\s-*" rend t nil)
  4273. (remove-text-properties (match-beginning 0)
  4274. (match-end 0)
  4275. '(font-lock-face t))))))
  4276. (when not-fontified-p
  4277. (when (memq Info-hide-note-references '(t hide))
  4278. (add-text-properties (match-beginning 3) (match-end 3)
  4279. '(invisible t front-sticky nil rear-nonsticky t))
  4280. ;; Unhide the file name of the external reference in parens
  4281. (if (and (match-string 6) (not (eq Info-hide-note-references 'hide)))
  4282. (remove-text-properties (match-beginning 6) (match-end 6)
  4283. '(invisible t front-sticky nil rear-nonsticky t)))
  4284. ;; Unhide newline because hidden newlines cause too long lines
  4285. (save-match-data
  4286. (let ((beg3 (match-beginning 3))
  4287. (end3 (match-end 3)))
  4288. (if (and (string-match "\n[ \t]*" (match-string 3))
  4289. (not (save-match-data
  4290. (save-excursion
  4291. (goto-char (1+ end3))
  4292. (looking-at "[.)]*$")))))
  4293. (remove-text-properties (+ beg3 (match-beginning 0))
  4294. (+ beg3 (match-end 0))
  4295. '(invisible t front-sticky nil rear-nonsticky t))))))
  4296. (when (and Info-refill-paragraphs Info-hide-note-references)
  4297. (push (set-marker (make-marker) start)
  4298. paragraph-markers))))))
  4299. ;; Refill paragraphs (experimental feature)
  4300. (when (and not-fontified-p
  4301. Info-refill-paragraphs
  4302. paragraph-markers)
  4303. (let ((fill-nobreak-invisible t)
  4304. (fill-individual-varying-indent nil)
  4305. (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
  4306. (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
  4307. (adaptive-fill-mode nil))
  4308. (goto-char (point-max))
  4309. (dolist (m paragraph-markers)
  4310. (when (< m (point))
  4311. (goto-char m)
  4312. (beginning-of-line)
  4313. (let ((beg (point)))
  4314. (when (zerop (forward-paragraph))
  4315. (fill-individual-paragraphs beg (point) nil nil)
  4316. (goto-char beg))))
  4317. (set-marker m nil))))
  4318. ;; Fontify menu items
  4319. (goto-char (point-min))
  4320. (when (and (or not-fontified-p fontify-visited-p)
  4321. (search-forward "\n* Menu:" nil t)
  4322. ;; Don't take time to annotate huge menus
  4323. Info-fontify-maximum-menu-size
  4324. (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
  4325. (let ((n 0)
  4326. cont)
  4327. (while (re-search-forward
  4328. (concat "^\\* Menu:\\|\\(?:^\\* +\\(" Info-menu-entry-name-re "\\)\\(:"
  4329. Info-node-spec-re "\\([ \t]*\\)\\)\\)")
  4330. nil t)
  4331. (when (match-beginning 1)
  4332. (when not-fontified-p
  4333. (setq n (1+ n))
  4334. (if (and (<= n 9) (zerop (% n 3))) ; visual aids to help with 1-9 keys
  4335. (put-text-property (match-beginning 0)
  4336. (1+ (match-beginning 0))
  4337. 'font-lock-face 'info-menu-star)))
  4338. (when not-fontified-p
  4339. (add-text-properties
  4340. (match-beginning 1) (match-end 1)
  4341. (list
  4342. 'help-echo (if (and (match-end 3)
  4343. (not (equal (match-string 3) "")))
  4344. (concat "mouse-2: go to " (match-string 3))
  4345. "mouse-2: go to this node")
  4346. 'mouse-face 'highlight)))
  4347. (when (or not-fontified-p fontify-visited-p)
  4348. (put-text-property
  4349. (match-beginning 1) (match-end 1)
  4350. 'font-lock-face
  4351. ;; Display visited menu items in a different face
  4352. (if (and Info-fontify-visited-nodes
  4353. (save-match-data
  4354. (let* ((node (if (equal (match-string 3) "")
  4355. (match-string-no-properties 1)
  4356. (match-string-no-properties 3)))
  4357. (external-link-p
  4358. (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
  4359. (file (if external-link-p
  4360. (file-name-nondirectory
  4361. (match-string-no-properties 1 node))
  4362. Info-current-file))
  4363. (hl Info-history-list)
  4364. res)
  4365. (if external-link-p
  4366. (setq node (if (equal (match-string 2 node) "")
  4367. "Top"
  4368. (match-string-no-properties 2 node))))
  4369. (while hl
  4370. (if (and (string-equal node (nth 1 (car hl)))
  4371. (equal file
  4372. (if (and external-link-p
  4373. (stringp (caar hl)))
  4374. (file-name-nondirectory
  4375. (caar hl))
  4376. (caar hl))))
  4377. (setq res (car hl) hl nil)
  4378. (setq hl (cdr hl))))
  4379. res))) 'info-xref-visited 'info-xref)))
  4380. (when (and not-fontified-p
  4381. (memq Info-hide-note-references '(t hide))
  4382. (not (Info-index-node)))
  4383. (put-text-property (match-beginning 2) (1- (match-end 6))
  4384. 'invisible t)
  4385. ;; Unhide the file name in parens
  4386. (if (and (match-end 4) (not (eq (char-after (match-end 4)) ?.)))
  4387. (remove-text-properties (match-beginning 4) (match-end 4)
  4388. '(invisible t)))
  4389. ;; We need a stretchable space like :align-to but with
  4390. ;; a minimum value.
  4391. (put-text-property (1- (match-end 6)) (match-end 6) 'display
  4392. (if (>= 22 (- (match-end 1)
  4393. (match-beginning 0)))
  4394. '(space :align-to 24)
  4395. '(space :width 2)))
  4396. (setq cont (looking-at "."))
  4397. (while (and (= (forward-line 1) 0)
  4398. (looking-at "\\([ \t]+\\)[^*\n]"))
  4399. (put-text-property (match-beginning 1) (1- (match-end 1))
  4400. 'invisible t)
  4401. (put-text-property (1- (match-end 1)) (match-end 1)
  4402. 'display
  4403. (if cont
  4404. '(space :align-to 26)
  4405. '(space :align-to 24)))
  4406. (setq cont t)))))))
  4407. ;; Fontify menu headers
  4408. ;; Add the face `info-menu-header' to any header before a menu entry
  4409. (goto-char (point-min))
  4410. (when (and not-fontified-p (re-search-forward "^\\* Menu:" nil t))
  4411. (put-text-property (match-beginning 0) (match-end 0)
  4412. 'font-lock-face 'info-menu-header)
  4413. (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
  4414. (put-text-property (match-beginning 1) (match-end 1)
  4415. 'font-lock-face 'info-menu-header)))
  4416. ;; Hide index line numbers
  4417. (goto-char (point-min))
  4418. (when (and not-fontified-p (Info-index-node))
  4419. (while (re-search-forward "[ \t\n]*(line +[0-9]+)" nil t)
  4420. (put-text-property (match-beginning 0) (match-end 0)
  4421. 'invisible t)))
  4422. ;; Fontify http and ftp references
  4423. (goto-char (point-min))
  4424. (when not-fontified-p
  4425. (while (re-search-forward "\\(https?\\|ftp\\)://[^ \t\n\"`({<>})']+"
  4426. nil t)
  4427. (add-text-properties (match-beginning 0) (match-end 0)
  4428. '(font-lock-face info-xref
  4429. mouse-face highlight
  4430. help-echo "mouse-2: go to this URL"))))
  4431. (set-buffer-modified-p nil))))
  4432. ;;; Speedbar support:
  4433. ;; These functions permit speedbar to display the "tags" in the
  4434. ;; current Info node.
  4435. (eval-when-compile (require 'speedbar))
  4436. (defvar Info-speedbar-key-map nil
  4437. "Keymap used when in the Info display mode.")
  4438. (defun Info-install-speedbar-variables ()
  4439. "Install those variables used by speedbar to enhance Info."
  4440. (if Info-speedbar-key-map
  4441. nil
  4442. (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
  4443. ;; Basic tree features
  4444. (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
  4445. (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
  4446. (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
  4447. (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
  4448. )
  4449. (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
  4450. Info-speedbar-key-map
  4451. Info-speedbar-hierarchy-buttons)))
  4452. (defvar Info-speedbar-menu-items
  4453. '(["Browse Node" speedbar-edit-line t]
  4454. ["Expand Node" speedbar-expand-line
  4455. (save-excursion (beginning-of-line)
  4456. (looking-at "[0-9]+: *.\\+. "))]
  4457. ["Contract Node" speedbar-contract-line
  4458. (save-excursion (beginning-of-line)
  4459. (looking-at "[0-9]+: *.-. "))]
  4460. )
  4461. "Additional menu-items to add to speedbar frame.")
  4462. ;; Make sure our special speedbar major mode is loaded
  4463. (if (featurep 'speedbar)
  4464. (Info-install-speedbar-variables)
  4465. (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
  4466. ;;; Info hierarchy display method
  4467. ;;;###autoload
  4468. (defun Info-speedbar-browser ()
  4469. "Initialize speedbar to display an Info node browser.
  4470. This will add a speedbar major display mode."
  4471. (interactive)
  4472. (require 'speedbar)
  4473. ;; Make sure that speedbar is active
  4474. (speedbar-frame-mode 1)
  4475. ;; Now, throw us into Info mode on speedbar.
  4476. (speedbar-change-initial-expansion-list "Info")
  4477. )
  4478. (defun Info-speedbar-hierarchy-buttons (_directory depth &optional node)
  4479. "Display an Info directory hierarchy in speedbar.
  4480. DIRECTORY is the current directory in the attached frame.
  4481. DEPTH is the current indentation depth.
  4482. NODE is an optional argument that is used to represent the
  4483. specific node to expand."
  4484. (if (and (not node)
  4485. (save-excursion (goto-char (point-min))
  4486. (let ((case-fold-search t))
  4487. (looking-at "Info Nodes:"))))
  4488. ;; Update our "current node" maybe?
  4489. nil
  4490. ;; We cannot use the generic list code, that depends on all leaves
  4491. ;; being known at creation time.
  4492. (if (not node)
  4493. (speedbar-with-writable (insert "Info Nodes:\n")))
  4494. (let ((completions nil))
  4495. (speedbar-select-attached-frame)
  4496. (save-window-excursion
  4497. (setq completions
  4498. (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
  4499. (select-frame (speedbar-current-frame))
  4500. (if completions
  4501. (speedbar-with-writable
  4502. (dolist (completion completions)
  4503. (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
  4504. (cdr completion)
  4505. (car completion)
  4506. 'Info-speedbar-goto-node
  4507. (cdr completion)
  4508. 'info-xref depth))
  4509. t)
  4510. nil))))
  4511. (defun Info-speedbar-goto-node (_text node _indent)
  4512. "When user clicks on TEXT, go to an info NODE.
  4513. The INDENT level is ignored."
  4514. (speedbar-select-attached-frame)
  4515. (let* ((buff (or (get-buffer "*info*")
  4516. (progn (info) (get-buffer "*info*"))))
  4517. (bwin (get-buffer-window buff 0)))
  4518. (if bwin
  4519. (progn
  4520. (select-window bwin)
  4521. (raise-frame (window-frame bwin)))
  4522. (if speedbar-power-click
  4523. (switch-to-buffer-other-frame buff)
  4524. (speedbar-select-attached-frame)
  4525. (switch-to-buffer buff)))
  4526. (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
  4527. (error "Invalid node %s" node)
  4528. (Info-find-node (match-string 1 node) (match-string 2 node))
  4529. ;; If we do a find-node, and we were in info mode, restore
  4530. ;; the old default method. Once we are in info mode, it makes
  4531. ;; sense to return to whatever method the user was using before.
  4532. (if (string= speedbar-initial-expansion-list-name "Info")
  4533. (speedbar-change-initial-expansion-list
  4534. speedbar-previously-used-expansion-list-name)))))
  4535. (defun Info-speedbar-expand-node (text token indent)
  4536. "Expand the node the user clicked on.
  4537. TEXT is the text of the button we clicked on, a + or - item.
  4538. TOKEN is data related to this node (NAME . FILE).
  4539. INDENT is the current indentation depth."
  4540. (cond ((string-match "+" text) ;we have to expand this file
  4541. (speedbar-change-expand-button-char ?-)
  4542. (if (speedbar-with-writable
  4543. (save-excursion
  4544. (end-of-line) (forward-char 1)
  4545. (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
  4546. (speedbar-change-expand-button-char ?-)
  4547. (speedbar-change-expand-button-char ??)))
  4548. ((string-match "-" text) ;we have to contract this node
  4549. (speedbar-change-expand-button-char ?+)
  4550. (speedbar-delete-subblock indent))
  4551. (t (error "Ooops... not sure what to do")))
  4552. (speedbar-center-buffer-smartly))
  4553. (defun Info-speedbar-fetch-file-nodes (nodespec)
  4554. "Fetch the subnodes from the info NODESPEC.
  4555. NODESPEC is a string of the form: (file)node."
  4556. ;; Set up a buffer we can use to fake-out Info.
  4557. (with-current-buffer (get-buffer-create " *info-browse-tmp*")
  4558. (if (not (equal major-mode 'Info-mode))
  4559. (Info-mode))
  4560. ;; Get the node into this buffer
  4561. (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
  4562. (error "Invalid node specification %s" nodespec)
  4563. (Info-find-node (match-string 1 nodespec) (match-string 2 nodespec)))
  4564. ;; Scan the created buffer
  4565. (goto-char (point-min))
  4566. (let ((completions nil)
  4567. (case-fold-search t)
  4568. (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
  4569. (match-string 1 nodespec))))
  4570. ;; Always skip the first one...
  4571. (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
  4572. (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
  4573. (let ((name (match-string 1)))
  4574. (push (cons name
  4575. (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
  4576. (match-string 1)
  4577. (if (looking-at " *\\(([^)]+)\\)\\.")
  4578. (concat (match-string 1) "Top")
  4579. (concat "(" thisfile ")"
  4580. (if (looking-at " \\([^.]+\\).")
  4581. (match-string 1)
  4582. name)))))
  4583. completions)))
  4584. (nreverse completions))))
  4585. ;;; Info mode node listing
  4586. ;; This is called by `speedbar-add-localized-speedbar-support'
  4587. (defun Info-speedbar-buttons (_buffer)
  4588. "Create a speedbar display to help navigation in an Info file.
  4589. BUFFER is the buffer speedbar is requesting buttons for."
  4590. (if (save-excursion (goto-char (point-min))
  4591. (let ((case-fold-search t))
  4592. (not (looking-at "Info Nodes:"))))
  4593. (erase-buffer))
  4594. (Info-speedbar-hierarchy-buttons nil 0))
  4595. ;; FIXME: Really? Why here?
  4596. (add-to-list 'debug-ignored-errors 'search-failed)
  4597. ;;;; Desktop support
  4598. (defun Info-desktop-buffer-misc-data (_desktop-dirname)
  4599. "Auxiliary information to be saved in desktop file."
  4600. (list Info-current-file
  4601. Info-current-node
  4602. ;; Additional data as an association list.
  4603. (delq nil (list
  4604. (and Info-history
  4605. (cons 'history Info-history))
  4606. (and (Info-virtual-fun
  4607. 'slow Info-current-file Info-current-node)
  4608. (cons 'slow t))))))
  4609. (defun Info-restore-desktop-buffer (_desktop-buffer-file-name
  4610. desktop-buffer-name
  4611. desktop-buffer-misc)
  4612. "Restore an Info buffer specified in a desktop file."
  4613. (let* ((file (nth 0 desktop-buffer-misc))
  4614. (node (nth 1 desktop-buffer-misc))
  4615. (data (nth 2 desktop-buffer-misc))
  4616. (hist (assq 'history data))
  4617. (slow (assq 'slow data)))
  4618. ;; Don't restore nodes slow to regenerate.
  4619. (unless slow
  4620. (when (and file node)
  4621. (when desktop-buffer-name
  4622. (set-buffer (get-buffer-create desktop-buffer-name))
  4623. (Info-mode))
  4624. (Info-find-node file node)
  4625. (when hist
  4626. (setq Info-history (cdr hist)))
  4627. (current-buffer)))))
  4628. (add-to-list 'desktop-buffer-mode-handlers
  4629. '(Info-mode . Info-restore-desktop-buffer))
  4630. ;;;; Bookmark support
  4631. (declare-function bookmark-make-record-default
  4632. "bookmark" (&optional no-file no-context posn))
  4633. (declare-function bookmark-prop-get "bookmark" (bookmark prop))
  4634. (declare-function bookmark-default-handler "bookmark" (bmk))
  4635. (declare-function bookmark-get-bookmark-record "bookmark" (bmk))
  4636. (defun Info-bookmark-make-record ()
  4637. "This implements the `bookmark-make-record-function' type (which see)
  4638. for Info nodes."
  4639. `(,Info-current-node
  4640. ,@(bookmark-make-record-default 'no-file)
  4641. (filename . ,Info-current-file)
  4642. (info-node . ,Info-current-node)
  4643. (handler . Info-bookmark-jump)))
  4644. ;;;###autoload
  4645. (defun Info-bookmark-jump (bmk)
  4646. "This implements the `handler' function interface for the record
  4647. type returned by `Info-bookmark-make-record', which see."
  4648. (let* ((file (bookmark-prop-get bmk 'filename))
  4649. (info-node (bookmark-prop-get bmk 'info-node))
  4650. (buf (save-window-excursion ;FIXME: doesn't work with frames!
  4651. (Info-find-node file info-node) (current-buffer))))
  4652. ;; Use bookmark-default-handler to move to the appropriate location
  4653. ;; within the node.
  4654. (bookmark-default-handler
  4655. `("" (buffer . ,buf) . ,(bookmark-get-bookmark-record bmk)))))
  4656. ;;;###autoload
  4657. (defun info-display-manual (manual)
  4658. "Go to Info buffer that displays MANUAL, creating it if none already exists."
  4659. (interactive "sManual name: ")
  4660. (let ((blist (buffer-list))
  4661. (manual-re (concat "\\(/\\|\\`\\)" manual "\\(\\.\\|\\'\\)"))
  4662. (case-fold-search t)
  4663. found)
  4664. (dolist (buffer blist)
  4665. (with-current-buffer buffer
  4666. (when (and (eq major-mode 'Info-mode)
  4667. (stringp Info-current-file)
  4668. (string-match manual-re Info-current-file))
  4669. (setq found buffer
  4670. blist nil))))
  4671. (if found
  4672. (switch-to-buffer found)
  4673. (info-initialize)
  4674. (info (Info-find-file manual)))))
  4675. (provide 'info)
  4676. ;;; info.el ends here