texinfmt.el 157 KB

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