info.el 191 KB

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