texinfmt.el 156 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301
  1. ;;; texinfmt.el --- format Texinfo files into Info files
  2. ;; Copyright (C) 1985-1986, 1988, 1990-1998, 2000-2012
  3. ;; Free Software Foundation, Inc.
  4. ;; Maintainer: Robert J. Chassell <bug-texinfo@gnu.org>
  5. ;; Keywords: maint, tex, docs
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;;; Code:
  19. ;;; Emacs lisp functions to convert Texinfo files to Info files.
  20. (defvar texinfmt-version "2.42 of 7 Jul 2006")
  21. (defun texinfmt-version (&optional here)
  22. "Show the version of texinfmt.el in the minibuffer.
  23. If optional argument HERE is non-nil, insert info at point."
  24. (interactive "P")
  25. (let ((version-string
  26. (format "Version of \`texinfmt.el\': %s" texinfmt-version)))
  27. (if here
  28. (insert version-string)
  29. (if (called-interactively-p 'interactive)
  30. (message "%s" version-string)
  31. version-string))))
  32. ;;; Variable definitions
  33. (require 'texinfo) ; So `texinfo-footnote-style' is defined.
  34. (require 'texnfo-upd) ; So `texinfo-section-types-regexp' is defined.
  35. (defvar texinfo-vindex)
  36. (defvar texinfo-findex)
  37. (defvar texinfo-cindex)
  38. (defvar texinfo-pindex)
  39. (defvar texinfo-tindex)
  40. (defvar texinfo-kindex)
  41. (defvar texinfo-last-node)
  42. (defvar texinfo-node-names)
  43. (defvar texinfo-enclosure-list)
  44. (defvar texinfo-alias-list)
  45. (defvar texinfo-fold-nodename-case nil)
  46. (defvar texinfo-command-start)
  47. (defvar texinfo-command-end)
  48. (defvar texinfo-command-name)
  49. (defvar texinfo-defun-type)
  50. (defvar texinfo-last-node-pos)
  51. (defvar texinfo-stack)
  52. (defvar texinfo-short-index-cmds-alist)
  53. (defvar texinfo-short-index-format-cmds-alist)
  54. (defvar texinfo-format-filename)
  55. (defvar texinfo-footnote-number)
  56. (defvar texinfo-raisesections-alist
  57. '((@chapter . @chapter) ; Cannot go higher
  58. (@unnumbered . @unnumbered)
  59. (@centerchap . @unnumbered)
  60. (@majorheading . @majorheading)
  61. (@chapheading . @chapheading)
  62. (@appendix . @appendix)
  63. (@section . @chapter)
  64. (@unnumberedsec . @unnumbered)
  65. (@heading . @chapheading)
  66. (@appendixsec . @appendix)
  67. (@subsection . @section)
  68. (@unnumberedsubsec . @unnumberedsec)
  69. (@subheading . @heading)
  70. (@appendixsubsec . @appendixsec)
  71. (@subsubsection . @subsection)
  72. (@unnumberedsubsubsec . @unnumberedsubsec)
  73. (@subsubheading . @subheading)
  74. (@appendixsubsubsec . @appendixsubsec))
  75. "*An alist of next higher levels for chapters, sections, etc...
  76. For example, section to chapter, subsection to section.
  77. Used by `texinfo-raise-lower-sections'.
  78. The keys specify types of section; the values correspond to the next
  79. higher types.")
  80. (defvar texinfo-lowersections-alist
  81. '((@chapter . @section)
  82. (@unnumbered . @unnumberedsec)
  83. (@centerchap . @unnumberedsec)
  84. (@majorheading . @heading)
  85. (@chapheading . @heading)
  86. (@appendix . @appendixsec)
  87. (@section . @subsection)
  88. (@unnumberedsec . @unnumberedsubsec)
  89. (@heading . @subheading)
  90. (@appendixsec . @appendixsubsec)
  91. (@subsection . @subsubsection)
  92. (@unnumberedsubsec . @unnumberedsubsubsec)
  93. (@subheading . @subsubheading)
  94. (@appendixsubsec . @appendixsubsubsec)
  95. (@subsubsection . @subsubsection) ; Cannot go lower.
  96. (@unnumberedsubsubsec . @unnumberedsubsubsec)
  97. (@subsubheading . @subsubheading)
  98. (@appendixsubsubsec . @appendixsubsubsec))
  99. "*An alist of next lower levels for chapters, sections, etc...
  100. For example, chapter to section, section to subsection.
  101. Used by `texinfo-raise-lower-sections'.
  102. The keys specify types of section; the values correspond to the next
  103. lower types.")
  104. ;;; Syntax table
  105. (defvar texinfo-format-syntax-table
  106. (let ((st (make-syntax-table)))
  107. (modify-syntax-entry ?\" " " st)
  108. (modify-syntax-entry ?\\ " " st)
  109. (modify-syntax-entry ?@ "\\" st)
  110. (modify-syntax-entry ?\^q "\\" st)
  111. (modify-syntax-entry ?\[ "." st)
  112. (modify-syntax-entry ?\] "." st)
  113. (modify-syntax-entry ?\( "." st)
  114. (modify-syntax-entry ?\) "." st)
  115. (modify-syntax-entry ?{ "(}" st)
  116. (modify-syntax-entry ?} "){" st)
  117. (modify-syntax-entry ?\' "." st)
  118. st))
  119. ;;; Top level buffer and region formatting functions
  120. ;;;###autoload
  121. (defun texinfo-format-buffer (&optional nosplit)
  122. "Process the current buffer as texinfo code, into an Info file.
  123. The Info file output is generated in a buffer visiting the Info file
  124. name specified in the @setfilename command.
  125. Non-nil argument (prefix, if interactive) means don't make tag table
  126. and don't split the file if large. You can use `Info-tagify' and
  127. `Info-split' to do these manually."
  128. (interactive "P")
  129. (let ((lastmessage "Formatting Info file...")
  130. (coding-system-for-write buffer-file-coding-system))
  131. (message lastmessage)
  132. (widen)
  133. (texinfo-format-buffer-1)
  134. (Info-tagify)
  135. (if nosplit
  136. nil
  137. (if (> (buffer-size) (+ 50000 Info-split-threshold))
  138. (progn
  139. (message (setq lastmessage "Splitting Info file..."))
  140. (Info-split))))
  141. (message (concat lastmessage
  142. (if (called-interactively-p 'interactive)
  143. "done. Now save it." "done.")))))
  144. (defvar texinfo-region-buffer-name "*Info Region*"
  145. "*Name of the temporary buffer used by \\[texinfo-format-region].")
  146. (defvar texinfo-pre-format-hook nil
  147. "Hook called before the conversion of the Texinfo file to Info format.
  148. The functions on this hook are called with argument BUFFER, the buffer
  149. containing the Texinfo file.")
  150. ;; These come from tex-mode.el.
  151. (defvar tex-start-of-header)
  152. (defvar tex-end-of-header)
  153. ;;;###autoload
  154. (defun texinfo-format-region (region-beginning region-end)
  155. "Convert the current region of the Texinfo file to Info format.
  156. This lets you see what that part of the file will look like in Info.
  157. The command is bound to \\[texinfo-format-region]. The text that is
  158. converted to Info is stored in a temporary buffer."
  159. (interactive "r")
  160. (message "Converting region to Info format...")
  161. (let (texinfo-command-start
  162. texinfo-command-end
  163. texinfo-command-name
  164. texinfo-vindex
  165. texinfo-findex
  166. texinfo-cindex
  167. texinfo-pindex
  168. texinfo-tindex
  169. texinfo-kindex
  170. texinfo-stack
  171. (texinfo-format-filename "")
  172. texinfo-example-start
  173. texinfo-last-node-pos
  174. texinfo-last-node
  175. texinfo-node-names
  176. (texinfo-footnote-number 0)
  177. last-input-buffer
  178. (fill-column-for-info fill-column)
  179. (input-buffer (current-buffer))
  180. (input-directory default-directory)
  181. (header-text "")
  182. (header-beginning 1)
  183. (header-end 1))
  184. ;;; Copy lines between beginning and end of header lines,
  185. ;;; if any, or else copy the `@setfilename' line, if any.
  186. (save-excursion
  187. (save-restriction
  188. (widen)
  189. (goto-char (point-min))
  190. (let ((search-end (line-beginning-position 101)))
  191. (if (or
  192. ;; Either copy header text.
  193. (and
  194. (prog1
  195. (search-forward tex-start-of-header search-end t)
  196. (forward-line 1)
  197. ;; Mark beginning of header.
  198. (setq header-beginning (point)))
  199. (prog1
  200. (search-forward tex-end-of-header nil t)
  201. (beginning-of-line)
  202. ;; Mark end of header
  203. (setq header-end (point))))
  204. ;; Or copy @filename line.
  205. (prog2
  206. (goto-char (point-min))
  207. (search-forward "@setfilename" search-end t)
  208. (beginning-of-line)
  209. (setq header-beginning (point))
  210. (forward-line 1)
  211. (setq header-end (point))))
  212. ;; Copy header
  213. (setq header-text
  214. (buffer-substring-no-properties
  215. (min header-beginning region-beginning)
  216. header-end))))))
  217. ;;; Find a buffer to use.
  218. (switch-to-buffer (get-buffer-create texinfo-region-buffer-name))
  219. (setq buffer-read-only t)
  220. (let ((inhibit-read-only t))
  221. (erase-buffer)
  222. ;; Insert the header into the buffer.
  223. (insert header-text)
  224. ;; Insert the region into the buffer.
  225. (insert-buffer-substring
  226. input-buffer
  227. (max region-beginning header-end)
  228. region-end)
  229. (run-hook-with-args 'texinfo-pre-format-hook input-buffer)
  230. ;; Make sure region ends in a newline.
  231. (or (= (preceding-char) ?\n)
  232. (insert "\n"))
  233. (goto-char (point-min))
  234. (texinfo-mode)
  235. (message "Converting region to Info format...")
  236. (setq fill-column fill-column-for-info)
  237. ;; Install a syntax table useful for scanning command operands.
  238. (set-syntax-table texinfo-format-syntax-table)
  239. ;; Insert @include files so `texinfo-raise-lower-sections' can
  240. ;; work on them without losing track of multiple
  241. ;; @raise/@lowersections commands.
  242. (while (re-search-forward "^@include" nil t)
  243. (setq texinfo-command-end (point))
  244. (let ((filename (concat input-directory
  245. (texinfo-parse-line-arg))))
  246. (re-search-backward "^@include")
  247. (delete-region (point) (line-beginning-position 2))
  248. (message "Reading included file: %s" filename)
  249. (save-excursion
  250. (save-restriction
  251. (narrow-to-region
  252. (point)
  253. (+ (point) (car (cdr (insert-file-contents filename)))))
  254. (goto-char (point-min))
  255. ;; Remove `@setfilename' line from included file, if any,
  256. ;; so @setfilename command not duplicated.
  257. (if (re-search-forward "^@setfilename" (line-end-position 100) t)
  258. (delete-region (line-beginning-position 1)
  259. (line-beginning-position 2)))))))
  260. ;; Raise or lower level of each section, if necessary.
  261. (goto-char (point-min))
  262. (texinfo-raise-lower-sections)
  263. ;; Append @refill to appropriate paragraphs for filling.
  264. (goto-char (point-min))
  265. (texinfo-append-refill)
  266. ;; If the region includes the effective end of the data,
  267. ;; discard everything after that.
  268. (goto-char (point-max))
  269. (if (re-search-backward "^@bye" nil t)
  270. (delete-region (point) (point-max)))
  271. ;; Make sure buffer ends in a newline.
  272. (or (= (preceding-char) ?\n)
  273. (insert "\n"))
  274. ;; Don't use a previous value of texinfo-enclosure-list.
  275. (setq texinfo-enclosure-list nil)
  276. (setq texinfo-alias-list nil)
  277. (goto-char (point-min))
  278. (if (looking-at "\\\\input[ \t]+texinfo")
  279. (delete-region (point) (line-beginning-position 2)))
  280. ;; Insert Info region title text.
  281. (goto-char (point-min))
  282. (if (search-forward "@setfilename" (line-beginning-position 101) t)
  283. (progn
  284. (setq texinfo-command-end (point))
  285. (beginning-of-line)
  286. (setq texinfo-command-start (point))
  287. (let ((arg (texinfo-parse-arg-discard)))
  288. (insert " "
  289. texinfo-region-buffer-name
  290. " buffer for: `")
  291. (insert (file-name-nondirectory (expand-file-name arg)))
  292. (insert "', -*-Text-*-\n")))
  293. ;; Else no `@setfilename' line
  294. (insert " "
  295. texinfo-region-buffer-name
  296. " buffer -*-Text-*-\n"))
  297. (insert "produced by `texinfo-format-region'\n"
  298. "from a region in: "
  299. (if (buffer-file-name input-buffer)
  300. (concat "`"
  301. (file-name-sans-versions
  302. (file-name-nondirectory
  303. (buffer-file-name input-buffer)))
  304. "'")
  305. (concat "buffer `" (buffer-name input-buffer) "'"))
  306. "\nusing `texinfmt.el' version "
  307. texinfmt-version
  308. ".\n\n")
  309. ;; Now convert for real.
  310. (goto-char (point-min))
  311. (texinfo-format-scan)
  312. (goto-char (point-min))
  313. (Info-tagify input-buffer)
  314. (goto-char (point-min))
  315. (message "Done."))))
  316. ;;;###autoload
  317. (defun texi2info (&optional nosplit)
  318. "Convert the current buffer (written in Texinfo code) into an Info file.
  319. The Info file output is generated in a buffer visiting the Info file
  320. names specified in the @setfilename command.
  321. This function automatically updates all node pointers and menus, and
  322. creates a master menu. This work is done on a temporary buffer that
  323. is automatically removed when the Info file is created. The original
  324. Texinfo source buffer is not changed.
  325. Non-nil argument (prefix, if interactive) means don't split the file
  326. if large. You can use `Info-split' to do this manually."
  327. (interactive "P")
  328. (let ((temp-buffer (concat "*--" (buffer-name) "--temporary-buffer*" )))
  329. (message "First updating nodes and menus, then creating Info file.")
  330. ;; (sit-for 2)
  331. (copy-to-buffer temp-buffer (point-min) (point-max))
  332. (switch-to-buffer temp-buffer)
  333. (texinfo-master-menu t)
  334. (message "Now creating Info file.")
  335. (sit-for 2)
  336. (texinfo-format-buffer nosplit)
  337. (save-buffer)
  338. (kill-buffer temp-buffer)))
  339. ;;; Primary internal formatting function for the whole buffer.
  340. (defun texinfo-format-buffer-1 ()
  341. (let (texinfo-format-filename
  342. texinfo-example-start
  343. texinfo-command-start
  344. texinfo-command-end
  345. texinfo-command-name
  346. texinfo-last-node
  347. texinfo-last-node-pos
  348. texinfo-vindex
  349. texinfo-findex
  350. texinfo-cindex
  351. texinfo-pindex
  352. texinfo-tindex
  353. texinfo-kindex
  354. texinfo-stack
  355. texinfo-node-names
  356. (texinfo-footnote-number 0)
  357. last-input-buffer
  358. outfile
  359. (fill-column-for-info fill-column)
  360. (input-buffer (current-buffer))
  361. (input-directory default-directory))
  362. (setq texinfo-enclosure-list nil)
  363. (setq texinfo-alias-list nil)
  364. (save-excursion
  365. (goto-char (point-min))
  366. (or (search-forward "@setfilename" nil t)
  367. (error "Texinfo file needs an `@setfilename FILENAME' line"))
  368. (setq texinfo-command-end (point))
  369. (setq outfile (texinfo-parse-line-arg)))
  370. (find-file outfile)
  371. (texinfo-mode)
  372. (erase-buffer)
  373. (buffer-disable-undo)
  374. (message "Formatting Info file: %s" outfile)
  375. (setq texinfo-format-filename
  376. (file-name-nondirectory (expand-file-name outfile)))
  377. (setq fill-column fill-column-for-info)
  378. (set-syntax-table texinfo-format-syntax-table)
  379. (insert-buffer-substring input-buffer)
  380. (run-hook-with-args 'texinfo-pre-format-hook input-buffer)
  381. (message "Converting %s to Info format..." (buffer-name input-buffer))
  382. ;; Insert @include files so `texinfo-raise-lower-sections' can
  383. ;; work on them without losing track of multiple
  384. ;; @raise/@lowersections commands.
  385. (goto-char (point-min))
  386. (while (re-search-forward "^@include" nil t)
  387. (setq texinfo-command-end (point))
  388. (let ((filename (concat input-directory
  389. (texinfo-parse-line-arg))))
  390. (re-search-backward "^@include")
  391. (delete-region (point) (line-beginning-position 2))
  392. (message "Reading included file: %s" filename)
  393. (save-excursion
  394. (save-restriction
  395. (narrow-to-region
  396. (point)
  397. (+ (point) (car (cdr (insert-file-contents filename)))))
  398. (goto-char (point-min))
  399. ;; Remove `@setfilename' line from included file, if any,
  400. ;; so @setfilename command not duplicated.
  401. (if (re-search-forward "^@setfilename" (line-end-position 100) t)
  402. (delete-region (line-beginning-position 1)
  403. (line-beginning-position 2)))))))
  404. ;; Raise or lower level of each section, if necessary.
  405. (goto-char (point-min))
  406. (texinfo-raise-lower-sections)
  407. ;; Append @refill to appropriate paragraphs
  408. (goto-char (point-min))
  409. (texinfo-append-refill)
  410. (goto-char (point-min))
  411. (search-forward "@setfilename")
  412. (beginning-of-line)
  413. (delete-region (point-min) (point))
  414. ;; Remove @bye at end of file, if it is there.
  415. (goto-char (point-max))
  416. (if (search-backward "@bye" nil t)
  417. (delete-region (point) (point-max)))
  418. ;; Make sure buffer ends in a newline.
  419. (or (= (preceding-char) ?\n)
  420. (insert "\n"))
  421. ;; Scan the whole buffer, converting to Info format.
  422. (texinfo-format-scan)
  423. (goto-char (point-min))
  424. ;; Insert info about how this file was made.
  425. (insert "Info file: "
  426. texinfo-format-filename ", -*-Text-*-\n"
  427. "produced by `texinfo-format-buffer'\n"
  428. ;; Date string removed so that regression testing is easier.
  429. ;; "on "
  430. ;; (insert (format-time-string "%e %b %Y")) " "
  431. "from file"
  432. (if (buffer-file-name input-buffer)
  433. (concat " `"
  434. (file-name-sans-versions
  435. (file-name-nondirectory
  436. (buffer-file-name input-buffer)))
  437. "'")
  438. (concat "buffer `" (buffer-name input-buffer) "'"))
  439. "\nusing `texinfmt.el' version "
  440. texinfmt-version
  441. ".\n\n")
  442. ;; Return data for indices.
  443. (list outfile
  444. texinfo-vindex texinfo-findex texinfo-cindex
  445. texinfo-pindex texinfo-tindex texinfo-kindex)))
  446. ;;; Perform non-@-command file conversions: quotes and hyphens
  447. (defun texinfo-format-convert (min max)
  448. ;; Convert left and right quotes to typewriter font quotes.
  449. (goto-char min)
  450. (while (search-forward "``" max t)
  451. (replace-match "\""))
  452. (goto-char min)
  453. (while (search-forward "''" max t)
  454. (replace-match "\""))
  455. ;; Convert three hyphens in a row to two.
  456. (goto-char min)
  457. (while (re-search-forward "\\( \\|\\w\\)\\(---\\)\\( \\|\\w\\)" max t)
  458. (delete-region (1+ (match-beginning 2)) (+ 2 (match-beginning 2)))))
  459. ;;; Handle paragraph filling
  460. ;; Keep as concatenated lists for ease of maintenance
  461. (defvar texinfo-no-refill-regexp
  462. (concat
  463. "^@"
  464. "\\("
  465. ;; add "itemize\\|" (from experiment of 2001 Nov 28)
  466. ;; because of a problem with @end itemize@refill
  467. ;; I don't know if this causes other problems.
  468. ;; I suspect itemized lists don't get filled properly and a
  469. ;; more precise fix is required. Bob
  470. ;; commented out on 2005 Feb 28 by Bob
  471. ;; "itemize\\|"
  472. "direntry\\|"
  473. "lisp\\|"
  474. "smalllisp\\|"
  475. "example\\|"
  476. "smallexample\\|"
  477. "display\\|"
  478. "smalldisplay\\|"
  479. "format\\|"
  480. "smallformat\\|"
  481. "flushleft\\|"
  482. "flushright\\|"
  483. "menu\\|"
  484. "multitable\\|"
  485. "titlepage\\|"
  486. "iftex\\|"
  487. "ifhtml\\|"
  488. "tex\\|"
  489. "html"
  490. "\\)")
  491. "Regexp specifying environments in which paragraphs are not filled.")
  492. (defvar texinfo-accent-commands
  493. (concat
  494. "@^\\|"
  495. "@`\\|"
  496. "@'\\|"
  497. "@\"\\|"
  498. "@,\\|"
  499. "@=\\|"
  500. "@~\\|"
  501. "@OE{\\|"
  502. "@oe{\\|"
  503. "@AA{\\|"
  504. "@aa{\\|"
  505. "@AE{\\|"
  506. "@ae{\\|"
  507. "@ss{\\|"
  508. "@questiondown{\\|"
  509. "@exclamdown{\\|"
  510. "@L{\\|"
  511. "@l{\\|"
  512. "@O{\\|"
  513. "@o{\\|"
  514. "@dotaccent{\\|"
  515. "@ubaraccent{\\|"
  516. "@d{\\|"
  517. "@H{\\|"
  518. "@ringaccent{\\|"
  519. "@tieaccent{\\|"
  520. "@u{\\|"
  521. "@v{\\|"
  522. "@dotless{"
  523. ))
  524. (defvar texinfo-part-of-para-regexp
  525. (concat
  526. "^@"
  527. "\\("
  528. "b{\\|"
  529. "bullet{\\|"
  530. "cite{\\|"
  531. "code{\\|"
  532. "email{\\|"
  533. "emph{\\|"
  534. "equiv{\\|"
  535. "error{\\|"
  536. "expansion{\\|"
  537. "file{\\|"
  538. "i{\\|"
  539. "inforef{\\|"
  540. "kbd{\\|"
  541. "key{\\|"
  542. "lisp{\\|"
  543. "minus{\\|"
  544. "point{\\|"
  545. "print{\\|"
  546. "pxref{\\|"
  547. "r{\\|"
  548. "ref{\\|"
  549. "result{\\|"
  550. "samp{\\|"
  551. "sc{\\|"
  552. "t{\\|"
  553. "TeX{\\|"
  554. "today{\\|"
  555. "url{\\|"
  556. "var{\\|"
  557. "w{\\|"
  558. "xref{\\|"
  559. "@-\\|" ; @- is a discretionary hyphen (not an accent) (a noop).
  560. texinfo-accent-commands
  561. "\\)"
  562. )
  563. "Regexp specifying @-commands found within paragraphs.")
  564. (defun texinfo-append-refill ()
  565. "Append @refill at end of each paragraph that should be filled.
  566. Do not append @refill to paragraphs within @example and similar environments.
  567. Do not append @refill to paragraphs containing @w{TEXT} or @*."
  568. ;; It is necessary to append @refill before other processing because
  569. ;; the other processing removes information that tells Texinfo
  570. ;; whether the text should or should not be filled.
  571. (while (< (point) (point-max))
  572. (let ((refill-blank-lines "^[ \t\n]*$")
  573. (case-fold-search nil)) ; Don't confuse @TeX and @tex....
  574. (beginning-of-line)
  575. ;; 1. Skip over blank lines;
  576. ;; skip over lines beginning with @-commands,
  577. ;; but do not skip over lines
  578. ;; that are no-refill environments such as @example or
  579. ;; that begin with within-paragraph @-commands such as @code.
  580. (while (and (looking-at (concat "^@\\|^\\\\\\|" refill-blank-lines))
  581. (not (looking-at
  582. (concat
  583. "\\("
  584. texinfo-no-refill-regexp
  585. "\\|"
  586. texinfo-part-of-para-regexp
  587. "\\)")))
  588. (< (point) (point-max)))
  589. (forward-line 1))
  590. ;; 2. Skip over @example and similar no-refill environments.
  591. (if (looking-at texinfo-no-refill-regexp)
  592. (let ((environment (match-string-no-properties 1)))
  593. (progn (re-search-forward (concat "^@end " environment) nil t)
  594. (forward-line 1)))
  595. ;; Else
  596. ;; 3. Do not refill a paragraph containing @w or @*, or ending
  597. ;; with @<newline> followed by a newline.
  598. (if (or (>= (point) (point-max))
  599. (re-search-forward
  600. "@w{\\|@\\*\\|@\n\n"
  601. (save-excursion (forward-paragraph)
  602. (line-beginning-position 2))
  603. t))
  604. ;; Go to end of paragraph and do nothing.
  605. (forward-paragraph)
  606. ;; 4. Else go to end of paragraph and insert @refill
  607. (forward-paragraph)
  608. (forward-line -1)
  609. (let ((line-beg (point)))
  610. (end-of-line)
  611. (delete-region
  612. (point)
  613. (save-excursion (skip-chars-backward " \t") (point)))
  614. (forward-char 1)
  615. (unless (re-search-backward "@c[ \t\n]\\|@comment[ \t\n]" line-beg t)
  616. (forward-char -1))
  617. (unless (re-search-backward "@refill\\|^[ \t]*@" line-beg t)
  618. (insert "@refill")))
  619. (forward-line 1))))))
  620. ;;; Handle `@raisesections' and `@lowersections' commands
  621. ;; These commands change the hierarchical level of chapter structuring
  622. ;; commands.
  623. ;;
  624. ;; @raisesections changes @subsection to @section,
  625. ;; @section to @chapter,
  626. ;; etc.
  627. ;;
  628. ;; @lowersections changes @chapter to @section
  629. ;; @subsection to @subsubsection,
  630. ;; etc.
  631. ;;
  632. ;; An @raisesections/@lowersections command changes only those
  633. ;; structuring commands that follow the @raisesections/@lowersections
  634. ;; command.
  635. ;;
  636. ;; Repeated @raisesections/@lowersections continue to raise or lower
  637. ;; the heading level.
  638. ;;
  639. ;; An @lowersections command cancels an @raisesections command, and
  640. ;; vice versa.
  641. ;;
  642. ;; You cannot raise or lower "beyond" chapters or subsubsections, but
  643. ;; trying to do so does not elicit an error---you just get more
  644. ;; headings that mean the same thing as you keep raising or lowering
  645. ;; (for example, after a single @raisesections, both @chapter and
  646. ;; @section produce chapter headings).
  647. (defun texinfo-raise-lower-sections ()
  648. "Raise or lower the hierarchical level of chapters, sections, etc.
  649. This function acts according to `@raisesections' and `@lowersections'
  650. commands in the Texinfo file.
  651. For example, an `@lowersections' command is useful if you wish to
  652. include what is written as an outer or standalone Texinfo file in
  653. another Texinfo file as an inner, included file. The `@lowersections'
  654. command changes chapters to sections, sections to subsections and so
  655. on.
  656. @raisesections changes @subsection to @section,
  657. @section to @chapter,
  658. @heading to @chapheading,
  659. etc.
  660. @lowersections changes @chapter to @section,
  661. @subsection to @subsubsection,
  662. @heading to @subheading,
  663. etc.
  664. An `@raisesections' or `@lowersections' command changes only those
  665. structuring commands that follow the `@raisesections' or
  666. `@lowersections' command.
  667. An `@lowersections' command cancels an `@raisesections' command, and
  668. vice versa.
  669. Repeated use of the commands continue to raise or lower the hierarchical
  670. level a step at a time.
  671. An attempt to raise above `chapters' reproduces chapter commands; an
  672. attempt to lower below subsubsections reproduces subsubsection
  673. commands."
  674. ;; `texinfo-section-types-regexp' is defined in `texnfo-upd.el';
  675. ;; it is a regexp matching chapter, section, other headings
  676. ;; (but not the top node).
  677. (let (type (level 0))
  678. (while
  679. (re-search-forward
  680. (concat
  681. "\\(\\(^@\\(raise\\|lower\\)sections\\)\\|\\("
  682. texinfo-section-types-regexp
  683. "\\)\\)")
  684. nil t)
  685. (beginning-of-line)
  686. (save-excursion (setq type (read (current-buffer))))
  687. (cond
  688. ;; 1. Increment level
  689. ((eq type '@raisesections)
  690. (setq level (1+ level))
  691. (delete-region
  692. (point) (line-beginning-position 2)))
  693. ;; 2. Decrement level
  694. ((eq type '@lowersections)
  695. (setq level (1- level))
  696. (delete-region
  697. (point) (line-beginning-position 2)))
  698. ;; Now handle structuring commands
  699. ((cond
  700. ;; 3. Raise level when positive
  701. ((> level 0)
  702. (let ((count level)
  703. (new-level type))
  704. (while (> count 0)
  705. (setq new-level
  706. (cdr (assq new-level texinfo-raisesections-alist)))
  707. (setq count (1- count)))
  708. (kill-word 1)
  709. (insert (symbol-name new-level))))
  710. ;; 4. Do nothing except move point when level is zero
  711. ((= level 0) (forward-line 1))
  712. ;; 5. Lower level when positive
  713. ((< level 0)
  714. (let ((count level)
  715. (new-level type))
  716. (while (< count 0)
  717. (setq new-level
  718. (cdr (assq new-level texinfo-lowersections-alist)))
  719. (setq count (1+ count)))
  720. (kill-word 1)
  721. (insert (symbol-name new-level))))))))))
  722. ;;; Perform those texinfo-to-info conversions that apply to the whole input
  723. ;;; uniformly.
  724. (defun texinfo-format-scan ()
  725. (texinfo-format-convert (point-min) (point-max))
  726. ;; Search for @copying, which has to be first since the
  727. ;; @insertcopying command then inserts the text elsewhere.
  728. (goto-char (point-min))
  729. (when (search-forward "@copying" nil t)
  730. (texinfo-copying))
  731. (while (search-forward "@insertcopying" nil t)
  732. (delete-region (match-beginning 0) (match-end 0))
  733. (texinfo-insertcopying))
  734. ;; Scan for other @-commands.
  735. (goto-char (point-min))
  736. (while (search-forward "@" nil t)
  737. ;;
  738. ;; These are the single-character accent commands: @^ @` @' @" @= @~
  739. ;; In Info, they are simply quoted and the @ deleted.
  740. ;; Other single-character commands:
  741. ;; @* forces a line break,
  742. ;; @- is a discretionary hyphenation point; does nothing in Info.
  743. ;; @<space>, @<tab>, @<newline> each produce a single space,
  744. ;; unless followed by a newline.
  745. ;;
  746. ;; Old version 2.34 expression: (looking-at "[@{}^'` *\"?!]")
  747. (if (looking-at "[@{}^'`\"=~ \t\n*?!-]")
  748. ;; @*, causes a line break.
  749. (cond
  750. ;; @*, a line break
  751. ((= (following-char) ?*)
  752. ;; remove command
  753. (delete-region (1- (point)) (1+ (point)))
  754. ;; insert return if not at end of line;
  755. ;; else line is already broken.
  756. (if (not (= (following-char) ?\n))
  757. (insert ?\n)))
  758. ;; @-, deleted
  759. ((= (following-char) ?-)
  760. (delete-region (1- (point)) (1+ (point))))
  761. ;; @<space>, @<tab>, @<newline>: produce a single space,
  762. ;; unless followed by a newline.
  763. ((= (following-char) ? )
  764. (delete-region (1- (point)) (1+ (point)))
  765. ;; insert single space if not at end of line;
  766. ;; else line is already broken.
  767. (if (not (= (following-char) ?\n))
  768. (insert ? )))
  769. ((= (following-char) ?\t)
  770. (delete-region (1- (point)) (1+ (point)))
  771. ;; insert single space if not at end of line;
  772. ;; else line is already broken.
  773. (if (not (= (following-char) ?\n))
  774. (insert ? )))
  775. ;; following char is a carriage return
  776. ((= (following-char) ?\n)
  777. ;; remove command
  778. (delete-region (1- (point)) (1+ (point)))
  779. ;; insert single space if not at end of line;
  780. ;; else line is already broken.
  781. (if (not (= (following-char) ?\n))
  782. (insert ? )))
  783. ;; Otherwise: the other characters are simply quoted. Delete the @.
  784. (t
  785. (delete-char -1)
  786. ;; Be compatible with makeinfo: if @' and its ilk are
  787. ;; followed by a @ without a brace, barf.
  788. (if (looking-at "[\"'^`~=]")
  789. (progn
  790. (if (= (char-after (1+ (point))) ?@)
  791. (error "Use braces to give a command as an argument to @%c"
  792. (following-char)))
  793. (forward-char 1)
  794. ;; @' etc. can optionally accept their argument in
  795. ;; braces (makeinfo supports that).
  796. (when (looking-at "{")
  797. (let ((start (point)))
  798. (forward-list 1)
  799. (delete-char -1)
  800. (goto-char start)
  801. (delete-char 1))))
  802. (forward-char 1))))
  803. ;; @ is followed by a command-word; find the end of the word.
  804. (setq texinfo-command-start (1- (point)))
  805. (if (= (char-syntax (following-char)) ?w)
  806. (forward-word 1)
  807. (forward-char 1))
  808. (setq texinfo-command-end (point))
  809. ;; Detect the case of two @-commands in a row;
  810. ;; process just the first one.
  811. (goto-char (1+ texinfo-command-start))
  812. (skip-chars-forward "^@" texinfo-command-end)
  813. (setq texinfo-command-end (point))
  814. ;; Handle let aliasing
  815. (setq texinfo-command-name
  816. (let (trial
  817. (cmdname
  818. (buffer-substring-no-properties
  819. (1+ texinfo-command-start) texinfo-command-end)))
  820. (while (setq trial (assoc cmdname texinfo-alias-list))
  821. (setq cmdname (cdr trial)))
  822. (intern cmdname)))
  823. ;; Call the handler for this command.
  824. (let ((enclosure-type
  825. (assoc
  826. (symbol-name texinfo-command-name)
  827. texinfo-enclosure-list)))
  828. (if enclosure-type
  829. (progn
  830. (insert
  831. (car (car (cdr enclosure-type)))
  832. (texinfo-parse-arg-discard)
  833. (car (cdr (car (cdr enclosure-type)))))
  834. (goto-char texinfo-command-start))
  835. (let ((cmd (get texinfo-command-name 'texinfo-format)))
  836. (if cmd (funcall cmd) (texinfo-unsupported)))))))
  837. (cond (texinfo-stack
  838. (goto-char (nth 2 (car texinfo-stack)))
  839. (error "Unterminated @%s" (car (car texinfo-stack)))))
  840. ;; Remove excess whitespace
  841. (let ((whitespace-silent t))
  842. (whitespace-cleanup)))
  843. (defvar texinfo-copying-text ""
  844. "Text of the copyright notice and copying permissions.")
  845. (defun texinfo-copying ()
  846. "Copy the copyright notice and copying permissions from the Texinfo file,
  847. as indicated by the @copying ... @end copying command;
  848. insert the text with the @insertcopying command."
  849. (let ((beg (progn (beginning-of-line) (point)))
  850. (end (progn (re-search-forward "^@end copying[ \t]*\n") (point))))
  851. (setq texinfo-copying-text
  852. (buffer-substring-no-properties
  853. (save-excursion (goto-char beg) (line-beginning-position 2))
  854. (save-excursion (goto-char end) (line-beginning-position 0))))
  855. (delete-region beg end)))
  856. (defun texinfo-insertcopying ()
  857. "Insert the copyright notice and copying permissions from the Texinfo file,
  858. which are indicated by the @copying ... @end copying command."
  859. (insert (concat "\n" texinfo-copying-text)))
  860. (put 'begin 'texinfo-format 'texinfo-format-begin)
  861. (defun texinfo-format-begin ()
  862. (texinfo-format-begin-end 'texinfo-format))
  863. (put 'end 'texinfo-format 'texinfo-format-end)
  864. (defun texinfo-format-end ()
  865. (texinfo-format-begin-end 'texinfo-end))
  866. (defun texinfo-format-begin-end (prop)
  867. (setq texinfo-command-name (intern (texinfo-parse-line-arg)))
  868. (let ((cmd (get texinfo-command-name prop)))
  869. (if cmd (funcall cmd)
  870. (texinfo-unsupported))))
  871. ;;; Parsing functions
  872. (defun texinfo-parse-line-arg ()
  873. "Return argument of @-command as string.
  874. Argument is separated from command either by a space or by a brace.
  875. If a space, return rest of line, with beginning and ending white
  876. space removed. If a brace, return string between braces.
  877. Leave point after argument."
  878. (goto-char texinfo-command-end)
  879. (let ((start (point)))
  880. (cond ((looking-at " ")
  881. (skip-chars-forward " ")
  882. (setq start (point))
  883. (end-of-line)
  884. (skip-chars-backward " ")
  885. (delete-region (point) (progn (end-of-line) (point)))
  886. (setq texinfo-command-end (1+ (point))))
  887. ((looking-at "{")
  888. (setq start (1+ (point)))
  889. (forward-list 1)
  890. (setq texinfo-command-end (point))
  891. (forward-char -1))
  892. (t
  893. (error "Invalid texinfo command arg format")))
  894. (prog1 (buffer-substring-no-properties start (point))
  895. (if (eolp) (forward-char 1)))))
  896. (defun texinfo-parse-expanded-arg ()
  897. (goto-char texinfo-command-end)
  898. (let ((start (point))
  899. marker)
  900. (cond ((looking-at " ")
  901. (skip-chars-forward " ")
  902. (setq start (point))
  903. (end-of-line)
  904. (setq texinfo-command-end (1+ (point))))
  905. ((looking-at "{")
  906. (setq start (1+ (point)))
  907. (forward-list 1)
  908. (setq texinfo-command-end (point))
  909. (forward-char -1))
  910. (t
  911. (error "Invalid texinfo command arg format")))
  912. (setq marker (move-marker (make-marker) texinfo-command-end))
  913. (texinfo-format-expand-region start (point))
  914. (setq texinfo-command-end (marker-position marker))
  915. (move-marker marker nil)
  916. (prog1 (buffer-substring-no-properties start (point))
  917. (if (eolp) (forward-char 1)))))
  918. (defun texinfo-format-expand-region (start end)
  919. (save-restriction
  920. (narrow-to-region start end)
  921. (let (texinfo-command-start
  922. texinfo-command-end
  923. texinfo-command-name
  924. texinfo-stack)
  925. (texinfo-format-scan))
  926. (goto-char (point-max))))
  927. (defun texinfo-parse-arg-discard ()
  928. "Delete command and argument; return argument of command."
  929. (prog1 (texinfo-parse-line-arg)
  930. (texinfo-discard-command)))
  931. (defun texinfo-discard-command ()
  932. (delete-region texinfo-command-start texinfo-command-end))
  933. (defun texinfo-optional-braces-discard ()
  934. "Discard braces following command, if any."
  935. (goto-char texinfo-command-end)
  936. (let ((start (point)))
  937. (cond ((looking-at "[ \t]*\n")) ; do nothing
  938. ((looking-at "{") ; remove braces, if any
  939. (forward-list 1)
  940. (setq texinfo-command-end (point)))
  941. (t
  942. (error
  943. "Invalid `texinfo-optional-braces-discard' format \(need braces?\)")))
  944. (delete-region texinfo-command-start texinfo-command-end)))
  945. (defun texinfo-format-parse-line-args ()
  946. (let ((start (1- (point)))
  947. next beg end
  948. args)
  949. (skip-chars-forward " ")
  950. (while (not (eolp))
  951. (setq beg (point))
  952. (re-search-forward "[\n,]")
  953. (setq next (point))
  954. (if (bolp) (setq next (1- next)))
  955. (forward-char -1)
  956. (skip-chars-backward " ")
  957. (setq end (point))
  958. (push (if (> end beg) (buffer-substring-no-properties beg end))
  959. args)
  960. (goto-char next)
  961. (skip-chars-forward " "))
  962. (if (eolp) (forward-char 1))
  963. (setq texinfo-command-end (point))
  964. (nreverse args)))
  965. (defun texinfo-format-parse-args ()
  966. (let ((start (1- (point)))
  967. next beg end
  968. args)
  969. (search-forward "{")
  970. (save-excursion
  971. (texinfo-format-expand-region
  972. (point)
  973. (save-excursion (up-list 1) (1- (point)))))
  974. ;; The following does not handle cross references of the form:
  975. ;; `@xref{bullet, , @code{@@bullet}@{@}}.' because the
  976. ;; re-search-forward finds the first right brace after the second
  977. ;; comma.
  978. (while (/= (preceding-char) ?\})
  979. (skip-chars-forward " \t\n")
  980. (setq beg (point))
  981. (re-search-forward "[},]")
  982. (setq next (point))
  983. (forward-char -1)
  984. (skip-chars-backward " \t\n")
  985. (setq end (point))
  986. (cond ((< beg end)
  987. (goto-char beg)
  988. (while (search-forward "\n" end t)
  989. (replace-match " "))))
  990. (push (if (> end beg) (buffer-substring-no-properties beg end))
  991. args)
  992. (goto-char next))
  993. ;;(if (eolp) (forward-char 1))
  994. (setq texinfo-command-end (point))
  995. (nreverse args)))
  996. (defun texinfo-format-parse-defun-args ()
  997. (goto-char texinfo-command-end)
  998. (let ((start (point)))
  999. (end-of-line)
  1000. (setq texinfo-command-end (1+ (point)))
  1001. (let ((marker (move-marker (make-marker) texinfo-command-end)))
  1002. (texinfo-format-expand-region start (point))
  1003. (setq texinfo-command-end (marker-position marker))
  1004. (move-marker marker nil))
  1005. (goto-char start)
  1006. (let ((args '())
  1007. beg end)
  1008. (skip-chars-forward " ")
  1009. (while (not (eolp))
  1010. (cond ((looking-at "{")
  1011. (setq beg (1+ (point)))
  1012. (forward-list 1)
  1013. (setq end (1- (point))))
  1014. (t
  1015. (setq beg (point))
  1016. (re-search-forward "[\n ]")
  1017. (forward-char -1)
  1018. (setq end (point))))
  1019. (push (buffer-substring-no-properties beg end) args)
  1020. (skip-chars-forward " "))
  1021. (forward-char 1)
  1022. (nreverse args))))
  1023. (defun texinfo-discard-line ()
  1024. (goto-char texinfo-command-end)
  1025. (skip-chars-forward " \t")
  1026. (or (eolp)
  1027. (error "Extraneous text at end of command line"))
  1028. (goto-char texinfo-command-start)
  1029. (or (bolp)
  1030. (error "Extraneous text at beginning of command line"))
  1031. (delete-region (point) (progn (forward-line 1) (point))))
  1032. (defun texinfo-discard-line-with-args ()
  1033. (goto-char texinfo-command-start)
  1034. (delete-region (point) (progn (forward-line 1) (point))))
  1035. ;;; @setfilename
  1036. ;; Only `texinfo-format-buffer' handles @setfilename with this
  1037. ;; definition; `texinfo-format-region' handles @setfilename, if any,
  1038. ;; specially.
  1039. (put 'setfilename 'texinfo-format 'texinfo-format-setfilename)
  1040. (defun texinfo-format-setfilename ()
  1041. (texinfo-parse-arg-discard))
  1042. ;;; @node, @menu, @detailmenu
  1043. (put 'node 'texinfo-format 'texinfo-format-node)
  1044. (put 'nwnode 'texinfo-format 'texinfo-format-node)
  1045. (defun texinfo-format-node ()
  1046. (let* ((args (texinfo-format-parse-line-args))
  1047. (name (nth 0 args))
  1048. (next (nth 1 args))
  1049. (prev (nth 2 args))
  1050. (up (nth 3 args)))
  1051. (texinfo-discard-command)
  1052. (setq texinfo-last-node name)
  1053. (let ((tem (if texinfo-fold-nodename-case (downcase name) name)))
  1054. (if (assoc tem texinfo-node-names)
  1055. (error "Duplicate node name: %s" name)
  1056. (push (list tem) texinfo-node-names)))
  1057. (setq texinfo-footnote-number 0)
  1058. ;; insert "\n\^_" unconditionally since this is what info is looking for
  1059. (insert "\n\^_\nFile: " texinfo-format-filename
  1060. ", Node: " name)
  1061. (if next
  1062. (insert ", Next: " next))
  1063. (if prev
  1064. (insert ", Prev: " prev))
  1065. (if up
  1066. (insert ", Up: " up))
  1067. (insert ?\n)
  1068. (setq texinfo-last-node-pos (point))))
  1069. (put 'anchor 'texinfo-format 'texinfo-anchor)
  1070. (defun texinfo-anchor ()
  1071. (let (anchor-string
  1072. (here (- (point) 7)) ; save location of beginning of `@anchor'
  1073. (arg (texinfo-parse-arg-discard)))
  1074. (if (looking-at " ") ; since a space may be left after -discard
  1075. (delete-char 1))
  1076. (forward-paragraph)
  1077. (let ((end (point)))
  1078. (if (save-excursion
  1079. (backward-word 1)
  1080. (search-forward "@refill" end t))
  1081. (setq anchor-string "@anchor-yes-refill")
  1082. (setq anchor-string "@anchor-no-refill")))
  1083. (goto-char here)
  1084. (insert anchor-string "{" arg "}")))
  1085. (put 'menu 'texinfo-format 'texinfo-format-menu)
  1086. (defun texinfo-format-menu ()
  1087. (texinfo-discard-line)
  1088. (insert "* Menu:\n\n"))
  1089. (put 'menu 'texinfo-end 'texinfo-discard-command)
  1090. ;; The @detailmenu should be removed eventually.
  1091. ;; According to Karl Berry, 31 August 1996:
  1092. ;;
  1093. ;; You don't like, I don't like it. I agree, it would be better just to
  1094. ;; fix the bug [in `makeinfo']. .. At this point, since inserting those
  1095. ;; two commands in the Elisp fn is trivial, I don't especially want to
  1096. ;; expend more effort...
  1097. ;;
  1098. ;; I added a couple sentences of documentation to the manual (putting the
  1099. ;; blame on makeinfo where it belongs :-().
  1100. (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
  1101. (put 'detailmenu 'texinfo-end 'texinfo-discard-command)
  1102. ;; (Also see `texnfo-upd.el')
  1103. ;;; Cross references
  1104. ;; @xref {NODE, FNAME, NAME, FILE, DOCUMENT}
  1105. ;; -> *Note FNAME: (FILE)NODE
  1106. ;; If FILE is missing,
  1107. ;; *Note FNAME: NODE
  1108. ;; If FNAME is empty and NAME is present
  1109. ;; *Note NAME: Node
  1110. ;; If both NAME and FNAME are missing
  1111. ;; *Note NODE::
  1112. ;; texinfo ignores the DOCUMENT argument.
  1113. ;; -> See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
  1114. ;; If FILE is specified, (FILE)NODE is used for xrefs.
  1115. ;; If fifth argument DOCUMENT is specified, produces
  1116. ;; See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
  1117. ;; of DOCUMENT
  1118. ;; @ref a reference that does not put `See' or `see' in
  1119. ;; the hardcopy and is the same as @xref in Info
  1120. (put 'ref 'texinfo-format 'texinfo-format-xref)
  1121. (put 'xref 'texinfo-format 'texinfo-format-xref)
  1122. (defun texinfo-format-xref ()
  1123. (let ((args (texinfo-format-parse-args)))
  1124. (texinfo-discard-command)
  1125. (insert "*Note ")
  1126. (let ((fname (or (nth 1 args) (nth 2 args))))
  1127. (if (null (or fname (nth 3 args)))
  1128. (insert (car args) "::")
  1129. (insert (or fname (car args)) ": ")
  1130. (if (nth 3 args)
  1131. (insert "(" (nth 3 args) ")"))
  1132. (and (car args) (insert (car args)))))))
  1133. (put 'pxref 'texinfo-format 'texinfo-format-pxref)
  1134. (defun texinfo-format-pxref ()
  1135. (texinfo-format-xref)
  1136. (or (save-excursion
  1137. (forward-char -2)
  1138. (looking-at "::"))
  1139. (insert ".")))
  1140. ;; @inforef{NODE, FNAME, FILE}
  1141. ;; Like @xref{NODE, FNAME,,FILE} in texinfo.
  1142. ;; In Tex, generates "See Info file FILE, node NODE"
  1143. (put 'inforef 'texinfo-format 'texinfo-format-inforef)
  1144. (defun texinfo-format-inforef ()
  1145. (let ((args (texinfo-format-parse-args)))
  1146. (texinfo-discard-command)
  1147. (if (nth 1 args)
  1148. (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
  1149. (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
  1150. ;;; URL Reference: @uref
  1151. ;; @uref produces a reference to a uniform resource locator (URL).
  1152. ;; It takes one mandatory argument, the URL, and one optional argument,
  1153. ;; the text to display (the default is the URL itself).
  1154. (put 'uref 'texinfo-format 'texinfo-format-uref)
  1155. (defun texinfo-format-uref ()
  1156. "Format URL and optional URL-TITLE.
  1157. Insert ` ... ' around URL if no URL-TITLE argument;
  1158. otherwise, insert URL-TITLE followed by URL in parentheses."
  1159. (let ((args (texinfo-format-parse-args)))
  1160. (texinfo-discard-command)
  1161. ;; if url-title
  1162. (if (nth 1 args)
  1163. (insert (nth 1 args) " (" (nth 0 args) ")")
  1164. (insert "`" (nth 0 args) "'"))
  1165. (goto-char texinfo-command-start)))
  1166. ;;; Section headings
  1167. (put 'majorheading 'texinfo-format 'texinfo-format-chapter)
  1168. (put 'chapheading 'texinfo-format 'texinfo-format-chapter)
  1169. (put 'ichapter 'texinfo-format 'texinfo-format-chapter)
  1170. (put 'chapter 'texinfo-format 'texinfo-format-chapter)
  1171. (put 'iappendix 'texinfo-format 'texinfo-format-chapter)
  1172. (put 'appendix 'texinfo-format 'texinfo-format-chapter)
  1173. (put 'iunnumbered 'texinfo-format 'texinfo-format-chapter)
  1174. (put 'top 'texinfo-format 'texinfo-format-chapter)
  1175. (put 'unnumbered 'texinfo-format 'texinfo-format-chapter)
  1176. (put 'centerchap 'texinfo-format 'texinfo-format-chapter)
  1177. (defun texinfo-format-chapter ()
  1178. (texinfo-format-chapter-1 ?*))
  1179. (put 'heading 'texinfo-format 'texinfo-format-section)
  1180. (put 'isection 'texinfo-format 'texinfo-format-section)
  1181. (put 'section 'texinfo-format 'texinfo-format-section)
  1182. (put 'iappendixsection 'texinfo-format 'texinfo-format-section)
  1183. (put 'appendixsection 'texinfo-format 'texinfo-format-section)
  1184. (put 'iappendixsec 'texinfo-format 'texinfo-format-section)
  1185. (put 'appendixsec 'texinfo-format 'texinfo-format-section)
  1186. (put 'iunnumberedsec 'texinfo-format 'texinfo-format-section)
  1187. (put 'unnumberedsec 'texinfo-format 'texinfo-format-section)
  1188. (defun texinfo-format-section ()
  1189. (texinfo-format-chapter-1 ?=))
  1190. (put 'subheading 'texinfo-format 'texinfo-format-subsection)
  1191. (put 'isubsection 'texinfo-format 'texinfo-format-subsection)
  1192. (put 'subsection 'texinfo-format 'texinfo-format-subsection)
  1193. (put 'iappendixsubsec 'texinfo-format 'texinfo-format-subsection)
  1194. (put 'appendixsubsec 'texinfo-format 'texinfo-format-subsection)
  1195. (put 'iunnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
  1196. (put 'unnumberedsubsec 'texinfo-format 'texinfo-format-subsection)
  1197. (defun texinfo-format-subsection ()
  1198. (texinfo-format-chapter-1 ?-))
  1199. (put 'subsubheading 'texinfo-format 'texinfo-format-subsubsection)
  1200. (put 'isubsubsection 'texinfo-format 'texinfo-format-subsubsection)
  1201. (put 'subsubsection 'texinfo-format 'texinfo-format-subsubsection)
  1202. (put 'iappendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
  1203. (put 'appendixsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
  1204. (put 'iunnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
  1205. (put 'unnumberedsubsubsec 'texinfo-format 'texinfo-format-subsubsection)
  1206. (defun texinfo-format-subsubsection ()
  1207. (texinfo-format-chapter-1 ?.))
  1208. (defun texinfo-format-chapter-1 (belowchar)
  1209. (let ((arg (texinfo-parse-arg-discard)))
  1210. (message "Formatting: %s ... " arg) ; So we can see where we are.
  1211. (insert ?\n arg ?\n "@SectionPAD " belowchar ?\n)
  1212. (forward-line -2)))
  1213. (put 'SectionPAD 'texinfo-format 'texinfo-format-sectionpad)
  1214. (defun texinfo-format-sectionpad ()
  1215. (let ((str (texinfo-parse-arg-discard)))
  1216. (forward-char -1)
  1217. (let ((column (current-column)))
  1218. (forward-char 1)
  1219. (while (> column 0)
  1220. (insert str)
  1221. (setq column (1- column))))
  1222. (insert ?\n)))
  1223. ;;; Space controlling commands: @. and @:, and the soft hyphen.
  1224. (put '\. 'texinfo-format 'texinfo-format-\.)
  1225. (defun texinfo-format-\. ()
  1226. (texinfo-discard-command)
  1227. (insert "."))
  1228. (put '\: 'texinfo-format 'texinfo-format-\:)
  1229. (defun texinfo-format-\: ()
  1230. (texinfo-discard-command))
  1231. (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
  1232. (defun texinfo-format-soft-hyphen ()
  1233. (texinfo-discard-command))
  1234. ;;; @kbdinputstyle, @vskip, headings & footings
  1235. ;; These commands for not for Info and should never
  1236. ;; appear in an Info environment; but if they do,
  1237. ;; this causes them to be discarded.
  1238. ;; @kbdinputstyle
  1239. (put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args)
  1240. ;; @vskip
  1241. (put 'vskip 'texinfo-format 'texinfo-discard-line-with-args)
  1242. ;; headings & footings
  1243. (put 'evenfooting 'texinfo-format 'texinfo-discard-line-with-args)
  1244. (put 'evenheading 'texinfo-format 'texinfo-discard-line-with-args)
  1245. (put 'oddfooting 'texinfo-format 'texinfo-discard-line-with-args)
  1246. (put 'oddheading 'texinfo-format 'texinfo-discard-line-with-args)
  1247. (put 'everyfooting 'texinfo-format 'texinfo-discard-line-with-args)
  1248. (put 'everyheading 'texinfo-format 'texinfo-discard-line-with-args)
  1249. ;;; @documentdescription ... @end documentdescription
  1250. ;; This command is for HTML output and should never
  1251. ;; appear in an Info environment; but if it does,
  1252. ;; this causes it to be discarded.
  1253. (put 'documentdescription 'texinfo-format 'texinfo-format-documentdescription)
  1254. (defun texinfo-format-documentdescription ()
  1255. (delete-region texinfo-command-start
  1256. (progn (re-search-forward "^@end documentdescription[ \t]*\n")
  1257. (point))))
  1258. ;;; @center, @sp, and @br
  1259. (put 'center 'texinfo-format 'texinfo-format-center)
  1260. (defun texinfo-format-center ()
  1261. (let ((arg (texinfo-parse-expanded-arg)))
  1262. (texinfo-discard-command)
  1263. (insert arg)
  1264. (insert ?\n)
  1265. (save-restriction
  1266. (goto-char (1- (point)))
  1267. (let ((indent-tabs-mode nil))
  1268. (center-line)))))
  1269. (put 'sp 'texinfo-format 'texinfo-format-sp)
  1270. (defun texinfo-format-sp ()
  1271. (let* ((arg (texinfo-parse-arg-discard))
  1272. (num (read arg)))
  1273. (insert-char ?\n num)))
  1274. (put 'br 'texinfo-format 'texinfo-format-paragraph-break)
  1275. (defun texinfo-format-paragraph-break ()
  1276. "Force a paragraph break.
  1277. If used within a line, follow `@br' with braces."
  1278. (texinfo-optional-braces-discard)
  1279. ;; insert one return if at end of line;
  1280. ;; else insert two returns, to generate a blank line.
  1281. (if (= (following-char) ?\n)
  1282. (insert ?\n)
  1283. (insert-char ?\n 2)))
  1284. ;;; @footnote and @footnotestyle
  1285. ;; In Texinfo, footnotes are created with the `@footnote' command.
  1286. ;; This command is followed immediately by a left brace, then by the text of
  1287. ;; the footnote, and then by a terminating right brace. The
  1288. ;; template for a footnote is:
  1289. ;;
  1290. ;; @footnote{TEXT}
  1291. ;;
  1292. ;; Info has two footnote styles:
  1293. ;;
  1294. ;; * In the End of node style, all the footnotes for a single node
  1295. ;; are placed at the end of that node. The footnotes are
  1296. ;; separated from the rest of the node by a line of dashes with
  1297. ;; the word `Footnotes' within it.
  1298. ;;
  1299. ;; * In the Separate node style, all the footnotes for a single node
  1300. ;; are placed in an automatically constructed node of their own.
  1301. ;; Footnote style is specified by the @footnotestyle command, either
  1302. ;; @footnotestyle separate
  1303. ;; or
  1304. ;; @footnotestyle end
  1305. ;;
  1306. ;; The default is separate
  1307. (defvar texinfo-footnote-style "separate"
  1308. "Footnote style, either separate or end.")
  1309. (put 'footnotestyle 'texinfo-format 'texinfo-footnotestyle)
  1310. (defun texinfo-footnotestyle ()
  1311. "Specify whether footnotes are at end of node or in separate nodes.
  1312. Argument is either end or separate."
  1313. (setq texinfo-footnote-style (texinfo-parse-arg-discard)))
  1314. (put 'footnote 'texinfo-format 'texinfo-format-footnote)
  1315. (defun texinfo-format-footnote ()
  1316. "Format a footnote in either end of node or separate node style.
  1317. The texinfo-footnote-style variable controls which style is used."
  1318. (setq texinfo-footnote-number (1+ texinfo-footnote-number))
  1319. (cond ((string= texinfo-footnote-style "end")
  1320. (texinfo-format-end-node))
  1321. ((string= texinfo-footnote-style "separate")
  1322. (texinfo-format-separate-node))))
  1323. (defun texinfo-format-separate-node ()
  1324. "Format footnote in Separate node style, with notes in own node.
  1325. The node is constructed automatically."
  1326. (let* (start
  1327. (arg (texinfo-parse-line-arg))
  1328. (node-name-beginning
  1329. (save-excursion
  1330. (re-search-backward
  1331. "^File: \\w+\\(\\w\\|\\s_\\|\\.\\|,\\)*[ \t]+Node:")
  1332. (match-end 0)))
  1333. (node-name
  1334. (save-excursion
  1335. (buffer-substring-no-properties
  1336. (progn (goto-char node-name-beginning) ; skip over node command
  1337. (skip-chars-forward " \t") ; and over spaces
  1338. (point))
  1339. (if (search-forward "," (line-end-position) t) ; bound search
  1340. (1- (point))
  1341. (end-of-line) (point))))))
  1342. (texinfo-discard-command) ; remove or insert whitespace, as needed
  1343. (delete-region (save-excursion (skip-chars-backward " \t\n") (point))
  1344. (point))
  1345. (insert (format " (%d) (*Note %s-Footnotes::)"
  1346. texinfo-footnote-number node-name))
  1347. (fill-paragraph nil)
  1348. (save-excursion
  1349. (if (re-search-forward "^@node" nil 'move)
  1350. (forward-line -1))
  1351. ;; two cases: for the first footnote, we must insert a node header;
  1352. ;; for the second and subsequent footnotes, we need only insert
  1353. ;; the text of the footnote.
  1354. (if (save-excursion
  1355. (search-backward
  1356. (concat node-name "-Footnotes, Up: ")
  1357. node-name-beginning
  1358. t))
  1359. (progn ; already at least one footnote
  1360. (setq start (point))
  1361. (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
  1362. (fill-region start (point)))
  1363. ;; else not yet a footnote
  1364. (insert "\n\^_\nFile: " texinfo-format-filename
  1365. " Node: " node-name "-Footnotes, Up: " node-name "\n")
  1366. (setq start (point))
  1367. (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
  1368. (narrow-to-region (save-excursion (goto-char start) (point)) (point))
  1369. (fill-region (point-min) (point-max))
  1370. (widen)))))
  1371. (defun texinfo-format-end-node ()
  1372. "Format footnote in the End of node style, with notes at end of node."
  1373. (let (start
  1374. (arg (texinfo-parse-line-arg)))
  1375. (texinfo-discard-command) ; remove or insert whitespace, as needed
  1376. (delete-region (save-excursion (skip-chars-backward " \t\n") (point))
  1377. (point))
  1378. (insert (format " (%d) " texinfo-footnote-number))
  1379. (fill-paragraph nil)
  1380. (save-excursion
  1381. (if (search-forward "\n--------- Footnotes ---------\n" nil t)
  1382. (progn ; already have footnote, put new one before end of node
  1383. (if (re-search-forward "^@node" nil 'move)
  1384. (forward-line -1))
  1385. (setq start (point))
  1386. (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))
  1387. (fill-region start (point)))
  1388. ;; else no prior footnote
  1389. (if (re-search-forward "^@node" nil 'move)
  1390. (forward-line -1))
  1391. (insert "\n--------- Footnotes ---------\n")
  1392. (setq start (point))
  1393. (insert (format "\n(%d) %s\n" texinfo-footnote-number arg))))))
  1394. ;;; @itemize, @enumerate, and similar commands
  1395. ;; @itemize pushes (itemize "COMMANDS" STARTPOS) on texinfo-stack.
  1396. ;; @enumerate pushes (enumerate 0 STARTPOS).
  1397. ;; @item dispatches to the texinfo-item prop of the first elt of the list.
  1398. ;; For itemize, this puts in and rescans the COMMANDS.
  1399. ;; For enumerate, this increments the number and puts it in.
  1400. ;; In either case, it puts a Backspace at the front of the line
  1401. ;; which marks it not to be indented later.
  1402. ;; All other lines get indented by 5 when the @end is reached.
  1403. (defvar texinfo-stack-depth 0
  1404. "Count of number of unpopped texinfo-push-stack calls.
  1405. Used by @refill indenting command to avoid indenting within lists, etc.")
  1406. (defun texinfo-push-stack (check arg)
  1407. (setq texinfo-stack-depth (1+ texinfo-stack-depth))
  1408. (push (list check arg texinfo-command-start)
  1409. texinfo-stack))
  1410. (defun texinfo-pop-stack (check)
  1411. (setq texinfo-stack-depth (1- texinfo-stack-depth))
  1412. (if (null texinfo-stack)
  1413. (error "Unmatched @end %s" check))
  1414. (if (not (eq (car (car texinfo-stack)) check))
  1415. (error "@end %s matches @%s"
  1416. check (car (car texinfo-stack))))
  1417. (prog1 (cdr (car texinfo-stack))
  1418. (setq texinfo-stack (cdr texinfo-stack))))
  1419. (put 'itemize 'texinfo-format 'texinfo-itemize)
  1420. (defun texinfo-itemize ()
  1421. (texinfo-push-stack
  1422. 'itemize
  1423. (progn (skip-chars-forward " \t")
  1424. (if (eolp)
  1425. "@bullet"
  1426. (texinfo-parse-line-arg))))
  1427. (texinfo-discard-line-with-args)
  1428. (setq fill-column (- fill-column 5)))
  1429. (put 'itemize 'texinfo-end 'texinfo-end-itemize)
  1430. (defun texinfo-end-itemize ()
  1431. (setq fill-column (+ fill-column 5))
  1432. (texinfo-discard-command)
  1433. (let ((stacktop
  1434. (texinfo-pop-stack 'itemize)))
  1435. (texinfo-do-itemize (nth 1 stacktop))))
  1436. (put 'enumerate 'texinfo-format 'texinfo-enumerate)
  1437. (defun texinfo-enumerate ()
  1438. (texinfo-push-stack
  1439. 'enumerate
  1440. (progn (skip-chars-forward " \t")
  1441. (if (eolp)
  1442. 1
  1443. (read (current-buffer)))))
  1444. (if (and (symbolp (car (cdr (car texinfo-stack))))
  1445. (> 1 (length (symbol-name (car (cdr (car texinfo-stack)))))))
  1446. (error
  1447. "@enumerate: Use a number or letter, eg: 1, A, a, 3, B, or d." ))
  1448. (texinfo-discard-line-with-args)
  1449. (setq fill-column (- fill-column 5)))
  1450. (put 'enumerate 'texinfo-end 'texinfo-end-enumerate)
  1451. (defun texinfo-end-enumerate ()
  1452. (setq fill-column (+ fill-column 5))
  1453. (texinfo-discard-command)
  1454. (let ((stacktop
  1455. (texinfo-pop-stack 'enumerate)))
  1456. (texinfo-do-itemize (nth 1 stacktop))))
  1457. ;; @alphaenumerate never became a standard part of Texinfo
  1458. (put 'alphaenumerate 'texinfo-format 'texinfo-alphaenumerate)
  1459. (defun texinfo-alphaenumerate ()
  1460. (texinfo-push-stack 'alphaenumerate (1- ?a))
  1461. (setq fill-column (- fill-column 5))
  1462. (texinfo-discard-line))
  1463. (put 'alphaenumerate 'texinfo-end 'texinfo-end-alphaenumerate)
  1464. (defun texinfo-end-alphaenumerate ()
  1465. (setq fill-column (+ fill-column 5))
  1466. (texinfo-discard-command)
  1467. (let ((stacktop
  1468. (texinfo-pop-stack 'alphaenumerate)))
  1469. (texinfo-do-itemize (nth 1 stacktop))))
  1470. ;; @capsenumerate never became a standard part of Texinfo
  1471. (put 'capsenumerate 'texinfo-format 'texinfo-capsenumerate)
  1472. (defun texinfo-capsenumerate ()
  1473. (texinfo-push-stack 'capsenumerate (1- ?A))
  1474. (setq fill-column (- fill-column 5))
  1475. (texinfo-discard-line))
  1476. (put 'capsenumerate 'texinfo-end 'texinfo-end-capsenumerate)
  1477. (defun texinfo-end-capsenumerate ()
  1478. (setq fill-column (+ fill-column 5))
  1479. (texinfo-discard-command)
  1480. (let ((stacktop
  1481. (texinfo-pop-stack 'capsenumerate)))
  1482. (texinfo-do-itemize (nth 1 stacktop))))
  1483. ;; At the @end, indent all the lines within the construct
  1484. ;; except those marked with backspace. FROM says where
  1485. ;; construct started.
  1486. (defun texinfo-do-itemize (from)
  1487. (save-excursion
  1488. (while (progn (forward-line -1)
  1489. (>= (point) from))
  1490. (if (= (following-char) ?\b)
  1491. (save-excursion
  1492. (delete-char 1)
  1493. (end-of-line)
  1494. (delete-char 6))
  1495. (if (not (looking-at "[ \t]*$"))
  1496. (save-excursion (insert " ")))))))
  1497. (put 'item 'texinfo-format 'texinfo-item)
  1498. (put 'itemx 'texinfo-format 'texinfo-item)
  1499. (defun texinfo-item ()
  1500. (funcall (get (car (car texinfo-stack)) 'texinfo-item)))
  1501. (put 'itemize 'texinfo-item 'texinfo-itemize-item)
  1502. (defun texinfo-itemize-item ()
  1503. ;; (texinfo-discard-line) ; Did not handle text on same line as @item.
  1504. (delete-region (1+ (point)) (line-beginning-position))
  1505. (if (looking-at "[ \t]*[^ \t\n]+")
  1506. ;; Text on same line as @item command.
  1507. (insert "\b " (nth 1 (car texinfo-stack)) " \n")
  1508. ;; Else text on next line.
  1509. (insert "\b " (nth 1 (car texinfo-stack)) " "))
  1510. (forward-line -1))
  1511. (put 'enumerate 'texinfo-item 'texinfo-enumerate-item)
  1512. (defun texinfo-enumerate-item ()
  1513. (texinfo-discard-line)
  1514. (let (enumerating-symbol)
  1515. (cond ((integerp (car (cdr (car texinfo-stack))))
  1516. (setq enumerating-symbol (car (cdr (car texinfo-stack))))
  1517. (insert ?\b (format "%3d. " enumerating-symbol) ?\n)
  1518. (setcar (cdr (car texinfo-stack)) (1+ enumerating-symbol)))
  1519. ((symbolp (car (cdr (car texinfo-stack))))
  1520. (setq enumerating-symbol
  1521. (symbol-name (car (cdr (car texinfo-stack)))))
  1522. (if (or (equal ?\[ (string-to-char enumerating-symbol))
  1523. (equal ?\{ (string-to-char enumerating-symbol)))
  1524. (error
  1525. "Too many items in enumerated list; alphabet ends at Z."))
  1526. (insert ?\b (format "%3s. " enumerating-symbol) ?\n)
  1527. (setcar (cdr (car texinfo-stack))
  1528. (make-symbol
  1529. (char-to-string
  1530. (1+
  1531. (string-to-char enumerating-symbol))))))
  1532. (t
  1533. (error
  1534. "@enumerate: Use a number or letter, eg: 1, A, a, 3, B or d." )))
  1535. (forward-line -1)))
  1536. (put 'alphaenumerate 'texinfo-item 'texinfo-alphaenumerate-item)
  1537. (defun texinfo-alphaenumerate-item ()
  1538. (texinfo-discard-line)
  1539. (let ((next (1+ (car (cdr (car texinfo-stack))))))
  1540. (if (> next ?z)
  1541. (error "More than 26 items in @alphaenumerate; get a bigger alphabet"))
  1542. (setcar (cdr (car texinfo-stack)) next)
  1543. (insert "\b " next ". \n"))
  1544. (forward-line -1))
  1545. (put 'capsenumerate 'texinfo-item 'texinfo-capsenumerate-item)
  1546. (defun texinfo-capsenumerate-item ()
  1547. (texinfo-discard-line)
  1548. (let ((next (1+ (car (cdr (car texinfo-stack))))))
  1549. (if (> next ?Z)
  1550. (error "More than 26 items in @capsenumerate; get a bigger alphabet"))
  1551. (setcar (cdr (car texinfo-stack)) next)
  1552. (insert "\b " next ". \n"))
  1553. (forward-line -1))
  1554. ;;; @table
  1555. ;; The `@table' command produces two-column tables.
  1556. (put 'table 'texinfo-format 'texinfo-table)
  1557. (defun texinfo-table ()
  1558. (texinfo-push-stack
  1559. 'table
  1560. (progn (skip-chars-forward " \t")
  1561. (if (eolp)
  1562. "@asis"
  1563. (texinfo-parse-line-arg))))
  1564. (texinfo-discard-line-with-args)
  1565. (setq fill-column (- fill-column 5)))
  1566. (put 'table 'texinfo-item 'texinfo-table-item)
  1567. (defun texinfo-table-item ()
  1568. (let ((arg (texinfo-parse-arg-discard))
  1569. (itemfont (car (cdr (car texinfo-stack)))))
  1570. (insert ?\b itemfont ?\{ arg "}\n \n"))
  1571. (forward-line -2))
  1572. (put 'table 'texinfo-end 'texinfo-end-table)
  1573. (defun texinfo-end-table ()
  1574. (setq fill-column (+ fill-column 5))
  1575. (texinfo-discard-command)
  1576. (let ((stacktop
  1577. (texinfo-pop-stack 'table)))
  1578. (texinfo-do-itemize (nth 1 stacktop))))
  1579. ;; @description appears to be an undocumented variant on @table that
  1580. ;; does not require an arg. It fails in texinfo.tex 2.58 and is not
  1581. ;; part of makeinfo.c The command appears to be a relic of the past.
  1582. (put 'description 'texinfo-end 'texinfo-end-table)
  1583. (put 'description 'texinfo-format 'texinfo-description)
  1584. (defun texinfo-description ()
  1585. (texinfo-push-stack 'table "@asis")
  1586. (setq fill-column (- fill-column 5))
  1587. (texinfo-discard-line))
  1588. ;;; @ftable, @vtable
  1589. ;; The `@ftable' and `@vtable' commands are like the `@table' command
  1590. ;; but they also insert each entry in the first column of the table
  1591. ;; into the function or variable index.
  1592. ;; Handle the @ftable and @vtable commands:
  1593. (put 'ftable 'texinfo-format 'texinfo-ftable)
  1594. (put 'vtable 'texinfo-format 'texinfo-vtable)
  1595. (defun texinfo-ftable () (texinfo-indextable 'ftable))
  1596. (defun texinfo-vtable () (texinfo-indextable 'vtable))
  1597. (defun texinfo-indextable (table-type)
  1598. (texinfo-push-stack table-type (texinfo-parse-arg-discard))
  1599. (setq fill-column (- fill-column 5)))
  1600. ;; Handle the @item commands within ftable and vtable:
  1601. (put 'ftable 'texinfo-item 'texinfo-ftable-item)
  1602. (put 'vtable 'texinfo-item 'texinfo-vtable-item)
  1603. (defun texinfo-ftable-item () (texinfo-indextable-item 'texinfo-findex))
  1604. (defun texinfo-vtable-item () (texinfo-indextable-item 'texinfo-vindex))
  1605. (defun texinfo-indextable-item (index-type)
  1606. (let ((item (texinfo-parse-arg-discard))
  1607. (itemfont (car (cdr (car texinfo-stack))))
  1608. (indexvar index-type))
  1609. (insert ?\b itemfont ?\{ item "}\n \n")
  1610. (set indexvar
  1611. (cons
  1612. (list item texinfo-last-node)
  1613. (symbol-value indexvar)))
  1614. (forward-line -2)))
  1615. ;; Handle @end ftable, @end vtable
  1616. (put 'ftable 'texinfo-end 'texinfo-end-ftable)
  1617. (put 'vtable 'texinfo-end 'texinfo-end-vtable)
  1618. (defun texinfo-end-ftable () (texinfo-end-indextable 'ftable))
  1619. (defun texinfo-end-vtable () (texinfo-end-indextable 'vtable))
  1620. (defun texinfo-end-indextable (table-type)
  1621. (setq fill-column (+ fill-column 5))
  1622. (texinfo-discard-command)
  1623. (let ((stacktop
  1624. (texinfo-pop-stack table-type)))
  1625. (texinfo-do-itemize (nth 1 stacktop))))
  1626. ;;; @multitable ... @end multitable
  1627. ;; Produce a multi-column table, with as many columns as desired.
  1628. ;;
  1629. ;; A multi-column table has this template:
  1630. ;;
  1631. ;; @multitable {A1} {A2} {A3}
  1632. ;; @item A1 @tab A2 @tab A3
  1633. ;; @item B1 @tab B2 @tab B3
  1634. ;; @item C1 @tab C2 @tab C3
  1635. ;; @end multitable
  1636. ;;
  1637. ;; where the width of the text in brackets specifies the width of the
  1638. ;; respective column.
  1639. ;;
  1640. ;; Or else:
  1641. ;;
  1642. ;; @multitable @columnfractions .25 .3 .45
  1643. ;; @item A1 @tab A2 @tab A3
  1644. ;; @item B1 @tab B2 @tab B3
  1645. ;; @end multitable
  1646. ;;
  1647. ;; where the fractions specify the width of each column as a percent
  1648. ;; of the current width of the text (i.e., of the fill-column).
  1649. ;;
  1650. ;; Long lines of text are filled within columns.
  1651. ;;
  1652. ;; Using the Emacs Lisp formatter, texinfmt.el,
  1653. ;; the whitespace between columns can be increased by setting
  1654. ;; `texinfo-extra-inter-column-width' to a value greater than 0. By default,
  1655. ;; there is at least one blank space between columns.
  1656. ;;
  1657. ;; The Emacs Lisp formatter, texinfmt.el, ignores the following four
  1658. ;; commands that are defined in texinfo.tex for printed output.
  1659. ;;
  1660. ;; @multitableparskip,
  1661. ;; @multitableparindent,
  1662. ;; @multitablecolmargin,
  1663. ;; @multitablelinespace.
  1664. ;; How @multitable works.
  1665. ;; =====================
  1666. ;;
  1667. ;; `texinfo-multitable' reads the @multitable line and determines from it
  1668. ;; how wide each column should be.
  1669. ;;
  1670. ;; Also, it pushes this information, along with an identifying symbol,
  1671. ;; onto the `texinfo-stack'. At the @end multitable command, the stack
  1672. ;; is checked for its matching @multitable command, and then popped, or
  1673. ;; else an error is signaled. Also, this command pushes the location of
  1674. ;; the start of the table onto the stack.
  1675. ;;
  1676. ;; `texinfo-end-multitable' checks the `texinfo-stack' that the @end
  1677. ;; multitable truly is ending a corresponding beginning, and if it is,
  1678. ;; pops the stack.
  1679. ;;
  1680. ;; `texinfo-multitable-widths' is called by `texinfo-multitable'.
  1681. ;; The function returns a list of the widths of each column in a
  1682. ;; multi-column table, based on the information supplied by the arguments
  1683. ;; to the @multitable command (by arguments, I mean the text on the rest
  1684. ;; of the @multitable line, not the remainder of the multi-column table
  1685. ;; environment).
  1686. ;;
  1687. ;; `texinfo-multitable-item' formats a row within a multicolumn table.
  1688. ;; This command is executed when texinfmt sees @item inside @multitable.
  1689. ;; Cells in row are separated by `@tab's. Widths of cells are specified
  1690. ;; by the arguments in the @multitable line. Cells are filled. All cells
  1691. ;; are made to be the same height by padding their bottoms, as needed,
  1692. ;; with blanks.
  1693. ;;
  1694. ;; `texinfo-multitable-extract-row' is called by `texinfo-multitable-item'.
  1695. ;; This function returns the text in a multitable row, as a string.
  1696. ;; The start of a row is marked by an @item and the end of row is the
  1697. ;; beginning of next @item or beginning of the @end multitable line.
  1698. ;; Cells within a row are separated by @tab.
  1699. ;;
  1700. ;; Note that @tab, the cell separators, are not treated as independent
  1701. ;; Texinfo commands.
  1702. (defvar texinfo-extra-inter-column-width 0
  1703. "*Number of extra spaces between entries (columns) in @multitable.")
  1704. (defvar texinfo-multitable-buffer-name "*multitable-temporary-buffer*")
  1705. (defvar texinfo-multitable-rectangle-name "texinfo-multitable-temp-")
  1706. ;; These commands are defined in texinfo.tex for printed output.
  1707. (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
  1708. (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
  1709. (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
  1710. (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
  1711. (put 'multitable 'texinfo-format 'texinfo-multitable)
  1712. (defun texinfo-multitable ()
  1713. "Produce multi-column tables.
  1714. A multi-column table has this template:
  1715. @multitable {A1} {A2} {A3}
  1716. @item A1 @tab A2 @tab A3
  1717. @item B1 @tab B2 @tab B3
  1718. @item C1 @tab C2 @tab C3
  1719. @end multitable
  1720. where the width of the text in brackets specifies the width of the
  1721. respective column.
  1722. Or else:
  1723. @multitable @columnfractions .25 .3 .45
  1724. @item A1 @tab A2 @tab A3
  1725. @item B1 @tab B2 @tab B3
  1726. @end multitable
  1727. where the fractions specify the width of each column as a percent
  1728. of the current width of the text (i.e., of the `fill-column').
  1729. Long lines of text are filled within columns.
  1730. Using the Emacs Lisp formatter, texinfmt.el,
  1731. the whitespace between columns can be increased by setting
  1732. `texinfo-extra-inter-column-width' to a value greater than 0. By default,
  1733. there is at least one blank space between columns.
  1734. The Emacs Lisp formatter, texinfmt.el, ignores the following four
  1735. commands that are defined in texinfo.tex for printed output.
  1736. @multitableparskip,
  1737. @multitableparindent,
  1738. @multitablecolmargin,
  1739. @multitablelinespace."
  1740. ;; This function pushes information onto the `texinfo-stack'.
  1741. ;; A stack element consists of:
  1742. ;; - type-of-command, i.e., multitable
  1743. ;; - the information about column widths, and
  1744. ;; - the position of texinfo-command-start.
  1745. ;; e.g., ('multitable (1 2 3 4) 123)
  1746. ;; The command line is then deleted.
  1747. (texinfo-push-stack
  1748. 'multitable
  1749. ;; push width information on stack
  1750. (texinfo-multitable-widths))
  1751. (texinfo-discard-line-with-args))
  1752. (put 'multitable 'texinfo-end 'texinfo-end-multitable)
  1753. (defun texinfo-end-multitable ()
  1754. "Discard the @end multitable line and pop the stack of multitable."
  1755. (texinfo-discard-command)
  1756. (texinfo-pop-stack 'multitable))
  1757. (defun texinfo-multitable-widths ()
  1758. "Return list of widths of each column in a multi-column table."
  1759. (let (texinfo-multitable-width-list)
  1760. ;; Fractions format:
  1761. ;; @multitable @columnfractions .25 .3 .45
  1762. ;;
  1763. ;; Template format:
  1764. ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
  1765. ;; Place point before first argument
  1766. (skip-chars-forward " \t")
  1767. (cond
  1768. ;; Check for common misspelling
  1769. ((looking-at "@columnfraction ")
  1770. (error "In @multitable, @columnfractions misspelled"))
  1771. ;; Case 1: @columnfractions .25 .3 .45
  1772. ((looking-at "@columnfractions")
  1773. (forward-word 1)
  1774. (while (not (eolp))
  1775. (push (truncate
  1776. (1-
  1777. (* fill-column (read (get-buffer (current-buffer))))))
  1778. texinfo-multitable-width-list)))
  1779. ;;
  1780. ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
  1781. ((looking-at "{")
  1782. (let ((start-of-templates (point)))
  1783. (while (not (eolp))
  1784. (skip-chars-forward " \t")
  1785. (let* ((start-of-template (1+ (point)))
  1786. (end-of-template
  1787. ;; forward-sexp works with braces in Texinfo mode
  1788. (progn (forward-sexp 1) (1- (point)))))
  1789. (push (- end-of-template start-of-template)
  1790. texinfo-multitable-width-list)
  1791. ;; Remove carriage return from within a template, if any.
  1792. ;; This helps those those who want to use more than
  1793. ;; one line's worth of words in @multitable line.
  1794. (narrow-to-region start-of-template end-of-template)
  1795. (goto-char (point-min))
  1796. (while (search-forward "
  1797. " nil t)
  1798. (delete-char -1))
  1799. (goto-char (point-max))
  1800. (widen)
  1801. (forward-char 1)))))
  1802. ;;
  1803. ;; Case 3: Trouble
  1804. (t
  1805. (error
  1806. "You probably need to specify column widths for @multitable correctly.")))
  1807. ;; Check whether columns fit on page.
  1808. (let ((desired-columns
  1809. (+
  1810. ;; between column spaces
  1811. (length texinfo-multitable-width-list)
  1812. ;; additional between column spaces, if any
  1813. texinfo-extra-inter-column-width
  1814. ;; sum of spaces for each entry
  1815. (apply '+ texinfo-multitable-width-list))))
  1816. (if (> desired-columns fill-column)
  1817. (error
  1818. "Multi-column table width, %d chars, is greater than page width, %d chars."
  1819. desired-columns fill-column)))
  1820. texinfo-multitable-width-list))
  1821. ;; @item A1 @tab A2 @tab A3
  1822. (defun texinfo-multitable-extract-row ()
  1823. "Return multitable row, as a string.
  1824. End of row is beginning of next @item or beginning of @end.
  1825. Cells within rows are separated by @tab."
  1826. (skip-chars-forward " \t")
  1827. (let* ((start (point))
  1828. (end (progn
  1829. (re-search-forward "@item\\|@end")
  1830. (match-beginning 0)))
  1831. (row (progn (goto-char end)
  1832. (skip-chars-backward " ")
  1833. ;; remove whitespace at end of argument
  1834. (delete-region (point) end)
  1835. (buffer-substring-no-properties start (point)))))
  1836. (delete-region texinfo-command-start end)
  1837. row))
  1838. (put 'multitable 'texinfo-item 'texinfo-multitable-item)
  1839. (defun texinfo-multitable-item ()
  1840. "Format a row within a multicolumn table.
  1841. Cells in row are separated by @tab.
  1842. Widths of cells are specified by the arguments in the @multitable line.
  1843. All cells are made to be the same height.
  1844. This command is executed when texinfmt sees @item inside @multitable."
  1845. (let ((original-buffer (current-buffer))
  1846. (table-widths (reverse (car (cdr (car texinfo-stack)))))
  1847. (existing-fill-column fill-column)
  1848. start
  1849. end
  1850. (table-column 0)
  1851. (table-entry-height 0)
  1852. ;; unformatted row looks like: A1 @tab A2 @tab A3
  1853. ;; extract-row command deletes the source line in the table.
  1854. (unformatted-row (texinfo-multitable-extract-row)))
  1855. ;; Use a temporary buffer
  1856. (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
  1857. (delete-region (point-min) (point-max))
  1858. (insert unformatted-row)
  1859. (goto-char (point-min))
  1860. ;; 1. Check for correct number of @tab in line.
  1861. (let ((tab-number 1)) ; one @tab between two columns
  1862. (while (search-forward "@tab" nil t)
  1863. (setq tab-number (1+ tab-number)))
  1864. (let ((needed-tabs (- (length table-widths) tab-number)))
  1865. (when (> needed-tabs 0)
  1866. (goto-char (point-min))
  1867. (end-of-line)
  1868. (while (> needed-tabs 0)
  1869. (insert "@w{ }\n@tab")
  1870. (setq needed-tabs (1- needed-tabs))
  1871. (message
  1872. "Added @tabs and empty spaces to a @multitable row")))))
  1873. (goto-char (point-min))
  1874. ;; 2. Format each cell, and copy to a rectangle
  1875. ;; buffer looks like this: A1 @tab A2 @tab A3
  1876. ;; Cell #1: format up to @tab
  1877. ;; Cell #2: format up to @tab
  1878. ;; Cell #3: format up to eob
  1879. (while (not (eobp))
  1880. (setq start (point))
  1881. (setq end (save-excursion
  1882. (if (search-forward "@tab" nil 'move)
  1883. ;; Delete the @tab command, including the @-sign
  1884. (delete-region
  1885. (point)
  1886. (progn (forward-word -1) (1- (point)))))
  1887. (point)))
  1888. ;; Set fill-column *wider* than needed to produce inter-column space
  1889. (setq fill-column (+ 1
  1890. texinfo-extra-inter-column-width
  1891. (nth table-column table-widths)))
  1892. (narrow-to-region start end)
  1893. ;; Remove whitespace before and after entry.
  1894. (skip-chars-forward " ")
  1895. (delete-region (point) (line-beginning-position))
  1896. (goto-char (point-max))
  1897. (skip-chars-backward " ")
  1898. (delete-region (point) (line-end-position))
  1899. ;; Temporarily set texinfo-stack to nil so texinfo-format-scan
  1900. ;; does not see an unterminated @multitable.
  1901. (let (texinfo-stack) ; nil
  1902. (texinfo-format-scan))
  1903. (let (fill-prefix) ; no fill prefix
  1904. (fill-region (point-min) (point-max)))
  1905. (setq table-entry-height
  1906. (max table-entry-height (count-lines (point-min) (point-max))))
  1907. ;; 3. Move point to end of bottom line, and pad that line to fill column.
  1908. (goto-char (point-min))
  1909. (forward-line (1- table-entry-height))
  1910. (let* ((beg (point)) ; beginning of line
  1911. ;; add one more space for inter-column spacing
  1912. (needed-whitespace
  1913. (1+
  1914. (- fill-column
  1915. (-
  1916. (progn (end-of-line) (point)) ; end of existing line
  1917. beg)))))
  1918. (insert (make-string
  1919. (if (> needed-whitespace 0) needed-whitespace 1)
  1920. ? )))
  1921. ;; now, put formatted cell into a rectangle
  1922. (set (intern (concat texinfo-multitable-rectangle-name
  1923. (int-to-string table-column)))
  1924. (extract-rectangle (point-min) (point)))
  1925. (delete-region (point-min) (point))
  1926. (goto-char (point-max))
  1927. (setq table-column (1+ table-column))
  1928. (widen))
  1929. ;; 4. Add extra lines to rectangles so all are of same height
  1930. (let ((total-number-of-columns table-column)
  1931. (column-number 0)
  1932. here)
  1933. (while (> table-column 0)
  1934. (let ((this-rectangle (int-to-string table-column)))
  1935. (while (< (length this-rectangle) table-entry-height)
  1936. (setq this-rectangle (append this-rectangle '("")))))
  1937. (setq table-column (1- table-column)))
  1938. ;; 5. Insert formatted rectangles in original buffer
  1939. (switch-to-buffer original-buffer)
  1940. (open-line table-entry-height)
  1941. (while (< column-number total-number-of-columns)
  1942. (setq here (point))
  1943. (insert-rectangle
  1944. (eval (intern
  1945. (concat texinfo-multitable-rectangle-name
  1946. (int-to-string column-number)))))
  1947. (goto-char here)
  1948. (end-of-line)
  1949. (setq column-number (1+ column-number))))
  1950. (kill-buffer texinfo-multitable-buffer-name)
  1951. (setq fill-column existing-fill-column)))
  1952. ;;; @image
  1953. ;; Use only the FILENAME argument to the command.
  1954. ;; In Info, ignore the other arguments.
  1955. (put 'image 'texinfo-format 'texinfo-format-image)
  1956. (defun texinfo-format-image ()
  1957. "Insert an image from a file ending in .txt.
  1958. Use only the FILENAME arg; for Info, ignore the other arguments to @image."
  1959. (let ((args (texinfo-format-parse-args))
  1960. filename)
  1961. (when (null (nth 0 args))
  1962. (error "Invalid image command"))
  1963. (texinfo-discard-command)
  1964. ;; makeinfo uses FILENAME.txt
  1965. (setq filename (format "%s.txt" (nth 0 args)))
  1966. (message "Reading included file: %s" filename)
  1967. ;; verbatim for Info output
  1968. (goto-char (+ (point) (cadr (insert-file-contents filename))))
  1969. (message "Reading included file: %s...done" filename)))
  1970. ;;; @ifinfo, @iftex, @tex, @ifhtml, @html, @ifplaintext, @ifxml, @xml
  1971. ;; @ifnottex, @ifnotinfo, @ifnothtml, @ifnotplaintext, @ifnotxml
  1972. (put 'ifinfo 'texinfo-format 'texinfo-discard-line)
  1973. (put 'ifinfo 'texinfo-end 'texinfo-discard-command)
  1974. (put 'iftex 'texinfo-format 'texinfo-format-iftex)
  1975. (defun texinfo-format-iftex ()
  1976. (delete-region texinfo-command-start
  1977. (re-search-forward "@end iftex[ \t]*\n")))
  1978. (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
  1979. (defun texinfo-format-ifhtml ()
  1980. (delete-region texinfo-command-start
  1981. (re-search-forward "@end ifhtml[ \t]*\n")))
  1982. (put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
  1983. (defun texinfo-format-ifplaintext ()
  1984. (delete-region texinfo-command-start
  1985. (re-search-forward "@end ifplaintext[ \t]*\n")))
  1986. (put 'ifxml 'texinfo-format 'texinfo-format-ifxml)
  1987. (defun texinfo-format-ifxml ()
  1988. (delete-region texinfo-command-start
  1989. (progn (re-search-forward "^@end ifxml[ \t]*\n")
  1990. (point))))
  1991. (put 'tex 'texinfo-format 'texinfo-format-tex)
  1992. (defun texinfo-format-tex ()
  1993. (delete-region texinfo-command-start
  1994. (re-search-forward "@end tex[ \t]*\n")))
  1995. (put 'html 'texinfo-format 'texinfo-format-html)
  1996. (defun texinfo-format-html ()
  1997. (delete-region texinfo-command-start
  1998. (re-search-forward "@end html[ \t]*\n")))
  1999. (put 'xml 'texinfo-format 'texinfo-format-xml)
  2000. (defun texinfo-format-xml ()
  2001. (delete-region texinfo-command-start
  2002. (progn (re-search-forward "^@end xml[ \t]*\n")
  2003. (point))))
  2004. (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
  2005. (defun texinfo-format-ifnotinfo ()
  2006. (delete-region texinfo-command-start
  2007. (re-search-forward "@end ifnotinfo[ \t]*\n")))
  2008. (put 'ifnotplaintext 'texinfo-format 'texinfo-discard-line)
  2009. (put 'ifnotplaintext 'texinfo-end 'texinfo-discard-command)
  2010. (put 'ifnottex 'texinfo-format 'texinfo-discard-line)
  2011. (put 'ifnottex 'texinfo-end 'texinfo-discard-command)
  2012. (put 'ifnothtml 'texinfo-format 'texinfo-discard-line)
  2013. (put 'ifnothtml 'texinfo-end 'texinfo-discard-command)
  2014. (put 'ifnotxml 'texinfo-format 'texinfo-discard-line)
  2015. (put 'ifnotxml 'texinfo-end 'texinfo-discard-command)
  2016. ;;; @titlepage
  2017. (put 'titlepage 'texinfo-format 'texinfo-format-titlepage)
  2018. (defun texinfo-format-titlepage ()
  2019. (delete-region texinfo-command-start
  2020. (re-search-forward "@end titlepage[ \t]*\n")))
  2021. (put 'endtitlepage 'texinfo-format 'texinfo-discard-line)
  2022. ;; @titlespec an alternative titling command; ignored by Info
  2023. (put 'titlespec 'texinfo-format 'texinfo-format-titlespec)
  2024. (defun texinfo-format-titlespec ()
  2025. (delete-region texinfo-command-start
  2026. (re-search-forward "@end titlespec[ \t]*\n")))
  2027. (put 'endtitlespec 'texinfo-format 'texinfo-discard-line)
  2028. ;;; @today
  2029. (put 'today 'texinfo-format 'texinfo-format-today)
  2030. ;; Produces Day Month Year style of output. eg `1 Jan 1900'
  2031. ;; The `@today{}' command requires a pair of braces, like `@dots{}'.
  2032. (defun texinfo-format-today ()
  2033. (texinfo-parse-arg-discard)
  2034. (insert (format-time-string "%e %b %Y")))
  2035. ;;; @timestamp{}
  2036. ;; Produce `Day Month Year Hour:Min' style of output.
  2037. ;; eg `1 Jan 1900 13:52'
  2038. (put 'timestamp 'texinfo-format 'texinfo-format-timestamp)
  2039. ;; The `@timestamp{}' command requires a pair of braces, like `@dots{}'.
  2040. (defun texinfo-format-timestamp ()
  2041. "Insert the current local time and date."
  2042. (texinfo-parse-arg-discard)
  2043. ;; For seconds and time zone, replace format string with "%e %b %Y %T %Z"
  2044. (insert (format-time-string "%e %b %Y %R")))
  2045. ;;; @ignore
  2046. (put 'ignore 'texinfo-format 'texinfo-format-ignore)
  2047. (defun texinfo-format-ignore ()
  2048. (delete-region texinfo-command-start
  2049. (re-search-forward "@end ignore[ \t]*\n")))
  2050. (put 'endignore 'texinfo-format 'texinfo-discard-line)
  2051. ;;; Define the Info enclosure command: @definfoenclose
  2052. ;; A `@definfoenclose' command may be used to define a highlighting
  2053. ;; command for Info, but not for TeX. A command defined using
  2054. ;; `@definfoenclose' marks text by enclosing it in strings that precede
  2055. ;; and follow the text.
  2056. ;;
  2057. ;; Presumably, if you define a command with `@definfoenclose` for Info,
  2058. ;; you will also define the same command in the TeX definitions file,
  2059. ;; `texinfo.tex' in a manner appropriate for typesetting.
  2060. ;;
  2061. ;; Write a `@definfoenclose' command on a line and follow it with three
  2062. ;; arguments separated by commas (commas are used as separators in an
  2063. ;; `@node' line in the same way). The first argument to
  2064. ;; `@definfoenclose' is the @-command name \(without the `@'\); the
  2065. ;; second argument is the Info start delimiter string; and the third
  2066. ;; argument is the Info end delimiter string. The latter two arguments
  2067. ;; enclose the highlighted text in the Info file. A delimiter string
  2068. ;; may contain spaces. Neither the start nor end delimiter is
  2069. ;; required. However, if you do not provide a start delimiter, you
  2070. ;; must follow the command name with two commas in a row; otherwise,
  2071. ;; the Info formatting commands will misinterpret the end delimiter
  2072. ;; string as a start delimiter string.
  2073. ;;
  2074. ;; If you do a @definfoenclose{} on the name of a pre-defined macro (such
  2075. ;; as @emph{}, @strong{}, @tt{}, or @i{}) the enclosure definition will
  2076. ;; override the built-in definition.
  2077. ;;
  2078. ;; An enclosure command defined this way takes one argument in braces.
  2079. ;;
  2080. ;; For example, you can write:
  2081. ;;
  2082. ;; @ifinfo
  2083. ;; @definfoenclose phoo, //, \\
  2084. ;; @end ifinfo
  2085. ;;
  2086. ;; near the beginning of a Texinfo file at the beginning of the lines
  2087. ;; to define `@phoo' as an Info formatting command that inserts `//'
  2088. ;; before and `\\' after the argument to `@phoo'. You can then write
  2089. ;; `@phoo{bar}' wherever you want `//bar\\' highlighted in Info.
  2090. ;;
  2091. ;; Also, for TeX formatting, you could write
  2092. ;;
  2093. ;; @iftex
  2094. ;; @global@let@phoo=@i
  2095. ;; @end iftex
  2096. ;;
  2097. ;; to define `@phoo' as a command that causes TeX to typeset
  2098. ;; the argument to `@phoo' in italics.
  2099. ;;
  2100. ;; Note that each definition applies to its own formatter: one for TeX,
  2101. ;; the other for texinfo-format-buffer or texinfo-format-region.
  2102. ;;
  2103. ;; Here is another example: write
  2104. ;;
  2105. ;; @definfoenclose headword, , :
  2106. ;;
  2107. ;; near the beginning of the file, to define `@headword' as an Info
  2108. ;; formatting command that inserts nothing before and a colon after the
  2109. ;; argument to `@headword'.
  2110. (put 'definfoenclose 'texinfo-format 'texinfo-define-info-enclosure)
  2111. (defun texinfo-define-info-enclosure ()
  2112. (let* ((args (texinfo-format-parse-line-args))
  2113. (command-name (nth 0 args))
  2114. (beginning-delimiter (or (nth 1 args) ""))
  2115. (end-delimiter (or (nth 2 args) "")))
  2116. (texinfo-discard-command)
  2117. (push (list command-name
  2118. (list
  2119. beginning-delimiter
  2120. end-delimiter))
  2121. texinfo-enclosure-list)))
  2122. ;;; @alias
  2123. (put 'alias 'texinfo-format 'texinfo-alias)
  2124. (defun texinfo-alias ()
  2125. (let ((start (1- (point)))
  2126. args)
  2127. (skip-chars-forward " ")
  2128. (setq texinfo-command-end (line-end-position))
  2129. (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
  2130. (error "Invalid alias command")
  2131. (push (cons
  2132. (match-string-no-properties 1)
  2133. (match-string-no-properties 2))
  2134. texinfo-alias-list)
  2135. (texinfo-discard-command))))
  2136. ;;; @var, @code and the like
  2137. (put 'var 'texinfo-format 'texinfo-format-var)
  2138. ;; @sc a small caps font for TeX; formatted as `var' in Info
  2139. (put 'sc 'texinfo-format 'texinfo-format-var)
  2140. ;; @acronym for abbreviations in all caps, such as `NASA'.
  2141. ;; Convert all letters to uppercase if they are not already.
  2142. (put 'acronym 'texinfo-format 'texinfo-format-var)
  2143. (defun texinfo-format-var ()
  2144. (let ((arg (texinfo-parse-expanded-arg)))
  2145. (texinfo-discard-command)
  2146. (insert (upcase arg))))
  2147. (put 'cite 'texinfo-format 'texinfo-format-code)
  2148. (put 'code 'texinfo-format 'texinfo-format-code)
  2149. ;; @command (for command names)
  2150. (put 'command 'texinfo-format 'texinfo-format-code)
  2151. ;; @env (for environment variables)
  2152. (put 'env 'texinfo-format 'texinfo-format-code)
  2153. (put 'file 'texinfo-format 'texinfo-format-code)
  2154. (put 'samp 'texinfo-format 'texinfo-format-code)
  2155. (put 'url 'texinfo-format 'texinfo-format-code)
  2156. (defun texinfo-format-code ()
  2157. (insert "`" (texinfo-parse-arg-discard) "'")
  2158. (goto-char texinfo-command-start))
  2159. ;; @option (for command-line options) must be different from @code
  2160. ;; because of its special formatting in @table; namely that it does
  2161. ;; not lead to inserted ` ... ' in a table, but does elsewhere.
  2162. (put 'option 'texinfo-format 'texinfo-format-option)
  2163. (defun texinfo-format-option ()
  2164. "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
  2165. ;; `looking-at-backward' not available in v. 18.57, 20.2
  2166. (if (not (search-backward "" ; searched-for character is a control-H
  2167. (line-beginning-position)
  2168. t))
  2169. (insert "`" (texinfo-parse-arg-discard) "'")
  2170. (insert (texinfo-parse-arg-discard)))
  2171. (goto-char texinfo-command-start))
  2172. (put 'emph 'texinfo-format 'texinfo-format-emph)
  2173. (put 'strong 'texinfo-format 'texinfo-format-emph)
  2174. (defun texinfo-format-emph ()
  2175. (insert "*" (texinfo-parse-arg-discard) "*")
  2176. (goto-char texinfo-command-start))
  2177. (put 'dfn 'texinfo-format 'texinfo-format-defn)
  2178. (put 'defn 'texinfo-format 'texinfo-format-defn)
  2179. (defun texinfo-format-defn ()
  2180. (insert "\"" (texinfo-parse-arg-discard) "\"")
  2181. (goto-char texinfo-command-start))
  2182. (put 'email 'texinfo-format 'texinfo-format-email)
  2183. (defun texinfo-format-email ()
  2184. "Format email address and optional following full name.
  2185. Insert full name, if present, followed by email address
  2186. surrounded by in angle brackets."
  2187. (let ((args (texinfo-format-parse-args)))
  2188. (texinfo-discard-command)
  2189. ;; if full-name
  2190. (if (nth 1 args)
  2191. (insert (nth 1 args) " "))
  2192. (insert "<" (nth 0 args) ">")))
  2193. (put 'key 'texinfo-format 'texinfo-format-key)
  2194. ;; I've decided not want to have angle brackets around these -- rms.
  2195. (defun texinfo-format-key ()
  2196. (insert (texinfo-parse-arg-discard))
  2197. (goto-char texinfo-command-start))
  2198. ;; @verb{<char>TEXT<char>} (in `makeinfo' 4.1 and later)
  2199. (put 'verb 'texinfo-format 'texinfo-format-verb)
  2200. (defun texinfo-format-verb ()
  2201. "Format text between non-quoted unique delimiter characters verbatim.
  2202. Enclose the verbatim text, including the delimiters, in braces. Print
  2203. text exactly as written (but not the delimiters) in a fixed-width.
  2204. For example, @verb\{|@|\} results in @ and
  2205. @verb\{+@'e?`!`+} results in @'e?`!`."
  2206. (let ((delimiter (buffer-substring-no-properties
  2207. (1+ texinfo-command-end) (+ 2 texinfo-command-end))))
  2208. (unless (looking-at "{")
  2209. (error "Not found: @verb start brace"))
  2210. (delete-region texinfo-command-start (+ 2 texinfo-command-end))
  2211. (search-forward delimiter))
  2212. (delete-char -1)
  2213. (unless (looking-at "}")
  2214. (error "Not found: @verb end brace"))
  2215. (delete-char 1))
  2216. ;; as of 2002 Dec 10
  2217. ;; see (texinfo)Block Enclosing Commands
  2218. ;; need: @verbatim
  2219. ;; as of 2002 Dec 10
  2220. ;; see (texinfo)verbatiminclude
  2221. ;; need: @verbatiminclude FILENAME
  2222. (put 'bullet 'texinfo-format 'texinfo-format-bullet)
  2223. (defun texinfo-format-bullet ()
  2224. "Insert an asterisk.
  2225. If used within a line, follow `@bullet' with braces."
  2226. (texinfo-optional-braces-discard)
  2227. (insert "*"))
  2228. ;;; @kbd
  2229. ;; Inside of @example ... @end example and similar environments,
  2230. ;; @kbd does nothing; but outside of such environments, it places
  2231. ;; single quotation marks around its argument.
  2232. (defvar texinfo-format-kbd-regexp
  2233. (concat
  2234. "^@"
  2235. "\\("
  2236. "display\\|"
  2237. "example\\|"
  2238. "smallexample\\|"
  2239. "lisp\\|"
  2240. "smalllisp"
  2241. "\\)")
  2242. "Regexp matching environments in which @kbd does not put `...' around arg.")
  2243. (defvar texinfo-format-kbd-end-regexp
  2244. (concat
  2245. "^@end "
  2246. "\\("
  2247. "display\\|"
  2248. "example\\|"
  2249. "smallexample\\|"
  2250. "lisp\\|"
  2251. "smalllisp"
  2252. "\\)")
  2253. "Regexp specifying end of environments in which @kbd does not put `...'
  2254. around argument. (See `texinfo-format-kbd-regexp')")
  2255. (put 'kbd 'texinfo-format 'texinfo-format-kbd)
  2256. (defun texinfo-format-kbd ()
  2257. "Place single quote marks around arg, except in @example and similar."
  2258. ;; Search forward for @end example closer than an @example.
  2259. ;; Can stop search at nearest @node or texinfo-section-types-regexp
  2260. (let* ((stop
  2261. (save-excursion
  2262. (re-search-forward
  2263. (concat "^@node\\|\\(" texinfo-section-types-regexp "\\)")
  2264. nil
  2265. 'move-to-end) ; if necessary, return point at end of buffer
  2266. (point)))
  2267. (example-location
  2268. (save-excursion
  2269. (re-search-forward texinfo-format-kbd-regexp stop 'move-to-end)
  2270. (point)))
  2271. (end-example-location
  2272. (save-excursion
  2273. (re-search-forward texinfo-format-kbd-end-regexp stop 'move-to-end)
  2274. (point))))
  2275. ;; If inside @example, @end example will be closer than @example
  2276. ;; or end of search i.e., end-example-location less than example-location
  2277. (if (>= end-example-location example-location)
  2278. ;; outside an @example or equivalent
  2279. (insert "`" (texinfo-parse-arg-discard) "'")
  2280. ;; else, in @example; do not surround with `...'
  2281. (insert (texinfo-parse-arg-discard)))
  2282. (goto-char texinfo-command-start)))
  2283. ;;; @example, @lisp, @quotation, @display, @smalllisp, @smallexample,
  2284. ;; @smalldisplay
  2285. (put 'display 'texinfo-format 'texinfo-format-example)
  2286. (put 'smalldisplay 'texinfo-format 'texinfo-format-example)
  2287. (put 'example 'texinfo-format 'texinfo-format-example)
  2288. (put 'lisp 'texinfo-format 'texinfo-format-example)
  2289. (put 'quotation 'texinfo-format 'texinfo-format-example)
  2290. (put 'smallexample 'texinfo-format 'texinfo-format-example)
  2291. (put 'smalllisp 'texinfo-format 'texinfo-format-example)
  2292. (defun texinfo-format-example ()
  2293. (texinfo-push-stack 'example nil)
  2294. (setq fill-column (- fill-column 5))
  2295. (texinfo-discard-line))
  2296. (put 'example 'texinfo-end 'texinfo-end-example)
  2297. (put 'display 'texinfo-end 'texinfo-end-example)
  2298. (put 'smalldisplay 'texinfo-end 'texinfo-end-example)
  2299. (put 'lisp 'texinfo-end 'texinfo-end-example)
  2300. (put 'quotation 'texinfo-end 'texinfo-end-example)
  2301. (put 'smallexample 'texinfo-end 'texinfo-end-example)
  2302. (put 'smalllisp 'texinfo-end 'texinfo-end-example)
  2303. (defun texinfo-end-example ()
  2304. (setq fill-column (+ fill-column 5))
  2305. (texinfo-discard-command)
  2306. (let ((stacktop
  2307. (texinfo-pop-stack 'example)))
  2308. (texinfo-do-itemize (nth 1 stacktop))))
  2309. (put 'exdent 'texinfo-format 'texinfo-format-exdent)
  2310. (defun texinfo-format-exdent ()
  2311. (texinfo-discard-command)
  2312. (delete-region (point)
  2313. (progn
  2314. (skip-chars-forward " ")
  2315. (point)))
  2316. (insert ?\b)
  2317. ;; Cancel out the deletion that texinfo-do-itemize
  2318. ;; is going to do at the end of this line.
  2319. (save-excursion
  2320. (end-of-line)
  2321. (insert "\n ")))
  2322. ;; @direntry and @dircategory
  2323. (put 'direntry 'texinfo-format 'texinfo-format-direntry)
  2324. (defun texinfo-format-direntry ()
  2325. (texinfo-push-stack 'direntry nil)
  2326. (texinfo-discard-line)
  2327. (insert "START-INFO-DIR-ENTRY\n"))
  2328. (put 'direntry 'texinfo-end 'texinfo-end-direntry)
  2329. (defun texinfo-end-direntry ()
  2330. (texinfo-discard-command)
  2331. (insert "END-INFO-DIR-ENTRY\n\n")
  2332. (texinfo-pop-stack 'direntry))
  2333. (put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
  2334. (defun texinfo-format-dircategory ()
  2335. (let ((str (texinfo-parse-arg-discard)))
  2336. (delete-region (point)
  2337. (progn
  2338. (skip-chars-forward " ")
  2339. (point)))
  2340. (insert "INFO-DIR-SECTION " str "\n")))
  2341. ;;; @cartouche
  2342. ;; The @cartouche command is a noop in Info; in a printed manual,
  2343. ;; it makes a box with rounded corners.
  2344. (put 'cartouche 'texinfo-format 'texinfo-discard-line)
  2345. (put 'cartouche 'texinfo-end 'texinfo-discard-command)
  2346. ;;; @flushleft and @format
  2347. ;; The @flushleft command left justifies every line but leaves the
  2348. ;; right end ragged. As far as Info is concerned, @flushleft is a
  2349. ;; `do-nothing' command
  2350. ;; The @format command is similar to @example except that it does not
  2351. ;; indent; this means that in Info, @format is similar to @flushleft.
  2352. (put 'format 'texinfo-format 'texinfo-format-flushleft)
  2353. (put 'smallformat 'texinfo-format 'texinfo-format-flushleft)
  2354. (put 'flushleft 'texinfo-format 'texinfo-format-flushleft)
  2355. (defun texinfo-format-flushleft ()
  2356. (texinfo-discard-line))
  2357. (put 'format 'texinfo-end 'texinfo-end-flushleft)
  2358. (put 'smallformat 'texinfo-end 'texinfo-end-flushleft)
  2359. (put 'flushleft 'texinfo-end 'texinfo-end-flushleft)
  2360. (defun texinfo-end-flushleft ()
  2361. (texinfo-discard-command))
  2362. ;;; @flushright
  2363. ;; The @flushright command right justifies every line but leaves the
  2364. ;; left end ragged. Spaces and tabs at the right ends of lines are
  2365. ;; removed so that visible text lines up on the right side.
  2366. (put 'flushright 'texinfo-format 'texinfo-format-flushright)
  2367. (defun texinfo-format-flushright ()
  2368. (texinfo-push-stack 'flushright nil)
  2369. (texinfo-discard-line))
  2370. (put 'flushright 'texinfo-end 'texinfo-end-flushright)
  2371. (defun texinfo-end-flushright ()
  2372. (texinfo-discard-command)
  2373. (let ((stacktop
  2374. (texinfo-pop-stack 'flushright)))
  2375. (texinfo-do-flushright (nth 1 stacktop))))
  2376. (defun texinfo-do-flushright (from)
  2377. (save-excursion
  2378. (while (progn (forward-line -1)
  2379. (>= (point) from))
  2380. (beginning-of-line)
  2381. (insert
  2382. (make-string
  2383. (- fill-column
  2384. (save-excursion
  2385. (end-of-line)
  2386. (skip-chars-backward " \t")
  2387. (delete-region (point) (progn (end-of-line) (point)))
  2388. (current-column)))
  2389. ? )))))
  2390. ;;; @ctrl, @TeX, @copyright, @minus, @dots, @enddots, @pounds
  2391. (put 'ctrl 'texinfo-format 'texinfo-format-ctrl)
  2392. (defun texinfo-format-ctrl ()
  2393. (let ((str (texinfo-parse-arg-discard)))
  2394. (insert (logand 31 (aref str 0)))))
  2395. (put 'TeX 'texinfo-format 'texinfo-format-TeX)
  2396. (defun texinfo-format-TeX ()
  2397. (texinfo-parse-arg-discard)
  2398. (insert "TeX"))
  2399. (put 'copyright 'texinfo-format 'texinfo-format-copyright)
  2400. (defun texinfo-format-copyright ()
  2401. (texinfo-parse-arg-discard)
  2402. (insert "(C)"))
  2403. (put 'minus 'texinfo-format 'texinfo-format-minus)
  2404. (defun texinfo-format-minus ()
  2405. "Insert a minus sign.
  2406. If used within a line, follow `@minus' with braces."
  2407. (texinfo-optional-braces-discard)
  2408. (insert "-"))
  2409. (put 'dots 'texinfo-format 'texinfo-format-dots)
  2410. (defun texinfo-format-dots ()
  2411. (texinfo-parse-arg-discard)
  2412. (insert "..."))
  2413. (put 'enddots 'texinfo-format 'texinfo-format-enddots)
  2414. (defun texinfo-format-enddots ()
  2415. (texinfo-parse-arg-discard)
  2416. (insert "...."))
  2417. (put 'pounds 'texinfo-format 'texinfo-format-pounds)
  2418. (defun texinfo-format-pounds ()
  2419. (texinfo-parse-arg-discard)
  2420. (insert "#"))
  2421. ;;; Refilling and indenting: @refill, @paragraphindent, @noindent
  2422. ;; Indent only those paragraphs that are refilled as a result of an
  2423. ;; @refill command.
  2424. ;; * If the value is `asis', do not change the existing indentation at
  2425. ;; the starts of paragraphs.
  2426. ;; * If the value zero, delete any existing indentation.
  2427. ;; * If the value is greater than zero, indent each paragraph by that
  2428. ;; number of spaces.
  2429. ;; But do not refill paragraphs with an @refill command that are
  2430. ;; preceded by @noindent or are part of a table, list, or deffn.
  2431. (defvar texinfo-paragraph-indent "asis"
  2432. "Number of spaces for @refill to indent a paragraph; else to leave as is.")
  2433. (put 'paragraphindent 'texinfo-format 'texinfo-paragraphindent)
  2434. (defun texinfo-paragraphindent ()
  2435. "Specify the number of spaces for @refill to indent a paragraph.
  2436. Default is to leave the number of spaces as is."
  2437. (let ((arg (texinfo-parse-arg-discard)))
  2438. (if (string= "asis" arg)
  2439. (setq texinfo-paragraph-indent "asis")
  2440. (setq texinfo-paragraph-indent (string-to-number arg)))))
  2441. (put 'refill 'texinfo-format 'texinfo-format-refill)
  2442. (defun texinfo-format-refill ()
  2443. "Refill paragraph. Also, indent first line as set by @paragraphindent.
  2444. Default is to leave paragraph indentation as is."
  2445. (texinfo-discard-command)
  2446. (let ((position (point-marker)))
  2447. (forward-paragraph -1)
  2448. (if (looking-at "[ \t\n]*$") (forward-line 1))
  2449. ;; Do not indent if an entry in a list, table, or deffn,
  2450. ;; or if paragraph is preceded by @noindent.
  2451. ;; Otherwise, indent
  2452. (cond
  2453. ;; delete a @noindent line and do not indent paragraph
  2454. ((save-excursion (forward-line -1)
  2455. (looking-at "^@noindent"))
  2456. (forward-line -1)
  2457. (delete-region (point) (progn (forward-line 1) (point))))
  2458. ;; do nothing if "asis"
  2459. ((equal texinfo-paragraph-indent "asis"))
  2460. ;; do no indenting in list, etc.
  2461. ((> texinfo-stack-depth 0))
  2462. ;; otherwise delete existing whitespace and indent
  2463. (t
  2464. (delete-region (point) (progn (skip-chars-forward " \t") (point)))
  2465. (insert (make-string texinfo-paragraph-indent ? ))))
  2466. (forward-paragraph 1)
  2467. (forward-line -1)
  2468. (end-of-line)
  2469. ;; Do not fill a section title line with asterisks, hyphens, etc. that
  2470. ;; are used to underline it. This could occur if the line following
  2471. ;; the underlining is not an index entry and has text within it.
  2472. (let* ((previous-paragraph-separate paragraph-separate)
  2473. (paragraph-separate
  2474. (concat paragraph-separate "\\|[-=.]+\\|\\*\\*+"))
  2475. (previous-paragraph-start paragraph-start)
  2476. (paragraph-start
  2477. (concat paragraph-start "\\|[-=.]+\\|\\*\\*+")))
  2478. (unwind-protect
  2479. (fill-paragraph nil)
  2480. (setq paragraph-separate previous-paragraph-separate)
  2481. (setq paragraph-start previous-paragraph-start)))
  2482. (goto-char position)))
  2483. (put 'noindent 'texinfo-format 'texinfo-noindent)
  2484. (defun texinfo-noindent ()
  2485. (save-excursion
  2486. (forward-paragraph 1)
  2487. (if (search-backward "@refill" (line-beginning-position 0) t)
  2488. () ; leave @noindent command so @refill command knows not to indent
  2489. ;; else
  2490. (texinfo-discard-line))))
  2491. ;;; Index generation
  2492. (put 'vindex 'texinfo-format 'texinfo-format-vindex)
  2493. (defun texinfo-format-vindex ()
  2494. (texinfo-index 'texinfo-vindex))
  2495. (put 'cindex 'texinfo-format 'texinfo-format-cindex)
  2496. (defun texinfo-format-cindex ()
  2497. (texinfo-index 'texinfo-cindex))
  2498. (put 'findex 'texinfo-format 'texinfo-format-findex)
  2499. (defun texinfo-format-findex ()
  2500. (texinfo-index 'texinfo-findex))
  2501. (put 'pindex 'texinfo-format 'texinfo-format-pindex)
  2502. (defun texinfo-format-pindex ()
  2503. (texinfo-index 'texinfo-pindex))
  2504. (put 'tindex 'texinfo-format 'texinfo-format-tindex)
  2505. (defun texinfo-format-tindex ()
  2506. (texinfo-index 'texinfo-tindex))
  2507. (put 'kindex 'texinfo-format 'texinfo-format-kindex)
  2508. (defun texinfo-format-kindex ()
  2509. (texinfo-index 'texinfo-kindex))
  2510. (defun texinfo-index (indexvar)
  2511. (let ((arg (texinfo-parse-expanded-arg)))
  2512. (texinfo-discard-command)
  2513. (set indexvar
  2514. (cons (list arg
  2515. texinfo-last-node
  2516. ;; Region formatting may not provide last node position.
  2517. (if texinfo-last-node-pos
  2518. (1+ (count-lines texinfo-last-node-pos (point)))
  2519. 1))
  2520. (symbol-value indexvar)))))
  2521. (defvar texinfo-indexvar-alist
  2522. '(("cp" . texinfo-cindex)
  2523. ("fn" . texinfo-findex)
  2524. ("vr" . texinfo-vindex)
  2525. ("tp" . texinfo-tindex)
  2526. ("pg" . texinfo-pindex)
  2527. ("ky" . texinfo-kindex)))
  2528. ;;; @defindex @defcodeindex
  2529. (put 'defindex 'texinfo-format 'texinfo-format-defindex)
  2530. (put 'defcodeindex 'texinfo-format 'texinfo-format-defindex)
  2531. (defun texinfo-format-defindex ()
  2532. (let* ((index-name (texinfo-parse-arg-discard)) ; eg: `aa'
  2533. (indexing-command (intern (concat index-name "index")))
  2534. (index-formatting-command ; eg: `texinfo-format-aaindex'
  2535. (intern (concat "texinfo-format-" index-name "index")))
  2536. (index-alist-name ; eg: `texinfo-aaindex'
  2537. (intern (concat "texinfo-" index-name "index"))))
  2538. (set index-alist-name nil)
  2539. (put indexing-command ; eg, aaindex
  2540. 'texinfo-format
  2541. index-formatting-command) ; eg, texinfo-format-aaindex
  2542. ;; eg: "aa" . texinfo-aaindex
  2543. (or (assoc index-name texinfo-indexvar-alist)
  2544. (push (cons index-name
  2545. index-alist-name)
  2546. texinfo-indexvar-alist))
  2547. (fset index-formatting-command
  2548. (list 'lambda 'nil
  2549. (list 'texinfo-index
  2550. (list 'quote index-alist-name))))))
  2551. ;;; @synindex @syncodeindex
  2552. (put 'synindex 'texinfo-format 'texinfo-format-synindex)
  2553. (put 'syncodeindex 'texinfo-format 'texinfo-format-synindex)
  2554. (defun texinfo-format-synindex ()
  2555. (let* ((args (texinfo-parse-arg-discard))
  2556. (second (cdr (read-from-string args)))
  2557. (joiner (symbol-name (car (read-from-string args))))
  2558. (joined (symbol-name (car (read-from-string args second)))))
  2559. (if (assoc joiner texinfo-short-index-cmds-alist)
  2560. (put
  2561. (cdr (assoc joiner texinfo-short-index-cmds-alist))
  2562. 'texinfo-format
  2563. (or (cdr (assoc joined texinfo-short-index-format-cmds-alist))
  2564. (intern (concat "texinfo-format-" joined "index"))))
  2565. (put
  2566. (intern (concat joiner "index"))
  2567. 'texinfo-format
  2568. (or (cdr(assoc joined texinfo-short-index-format-cmds-alist))
  2569. (intern (concat "texinfo-format-" joined "index")))))))
  2570. (defconst texinfo-short-index-cmds-alist
  2571. '(("cp" . cindex)
  2572. ("fn" . findex)
  2573. ("vr" . vindex)
  2574. ("tp" . tindex)
  2575. ("pg" . pindex)
  2576. ("ky" . kindex)))
  2577. (defconst texinfo-short-index-format-cmds-alist
  2578. '(("cp" . texinfo-format-cindex)
  2579. ("fn" . texinfo-format-findex)
  2580. ("vr" . texinfo-format-vindex)
  2581. ("tp" . texinfo-format-tindex)
  2582. ("pg" . texinfo-format-pindex)
  2583. ("ky" . texinfo-format-kindex)))
  2584. ;;; @printindex
  2585. (put 'printindex 'texinfo-format 'texinfo-format-printindex)
  2586. (defun texinfo-format-printindex ()
  2587. (let* ((arg (texinfo-parse-arg-discard))
  2588. (fmt (cdr (assoc arg texinfo-short-index-format-cmds-alist)))
  2589. (index-list (delq nil (mapcar (lambda (e)
  2590. (and (eq fmt (get (cdr e) 'texinfo-format))
  2591. (cdr (assoc (car e) texinfo-indexvar-alist))))
  2592. texinfo-short-index-cmds-alist)))
  2593. (indexelts (apply #'append nil (mapcar #'symbol-value index-list)))
  2594. opoint)
  2595. (insert "\n* Menu:\n\n")
  2596. (setq opoint (point))
  2597. (texinfo-print-index nil indexelts)
  2598. (shell-command-on-region opoint (point) "sort -fd" 1)))
  2599. (defun texinfo-print-index (file indexelts)
  2600. (while indexelts
  2601. (if (stringp (car (car indexelts)))
  2602. (progn
  2603. (insert "* " (car (car indexelts)) ": " )
  2604. (indent-to 32)
  2605. (insert
  2606. (if file (concat "(" file ")") "")
  2607. (nth 1 (car indexelts)) ".")
  2608. (indent-to 54)
  2609. (insert
  2610. (if (nth 2 (car indexelts))
  2611. (format " (line %3d)" (1+ (nth 2 (car indexelts))))
  2612. "")
  2613. "\n"))
  2614. ;; index entries from @include'd file
  2615. (texinfo-print-index (nth 1 (car indexelts))
  2616. (nth 2 (car indexelts))))
  2617. (setq indexelts (cdr indexelts))))
  2618. ;;; Glyphs: @equiv, @error, etc
  2619. ;; @equiv to show that two expressions are equivalent
  2620. ;; @error to show an error message
  2621. ;; @expansion to show what a macro expands to
  2622. ;; @point to show the location of point in an example
  2623. ;; @print to show what an evaluated expression prints
  2624. ;; @result to indicate the value returned by an expression
  2625. (put 'equiv 'texinfo-format 'texinfo-format-equiv)
  2626. (defun texinfo-format-equiv ()
  2627. (texinfo-parse-arg-discard)
  2628. (insert "=="))
  2629. (put 'error 'texinfo-format 'texinfo-format-error)
  2630. (defun texinfo-format-error ()
  2631. (texinfo-parse-arg-discard)
  2632. (insert "error-->"))
  2633. (put 'expansion 'texinfo-format 'texinfo-format-expansion)
  2634. (defun texinfo-format-expansion ()
  2635. (texinfo-parse-arg-discard)
  2636. (insert "==>"))
  2637. (put 'point 'texinfo-format 'texinfo-format-point)
  2638. (defun texinfo-format-point ()
  2639. (texinfo-parse-arg-discard)
  2640. (insert "-!-"))
  2641. (put 'print 'texinfo-format 'texinfo-format-print)
  2642. (defun texinfo-format-print ()
  2643. (texinfo-parse-arg-discard)
  2644. (insert "-|"))
  2645. (put 'result 'texinfo-format 'texinfo-format-result)
  2646. (defun texinfo-format-result ()
  2647. (texinfo-parse-arg-discard)
  2648. (insert "=>"))
  2649. ;;; Accent commands
  2650. ;; Info presumes a plain ASCII output, so the accented characters do
  2651. ;; not look as they would if typeset, or output with a different
  2652. ;; character set.
  2653. ;; See the `texinfo-accent-commands' variable
  2654. ;; in the section for `texinfo-append-refill'.
  2655. ;; Also, see the defun for `texinfo-format-scan'
  2656. ;; for single-character accent commands.
  2657. ;; Command Info output Name
  2658. ;; These do not have braces:
  2659. ;; @^ ==> ^ circumflex accent
  2660. ;; @` ==> ` grave accent
  2661. ;; @' ==> ' acute accent
  2662. ;; @" ==> " umlaut accent
  2663. ;; @= ==> = overbar accent
  2664. ;; @~ ==> ~ tilde accent
  2665. ;; These have braces, but take no argument:
  2666. ;; @OE{} ==> OE French-OE-ligature
  2667. ;; @oe{} ==> oe
  2668. ;; @AA{} ==> AA Scandinavian-A-with-circle
  2669. ;; @aa{} ==> aa
  2670. ;; @AE{} ==> AE Latin-Scandinavian-AE
  2671. ;; @ae{} ==> ae
  2672. ;; @ss{} ==> ss German-sharp-S
  2673. ;; @questiondown{} ==> ? upside-down-question-mark
  2674. ;; @exclamdown{} ==> ! upside-down-exclamation-mark
  2675. ;; @L{} ==> L/ Polish suppressed-L (Lslash)
  2676. ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
  2677. ;; @O{} ==> O/ Scandinavian O-with-slash
  2678. ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
  2679. ;; These have braces, and take an argument:
  2680. ;; @,{c} ==> c, cedilla accent
  2681. ;; @dotaccent{o} ==> .o overdot-accent
  2682. ;; @ubaraccent{o} ==> _o underbar-accent
  2683. ;; @udotaccent{o} ==> o-. underdot-accent
  2684. ;; @H{o} ==> ""o long Hungarian umlaut
  2685. ;; @ringaccent{o} ==> *o ring accent
  2686. ;; @tieaccent{oo} ==> [oo tie after accent
  2687. ;; @u{o} ==> (o breve accent
  2688. ;; @v{o} ==> <o hacek accent
  2689. ;; @dotless{i} ==> i dotless i and dotless j
  2690. ;; ==========
  2691. ;; Note: The defun texinfo-format-scan
  2692. ;; looks at "[@{}^'`\",=~ *?!-]"
  2693. ;; In the case of @*, a line break is inserted;
  2694. ;; in the other cases, the characters are simply quoted and the @ is deleted.
  2695. ;; Thus, `texinfo-format-scan' handles the following
  2696. ;; single-character accent commands: @^ @` @' @" @, @- @= @~
  2697. ;; @^ ==> ^ circumflex accent
  2698. ;; (put '^ 'texinfo-format 'texinfo-format-circumflex-accent)
  2699. ;; (defun texinfo-format-circumflex-accent ()
  2700. ;; (texinfo-discard-command)
  2701. ;; (insert "^"))
  2702. ;;
  2703. ;; @` ==> ` grave accent
  2704. ;; (put '\` 'texinfo-format 'texinfo-format-grave-accent)
  2705. ;; (defun texinfo-format-grave-accent ()
  2706. ;; (texinfo-discard-command)
  2707. ;; (insert "\`"))
  2708. ;;
  2709. ;; @' ==> ' acute accent
  2710. ;; (put '\' 'texinfo-format 'texinfo-format-acute-accent)
  2711. ;; (defun texinfo-format-acute-accent ()
  2712. ;; (texinfo-discard-command)
  2713. ;; (insert "'"))
  2714. ;;
  2715. ;; @" ==> " umlaut accent
  2716. ;; (put '\" 'texinfo-format 'texinfo-format-umlaut-accent)
  2717. ;; (defun texinfo-format-umlaut-accent ()
  2718. ;; (texinfo-discard-command)
  2719. ;; (insert "\""))
  2720. ;;
  2721. ;; @= ==> = overbar accent
  2722. ;; (put '= 'texinfo-format 'texinfo-format-overbar-accent)
  2723. ;; (defun texinfo-format-overbar-accent ()
  2724. ;; (texinfo-discard-command)
  2725. ;; (insert "="))
  2726. ;;
  2727. ;; @~ ==> ~ tilde accent
  2728. ;; (put '~ 'texinfo-format 'texinfo-format-tilde-accent)
  2729. ;; (defun texinfo-format-tilde-accent ()
  2730. ;; (texinfo-discard-command)
  2731. ;; (insert "~"))
  2732. ;; @OE{} ==> OE French-OE-ligature
  2733. (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
  2734. (defun texinfo-format-French-OE-ligature ()
  2735. (insert "OE" (texinfo-parse-arg-discard))
  2736. (goto-char texinfo-command-start))
  2737. ;; @oe{} ==> oe
  2738. (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
  2739. (defun texinfo-format-French-oe-ligature () ; lower case
  2740. (insert "oe" (texinfo-parse-arg-discard))
  2741. (goto-char texinfo-command-start))
  2742. ;; @AA{} ==> AA Scandinavian-A-with-circle
  2743. (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
  2744. (defun texinfo-format-Scandinavian-A-with-circle ()
  2745. (insert "AA" (texinfo-parse-arg-discard))
  2746. (goto-char texinfo-command-start))
  2747. ;; @aa{} ==> aa
  2748. (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
  2749. (defun texinfo-format-Scandinavian-a-with-circle () ; lower case
  2750. (insert "aa" (texinfo-parse-arg-discard))
  2751. (goto-char texinfo-command-start))
  2752. ;; @AE{} ==> AE Latin-Scandinavian-AE
  2753. (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
  2754. (defun texinfo-format-Latin-Scandinavian-AE ()
  2755. (insert "AE" (texinfo-parse-arg-discard))
  2756. (goto-char texinfo-command-start))
  2757. ;; @ae{} ==> ae
  2758. (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
  2759. (defun texinfo-format-Latin-Scandinavian-ae () ; lower case
  2760. (insert "ae" (texinfo-parse-arg-discard))
  2761. (goto-char texinfo-command-start))
  2762. ;; @ss{} ==> ss German-sharp-S
  2763. (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
  2764. (defun texinfo-format-German-sharp-S ()
  2765. (insert "ss" (texinfo-parse-arg-discard))
  2766. (goto-char texinfo-command-start))
  2767. ;; @questiondown{} ==> ? upside-down-question-mark
  2768. (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
  2769. (defun texinfo-format-upside-down-question-mark ()
  2770. (insert "?" (texinfo-parse-arg-discard))
  2771. (goto-char texinfo-command-start))
  2772. ;; @exclamdown{} ==> ! upside-down-exclamation-mark
  2773. (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
  2774. (defun texinfo-format-upside-down-exclamation-mark ()
  2775. (insert "!" (texinfo-parse-arg-discard))
  2776. (goto-char texinfo-command-start))
  2777. ;; @L{} ==> L/ Polish suppressed-L (Lslash)
  2778. (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
  2779. (defun texinfo-format-Polish-suppressed-L ()
  2780. (insert (texinfo-parse-arg-discard) "/L")
  2781. (goto-char texinfo-command-start))
  2782. ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
  2783. (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
  2784. (defun texinfo-format-Polish-suppressed-l-lower-case ()
  2785. (insert (texinfo-parse-arg-discard) "/l")
  2786. (goto-char texinfo-command-start))
  2787. ;; @O{} ==> O/ Scandinavian O-with-slash
  2788. (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
  2789. (defun texinfo-format-Scandinavian-O-with-slash ()
  2790. (insert (texinfo-parse-arg-discard) "O/")
  2791. (goto-char texinfo-command-start))
  2792. ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
  2793. (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
  2794. (defun texinfo-format-Scandinavian-o-with-slash-lower-case ()
  2795. (insert (texinfo-parse-arg-discard) "o/")
  2796. (goto-char texinfo-command-start))
  2797. ;; Take arguments
  2798. ;; @,{c} ==> c, cedilla accent
  2799. (put '\, 'texinfo-format 'texinfo-format-cedilla-accent)
  2800. (defun texinfo-format-cedilla-accent ()
  2801. (insert (texinfo-parse-arg-discard) ",")
  2802. (goto-char texinfo-command-start))
  2803. ;; @dotaccent{o} ==> .o overdot-accent
  2804. (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
  2805. (defun texinfo-format-overdot-accent ()
  2806. (insert "." (texinfo-parse-arg-discard))
  2807. (goto-char texinfo-command-start))
  2808. ;; @ubaraccent{o} ==> _o underbar-accent
  2809. (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
  2810. (defun texinfo-format-underbar-accent ()
  2811. (insert "_" (texinfo-parse-arg-discard))
  2812. (goto-char texinfo-command-start))
  2813. ;; @udotaccent{o} ==> o-. underdot-accent
  2814. (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
  2815. (defun texinfo-format-underdot-accent ()
  2816. (insert (texinfo-parse-arg-discard) "-.")
  2817. (goto-char texinfo-command-start))
  2818. ;; @H{o} ==> ""o long Hungarian umlaut
  2819. (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
  2820. (defun texinfo-format-long-Hungarian-umlaut ()
  2821. (insert "\"\"" (texinfo-parse-arg-discard))
  2822. (goto-char texinfo-command-start))
  2823. ;; @ringaccent{o} ==> *o ring accent
  2824. (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
  2825. (defun texinfo-format-ring-accent ()
  2826. (insert "*" (texinfo-parse-arg-discard))
  2827. (goto-char texinfo-command-start))
  2828. ;; @tieaccent{oo} ==> [oo tie after accent
  2829. (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
  2830. (defun texinfo-format-tie-after-accent ()
  2831. (insert "[" (texinfo-parse-arg-discard))
  2832. (goto-char texinfo-command-start))
  2833. ;; @u{o} ==> (o breve accent
  2834. (put 'u 'texinfo-format 'texinfo-format-breve-accent)
  2835. (defun texinfo-format-breve-accent ()
  2836. (insert "(" (texinfo-parse-arg-discard))
  2837. (goto-char texinfo-command-start))
  2838. ;; @v{o} ==> <o hacek accent
  2839. (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
  2840. (defun texinfo-format-hacek-accent ()
  2841. (insert "<" (texinfo-parse-arg-discard))
  2842. (goto-char texinfo-command-start))
  2843. ;; @dotless{i} ==> i dotless i and dotless j
  2844. (put 'dotless 'texinfo-format 'texinfo-format-dotless)
  2845. (defun texinfo-format-dotless ()
  2846. (insert (texinfo-parse-arg-discard))
  2847. (goto-char texinfo-command-start))
  2848. ;;; Definition formatting: @deffn, @defun, etc
  2849. ;; What definition formatting produces:
  2850. ;;
  2851. ;; @deffn category name args...
  2852. ;; In Info, `Category: name ARGS'
  2853. ;; In index: name: node. line#.
  2854. ;;
  2855. ;; @defvr category name
  2856. ;; In Info, `Category: name'
  2857. ;; In index: name: node. line#.
  2858. ;;
  2859. ;; @deftp category name attributes...
  2860. ;; `category name attributes...' Note: @deftp args in lower case.
  2861. ;; In index: name: node. line#.
  2862. ;;
  2863. ;; Specialized function-like or variable-like entity:
  2864. ;;
  2865. ;; @defun, @defmac, @defspec, @defvar, @defopt
  2866. ;;
  2867. ;; @defun name args In Info, `Function: name ARGS'
  2868. ;; @defmac name args In Info, `Macro: name ARGS'
  2869. ;; @defvar name In Info, `Variable: name'
  2870. ;; etc.
  2871. ;; In index: name: node. line#.
  2872. ;;
  2873. ;; Generalized typed-function-like or typed-variable-like entity:
  2874. ;; @deftypefn category data-type name args...
  2875. ;; In Info, `Category: data-type name args...'
  2876. ;; @deftypevr category data-type name
  2877. ;; In Info, `Category: data-type name'
  2878. ;; In index: name: node. line#.
  2879. ;;
  2880. ;; Specialized typed-function-like or typed-variable-like entity:
  2881. ;; @deftypefun data-type name args...
  2882. ;; In Info, `Function: data-type name ARGS'
  2883. ;; In index: name: node. line#.
  2884. ;;
  2885. ;; @deftypevar data-type name
  2886. ;; In Info, `Variable: data-type name'
  2887. ;; In index: name: node. line#. but include args after name!?
  2888. ;;
  2889. ;; Generalized object oriented entity:
  2890. ;; @defop category class name args...
  2891. ;; In Info, `Category on class: name ARG'
  2892. ;; In index: name on class: node. line#.
  2893. ;;
  2894. ;; @defcv category class name
  2895. ;; In Info, `Category of class: name'
  2896. ;; In index: name of class: node. line#.
  2897. ;;
  2898. ;; Specialized object oriented entity:
  2899. ;; @defmethod class name args...
  2900. ;; In Info, `Method on class: name ARGS'
  2901. ;; In index: name on class: node. line#.
  2902. ;;
  2903. ;; @defivar class name
  2904. ;; In Info, `Instance variable of class: name'
  2905. ;; In index: name of class: node. line#.
  2906. ;;; The definition formatting functions
  2907. (defun texinfo-format-defun ()
  2908. (texinfo-push-stack 'defun nil)
  2909. (setq fill-column (- fill-column 5))
  2910. (texinfo-format-defun-1 t))
  2911. (defun texinfo-end-defun ()
  2912. (setq fill-column (+ fill-column 5))
  2913. (texinfo-discard-command)
  2914. (let ((start (nth 1 (texinfo-pop-stack 'defun))))
  2915. (texinfo-do-itemize start)
  2916. ;; Delete extra newline inserted after header.
  2917. (save-excursion
  2918. (goto-char start)
  2919. (delete-char -1))))
  2920. (defun texinfo-format-defunx ()
  2921. (texinfo-format-defun-1 nil))
  2922. (defun texinfo-format-defun-1 (first-p)
  2923. (let ((parse-args (texinfo-format-parse-defun-args))
  2924. (texinfo-defun-type (get texinfo-command-name 'texinfo-defun-type)))
  2925. (texinfo-discard-command)
  2926. ;; Delete extra newline inserted after previous header line.
  2927. (if (not first-p)
  2928. (delete-char -1))
  2929. (funcall
  2930. (get texinfo-command-name 'texinfo-deffn-formatting-property) parse-args)
  2931. ;; Insert extra newline so that paragraph filling does not mess
  2932. ;; with header line.
  2933. (insert "\n\n")
  2934. (rplaca (cdr (cdr (car texinfo-stack))) (point))
  2935. (funcall
  2936. (get texinfo-command-name 'texinfo-defun-indexing-property) parse-args)))
  2937. ;;; Formatting the first line of a definition
  2938. ;; @deffn, @defvr, @deftp
  2939. (put 'deffn 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
  2940. (put 'deffnx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
  2941. (put 'defvr 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
  2942. (put 'defvrx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
  2943. (put 'deftp 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
  2944. (put 'deftpx 'texinfo-deffn-formatting-property 'texinfo-format-deffn)
  2945. (defun texinfo-format-deffn (parsed-args)
  2946. ;; Generalized function-like, variable-like, or generic data-type entity:
  2947. ;; @deffn category name args...
  2948. ;; In Info, `Category: name ARGS'
  2949. ;; @deftp category name attributes...
  2950. ;; `category name attributes...' Note: @deftp args in lower case.
  2951. (let ((category (car parsed-args))
  2952. (name (car (cdr parsed-args)))
  2953. (args (cdr (cdr parsed-args))))
  2954. (insert " -- " category ": " name)
  2955. (while args
  2956. (insert " "
  2957. (if (or (= ?& (aref (car args) 0))
  2958. (eq (eval (car texinfo-defun-type)) 'deftp-type))
  2959. (car args)
  2960. (upcase (car args))))
  2961. (setq args (cdr args)))))
  2962. ;; @defun, @defmac, @defspec, @defvar, @defopt: Specialized, simple
  2963. (put 'defun 'texinfo-deffn-formatting-property
  2964. 'texinfo-format-specialized-defun)
  2965. (put 'defunx 'texinfo-deffn-formatting-property
  2966. 'texinfo-format-specialized-defun)
  2967. (put 'defmac 'texinfo-deffn-formatting-property
  2968. 'texinfo-format-specialized-defun)
  2969. (put 'defmacx 'texinfo-deffn-formatting-property
  2970. 'texinfo-format-specialized-defun)
  2971. (put 'defspec 'texinfo-deffn-formatting-property
  2972. 'texinfo-format-specialized-defun)
  2973. (put 'defspecx 'texinfo-deffn-formatting-property
  2974. 'texinfo-format-specialized-defun)
  2975. (put 'defvar 'texinfo-deffn-formatting-property
  2976. 'texinfo-format-specialized-defun)
  2977. (put 'defvarx 'texinfo-deffn-formatting-property
  2978. 'texinfo-format-specialized-defun)
  2979. (put 'defopt 'texinfo-deffn-formatting-property
  2980. 'texinfo-format-specialized-defun)
  2981. (put 'defoptx 'texinfo-deffn-formatting-property
  2982. 'texinfo-format-specialized-defun)
  2983. (defun texinfo-format-specialized-defun (parsed-args)
  2984. ;; Specialized function-like or variable-like entity:
  2985. ;; @defun name args In Info, `Function: Name ARGS'
  2986. ;; @defmac name args In Info, `Macro: Name ARGS'
  2987. ;; @defvar name In Info, `Variable: Name'
  2988. ;; Use cdr of texinfo-defun-type to determine category:
  2989. (let ((category (car (cdr texinfo-defun-type)))
  2990. (name (car parsed-args))
  2991. (args (cdr parsed-args)))
  2992. (insert " -- " category ": " name)
  2993. (while args
  2994. (insert " "
  2995. (if (= ?& (aref (car args) 0))
  2996. (car args)
  2997. (upcase (car args))))
  2998. (setq args (cdr args)))))
  2999. ;; @deftypefn, @deftypevr: Generalized typed
  3000. (put 'deftypefn 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
  3001. (put 'deftypefnx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
  3002. (put 'deftypevr 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
  3003. (put 'deftypevrx 'texinfo-deffn-formatting-property 'texinfo-format-deftypefn)
  3004. (defun texinfo-format-deftypefn (parsed-args)
  3005. ;; Generalized typed-function-like or typed-variable-like entity:
  3006. ;; @deftypefn category data-type name args...
  3007. ;; In Info, `Category: data-type name args...'
  3008. ;; @deftypevr category data-type name
  3009. ;; In Info, `Category: data-type name'
  3010. ;; Note: args in lower case, unless modified in command line.
  3011. (let ((category (car parsed-args))
  3012. (data-type (car (cdr parsed-args)))
  3013. (name (car (cdr (cdr parsed-args))))
  3014. (args (cdr (cdr (cdr parsed-args)))))
  3015. (insert " -- " category ": " data-type " " name)
  3016. (while args
  3017. (insert " " (car args))
  3018. (setq args (cdr args)))))
  3019. ;; @deftypefun, @deftypevar: Specialized typed
  3020. (put 'deftypefun 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun)
  3021. (put 'deftypefunx 'texinfo-deffn-formatting-property
  3022. 'texinfo-format-deftypefun)
  3023. (put 'deftypevar 'texinfo-deffn-formatting-property 'texinfo-format-deftypefun)
  3024. (put 'deftypevarx 'texinfo-deffn-formatting-property
  3025. 'texinfo-format-deftypefun)
  3026. (defun texinfo-format-deftypefun (parsed-args)
  3027. ;; Specialized typed-function-like or typed-variable-like entity:
  3028. ;; @deftypefun data-type name args...
  3029. ;; In Info, `Function: data-type name ARGS'
  3030. ;; @deftypevar data-type name
  3031. ;; In Info, `Variable: data-type name'
  3032. ;; Note: args in lower case, unless modified in command line.
  3033. ;; Use cdr of texinfo-defun-type to determine category:
  3034. (let ((category (car (cdr texinfo-defun-type)))
  3035. (data-type (car parsed-args))
  3036. (name (car (cdr parsed-args)))
  3037. (args (cdr (cdr parsed-args))))
  3038. (insert " -- " category ": " data-type " " name)
  3039. (while args
  3040. (insert " " (car args))
  3041. (setq args (cdr args)))))
  3042. ;; @defop: Generalized object-oriented
  3043. (put 'defop 'texinfo-deffn-formatting-property 'texinfo-format-defop)
  3044. (put 'defopx 'texinfo-deffn-formatting-property 'texinfo-format-defop)
  3045. (defun texinfo-format-defop (parsed-args)
  3046. ;; Generalized object oriented entity:
  3047. ;; @defop category class name args...
  3048. ;; In Info, `Category on class: name ARG'
  3049. ;; Note: args in upper case; use of `on'
  3050. (let ((category (car parsed-args))
  3051. (class (car (cdr parsed-args)))
  3052. (name (car (cdr (cdr parsed-args))))
  3053. (args (cdr (cdr (cdr parsed-args)))))
  3054. (insert " -- " category " on " class ": " name)
  3055. (while args
  3056. (insert " " (upcase (car args)))
  3057. (setq args (cdr args)))))
  3058. ;; @defcv: Generalized object-oriented
  3059. (put 'defcv 'texinfo-deffn-formatting-property 'texinfo-format-defcv)
  3060. (put 'defcvx 'texinfo-deffn-formatting-property 'texinfo-format-defcv)
  3061. (defun texinfo-format-defcv (parsed-args)
  3062. ;; Generalized object oriented entity:
  3063. ;; @defcv category class name
  3064. ;; In Info, `Category of class: name'
  3065. ;; Note: args in upper case; use of `of'
  3066. (let ((category (car parsed-args))
  3067. (class (car (cdr parsed-args)))
  3068. (name (car (cdr (cdr parsed-args))))
  3069. (args (cdr (cdr (cdr parsed-args)))))
  3070. (insert " -- " category " of " class ": " name)
  3071. (while args
  3072. (insert " " (upcase (car args)))
  3073. (setq args (cdr args)))))
  3074. ;; @defmethod: Specialized object-oriented
  3075. (put 'defmethod 'texinfo-deffn-formatting-property 'texinfo-format-defmethod)
  3076. (put 'defmethodx 'texinfo-deffn-formatting-property 'texinfo-format-defmethod)
  3077. (defun texinfo-format-defmethod (parsed-args)
  3078. ;; Specialized object oriented entity:
  3079. ;; @defmethod class name args...
  3080. ;; In Info, `Method on class: name ARGS'
  3081. ;; Note: args in upper case; use of `on'
  3082. ;; Use cdr of texinfo-defun-type to determine category:
  3083. (let ((category (car (cdr texinfo-defun-type)))
  3084. (class (car parsed-args))
  3085. (name (car (cdr parsed-args)))
  3086. (args (cdr (cdr parsed-args))))
  3087. (insert " -- " category " on " class ": " name)
  3088. (while args
  3089. (insert " " (upcase (car args)))
  3090. (setq args (cdr args)))))
  3091. ;; @defivar: Specialized object-oriented
  3092. (put 'defivar 'texinfo-deffn-formatting-property 'texinfo-format-defivar)
  3093. (put 'defivarx 'texinfo-deffn-formatting-property 'texinfo-format-defivar)
  3094. (defun texinfo-format-defivar (parsed-args)
  3095. ;; Specialized object oriented entity:
  3096. ;; @defivar class name
  3097. ;; In Info, `Instance variable of class: name'
  3098. ;; Note: args in upper case; use of `of'
  3099. ;; Use cdr of texinfo-defun-type to determine category:
  3100. (let ((category (car (cdr texinfo-defun-type)))
  3101. (class (car parsed-args))
  3102. (name (car (cdr parsed-args)))
  3103. (args (cdr (cdr parsed-args))))
  3104. (insert " -- " category " of " class ": " name)
  3105. (while args
  3106. (insert " " (upcase (car args)))
  3107. (setq args (cdr args)))))
  3108. ;;; Indexing for definitions
  3109. ;; An index entry has three parts: the `entry proper', the node name, and the
  3110. ;; line number. Depending on the which command is used, the entry is
  3111. ;; formatted differently:
  3112. ;;
  3113. ;; @defun,
  3114. ;; @defmac,
  3115. ;; @defspec,
  3116. ;; @defvar,
  3117. ;; @defopt all use their 1st argument as the entry-proper
  3118. ;;
  3119. ;; @deffn,
  3120. ;; @defvr,
  3121. ;; @deftp
  3122. ;; @deftypefun
  3123. ;; @deftypevar all use their 2nd argument as the entry-proper
  3124. ;;
  3125. ;; @deftypefn,
  3126. ;; @deftypevr both use their 3rd argument as the entry-proper
  3127. ;;
  3128. ;; @defmethod uses its 2nd and 1st arguments as an entry-proper
  3129. ;; formatted: NAME on CLASS
  3130. ;; @defop uses its 3rd and 2nd arguments as an entry-proper
  3131. ;; formatted: NAME on CLASS
  3132. ;;
  3133. ;; @defivar uses its 2nd and 1st arguments as an entry-proper
  3134. ;; formatted: NAME of CLASS
  3135. ;;
  3136. ;; @defcv uses its 3rd and 2nd argument as an entry-proper
  3137. ;; formatted: NAME of CLASS
  3138. (put 'defun 'texinfo-defun-indexing-property 'texinfo-index-defun)
  3139. (put 'defunx 'texinfo-defun-indexing-property 'texinfo-index-defun)
  3140. (put 'defmac 'texinfo-defun-indexing-property 'texinfo-index-defun)
  3141. (put 'defmacx 'texinfo-defun-indexing-property 'texinfo-index-defun)
  3142. (put 'defspec 'texinfo-defun-indexing-property 'texinfo-index-defun)
  3143. (put 'defspecx 'texinfo-defun-indexing-property 'texinfo-index-defun)
  3144. (put 'defvar 'texinfo-defun-indexing-property 'texinfo-index-defun)
  3145. (put 'defvarx 'texinfo-defun-indexing-property 'texinfo-index-defun)
  3146. (put 'defopt 'texinfo-defun-indexing-property 'texinfo-index-defun)
  3147. (put 'defoptx 'texinfo-defun-indexing-property 'texinfo-index-defun)
  3148. (defun texinfo-index-defun (parsed-args)
  3149. ;; use 1st parsed-arg as entry-proper
  3150. ;; `index-list' will be texinfo-findex or the like
  3151. (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  3152. (set index-list
  3153. (cons
  3154. ;; Three elements: entry-proper, node-name, line-number
  3155. (list
  3156. (car parsed-args)
  3157. texinfo-last-node
  3158. ;; Region formatting may not provide last node position.
  3159. (if texinfo-last-node-pos
  3160. (1+ (count-lines texinfo-last-node-pos (point)))
  3161. 1))
  3162. (symbol-value index-list)))))
  3163. (put 'deffn 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  3164. (put 'deffnx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  3165. (put 'defvr 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  3166. (put 'defvrx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  3167. (put 'deftp 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  3168. (put 'deftpx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  3169. (put 'deftypefun 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  3170. (put 'deftypefunx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  3171. (put 'deftypevar 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  3172. (put 'deftypevarx 'texinfo-defun-indexing-property 'texinfo-index-deffn)
  3173. (defun texinfo-index-deffn (parsed-args)
  3174. ;; use 2nd parsed-arg as entry-proper
  3175. ;; `index-list' will be texinfo-findex or the like
  3176. (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  3177. (set index-list
  3178. (cons
  3179. ;; Three elements: entry-proper, node-name, line-number
  3180. (list
  3181. (car (cdr parsed-args))
  3182. texinfo-last-node
  3183. ;; Region formatting may not provide last node position.
  3184. (if texinfo-last-node-pos
  3185. (1+ (count-lines texinfo-last-node-pos (point)))
  3186. 1))
  3187. (symbol-value index-list)))))
  3188. (put 'deftypefn 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
  3189. (put 'deftypefnx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
  3190. (put 'deftypevr 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
  3191. (put 'deftypevrx 'texinfo-defun-indexing-property 'texinfo-index-deftypefn)
  3192. (defun texinfo-index-deftypefn (parsed-args)
  3193. ;; use 3rd parsed-arg as entry-proper
  3194. ;; `index-list' will be texinfo-findex or the like
  3195. (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  3196. (set index-list
  3197. (cons
  3198. ;; Three elements: entry-proper, node-name, line-number
  3199. (list
  3200. (car (cdr (cdr parsed-args)))
  3201. texinfo-last-node
  3202. ;; Region formatting may not provide last node position.
  3203. (if texinfo-last-node-pos
  3204. (1+ (count-lines texinfo-last-node-pos (point)))
  3205. 1))
  3206. (symbol-value index-list)))))
  3207. (put 'defmethod 'texinfo-defun-indexing-property 'texinfo-index-defmethod)
  3208. (put 'defmethodx 'texinfo-defun-indexing-property 'texinfo-index-defmethod)
  3209. (defun texinfo-index-defmethod (parsed-args)
  3210. ;; use 2nd on 1st parsed-arg as entry-proper
  3211. ;; `index-list' will be texinfo-findex or the like
  3212. (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  3213. (set index-list
  3214. (cons
  3215. ;; Three elements: entry-proper, node-name, line-number
  3216. (list
  3217. (format "%s on %s"
  3218. (car (cdr parsed-args))
  3219. (car parsed-args))
  3220. texinfo-last-node
  3221. ;; Region formatting may not provide last node position.
  3222. (if texinfo-last-node-pos
  3223. (1+ (count-lines texinfo-last-node-pos (point)))
  3224. 1))
  3225. (symbol-value index-list)))))
  3226. (put 'defop 'texinfo-defun-indexing-property 'texinfo-index-defop)
  3227. (put 'defopx 'texinfo-defun-indexing-property 'texinfo-index-defop)
  3228. (defun texinfo-index-defop (parsed-args)
  3229. ;; use 3rd on 2nd parsed-arg as entry-proper
  3230. ;; `index-list' will be texinfo-findex or the like
  3231. (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  3232. (set index-list
  3233. (cons
  3234. ;; Three elements: entry-proper, node-name, line-number
  3235. (list
  3236. (format "%s on %s"
  3237. (car (cdr (cdr parsed-args)))
  3238. (car (cdr parsed-args)))
  3239. texinfo-last-node
  3240. ;; Region formatting may not provide last node position.
  3241. (if texinfo-last-node-pos
  3242. (1+ (count-lines texinfo-last-node-pos (point)))
  3243. 1))
  3244. (symbol-value index-list)))))
  3245. (put 'defivar 'texinfo-defun-indexing-property 'texinfo-index-defivar)
  3246. (put 'defivarx 'texinfo-defun-indexing-property 'texinfo-index-defivar)
  3247. (defun texinfo-index-defivar (parsed-args)
  3248. ;; use 2nd of 1st parsed-arg as entry-proper
  3249. ;; `index-list' will be texinfo-findex or the like
  3250. (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  3251. (set index-list
  3252. (cons
  3253. ;; Three elements: entry-proper, node-name, line-number
  3254. (list
  3255. (format "%s of %s"
  3256. (car (cdr parsed-args))
  3257. (car parsed-args))
  3258. texinfo-last-node
  3259. ;; Region formatting may not provide last node position.
  3260. (if texinfo-last-node-pos
  3261. (1+ (count-lines texinfo-last-node-pos (point)))
  3262. 1))
  3263. (symbol-value index-list)))))
  3264. (put 'defcv 'texinfo-defun-indexing-property 'texinfo-index-defcv)
  3265. (put 'defcvx 'texinfo-defun-indexing-property 'texinfo-index-defcv)
  3266. (defun texinfo-index-defcv (parsed-args)
  3267. ;; use 3rd of 2nd parsed-arg as entry-proper
  3268. ;; `index-list' will be texinfo-findex or the like
  3269. (let ((index-list (get texinfo-command-name 'texinfo-defun-index)))
  3270. (set index-list
  3271. (cons
  3272. ;; Three elements: entry-proper, node-name, line-number
  3273. (list
  3274. (format "%s of %s"
  3275. (car (cdr (cdr parsed-args)))
  3276. (car (cdr parsed-args)))
  3277. texinfo-last-node
  3278. ;; Region formatting may not provide last node position.
  3279. (if texinfo-last-node-pos
  3280. (1+ (count-lines texinfo-last-node-pos (point)))
  3281. 1))
  3282. (symbol-value index-list)))))
  3283. ;;; Properties for definitions
  3284. ;; Each definition command has six properties:
  3285. ;;
  3286. ;; 1. texinfo-deffn-formatting-property to format definition line
  3287. ;; 2. texinfo-defun-indexing-property to create index entry
  3288. ;; 3. texinfo-format formatting command
  3289. ;; 4. texinfo-end end formatting command
  3290. ;; 5. texinfo-defun-type type of deffn to format
  3291. ;; 6. texinfo-defun-index type of index to use
  3292. ;;
  3293. ;; The `x' forms of each definition command are used for the second
  3294. ;; and subsequent header lines.
  3295. ;; The texinfo-deffn-formatting-property and texinfo-defun-indexing-property
  3296. ;; are listed just before the appropriate formatting and indexing commands.
  3297. (put 'deffn 'texinfo-format 'texinfo-format-defun)
  3298. (put 'deffnx 'texinfo-format 'texinfo-format-defunx)
  3299. (put 'deffn 'texinfo-end 'texinfo-end-defun)
  3300. (put 'deffn 'texinfo-defun-type '('deffn-type nil))
  3301. (put 'deffnx 'texinfo-defun-type '('deffn-type nil))
  3302. (put 'deffn 'texinfo-defun-index 'texinfo-findex)
  3303. (put 'deffnx 'texinfo-defun-index 'texinfo-findex)
  3304. (put 'defun 'texinfo-format 'texinfo-format-defun)
  3305. (put 'defunx 'texinfo-format 'texinfo-format-defunx)
  3306. (put 'defun 'texinfo-end 'texinfo-end-defun)
  3307. (put 'defun 'texinfo-defun-type '('defun-type "Function"))
  3308. (put 'defunx 'texinfo-defun-type '('defun-type "Function"))
  3309. (put 'defun 'texinfo-defun-index 'texinfo-findex)
  3310. (put 'defunx 'texinfo-defun-index 'texinfo-findex)
  3311. (put 'defmac 'texinfo-format 'texinfo-format-defun)
  3312. (put 'defmacx 'texinfo-format 'texinfo-format-defunx)
  3313. (put 'defmac 'texinfo-end 'texinfo-end-defun)
  3314. (put 'defmac 'texinfo-defun-type '('defun-type "Macro"))
  3315. (put 'defmacx 'texinfo-defun-type '('defun-type "Macro"))
  3316. (put 'defmac 'texinfo-defun-index 'texinfo-findex)
  3317. (put 'defmacx 'texinfo-defun-index 'texinfo-findex)
  3318. (put 'defspec 'texinfo-format 'texinfo-format-defun)
  3319. (put 'defspecx 'texinfo-format 'texinfo-format-defunx)
  3320. (put 'defspec 'texinfo-end 'texinfo-end-defun)
  3321. (put 'defspec 'texinfo-defun-type '('defun-type "Special form"))
  3322. (put 'defspecx 'texinfo-defun-type '('defun-type "Special form"))
  3323. (put 'defspec 'texinfo-defun-index 'texinfo-findex)
  3324. (put 'defspecx 'texinfo-defun-index 'texinfo-findex)
  3325. (put 'defvr 'texinfo-format 'texinfo-format-defun)
  3326. (put 'defvrx 'texinfo-format 'texinfo-format-defunx)
  3327. (put 'defvr 'texinfo-end 'texinfo-end-defun)
  3328. (put 'defvr 'texinfo-defun-type '('deffn-type nil))
  3329. (put 'defvrx 'texinfo-defun-type '('deffn-type nil))
  3330. (put 'defvr 'texinfo-defun-index 'texinfo-vindex)
  3331. (put 'defvrx 'texinfo-defun-index 'texinfo-vindex)
  3332. (put 'defvar 'texinfo-format 'texinfo-format-defun)
  3333. (put 'defvarx 'texinfo-format 'texinfo-format-defunx)
  3334. (put 'defvar 'texinfo-end 'texinfo-end-defun)
  3335. (put 'defvar 'texinfo-defun-type '('defun-type "Variable"))
  3336. (put 'defvarx 'texinfo-defun-type '('defun-type "Variable"))
  3337. (put 'defvar 'texinfo-defun-index 'texinfo-vindex)
  3338. (put 'defvarx 'texinfo-defun-index 'texinfo-vindex)
  3339. (put 'defconst 'texinfo-format 'texinfo-format-defun)
  3340. (put 'defconstx 'texinfo-format 'texinfo-format-defunx)
  3341. (put 'defconst 'texinfo-end 'texinfo-end-defun)
  3342. (put 'defconst 'texinfo-defun-type '('defun-type "Constant"))
  3343. (put 'defconstx 'texinfo-defun-type '('defun-type "Constant"))
  3344. (put 'defconst 'texinfo-defun-index 'texinfo-vindex)
  3345. (put 'defconstx 'texinfo-defun-index 'texinfo-vindex)
  3346. (put 'defcmd 'texinfo-format 'texinfo-format-defun)
  3347. (put 'defcmdx 'texinfo-format 'texinfo-format-defunx)
  3348. (put 'defcmd 'texinfo-end 'texinfo-end-defun)
  3349. (put 'defcmd 'texinfo-defun-type '('defun-type "Command"))
  3350. (put 'defcmdx 'texinfo-defun-type '('defun-type "Command"))
  3351. (put 'defcmd 'texinfo-defun-index 'texinfo-findex)
  3352. (put 'defcmdx 'texinfo-defun-index 'texinfo-findex)
  3353. (put 'defopt 'texinfo-format 'texinfo-format-defun)
  3354. (put 'defoptx 'texinfo-format 'texinfo-format-defunx)
  3355. (put 'defopt 'texinfo-end 'texinfo-end-defun)
  3356. (put 'defopt 'texinfo-defun-type '('defun-type "User Option"))
  3357. (put 'defoptx 'texinfo-defun-type '('defun-type "User Option"))
  3358. (put 'defopt 'texinfo-defun-index 'texinfo-vindex)
  3359. (put 'defoptx 'texinfo-defun-index 'texinfo-vindex)
  3360. (put 'deftp 'texinfo-format 'texinfo-format-defun)
  3361. (put 'deftpx 'texinfo-format 'texinfo-format-defunx)
  3362. (put 'deftp 'texinfo-end 'texinfo-end-defun)
  3363. (put 'deftp 'texinfo-defun-type '('deftp-type nil))
  3364. (put 'deftpx 'texinfo-defun-type '('deftp-type nil))
  3365. (put 'deftp 'texinfo-defun-index 'texinfo-tindex)
  3366. (put 'deftpx 'texinfo-defun-index 'texinfo-tindex)
  3367. ;;; Object-oriented stuff is a little hairier.
  3368. (put 'defop 'texinfo-format 'texinfo-format-defun)
  3369. (put 'defopx 'texinfo-format 'texinfo-format-defunx)
  3370. (put 'defop 'texinfo-end 'texinfo-end-defun)
  3371. (put 'defop 'texinfo-defun-type '('defop-type nil))
  3372. (put 'defopx 'texinfo-defun-type '('defop-type nil))
  3373. (put 'defop 'texinfo-defun-index 'texinfo-findex)
  3374. (put 'defopx 'texinfo-defun-index 'texinfo-findex)
  3375. (put 'defmethod 'texinfo-format 'texinfo-format-defun)
  3376. (put 'defmethodx 'texinfo-format 'texinfo-format-defunx)
  3377. (put 'defmethod 'texinfo-end 'texinfo-end-defun)
  3378. (put 'defmethod 'texinfo-defun-type '('defmethod-type "Method"))
  3379. (put 'defmethodx 'texinfo-defun-type '('defmethod-type "Method"))
  3380. (put 'defmethod 'texinfo-defun-index 'texinfo-findex)
  3381. (put 'defmethodx 'texinfo-defun-index 'texinfo-findex)
  3382. (put 'defcv 'texinfo-format 'texinfo-format-defun)
  3383. (put 'defcvx 'texinfo-format 'texinfo-format-defunx)
  3384. (put 'defcv 'texinfo-end 'texinfo-end-defun)
  3385. (put 'defcv 'texinfo-defun-type '('defop-type nil))
  3386. (put 'defcvx 'texinfo-defun-type '('defop-type nil))
  3387. (put 'defcv 'texinfo-defun-index 'texinfo-vindex)
  3388. (put 'defcvx 'texinfo-defun-index 'texinfo-vindex)
  3389. (put 'defivar 'texinfo-format 'texinfo-format-defun)
  3390. (put 'defivarx 'texinfo-format 'texinfo-format-defunx)
  3391. (put 'defivar 'texinfo-end 'texinfo-end-defun)
  3392. (put 'defivar 'texinfo-defun-type '('defmethod-type "Instance variable"))
  3393. (put 'defivarx 'texinfo-defun-type '('defmethod-type "Instance variable"))
  3394. (put 'defivar 'texinfo-defun-index 'texinfo-vindex)
  3395. (put 'defivarx 'texinfo-defun-index 'texinfo-vindex)
  3396. ;;; Typed functions and variables
  3397. (put 'deftypefn 'texinfo-format 'texinfo-format-defun)
  3398. (put 'deftypefnx 'texinfo-format 'texinfo-format-defunx)
  3399. (put 'deftypefn 'texinfo-end 'texinfo-end-defun)
  3400. (put 'deftypefn 'texinfo-defun-type '('deftypefn-type nil))
  3401. (put 'deftypefnx 'texinfo-defun-type '('deftypefn-type nil))
  3402. (put 'deftypefn 'texinfo-defun-index 'texinfo-findex)
  3403. (put 'deftypefnx 'texinfo-defun-index 'texinfo-findex)
  3404. (put 'deftypefun 'texinfo-format 'texinfo-format-defun)
  3405. (put 'deftypefunx 'texinfo-format 'texinfo-format-defunx)
  3406. (put 'deftypefun 'texinfo-end 'texinfo-end-defun)
  3407. (put 'deftypefun 'texinfo-defun-type '('deftypefun-type "Function"))
  3408. (put 'deftypefunx 'texinfo-defun-type '('deftypefun-type "Function"))
  3409. (put 'deftypefun 'texinfo-defun-index 'texinfo-findex)
  3410. (put 'deftypefunx 'texinfo-defun-index 'texinfo-findex)
  3411. (put 'deftypevr 'texinfo-format 'texinfo-format-defun)
  3412. (put 'deftypevrx 'texinfo-format 'texinfo-format-defunx)
  3413. (put 'deftypevr 'texinfo-end 'texinfo-end-defun)
  3414. (put 'deftypevr 'texinfo-defun-type '('deftypefn-type nil))
  3415. (put 'deftypevrx 'texinfo-defun-type '('deftypefn-type nil))
  3416. (put 'deftypevr 'texinfo-defun-index 'texinfo-vindex)
  3417. (put 'deftypevrx 'texinfo-defun-index 'texinfo-vindex)
  3418. (put 'deftypevar 'texinfo-format 'texinfo-format-defun)
  3419. (put 'deftypevarx 'texinfo-format 'texinfo-format-defunx)
  3420. (put 'deftypevar 'texinfo-end 'texinfo-end-defun)
  3421. (put 'deftypevar 'texinfo-defun-type '('deftypevar-type "Variable"))
  3422. (put 'deftypevarx 'texinfo-defun-type '('deftypevar-type "Variable"))
  3423. (put 'deftypevar 'texinfo-defun-index 'texinfo-vindex)
  3424. (put 'deftypevarx 'texinfo-defun-index 'texinfo-vindex)
  3425. ;;; @set, @clear, @ifset, @ifclear
  3426. ;; If a flag is set with @set FLAG, then text between @ifset and @end
  3427. ;; ifset is formatted normally, but if the flag is cleared with
  3428. ;; @clear FLAG, then the text is not formatted; it is ignored.
  3429. ;; If a flag is cleared with @clear FLAG, then text between @ifclear
  3430. ;; and @end ifclear is formatted normally, but if the flag is set with
  3431. ;; @set FLAG, then the text is not formatted; it is ignored. @ifclear
  3432. ;; is the opposite of @ifset.
  3433. ;; If a flag is set to a string with @set FLAG,
  3434. ;; replace @value{FLAG} with the string.
  3435. ;; If a flag with a value is cleared,
  3436. ;; @value{FLAG} is invalid,
  3437. ;; as if there had never been any @set FLAG previously.
  3438. (put 'clear 'texinfo-format 'texinfo-clear)
  3439. (defun texinfo-clear ()
  3440. "Clear the value of the flag."
  3441. (let* ((arg (texinfo-parse-arg-discard))
  3442. (flag (car (read-from-string arg)))
  3443. (value (substring arg (cdr (read-from-string arg)))))
  3444. (put flag 'texinfo-whether-setp 'flag-cleared)
  3445. (put flag 'texinfo-set-value "")))
  3446. (put 'set 'texinfo-format 'texinfo-set)
  3447. (defun texinfo-set ()
  3448. "Set the value of the flag, optionally to a string.
  3449. The command `@set foo This is a string.'
  3450. sets flag foo to the value: `This is a string.'
  3451. The command `@value{foo}' expands to the value."
  3452. (let* ((arg (texinfo-parse-arg-discard))
  3453. (flag (car (read-from-string arg)))
  3454. (value (substring arg (cdr (read-from-string arg)))))
  3455. (if (string-match "^[ \t]+" value)
  3456. (setq value (substring value (match-end 0))))
  3457. (put flag 'texinfo-whether-setp 'flag-set)
  3458. (put flag 'texinfo-set-value value)))
  3459. (put 'value 'texinfo-format 'texinfo-value)
  3460. (defun texinfo-value ()
  3461. "Insert the string to which the flag is set.
  3462. The command `@set foo This is a string.'
  3463. sets flag foo to the value: `This is a string.'
  3464. The command `@value{foo}' expands to the value."
  3465. (let ((arg (texinfo-parse-arg-discard)))
  3466. (cond ((and
  3467. (eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
  3468. 'flag-set)
  3469. (get (car (read-from-string arg)) 'texinfo-set-value))
  3470. (insert (get (car (read-from-string arg)) 'texinfo-set-value)))
  3471. ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
  3472. 'flag-cleared)
  3473. (insert (format "{No value for \"%s\"}" arg)))
  3474. ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) nil)
  3475. (insert (format "{No value for \"%s\"}" arg))))))
  3476. (put 'ifset 'texinfo-end 'texinfo-discard-command)
  3477. (put 'ifset 'texinfo-format 'texinfo-if-set)
  3478. (defun texinfo-if-set ()
  3479. "If set, continue formatting; else do not format region up to @end ifset."
  3480. (let ((arg (texinfo-parse-arg-discard)))
  3481. (cond
  3482. ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
  3483. 'flag-set)
  3484. ;; Format the text (i.e., do not remove it); do nothing here.
  3485. ())
  3486. ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
  3487. 'flag-cleared)
  3488. ;; Clear region (i.e., cause the text to be ignored).
  3489. (delete-region texinfo-command-start
  3490. (re-search-forward "@end ifset[ \t]*\n")))
  3491. ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
  3492. nil)
  3493. ;; In this case flag is neither set nor cleared.
  3494. ;; Act as if set, i.e. do nothing.
  3495. ()))))
  3496. (put 'ifclear 'texinfo-end 'texinfo-discard-command)
  3497. (put 'ifclear 'texinfo-format 'texinfo-if-clear)
  3498. (defun texinfo-if-clear ()
  3499. "If clear, continue formatting; if set, do not format up to @end ifset."
  3500. (let ((arg (texinfo-parse-arg-discard)))
  3501. (cond
  3502. ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
  3503. 'flag-set)
  3504. ;; Clear region (i.e., cause the text to be ignored).
  3505. (delete-region texinfo-command-start
  3506. (re-search-forward "@end ifclear[ \t]*\n")))
  3507. ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
  3508. 'flag-cleared)
  3509. ;; Format the text (i.e., do not remove it); do nothing here.
  3510. ())
  3511. ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp)
  3512. nil)
  3513. ;; In this case flag is neither set nor cleared.
  3514. ;; Act as if clear, i.e. do nothing.
  3515. ()))))
  3516. ;;; @ifeq
  3517. (put 'ifeq 'texinfo-format 'texinfo-format-ifeq)
  3518. (defun texinfo-format-ifeq ()
  3519. "If ARG1 and ARG2 caselessly string compare to same string, perform COMMAND.
  3520. Otherwise produces no output.
  3521. Thus:
  3522. @ifeq{ arg1 , arg1 , @code{foo}} bar
  3523. ==> `foo' bar.
  3524. but
  3525. @ifeq{ arg1 , arg2 , @code{foo}} bar
  3526. ==> bar
  3527. Note that the Texinfo command and its arguments must be arguments to
  3528. the @ifeq command."
  3529. ;; compare-buffer-substrings does not exist in version 18; don't use
  3530. (goto-char texinfo-command-end)
  3531. (let* ((case-fold-search t)
  3532. (stop (save-excursion (forward-sexp 1) (point)))
  3533. start end
  3534. ;; @ifeq{arg1, arg2, @command{optional-args}}
  3535. (arg1
  3536. (progn
  3537. (forward-char 1)
  3538. (skip-chars-forward " ")
  3539. (setq start (point))
  3540. (search-forward "," stop t)
  3541. (skip-chars-backward ", ")
  3542. (buffer-substring-no-properties start (point))))
  3543. (arg2
  3544. (progn
  3545. (search-forward "," stop t)
  3546. (skip-chars-forward " ")
  3547. (setq start (point))
  3548. (search-forward "," stop t)
  3549. (skip-chars-backward ", ")
  3550. (buffer-substring-no-properties start (point))))
  3551. (texinfo-command
  3552. (progn
  3553. (search-forward "," stop t)
  3554. (skip-chars-forward " ")
  3555. (setq start (point))
  3556. (goto-char (1- stop))
  3557. (skip-chars-backward " ")
  3558. (buffer-substring-no-properties start (point)))))
  3559. (delete-region texinfo-command-start stop)
  3560. (if (equal arg1 arg2)
  3561. (insert texinfo-command))
  3562. (goto-char texinfo-command-start)))
  3563. ;;; Process included files: `@include' command
  3564. ;; Updated 19 October 1990
  3565. ;; In the original version, include files were ignored by Info but
  3566. ;; incorporated in to the printed manual. To make references to the
  3567. ;; included file, the Texinfo source file has to refer to the included
  3568. ;; files using the `(filename)nodename' format for referring to other
  3569. ;; Info files. Also, the included files had to be formatted on their
  3570. ;; own. It was just like they were another file.
  3571. ;; Currently, include files are inserted into the buffer that is
  3572. ;; formatted for Info. If large, the resulting info file is split and
  3573. ;; tagified. For current include files to work, the master menu must
  3574. ;; refer to all the nodes, and the highest level nodes in the include
  3575. ;; files must have the correct next, prev, and up pointers.
  3576. ;; The included file may have an @setfilename and even an @settitle,
  3577. ;; but not an `\input texinfo' line.
  3578. ;; Updated 24 March 1993
  3579. ;; In order for @raisesections and @lowersections to work, included
  3580. ;; files must be inserted into the buffer holding the outer file
  3581. ;; before other Info formatting takes place. So @include is no longer
  3582. ;; is treated like other @-commands.
  3583. (put 'include 'texinfo-format 'texinfo-format-noop)
  3584. ;; Original definition:
  3585. ;; (defun texinfo-format-include ()
  3586. ;; (let ((filename (texinfo-parse-arg-discard))
  3587. ;; (default-directory input-directory)
  3588. ;; subindex)
  3589. ;; (setq subindex
  3590. ;; (save-excursion
  3591. ;; (progn (find-file
  3592. ;; (cond ((file-readable-p (concat filename ".texinfo"))
  3593. ;; (concat filename ".texinfo"))
  3594. ;; ((file-readable-p (concat filename ".texi"))
  3595. ;; (concat filename ".texi"))
  3596. ;; ((file-readable-p (concat filename ".tex"))
  3597. ;; (concat filename ".tex"))
  3598. ;; ((file-readable-p filename)
  3599. ;; filename)
  3600. ;; (t (error "@include'd file %s not found"
  3601. ;; filename))))
  3602. ;; (texinfo-format-buffer-1))))
  3603. ;; (texinfo-subindex 'texinfo-vindex (car subindex) (nth 1 subindex))
  3604. ;; (texinfo-subindex 'texinfo-findex (car subindex) (nth 2 subindex))
  3605. ;; (texinfo-subindex 'texinfo-cindex (car subindex) (nth 3 subindex))
  3606. ;; (texinfo-subindex 'texinfo-pindex (car subindex) (nth 4 subindex))
  3607. ;; (texinfo-subindex 'texinfo-tindex (car subindex) (nth 5 subindex))
  3608. ;; (texinfo-subindex 'texinfo-kindex (car subindex) (nth 6 subindex))))
  3609. ;;
  3610. ;;(defun texinfo-subindex (indexvar file content)
  3611. ;; (set indexvar (cons (list 'recurse file content)
  3612. ;; (symbol-value indexvar))))
  3613. ;; Second definition:
  3614. ;; (put 'include 'texinfo-format 'texinfo-format-include)
  3615. ;; (defun texinfo-format-include ()
  3616. ;; (let ((filename (concat input-directory
  3617. ;; (texinfo-parse-arg-discard)))
  3618. ;; (default-directory input-directory))
  3619. ;; (message "Reading: %s" filename)
  3620. ;; (save-excursion
  3621. ;; (save-restriction
  3622. ;; (narrow-to-region
  3623. ;; (point)
  3624. ;; (+ (point) (car (cdr (insert-file-contents filename)))))
  3625. ;; (goto-char (point-min))
  3626. ;; (texinfo-append-refill)
  3627. ;; (texinfo-format-convert (point-min) (point-max))))
  3628. ;; (setq last-input-buffer input-buffer) ; to bypass setfilename
  3629. ;; ))
  3630. ;;; Numerous commands do nothing in Info
  3631. ;; These commands are defined in texinfo.tex for printed output.
  3632. ;;; various noops, such as @b{foo}, that take arguments in braces
  3633. (put 'b 'texinfo-format 'texinfo-format-noop)
  3634. (put 'i 'texinfo-format 'texinfo-format-noop)
  3635. (put 'r 'texinfo-format 'texinfo-format-noop)
  3636. (put 't 'texinfo-format 'texinfo-format-noop)
  3637. (put 'w 'texinfo-format 'texinfo-format-noop)
  3638. (put 'asis 'texinfo-format 'texinfo-format-noop)
  3639. (put 'dmn 'texinfo-format 'texinfo-format-noop)
  3640. (put 'math 'texinfo-format 'texinfo-format-noop)
  3641. (put 'titlefont 'texinfo-format 'texinfo-format-noop)
  3642. (defun texinfo-format-noop ()
  3643. (insert (texinfo-parse-arg-discard))
  3644. (goto-char texinfo-command-start))
  3645. ;; @hyphenation command discards an argument within braces
  3646. (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
  3647. (defun texinfo-discard-command-and-arg ()
  3648. "Discard both @-command and its argument in braces."
  3649. (goto-char texinfo-command-end)
  3650. (forward-list 1)
  3651. (setq texinfo-command-end (point))
  3652. (delete-region texinfo-command-start texinfo-command-end))
  3653. ;;; Do nothing commands, such as @smallbook, that have no args and no braces
  3654. ;; These must appear on a line of their own
  3655. (put 'bye 'texinfo-format 'texinfo-discard-line)
  3656. (put 'smallbook 'texinfo-format 'texinfo-discard-line)
  3657. (put 'finalout 'texinfo-format 'texinfo-discard-line)
  3658. (put 'overfullrule 'texinfo-format 'texinfo-discard-line)
  3659. (put 'smallbreak 'texinfo-format 'texinfo-discard-line)
  3660. (put 'medbreak 'texinfo-format 'texinfo-discard-line)
  3661. (put 'bigbreak 'texinfo-format 'texinfo-discard-line)
  3662. (put 'afourpaper 'texinfo-format 'texinfo-discard-line)
  3663. (put 'afivepaper 'texinfo-format 'texinfo-discard-line)
  3664. (put 'afourlatex 'texinfo-format 'texinfo-discard-line)
  3665. (put 'afourwide 'texinfo-format 'texinfo-discard-line)
  3666. ;;; These noop commands discard the rest of the line.
  3667. (put 'c 'texinfo-format 'texinfo-discard-line-with-args)
  3668. (put 'comment 'texinfo-format 'texinfo-discard-line-with-args)
  3669. (put 'contents 'texinfo-format 'texinfo-discard-line-with-args)
  3670. (put 'group 'texinfo-end 'texinfo-discard-line-with-args)
  3671. (put 'group 'texinfo-format 'texinfo-discard-line-with-args)
  3672. (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
  3673. (put 'setchapterstyle 'texinfo-format 'texinfo-discard-line-with-args)
  3674. (put 'hsize 'texinfo-format 'texinfo-discard-line-with-args)
  3675. (put 'itemindent 'texinfo-format 'texinfo-discard-line-with-args)
  3676. (put 'lispnarrowing 'texinfo-format 'texinfo-discard-line-with-args)
  3677. (put 'need 'texinfo-format 'texinfo-discard-line-with-args)
  3678. (put 'nopara 'texinfo-format 'texinfo-discard-line-with-args)
  3679. ;; @novalidate suppresses cross-reference checking and auxiliary file
  3680. ;; creation with TeX. The Info-validate command checks that every
  3681. ;; node pointer points to an existing node. Since this Info command
  3682. ;; is not invoked automatically, the @novalidate command is irrelevant
  3683. ;; and not supported by texinfmt.el
  3684. (put 'novalidate 'texinfo-format 'texinfo-discard-line-with-args)
  3685. (put 'page 'texinfo-format 'texinfo-discard-line-with-args)
  3686. (put 'pagesizes 'texinfo-format 'texinfo-discard-line-with-args)
  3687. (put 'parindent 'texinfo-format 'texinfo-discard-line-with-args)
  3688. (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
  3689. (put 'setq 'texinfo-format 'texinfo-discard-line-with-args)
  3690. (put 'setcontentsaftertitlepage
  3691. 'texinfo-format 'texinfo-discard-line-with-args)
  3692. (put 'setshortcontentsaftertitlepage
  3693. 'texinfo-format 'texinfo-discard-line-with-args)
  3694. (put 'settitle 'texinfo-format 'texinfo-discard-line-with-args)
  3695. (put 'setx 'texinfo-format 'texinfo-discard-line-with-args)
  3696. (put 'shortcontents 'texinfo-format 'texinfo-discard-line-with-args)
  3697. (put 'shorttitlepage 'texinfo-format 'texinfo-discard-line-with-args)
  3698. (put 'summarycontents 'texinfo-format 'texinfo-discard-line-with-args)
  3699. (put 'input 'texinfo-format 'texinfo-discard-line-with-args)
  3700. (put 'documentlanguage 'texinfo-format 'texinfo-discard-line-with-args)
  3701. (put 'documentencoding 'texinfo-format 'texinfo-discard-line-with-args)
  3702. ;;; Some commands cannot be handled
  3703. (defun texinfo-unsupported ()
  3704. (error "%s is not handled by texinfo"
  3705. (buffer-substring-no-properties texinfo-command-start texinfo-command-end)))
  3706. ;;; Batch formatting
  3707. (defun batch-texinfo-format ()
  3708. "Run `texinfo-format-buffer' on the files remaining on the command line.
  3709. Must be used only with -batch, and kills Emacs on completion.
  3710. Each file will be processed even if an error occurred previously.
  3711. For example, invoke
  3712. \"emacs -batch -l texinfmt -f batch-texinfo-format $docs/ ~/*.texinfo\"."
  3713. (if (not noninteractive)
  3714. (error "batch-texinfo-format may only be used -batch"))
  3715. (let ((version-control t)
  3716. (auto-save-default nil)
  3717. (find-file-run-dired nil)
  3718. (kept-old-versions 259259)
  3719. (kept-new-versions 259259))
  3720. (let ((error 0)
  3721. file
  3722. (files ()))
  3723. (while command-line-args-left
  3724. (setq file (expand-file-name (car command-line-args-left)))
  3725. (cond ((not (file-exists-p file))
  3726. (message ">> %s does not exist!" file)
  3727. (setq error 1
  3728. command-line-args-left (cdr command-line-args-left)))
  3729. ((file-directory-p file)
  3730. (setq command-line-args-left
  3731. (nconc (directory-files file)
  3732. (cdr command-line-args-left))))
  3733. (t
  3734. (push file files)
  3735. (setq command-line-args-left (cdr command-line-args-left)))))
  3736. (while files
  3737. (setq file (car files)
  3738. files (cdr files))
  3739. (condition-case err
  3740. (progn
  3741. (if buffer-file-name (kill-buffer (current-buffer)))
  3742. (find-file file)
  3743. (buffer-disable-undo (current-buffer))
  3744. (set-buffer-modified-p nil)
  3745. (texinfo-mode)
  3746. (message "texinfo formatting %s..." file)
  3747. (texinfo-format-buffer nil)
  3748. (if (buffer-modified-p)
  3749. (progn (message "Saving modified %s" (buffer-file-name))
  3750. (save-buffer))))
  3751. (error
  3752. (message ">> Error: %s" (prin1-to-string err))
  3753. (message ">> point at")
  3754. (let ((s (buffer-substring-no-properties (point)
  3755. (min (+ (point) 100)
  3756. (point-max))))
  3757. (tem 0))
  3758. (while (setq tem (string-match "\n+" s tem))
  3759. (setq s (concat (substring s 0 (match-beginning 0))
  3760. "\n>> "
  3761. (substring s (match-end 0)))
  3762. tem (1+ tem)))
  3763. (message ">> %s" s))
  3764. (setq error 1))))
  3765. (kill-emacs error))))
  3766. ;;; Place `provide' at end of file.
  3767. (provide 'texinfmt)
  3768. ;;; texinfmt.el ends here