info.el 208 KB

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