ox-texinfo.el 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724
  1. ;;; ox-texinfo.el --- Texinfo Back-End for Org Export Engine
  2. ;; Copyright (C) 2012-2014 Free Software Foundation, Inc.
  3. ;; Author: Jonathan Leech-Pepin <jonathan.leechpepin at gmail dot com>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;;
  18. ;; See Org manual for details.
  19. ;;; Code:
  20. (eval-when-compile (require 'cl))
  21. (require 'ox)
  22. (defvar orgtbl-exp-regexp)
  23. ;;; Define Back-End
  24. (org-export-define-backend 'texinfo
  25. '((bold . org-texinfo-bold)
  26. (center-block . org-texinfo-center-block)
  27. (clock . org-texinfo-clock)
  28. (code . org-texinfo-code)
  29. (comment . (lambda (&rest args) ""))
  30. (comment-block . (lambda (&rest args) ""))
  31. (drawer . org-texinfo-drawer)
  32. (dynamic-block . org-texinfo-dynamic-block)
  33. (entity . org-texinfo-entity)
  34. (example-block . org-texinfo-example-block)
  35. (export-snippet . org-texinfo-export-snippet)
  36. (fixed-width . org-texinfo-fixed-width)
  37. (footnote-definition . org-texinfo-footnote-definition)
  38. (footnote-reference . org-texinfo-footnote-reference)
  39. (headline . org-texinfo-headline)
  40. (inline-src-block . org-texinfo-inline-src-block)
  41. (inlinetask . org-texinfo-inlinetask)
  42. (italic . org-texinfo-italic)
  43. (item . org-texinfo-item)
  44. (keyword . org-texinfo-keyword)
  45. (line-break . org-texinfo-line-break)
  46. (link . org-texinfo-link)
  47. (node-property . org-texinfo-node-property)
  48. (paragraph . org-texinfo-paragraph)
  49. (plain-list . org-texinfo-plain-list)
  50. (plain-text . org-texinfo-plain-text)
  51. (planning . org-texinfo-planning)
  52. (property-drawer . org-texinfo-property-drawer)
  53. (quote-block . org-texinfo-quote-block)
  54. (radio-target . org-texinfo-radio-target)
  55. (section . org-texinfo-section)
  56. (special-block . org-texinfo-special-block)
  57. (src-block . org-texinfo-src-block)
  58. (statistics-cookie . org-texinfo-statistics-cookie)
  59. (subscript . org-texinfo-subscript)
  60. (superscript . org-texinfo-superscript)
  61. (table . org-texinfo-table)
  62. (table-cell . org-texinfo-table-cell)
  63. (table-row . org-texinfo-table-row)
  64. (target . org-texinfo-target)
  65. (template . org-texinfo-template)
  66. (timestamp . org-texinfo-timestamp)
  67. (verbatim . org-texinfo-verbatim)
  68. (verse-block . org-texinfo-verse-block))
  69. :export-block "TEXINFO"
  70. :filters-alist
  71. '((:filter-headline . org-texinfo-filter-section-blank-lines)
  72. (:filter-section . org-texinfo-filter-section-blank-lines))
  73. :menu-entry
  74. '(?i "Export to Texinfo"
  75. ((?t "As TEXI file" org-texinfo-export-to-texinfo)
  76. (?i "As INFO file" org-texinfo-export-to-info)))
  77. :options-alist
  78. '((:texinfo-filename "TEXINFO_FILENAME" nil nil t)
  79. (:texinfo-class "TEXINFO_CLASS" nil org-texinfo-default-class t)
  80. (:texinfo-header "TEXINFO_HEADER" nil nil newline)
  81. (:texinfo-post-header "TEXINFO_POST_HEADER" nil nil newline)
  82. (:subtitle "SUBTITLE" nil nil newline)
  83. (:subauthor "SUBAUTHOR" nil nil newline)
  84. (:texinfo-dircat "TEXINFO_DIR_CATEGORY" nil nil t)
  85. (:texinfo-dirtitle "TEXINFO_DIR_TITLE" nil nil t)
  86. (:texinfo-dirdesc "TEXINFO_DIR_DESC" nil nil t)
  87. (:texinfo-printed-title "TEXINFO_PRINTED_TITLE" nil nil t)
  88. ;; Other variables.
  89. (:texinfo-classes nil nil org-texinfo-classes)
  90. (:texinfo-format-headline-function nil nil org-texinfo-format-headline-function)
  91. (:texinfo-node-description-column nil nil org-texinfo-node-description-column)
  92. (:texinfo-active-timestamp-format nil nil org-texinfo-active-timestamp-format)
  93. (:texinfo-inactive-timestamp-format nil nil org-texinfo-inactive-timestamp-format)
  94. (:texinfo-diary-timestamp-format nil nil org-texinfo-diary-timestamp-format)
  95. (:texinfo-link-with-unknown-path-format nil nil org-texinfo-link-with-unknown-path-format)
  96. (:texinfo-tables-verbatim nil nil org-texinfo-tables-verbatim)
  97. (:texinfo-table-scientific-notation nil nil org-texinfo-table-scientific-notation)
  98. (:texinfo-def-table-markup nil nil org-texinfo-def-table-markup)
  99. (:texinfo-text-markup-alist nil nil org-texinfo-text-markup-alist)
  100. (:texinfo-format-drawer-function nil nil org-texinfo-format-drawer-function)
  101. (:texinfo-format-inlinetask-function nil nil org-texinfo-format-inlinetask-function)))
  102. ;;; User Configurable Variables
  103. (defgroup org-export-texinfo nil
  104. "Options for exporting Org mode files to Texinfo."
  105. :tag "Org Export Texinfo"
  106. :version "24.4"
  107. :package-version '(Org . "8.0")
  108. :group 'org-export)
  109. ;;;; Preamble
  110. (defcustom org-texinfo-coding-system nil
  111. "Default document encoding for Texinfo output.
  112. If `nil' it will default to `buffer-file-coding-system'."
  113. :group 'org-export-texinfo
  114. :type 'coding-system)
  115. (defcustom org-texinfo-default-class "info"
  116. "The default Texinfo class."
  117. :group 'org-export-texinfo
  118. :type '(string :tag "Texinfo class"))
  119. (defcustom org-texinfo-classes
  120. '(("info"
  121. "@documentencoding AUTO\n@documentlanguage AUTO"
  122. ("@chapter %s" . "@unnumbered %s")
  123. ("@section %s" . "@unnumberedsec %s")
  124. ("@subsection %s" . "@unnumberedsubsec %s")
  125. ("@subsubsection %s" . "@unnumberedsubsubsec %s")))
  126. "Alist of Texinfo classes and associated header and structure.
  127. If #+TEXINFO_CLASS is set in the buffer, use its value and the
  128. associated information. Here is the structure of each cell:
  129. \(class-name
  130. header-string
  131. \(numbered-section . unnumbered-section)
  132. ...)
  133. The header string
  134. -----------------
  135. The header string is inserted in the header of the generated
  136. document, right after \"@setfilename\" and \"@settitle\"
  137. commands.
  138. If it contains the special string
  139. \"@documentencoding AUTO\"
  140. \"AUTO\" will be replaced with an appropriate coding system. See
  141. `org-texinfo-coding-system' for more information. Likewise, if
  142. the string contains the special string
  143. \"@documentlanguage AUTO\"
  144. \"AUTO\" will be replaced with the language defined in the
  145. buffer, through #+LANGUAGE keyword, or globally, with
  146. `org-export-default-language', which see.
  147. The sectioning structure
  148. ------------------------
  149. The sectioning structure of the class is given by the elements
  150. following the header string. For each sectioning level, a number
  151. of strings is specified. A %s formatter is mandatory in each
  152. section string and will be replaced by the title of the section.
  153. Instead of a list of sectioning commands, you can also specify
  154. a function name. That function will be called with two
  155. parameters, the reduced) level of the headline, and a predicate
  156. non-nil when the headline should be numbered. It must return
  157. a format string in which the section title will be added."
  158. :group 'org-export-texinfo
  159. :version "24.4"
  160. :package-version '(Org . "8.2")
  161. :type '(repeat
  162. (list (string :tag "Texinfo class")
  163. (string :tag "Texinfo header")
  164. (repeat :tag "Levels" :inline t
  165. (choice
  166. (cons :tag "Heading"
  167. (string :tag " numbered")
  168. (string :tag "unnumbered"))
  169. (function :tag "Hook computing sectioning"))))))
  170. ;;;; Headline
  171. (defcustom org-texinfo-format-headline-function
  172. 'org-texinfo-format-headline-default-function
  173. "Function to format headline text.
  174. This function will be called with 5 arguments:
  175. TODO the todo keyword (string or nil).
  176. TODO-TYPE the type of todo (symbol: `todo', `done', nil)
  177. PRIORITY the priority of the headline (integer or nil)
  178. TEXT the main headline text (string).
  179. TAGS the tags as a list of strings (list of strings or nil).
  180. The function result will be used in the section format string."
  181. :group 'org-export-texinfo
  182. :type 'function
  183. :version "24.5"
  184. :package-version '(Org . "8.3"))
  185. ;;;; Node listing (menu)
  186. (defcustom org-texinfo-node-description-column 32
  187. "Column at which to start the description in the node listings.
  188. If a node title is greater than this length, the description will
  189. be placed after the end of the title."
  190. :group 'org-export-texinfo
  191. :type 'integer)
  192. ;;;; Timestamps
  193. (defcustom org-texinfo-active-timestamp-format "@emph{%s}"
  194. "A printf format string to be applied to active timestamps."
  195. :group 'org-export-texinfo
  196. :type 'string)
  197. (defcustom org-texinfo-inactive-timestamp-format "@emph{%s}"
  198. "A printf format string to be applied to inactive timestamps."
  199. :group 'org-export-texinfo
  200. :type 'string)
  201. (defcustom org-texinfo-diary-timestamp-format "@emph{%s}"
  202. "A printf format string to be applied to diary timestamps."
  203. :group 'org-export-texinfo
  204. :type 'string)
  205. ;;;; Links
  206. (defcustom org-texinfo-link-with-unknown-path-format "@indicateurl{%s}"
  207. "Format string for links with unknown path type."
  208. :group 'org-export-texinfo
  209. :type 'string)
  210. ;;;; Tables
  211. (defcustom org-texinfo-tables-verbatim nil
  212. "When non-nil, tables are exported verbatim."
  213. :group 'org-export-texinfo
  214. :type 'boolean)
  215. (defcustom org-texinfo-table-scientific-notation "%s\\,(%s)"
  216. "Format string to display numbers in scientific notation.
  217. The format should have \"%s\" twice, for mantissa and exponent
  218. \(i.e. \"%s\\\\times10^{%s}\").
  219. When nil, no transformation is made."
  220. :group 'org-export-texinfo
  221. :type '(choice
  222. (string :tag "Format string")
  223. (const :tag "No formatting" nil)))
  224. (defcustom org-texinfo-def-table-markup "@samp"
  225. "Default setting for @table environments."
  226. :group 'org-export-texinfo
  227. :type 'string)
  228. ;;;; Text markup
  229. (defcustom org-texinfo-text-markup-alist '((bold . "@strong{%s}")
  230. (code . code)
  231. (italic . "@emph{%s}")
  232. (verbatim . verb)
  233. (comment . "@c %s"))
  234. "Alist of Texinfo expressions to convert text markup.
  235. The key must be a symbol among `bold', `italic' and `comment'.
  236. The value is a formatting string to wrap fontified text with.
  237. Value can also be set to the following symbols: `verb' and
  238. `code'. For the former, Org will use \"@verb\" to
  239. create a format string and select a delimiter character that
  240. isn't in the string. For the latter, Org will use \"@code\"
  241. to typeset and try to protect special characters.
  242. If no association can be found for a given markup, text will be
  243. returned as-is."
  244. :group 'org-export-texinfo
  245. :type 'alist
  246. :options '(bold code italic verbatim comment))
  247. ;;;; Drawers
  248. (defcustom org-texinfo-format-drawer-function
  249. (lambda (name contents) contents)
  250. "Function called to format a drawer in Texinfo code.
  251. The function must accept two parameters:
  252. NAME the drawer name, like \"LOGBOOK\"
  253. CONTENTS the contents of the drawer.
  254. The function should return the string to be exported.
  255. The default function simply returns the value of CONTENTS."
  256. :group 'org-export-texinfo
  257. :version "24.4"
  258. :package-version '(Org . "8.2")
  259. :type 'function)
  260. ;;;; Inlinetasks
  261. (defcustom org-texinfo-format-inlinetask-function
  262. 'org-texinfo-format-inlinetask-default-function
  263. "Function called to format an inlinetask in Texinfo code.
  264. The function must accept six parameters:
  265. TODO the todo keyword, as a string
  266. TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
  267. PRIORITY the inlinetask priority, as a string
  268. NAME the inlinetask name, as a string.
  269. TAGS the inlinetask tags, as a list of strings.
  270. CONTENTS the contents of the inlinetask, as a string.
  271. The function should return the string to be exported."
  272. :group 'org-export-texinfo
  273. :type 'function)
  274. ;;;; Compilation
  275. (defcustom org-texinfo-info-process
  276. '("makeinfo %f")
  277. "Commands to process a Texinfo file to an INFO file.
  278. This is list of strings, each of them will be given to the shell
  279. as a command. %f in the command will be replaced by the full
  280. file name, %b by the file base name \(i.e without extension) and
  281. %o by the base directory of the file."
  282. :group 'org-export-texinfo
  283. :type '(repeat :tag "Shell command sequence"
  284. (string :tag "Shell command")))
  285. (defcustom org-texinfo-logfiles-extensions
  286. '("aux" "toc" "cp" "fn" "ky" "pg" "tp" "vr")
  287. "The list of file extensions to consider as Texinfo logfiles.
  288. The logfiles will be remove if `org-texinfo-remove-logfiles' is
  289. non-nil."
  290. :group 'org-export-texinfo
  291. :type '(repeat (string :tag "Extension")))
  292. (defcustom org-texinfo-remove-logfiles t
  293. "Non-nil means remove the logfiles produced by compiling a Texinfo file.
  294. By default, logfiles are files with these extensions: .aux, .toc,
  295. .cp, .fn, .ky, .pg and .tp. To define the set of logfiles to remove,
  296. set `org-texinfo-logfiles-extensions'."
  297. :group 'org-export-latex
  298. :type 'boolean)
  299. ;;; Constants
  300. (defconst org-texinfo-max-toc-depth 4
  301. "Maximum depth for creation of detailed menu listings. Beyond
  302. this depth Texinfo will not recognize the nodes and will cause
  303. errors. Left as a constant in case this value ever changes.")
  304. (defconst org-texinfo-supported-coding-systems
  305. '("US-ASCII" "UTF-8" "ISO-8859-15" "ISO-8859-1" "ISO-8859-2" "koi8-r" "koi8-u")
  306. "List of coding systems supported by Texinfo, as strings.
  307. Specified coding system will be matched against these strings.
  308. If two strings share the same prefix (e.g. \"ISO-8859-1\" and
  309. \"ISO-8859-15\"), the most specific one has to be listed first.")
  310. ;;; Internal Functions
  311. (defun org-texinfo-filter-section-blank-lines (headline back-end info)
  312. "Filter controlling number of blank lines after a section."
  313. (let ((blanks (make-string 2 ?\n)))
  314. (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" blanks headline)))
  315. (defun org-texinfo--find-verb-separator (s)
  316. "Return a character not used in string S.
  317. This is used to choose a separator for constructs like \\verb."
  318. (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
  319. (loop for c across ll
  320. when (not (string-match (regexp-quote (char-to-string c)) s))
  321. return (char-to-string c))))
  322. (defun org-texinfo--make-option-string (options)
  323. "Return a comma separated string of keywords and values.
  324. OPTIONS is an alist where the key is the options keyword as
  325. a string, and the value a list containing the keyword value, or
  326. nil."
  327. (mapconcat (lambda (pair)
  328. (concat (first pair)
  329. (when (> (length (second pair)) 0)
  330. (concat "=" (second pair)))))
  331. options
  332. ","))
  333. (defun org-texinfo--text-markup (text markup info)
  334. "Format TEXT depending on MARKUP text markup.
  335. INFO is a plist used as a communication channel. See
  336. `org-texinfo-text-markup-alist' for details."
  337. (let ((fmt (cdr (assq markup org-texinfo-text-markup-alist))))
  338. (cond
  339. ;; No format string: Return raw text.
  340. ((not fmt) text)
  341. ((eq 'verb fmt)
  342. (let ((separator (org-texinfo--find-verb-separator text)))
  343. (concat "@verb{" separator text separator "}")))
  344. ((eq 'code fmt)
  345. (let ((start 0)
  346. (rtn "")
  347. char)
  348. (while (string-match "[@{}]" text)
  349. (setq char (match-string 0 text))
  350. (if (> (match-beginning 0) 0)
  351. (setq rtn (concat rtn (substring text 0 (match-beginning 0)))))
  352. (setq text (substring text (1+ (match-beginning 0))))
  353. (setq char (concat "@" char)
  354. rtn (concat rtn char)))
  355. (setq text (concat rtn text)
  356. fmt "@code{%s}")
  357. (format fmt text)))
  358. ;; Else use format string.
  359. (t (format fmt text)))))
  360. (defun org-texinfo--get-node (headline info)
  361. "Return node entry associated to HEADLINE.
  362. INFO is a plist used as a communication channel."
  363. (let ((menu-title (org-export-get-alt-title headline info)))
  364. (org-texinfo--sanitize-menu
  365. (replace-regexp-in-string
  366. "%" "%%"
  367. (if menu-title (org-export-data menu-title info)
  368. (org-texinfo--sanitize-headline
  369. (org-element-property :title headline) info))))))
  370. ;;;; Headline sanitizing
  371. (defun org-texinfo--sanitize-headline (headline info)
  372. "Remove all formatting from the text of a headline for use in
  373. node and menu listing."
  374. (mapconcat 'identity
  375. (org-texinfo--sanitize-headline-contents headline info) " "))
  376. (defun org-texinfo--sanitize-headline-contents (headline info)
  377. "Retrieve the content of the headline.
  378. Any content that can contain further formatting is checked
  379. recursively, to ensure that nested content is also properly
  380. retrieved."
  381. (loop for contents in headline append
  382. (cond
  383. ;; already a string
  384. ((stringp contents)
  385. (list (replace-regexp-in-string " $" "" contents)))
  386. ;; Is exported as-is (value)
  387. ((org-element-map contents '(verbatim code)
  388. (lambda (value) (org-element-property :value value)) info))
  389. ;; Has content and recurse into the content
  390. ((org-element-contents contents)
  391. (org-texinfo--sanitize-headline-contents
  392. (org-element-contents contents) info)))))
  393. ;;;; Menu sanitizing
  394. (defun org-texinfo--sanitize-menu (title)
  395. "Remove invalid characters from TITLE for use in menus and
  396. nodes.
  397. Based on Texinfo specifications, the following must be removed:
  398. @ { } ( ) : . ,"
  399. (replace-regexp-in-string "[@{}():,.]" "" title))
  400. ;;;; Content sanitizing
  401. (defun org-texinfo--sanitize-content (text)
  402. "Ensure characters are properly escaped when used in headlines or blocks.
  403. Escape characters are: @ { }"
  404. (replace-regexp-in-string "\\\([@{}]\\\)" "@\\1" text))
  405. ;;;; Menu creation
  406. (defun org-texinfo--build-menu (tree level info &optional detailed)
  407. "Create the @menu/@end menu information from TREE at headline
  408. level LEVEL.
  409. TREE contains the parse-tree to work with, either of the entire
  410. document or of a specific parent headline. LEVEL indicates what
  411. level of headlines to look at when generating the menu. INFO is
  412. a plist containing contextual information.
  413. Detailed determines whether to build a single level of menu, or
  414. recurse into all children as well."
  415. (let ((menu (org-texinfo--generate-menu-list tree level info))
  416. output text-menu)
  417. (cond
  418. (detailed
  419. ;; Looping is done within the menu generation.
  420. (setq text-menu (org-texinfo--generate-detailed menu level info)))
  421. (t
  422. (setq text-menu (org-texinfo--generate-menu-items menu info))))
  423. (when text-menu
  424. (setq output (org-texinfo--format-menu text-menu info))
  425. (mapconcat 'identity output "\n"))))
  426. (defun org-texinfo--generate-detailed (menu level info)
  427. "Generate a detailed listing of all subheadings within MENU starting at LEVEL.
  428. MENU is the parse-tree to work with. LEVEL is the starting level
  429. for the menu headlines and from which recursion occurs. INFO is
  430. a plist containing contextual information."
  431. (when level
  432. (let ((max-depth (min org-texinfo-max-toc-depth
  433. (plist-get info :headline-levels))))
  434. (when (> max-depth level)
  435. (loop for headline in menu append
  436. (let* ((title (org-texinfo--menu-headlines headline info))
  437. ;; Create list of menu entries for the next level
  438. (sublist (org-texinfo--generate-menu-list
  439. headline (1+ level) info))
  440. ;; Generate the menu items for that level. If
  441. ;; there are none omit that heading completely,
  442. ;; otherwise join the title to it's related entries.
  443. (submenu (if (org-texinfo--generate-menu-items sublist info)
  444. (append (list title)
  445. (org-texinfo--generate-menu-items sublist info))
  446. 'nil))
  447. ;; Start the process over the next level down.
  448. (recursion (org-texinfo--generate-detailed sublist (1+ level) info)))
  449. (setq recursion (append submenu recursion))
  450. recursion))))))
  451. (defun org-texinfo--generate-menu-list (tree level info)
  452. "Generate the list of headlines that are within a given level
  453. of the tree for further formatting.
  454. TREE is the parse-tree containing the headlines. LEVEL is the
  455. headline level to generate a list of. INFO is a plist holding
  456. contextual information."
  457. (org-element-map tree 'headline
  458. (lambda (head)
  459. (and (= (org-export-get-relative-level head info) level)
  460. ;; Do not take note of footnotes or copying headlines.
  461. (not (org-not-nil (org-element-property :COPYING head)))
  462. (not (org-element-property :footnote-section-p head))
  463. ;; Collect headline.
  464. head))
  465. info))
  466. (defun org-texinfo--generate-menu-items (items info)
  467. "Generate a list of headline information from the listing ITEMS.
  468. ITEMS is a list of the headlines to be converted into entries.
  469. INFO is a plist containing contextual information.
  470. Returns a list containing the following information from each
  471. headline: length, title, description. This is used to format the
  472. menu using `org-texinfo--format-menu'."
  473. (loop for headline in items collect
  474. (let* ((menu-title (org-texinfo--sanitize-menu
  475. (org-export-data
  476. (org-export-get-alt-title headline info)
  477. info)))
  478. (title (org-texinfo--sanitize-menu
  479. (org-texinfo--sanitize-headline
  480. (org-element-property :title headline) info)))
  481. (descr (org-export-data
  482. (org-element-property :DESCRIPTION headline)
  483. info))
  484. (menu-entry (if (string= "" menu-title) title menu-title))
  485. (len (length menu-entry))
  486. (output (list len menu-entry descr)))
  487. output)))
  488. (defun org-texinfo--menu-headlines (headline info)
  489. "Retrieve the title from HEADLINE.
  490. INFO is a plist holding contextual information.
  491. Return the headline as a list of (length title description) with
  492. length of -1 and nil description. This is used in
  493. `org-texinfo--format-menu' to identify headlines as opposed to
  494. entries."
  495. (let ((title (org-export-data
  496. (org-element-property :title headline) info)))
  497. (list -1 title 'nil)))
  498. (defun org-texinfo--format-menu (text-menu info)
  499. "Format the TEXT-MENU items to be properly printed in the menu.
  500. INFO is a plist containing contextual information.
  501. Each entry in the menu should be provided as (length title
  502. description).
  503. Headlines in the detailed menu are given length -1 to ensure they
  504. are never confused with other entries. They also have no
  505. description.
  506. Other menu items are output as:
  507. Title:: description
  508. With the spacing between :: and description based on the length
  509. of the longest menu entry."
  510. (mapcar
  511. (lambda (name)
  512. (let* ((title (nth 1 name))
  513. (desc (nth 2 name))
  514. (length (nth 0 name))
  515. (column (max
  516. length
  517. ;; 6 is "* " ":: " for inserted text
  518. (- (plist-get info :texinfo-node-description-column) 6)))
  519. (spacing (- column length)))
  520. (if (> length -1)
  521. (concat "* " title ":: "
  522. (make-string spacing ?\s)
  523. (and desc (concat desc)))
  524. (concat "\n" title "\n"))))
  525. text-menu))
  526. ;;; Template
  527. (defun org-texinfo-template (contents info)
  528. "Return complete document string after Texinfo conversion.
  529. CONTENTS is the transcoded contents string. INFO is a plist
  530. holding export options."
  531. (let ((title (org-export-data (plist-get info :title) info))
  532. ;; Copying data is the contents of the first headline in
  533. ;; parse tree with a non-nil copying property.
  534. (copying (org-element-map (plist-get info :parse-tree) 'headline
  535. (lambda (hl)
  536. (and (org-not-nil (org-element-property :COPYING hl))
  537. (org-element-contents hl)))
  538. info t)))
  539. (concat
  540. "\\input texinfo @c -*- texinfo -*-\n"
  541. "@c %**start of header\n"
  542. (let ((file (or (plist-get info :texinfo-filename)
  543. (let ((f (plist-get info :output-file)))
  544. (and f (concat (file-name-sans-extension f) ".info"))))))
  545. (and file (format "@setfilename %s\n" file)))
  546. (format "@settitle %s\n" title)
  547. ;; Insert class-defined header.
  548. (org-element-normalize-string
  549. (let ((header (nth 1 (assoc (plist-get info :texinfo-class)
  550. org-texinfo-classes)))
  551. (coding
  552. (catch 'coding-system
  553. (let ((case-fold-search t)
  554. (name (symbol-name (or org-texinfo-coding-system
  555. buffer-file-coding-system))))
  556. (dolist (system org-texinfo-supported-coding-systems "UTF-8")
  557. (when (org-string-match-p (regexp-quote system) name)
  558. (throw 'coding-system system))))))
  559. (language (plist-get info :language))
  560. (case-fold-search nil))
  561. ;; Auto coding system.
  562. (replace-regexp-in-string
  563. "^@documentencoding \\(AUTO\\)$"
  564. coding
  565. (replace-regexp-in-string
  566. "^@documentlanguage \\(AUTO\\)$" language header nil nil 1)
  567. nil nil 1)))
  568. ;; Additional header options set by #+TEXINFO_HEADER.
  569. (let ((texinfo-header (plist-get info :texinfo-header)))
  570. (and texinfo-header (org-element-normalize-string texinfo-header)))
  571. "@c %**end of header\n\n"
  572. ;; Additional options set by #+TEXINFO_POST_HEADER.
  573. (let ((texinfo-post-header (plist-get info :texinfo-post-header)))
  574. (and texinfo-post-header
  575. (org-element-normalize-string texinfo-post-header)))
  576. ;; Copying.
  577. (and copying
  578. (format "@copying\n%s@end copying\n\n"
  579. (org-element-normalize-string
  580. (org-export-data copying info))))
  581. ;; Info directory information. Only supply if both title and
  582. ;; category are provided.
  583. (let ((dircat (plist-get info :texinfo-dircat))
  584. (dirtitle
  585. (let ((title (plist-get info :texinfo-dirtitle)))
  586. (and title
  587. (string-match "^\\(?:\\* \\)?\\(.*?\\)\\(\\.\\)?$" title)
  588. (format "* %s." (match-string 1 title))))))
  589. (when (and dircat dirtitle)
  590. (concat "@dircategory " dircat "\n"
  591. "@direntry\n"
  592. (let ((dirdesc
  593. (let ((desc (plist-get info :texinfo-dirdesc)))
  594. (cond ((not desc) nil)
  595. ((org-string-match-p "\\.$" desc) desc)
  596. (t (concat desc "."))))))
  597. (if dirdesc (format "%-23s %s" dirtitle dirdesc) dirtitle))
  598. "\n"
  599. "@end direntry\n\n")))
  600. ;; Title
  601. "@finalout\n"
  602. "@titlepage\n"
  603. (format "@title %s\n" (or (plist-get info :texinfo-printed-title) title))
  604. (let ((subtitle (plist-get info :subtitle)))
  605. (and subtitle
  606. (org-element-normalize-string
  607. (replace-regexp-in-string "^" "@subtitle " subtitle))))
  608. (when (plist-get info :with-author)
  609. (concat
  610. ;; Primary author.
  611. (let ((author (org-string-nw-p
  612. (org-export-data (plist-get info :author) info)))
  613. (email (and (plist-get info :with-email)
  614. (org-string-nw-p
  615. (org-export-data (plist-get info :email) info)))))
  616. (cond ((and author email)
  617. (format "@author %s (@email{%s})\n" author email))
  618. (author (format "@author %s\n" author))
  619. (email (format "@author @email{%s}\n" email))))
  620. ;; Other authors.
  621. (let ((subauthor (plist-get info :subauthor)))
  622. (and subauthor
  623. (org-element-normalize-string
  624. (replace-regexp-in-string "^" "@author " subauthor))))))
  625. (and copying "@page\n@vskip 0pt plus 1filll\n@insertcopying\n")
  626. "@end titlepage\n\n"
  627. ;; Table of contents.
  628. (and (plist-get info :with-toc) "@contents\n\n")
  629. ;; Configure Top Node when not for Tex
  630. "@ifnottex\n"
  631. "@node Top\n"
  632. (format "@top %s\n" title)
  633. (and copying "@insertcopying\n")
  634. "@end ifnottex\n\n"
  635. ;; Menu.
  636. (let ((menu (org-texinfo-make-menu info 'main))
  637. (detail-menu (org-texinfo-make-menu info 'detailed)))
  638. (and menu
  639. (concat "@menu\n"
  640. menu "\n"
  641. (and detail-menu
  642. (concat "\n@detailmenu\n"
  643. " --- The Detailed Node Listing ---\n"
  644. detail-menu "\n"
  645. "@end detailmenu\n"))
  646. "@end menu\n\n")))
  647. ;; Document's body.
  648. contents "\n"
  649. ;; Creator.
  650. (case (plist-get info :with-creator)
  651. ((nil) nil)
  652. (comment (format "@c %s\n" (plist-get info :creator)))
  653. (otherwise (concat (plist-get info :creator) "\n")))
  654. ;; Document end.
  655. "@bye")))
  656. ;;; Transcode Functions
  657. ;;;; Bold
  658. (defun org-texinfo-bold (bold contents info)
  659. "Transcode BOLD from Org to Texinfo.
  660. CONTENTS is the text with bold markup. INFO is a plist holding
  661. contextual information."
  662. (org-texinfo--text-markup contents 'bold info))
  663. ;;;; Center Block
  664. (defun org-texinfo-center-block (center-block contents info)
  665. "Transcode a CENTER-BLOCK element from Org to Texinfo.
  666. CONTENTS holds the contents of the block. INFO is a plist used
  667. as a communication channel."
  668. contents)
  669. ;;;; Clock
  670. (defun org-texinfo-clock (clock contents info)
  671. "Transcode a CLOCK element from Org to Texinfo.
  672. CONTENTS is nil. INFO is a plist holding contextual
  673. information."
  674. (concat
  675. "@noindent"
  676. (format "@strong{%s} " org-clock-string)
  677. (format (plist-get info :texinfo-inactive-timestamp-format)
  678. (concat (org-translate-time
  679. (org-element-property :raw-value
  680. (org-element-property :value clock)))
  681. (let ((time (org-element-property :duration clock)))
  682. (and time (format " (%s)" time)))))
  683. "@*"))
  684. ;;;; Code
  685. (defun org-texinfo-code (code contents info)
  686. "Transcode a CODE object from Org to Texinfo.
  687. CONTENTS is nil. INFO is a plist used as a communication
  688. channel."
  689. (org-texinfo--text-markup (org-element-property :value code) 'code info))
  690. ;;;; Drawer
  691. (defun org-texinfo-drawer (drawer contents info)
  692. "Transcode a DRAWER element from Org to Texinfo.
  693. CONTENTS holds the contents of the block. INFO is a plist
  694. holding contextual information."
  695. (let* ((name (org-element-property :drawer-name drawer))
  696. (output (funcall (plist-get info :texinfo-format-drawer-function)
  697. name contents)))
  698. output))
  699. ;;;; Dynamic Block
  700. (defun org-texinfo-dynamic-block (dynamic-block contents info)
  701. "Transcode a DYNAMIC-BLOCK element from Org to Texinfo.
  702. CONTENTS holds the contents of the block. INFO is a plist
  703. holding contextual information."
  704. contents)
  705. ;;;; Entity
  706. (defun org-texinfo-entity (entity contents info)
  707. "Transcode an ENTITY object from Org to Texinfo.
  708. CONTENTS are the definition itself. INFO is a plist holding
  709. contextual information."
  710. (let ((ent (org-element-property :latex entity)))
  711. (if (org-element-property :latex-math-p entity) (format "@math{%s}" ent) ent)))
  712. ;;;; Example Block
  713. (defun org-texinfo-example-block (example-block contents info)
  714. "Transcode an EXAMPLE-BLOCK element from Org to Texinfo.
  715. CONTENTS is nil. INFO is a plist holding contextual
  716. information."
  717. (format "@verbatim\n%s@end verbatim"
  718. (org-export-format-code-default example-block info)))
  719. ;;;; Export Snippet
  720. (defun org-texinfo-export-snippet (export-snippet contents info)
  721. "Transcode a EXPORT-SNIPPET object from Org to Texinfo.
  722. CONTENTS is nil. INFO is a plist holding contextual information."
  723. (when (eq (org-export-snippet-backend export-snippet) 'texinfo)
  724. (org-element-property :value export-snippet)))
  725. ;;;; Fixed Width
  726. (defun org-texinfo-fixed-width (fixed-width contents info)
  727. "Transcode a FIXED-WIDTH element from Org to Texinfo.
  728. CONTENTS is nil. INFO is a plist holding contextual information."
  729. (format "@example\n%s\n@end example"
  730. (org-remove-indentation
  731. (org-texinfo--sanitize-content
  732. (org-element-property :value fixed-width)))))
  733. ;;;; Footnote Reference
  734. (defun org-texinfo-footnote-reference (footnote contents info)
  735. "Create a footnote reference for FOOTNOTE.
  736. FOOTNOTE is the footnote to define. CONTENTS is nil. INFO is a
  737. plist holding contextual information."
  738. (let ((def (org-export-get-footnote-definition footnote info)))
  739. (format "@footnote{%s}"
  740. (org-trim (org-export-data def info)))))
  741. ;;;; Headline
  742. (defun org-texinfo-headline (headline contents info)
  743. "Transcode a HEADLINE element from Org to Texinfo.
  744. CONTENTS holds the contents of the headline. INFO is a plist
  745. holding contextual information."
  746. (let* ((class (plist-get info :texinfo-class))
  747. (level (org-export-get-relative-level headline info))
  748. (numberedp (org-export-numbered-headline-p headline info))
  749. (class-sectioning (assoc class (plist-get info :texinfo-classes)))
  750. ;; Find the index type, if any
  751. (index (org-element-property :INDEX headline))
  752. ;; Retrieve headline text
  753. (text (org-texinfo--sanitize-headline
  754. (org-element-property :title headline) info))
  755. ;; Create node info, to insert it before section formatting.
  756. ;; Use custom menu title if present
  757. (node (format "@node %s\n" (org-texinfo--get-node headline info)))
  758. ;; Menus must be generated with first child, otherwise they
  759. ;; will not nest properly
  760. (menu (let* ((first (org-export-first-sibling-p headline info))
  761. (parent (org-export-get-parent-headline headline))
  762. (title (org-texinfo--sanitize-headline
  763. (org-element-property :title parent) info))
  764. heading listing
  765. (tree (plist-get info :parse-tree)))
  766. (if first
  767. (org-element-map (plist-get info :parse-tree) 'headline
  768. (lambda (ref)
  769. (if (member title (org-element-property :title ref))
  770. (push ref heading)))
  771. info t))
  772. (setq listing (org-texinfo--build-menu
  773. (car heading) level info))
  774. (if listing
  775. (setq listing (replace-regexp-in-string
  776. "%" "%%" listing)
  777. listing (format
  778. "\n@menu\n%s\n@end menu\n\n" listing))
  779. 'nil)))
  780. ;; Section formatting will set two placeholders: one for the
  781. ;; title and the other for the contents.
  782. (section-fmt
  783. (if (org-not-nil (org-element-property :APPENDIX headline))
  784. (concat menu node "appendix\n%s")
  785. (let ((sec (if (and (symbolp (nth 2 class-sectioning))
  786. (fboundp (nth 2 class-sectioning)))
  787. (funcall (nth 2 class-sectioning) level numberedp)
  788. (nth (1+ level) class-sectioning))))
  789. (cond
  790. ;; No section available for that LEVEL.
  791. ((not sec) nil)
  792. ;; Section format directly returned by a function.
  793. ((stringp sec) sec)
  794. ;; (numbered-section . unnumbered-section)
  795. ((not (consp (cdr sec)))
  796. (concat menu
  797. node
  798. ;; An index is always unnumbered.
  799. (if (or index (not numberedp)) (cdr sec) (car sec))
  800. "\n%s"))))))
  801. (todo
  802. (and (plist-get info :with-todo-keywords)
  803. (let ((todo (org-element-property :todo-keyword headline)))
  804. (and todo (org-export-data todo info)))))
  805. (todo-type (and todo (org-element-property :todo-type headline)))
  806. (tags (and (plist-get info :with-tags)
  807. (org-export-get-tags headline info)))
  808. (priority (and (plist-get info :with-priority)
  809. (org-element-property :priority headline)))
  810. ;; Create the headline text along with a no-tag version. The
  811. ;; latter is required to remove tags from table of contents.
  812. (full-text (org-texinfo--sanitize-content
  813. (funcall (plist-get info :texinfo-format-headline-function)
  814. todo todo-type priority text tags)))
  815. (full-text-no-tag
  816. (org-texinfo--sanitize-content
  817. (funcall (plist-get info :texinfo-format-headline-function)
  818. todo todo-type priority text nil)))
  819. (pre-blanks
  820. (make-string (org-element-property :pre-blank headline) 10)))
  821. (cond
  822. ;; Case 1: This is a footnote section: ignore it.
  823. ((org-element-property :footnote-section-p headline) nil)
  824. ;; Case 2: This is the `copying' section: ignore it
  825. ;; This is used elsewhere.
  826. ((org-not-nil (org-element-property :COPYING headline)) nil)
  827. ;; Case 3: An index. If it matches one of the known indexes,
  828. ;; print it as such following the contents, otherwise
  829. ;; print the contents and leave the index up to the user.
  830. (index
  831. (format
  832. section-fmt full-text
  833. (concat pre-blanks contents "\n"
  834. (if (member index '("cp" "fn" "ky" "pg" "tp" "vr"))
  835. (concat "@printindex " index)))))
  836. ;; Case 4: This is a deep sub-tree: export it as a list item.
  837. ;; Also export as items headlines for which no section
  838. ;; format has been found.
  839. ((or (not section-fmt) (org-export-low-level-p headline info))
  840. ;; Build the real contents of the sub-tree.
  841. (let ((low-level-body
  842. (concat
  843. ;; If the headline is the first sibling, start a list.
  844. (when (org-export-first-sibling-p headline info)
  845. (format "@%s\n" (if numberedp 'enumerate 'itemize)))
  846. ;; Itemize headline
  847. "@item\n" full-text "\n" pre-blanks contents)))
  848. ;; If headline is not the last sibling simply return
  849. ;; LOW-LEVEL-BODY. Otherwise, also close the list, before any
  850. ;; blank line.
  851. (if (not (org-export-last-sibling-p headline info)) low-level-body
  852. (replace-regexp-in-string
  853. "[ \t\n]*\\'"
  854. (format "\n@end %s" (if numberedp 'enumerate 'itemize))
  855. low-level-body))))
  856. ;; Case 5: Standard headline. Export it as a section.
  857. (t
  858. (cond
  859. ((not (and tags (eq (plist-get info :with-tags) 'not-in-toc)))
  860. ;; Regular section. Use specified format string.
  861. (format (replace-regexp-in-string "%]" "%%]" section-fmt) full-text
  862. (concat pre-blanks contents)))
  863. ((string-match "\\`@\\(.*?\\){" section-fmt)
  864. ;; If tags should be removed from table of contents, insert
  865. ;; title without tags as an alternative heading in sectioning
  866. ;; command.
  867. (format (replace-match (concat (match-string 1 section-fmt) "[%s]")
  868. nil nil section-fmt 1)
  869. ;; Replace square brackets with parenthesis since
  870. ;; square brackets are not supported in optional
  871. ;; arguments.
  872. (replace-regexp-in-string
  873. "\\[" "("
  874. (replace-regexp-in-string
  875. "\\]" ")"
  876. full-text-no-tag))
  877. full-text
  878. (concat pre-blanks contents)))
  879. (t
  880. ;; Impossible to add an alternative heading. Fallback to
  881. ;; regular sectioning format string.
  882. (format (replace-regexp-in-string "%]" "%%]" section-fmt) full-text
  883. (concat pre-blanks contents))))))))
  884. (defun org-texinfo-format-headline-default-function
  885. (todo todo-type priority text tags)
  886. "Default format function for a headline.
  887. See `org-texinfo-format-headline-function' for details."
  888. (concat (when todo (format "@strong{%s} " todo))
  889. (when priority (format "@emph{#%s} " priority))
  890. text
  891. (when tags (format " :%s:" (mapconcat 'identity tags ":")))))
  892. ;;;; Inline Src Block
  893. (defun org-texinfo-inline-src-block (inline-src-block contents info)
  894. "Transcode an INLINE-SRC-BLOCK element from Org to Texinfo.
  895. CONTENTS holds the contents of the item. INFO is a plist holding
  896. contextual information."
  897. (let* ((code (org-element-property :value inline-src-block))
  898. (separator (org-texinfo--find-verb-separator code)))
  899. (concat "@verb{" separator code separator "}")))
  900. ;;;; Inlinetask
  901. (defun org-texinfo-inlinetask (inlinetask contents info)
  902. "Transcode an INLINETASK element from Org to Texinfo.
  903. CONTENTS holds the contents of the block. INFO is a plist
  904. holding contextual information."
  905. (let ((title (org-export-data (org-element-property :title inlinetask) info))
  906. (todo (and (plist-get info :with-todo-keywords)
  907. (let ((todo (org-element-property :todo-keyword inlinetask)))
  908. (and todo (org-export-data todo info)))))
  909. (todo-type (org-element-property :todo-type inlinetask))
  910. (tags (and (plist-get info :with-tags)
  911. (org-export-get-tags inlinetask info)))
  912. (priority (and (plist-get info :with-priority)
  913. (org-element-property :priority inlinetask))))
  914. (funcall (plist-get info :texinfo-format-inlinetask-function)
  915. todo todo-type priority title tags contents)))
  916. (defun org-texinfo-format-inlinetask-default-function
  917. (todo todo-type priority title tags contents)
  918. "Default format function for a inlinetasks.
  919. See `org-texinfo-format-inlinetask-function' for details."
  920. (let ((full-title
  921. (concat (when todo (format "@strong{%s} " todo))
  922. (when priority (format "#%c " priority))
  923. title
  924. (when tags (format ":%s:" (mapconcat #'identity tags ":"))))))
  925. (format "@center %s\n\n%s\n" full-title contents)))
  926. ;;;; Italic
  927. (defun org-texinfo-italic (italic contents info)
  928. "Transcode ITALIC from Org to Texinfo.
  929. CONTENTS is the text with italic markup. INFO is a plist holding
  930. contextual information."
  931. (org-texinfo--text-markup contents 'italic info))
  932. ;;;; Item
  933. (defun org-texinfo-item (item contents info)
  934. "Transcode an ITEM element from Org to Texinfo.
  935. CONTENTS holds the contents of the item. INFO is a plist holding
  936. contextual information."
  937. (format "@item%s\n%s"
  938. (let ((tag (org-element-property :tag item)))
  939. (if tag (concat " " (org-export-data tag info)) ""))
  940. (or contents "")))
  941. ;;;; Keyword
  942. (defun org-texinfo-keyword (keyword contents info)
  943. "Transcode a KEYWORD element from Org to Texinfo.
  944. CONTENTS is nil. INFO is a plist holding contextual information."
  945. (let ((key (org-element-property :key keyword))
  946. (value (org-element-property :value keyword)))
  947. (cond
  948. ((string= key "TEXINFO") value)
  949. ((string= key "CINDEX") (format "@cindex %s" value))
  950. ((string= key "FINDEX") (format "@findex %s" value))
  951. ((string= key "KINDEX") (format "@kindex %s" value))
  952. ((string= key "PINDEX") (format "@pindex %s" value))
  953. ((string= key "TINDEX") (format "@tindex %s" value))
  954. ((string= key "VINDEX") (format "@vindex %s" value)))))
  955. ;;;; Line Break
  956. (defun org-texinfo-line-break (line-break contents info)
  957. "Transcode a LINE-BREAK object from Org to Texinfo.
  958. CONTENTS is nil. INFO is a plist holding contextual information."
  959. "@*\n")
  960. ;;;; Link
  961. (defun org-texinfo-link (link desc info)
  962. "Transcode a LINK object from Org to Texinfo.
  963. DESC is the description part of the link, or the empty string.
  964. INFO is a plist holding contextual information. See
  965. `org-export-data'."
  966. (let* ((type (org-element-property :type link))
  967. (raw-path (org-element-property :path link))
  968. ;; Ensure DESC really exists, or set it to nil.
  969. (desc (and (not (string= desc "")) desc))
  970. (path (cond
  971. ((member type '("http" "https" "ftp"))
  972. (concat type ":" raw-path))
  973. ((and (string= type "file") (file-name-absolute-p raw-path))
  974. (concat "file:" raw-path))
  975. (t raw-path)))
  976. (email (if (string= type "mailto")
  977. (let ((text (replace-regexp-in-string
  978. "@" "@@" raw-path)))
  979. (concat text (if desc (concat "," desc))))))
  980. protocol)
  981. (cond
  982. ;; Links pointing to a headline: Find destination and build
  983. ;; appropriate referencing command.
  984. ((member type '("custom-id" "id"))
  985. (let ((destination (org-export-resolve-id-link link info)))
  986. (case (org-element-type destination)
  987. ;; Id link points to an external file.
  988. (plain-text
  989. (if desc (format "@uref{file://%s,%s}" destination desc)
  990. (format "@uref{file://%s}" destination)))
  991. ;; LINK points to a headline. Use the headline as the NODE target
  992. (headline
  993. (format "@ref{%s,%s}"
  994. (org-texinfo--get-node destination info)
  995. (or desc "")))
  996. (otherwise
  997. (let ((path (org-export-solidify-link-text path)))
  998. (if (not desc) (format "@ref{%s}" path)
  999. (format "@ref{%s,,%s}" path desc)))))))
  1000. ((member type '("info"))
  1001. (let* ((info-path (split-string path "[:#]"))
  1002. (info-manual (car info-path))
  1003. (info-node (or (cadr info-path) "top"))
  1004. (title (or desc "")))
  1005. (format "@ref{%s,%s,,%s,}" info-node title info-manual)))
  1006. ((member type '("fuzzy"))
  1007. (let ((destination (org-export-resolve-fuzzy-link link info)))
  1008. (case (org-element-type destination)
  1009. ;; Id link points to an external file.
  1010. (plain-text
  1011. (if desc (format "@uref{file://%s,%s}" destination desc)
  1012. (format "@uref{file://%s}" destination)))
  1013. ;; LINK points to a headline. Use the headline as the NODE target
  1014. (headline
  1015. (format "@ref{%s,%s}"
  1016. (org-texinfo--get-node destination info)
  1017. (or desc "")))
  1018. (otherwise
  1019. (let ((path (org-export-solidify-link-text path)))
  1020. (if (not desc) (format "@ref{%s}" path)
  1021. (format "@ref{%s,,%s}" path desc)))))))
  1022. ;; Special case for email addresses
  1023. (email
  1024. (format "@email{%s}" email))
  1025. ;; External link with a description part.
  1026. ((and path desc) (format "@uref{%s,%s}" path desc))
  1027. ;; External link without a description part.
  1028. (path (format "@uref{%s}" path))
  1029. ;; No path, only description. Try to do something useful.
  1030. (t
  1031. (format (plist-get info :texinfo-link-with-unknown-path-format) desc)))))
  1032. ;;;; Menu
  1033. (defun org-texinfo-make-menu (info level)
  1034. "Create the menu for inclusion in the texifo document.
  1035. INFO is the parsed buffer that contains the headlines. LEVEL
  1036. determines whether to make the main menu, or the detailed menu.
  1037. This is only used for generating the primary menu. In-Node menus
  1038. are generated directly."
  1039. (let ((parse (plist-get info :parse-tree)))
  1040. (cond
  1041. ;; Generate the main menu
  1042. ((eq level 'main) (org-texinfo--build-menu parse 1 info))
  1043. ;; Generate the detailed (recursive) menu
  1044. ((eq level 'detailed)
  1045. ;; Requires recursion
  1046. ;;(org-texinfo--build-detailed-menu parse top info)
  1047. (org-texinfo--build-menu parse 1 info 'detailed)))))
  1048. ;;;; Node Property
  1049. (defun org-texinfo-node-property (node-property contents info)
  1050. "Transcode a NODE-PROPERTY element from Org to Texinfo.
  1051. CONTENTS is nil. INFO is a plist holding contextual
  1052. information."
  1053. (format "%s:%s"
  1054. (org-element-property :key node-property)
  1055. (let ((value (org-element-property :value node-property)))
  1056. (if value (concat " " value) ""))))
  1057. ;;;; Paragraph
  1058. (defun org-texinfo-paragraph (paragraph contents info)
  1059. "Transcode a PARAGRAPH element from Org to Texinfo.
  1060. CONTENTS is the contents of the paragraph, as a string. INFO is
  1061. the plist used as a communication channel."
  1062. contents)
  1063. ;;;; Plain List
  1064. (defun org-texinfo-plain-list (plain-list contents info)
  1065. "Transcode a PLAIN-LIST element from Org to Texinfo.
  1066. CONTENTS is the contents of the list. INFO is a plist holding
  1067. contextual information."
  1068. (let* ((attr (org-export-read-attribute :attr_texinfo plain-list))
  1069. (indic (or (plist-get attr :indic)
  1070. (plist-get info :texinfo-def-table-markup)))
  1071. (table-type (plist-get attr :table-type))
  1072. (type (org-element-property :type plain-list))
  1073. (list-type (cond
  1074. ((eq type 'ordered) "enumerate")
  1075. ((eq type 'unordered) "itemize")
  1076. ((member table-type '("ftable" "vtable")) table-type)
  1077. (t "table"))))
  1078. (format "@%s\n%s@end %s"
  1079. (if (eq type 'descriptive) (concat list-type " " indic) list-type)
  1080. contents
  1081. list-type)))
  1082. ;;;; Plain Text
  1083. (defun org-texinfo-plain-text (text info)
  1084. "Transcode a TEXT string from Org to Texinfo.
  1085. TEXT is the string to transcode. INFO is a plist holding
  1086. contextual information."
  1087. ;; First protect @, { and }.
  1088. (let ((output (org-texinfo--sanitize-content text)))
  1089. ;; Activate smart quotes. Be sure to provide original TEXT string
  1090. ;; since OUTPUT may have been modified.
  1091. (when (plist-get info :with-smart-quotes)
  1092. (setq output
  1093. (org-export-activate-smart-quotes output :texinfo info text)))
  1094. ;; LaTeX into @LaTeX{} and TeX into @TeX{}
  1095. (let ((case-fold-search nil)
  1096. (start 0))
  1097. (while (string-match "\\(\\(?:La\\)?TeX\\)" output start)
  1098. (setq output (replace-match
  1099. (format "@%s{}" (match-string 1 output)) nil t output)
  1100. start (match-end 0))))
  1101. ;; Convert special strings.
  1102. (when (plist-get info :with-special-strings)
  1103. (while (string-match (regexp-quote "...") output)
  1104. (setq output (replace-match "@dots{}" nil t output))))
  1105. ;; Handle break preservation if required.
  1106. (when (plist-get info :preserve-breaks)
  1107. (setq output (replace-regexp-in-string
  1108. "\\(\\\\\\\\\\)?[ \t]*\n" " @*\n" output)))
  1109. ;; Return value.
  1110. output))
  1111. ;;;; Planning
  1112. (defun org-texinfo-planning (planning contents info)
  1113. "Transcode a PLANNING element from Org to Texinfo.
  1114. CONTENTS is nil. INFO is a plist holding contextual
  1115. information."
  1116. (concat
  1117. "@noindent"
  1118. (mapconcat
  1119. 'identity
  1120. (delq nil
  1121. (list
  1122. (let ((closed (org-element-property :closed planning)))
  1123. (when closed
  1124. (concat
  1125. (format "@strong{%s} " org-closed-string)
  1126. (format (plist-get info :texinfo-inactive-timestamp-format)
  1127. (org-translate-time
  1128. (org-element-property :raw-value closed))))))
  1129. (let ((deadline (org-element-property :deadline planning)))
  1130. (when deadline
  1131. (concat
  1132. (format "@strong{%s} " org-deadline-string)
  1133. (format (plist-get info :texinfo-active-timestamp-format)
  1134. (org-translate-time
  1135. (org-element-property :raw-value deadline))))))
  1136. (let ((scheduled (org-element-property :scheduled planning)))
  1137. (when scheduled
  1138. (concat
  1139. (format "@strong{%s} " org-scheduled-string)
  1140. (format (plist-get info :texinfo-active-timestamp-format)
  1141. (org-translate-time
  1142. (org-element-property :raw-value scheduled))))))))
  1143. " ")
  1144. "@*"))
  1145. ;;;; Property Drawer
  1146. (defun org-texinfo-property-drawer (property-drawer contents info)
  1147. "Transcode a PROPERTY-DRAWER element from Org to Texinfo.
  1148. CONTENTS holds the contents of the drawer. INFO is a plist
  1149. holding contextual information."
  1150. (and (org-string-nw-p contents)
  1151. (format "@verbatim\n%s@end verbatim" contents)))
  1152. ;;;; Quote Block
  1153. (defun org-texinfo-quote-block (quote-block contents info)
  1154. "Transcode a QUOTE-BLOCK element from Org to Texinfo.
  1155. CONTENTS holds the contents of the block. INFO is a plist
  1156. holding contextual information."
  1157. (let* ((title (org-element-property :name quote-block))
  1158. (start-quote (concat "@quotation"
  1159. (if title
  1160. (format " %s" title)))))
  1161. (format "%s\n%s@end quotation" start-quote contents)))
  1162. ;;;; Radio Target
  1163. (defun org-texinfo-radio-target (radio-target text info)
  1164. "Transcode a RADIO-TARGET object from Org to Texinfo.
  1165. TEXT is the text of the target. INFO is a plist holding
  1166. contextual information."
  1167. (format "@anchor{%s}%s"
  1168. (org-export-solidify-link-text
  1169. (org-element-property :value radio-target))
  1170. text))
  1171. ;;;; Section
  1172. (defun org-texinfo-section (section contents info)
  1173. "Transcode a SECTION element from Org to Texinfo.
  1174. CONTENTS holds the contents of the section. INFO is a plist
  1175. holding contextual information."
  1176. contents)
  1177. ;;;; Special Block
  1178. (defun org-texinfo-special-block (special-block contents info)
  1179. "Transcode a SPECIAL-BLOCK element from Org to Texinfo.
  1180. CONTENTS holds the contents of the block. INFO is a plist used
  1181. as a communication channel."
  1182. (if (org-export-raw-special-block-p special-block info)
  1183. (org-remove-indentation (org-element-property :raw-value special-block))
  1184. contents))
  1185. ;;;; Src Block
  1186. (defun org-texinfo-src-block (src-block contents info)
  1187. "Transcode a SRC-BLOCK element from Org to Texinfo.
  1188. CONTENTS holds the contents of the item. INFO is a plist holding
  1189. contextual information."
  1190. (let* ((lang (org-element-property :language src-block))
  1191. (lisp-p (string-match-p "lisp" lang))
  1192. (src-contents (org-texinfo--sanitize-content
  1193. (org-export-format-code-default src-block info))))
  1194. (cond
  1195. ;; Case 1. Lisp Block
  1196. (lisp-p
  1197. (format "@lisp\n%s@end lisp"
  1198. src-contents))
  1199. ;; Case 2. Other blocks
  1200. (t
  1201. (format "@example\n%s@end example"
  1202. src-contents)))))
  1203. ;;;; Statistics Cookie
  1204. (defun org-texinfo-statistics-cookie (statistics-cookie contents info)
  1205. "Transcode a STATISTICS-COOKIE object from Org to Texinfo.
  1206. CONTENTS is nil. INFO is a plist holding contextual information."
  1207. (org-element-property :value statistics-cookie))
  1208. ;;;; Subscript
  1209. (defun org-texinfo-subscript (subscript contents info)
  1210. "Transcode a SUBSCRIPT object from Org to Texinfo.
  1211. CONTENTS is the contents of the object. INFO is a plist holding
  1212. contextual information."
  1213. (format "@math{_%s}" contents))
  1214. ;;;; Superscript
  1215. (defun org-texinfo-superscript (superscript contents info)
  1216. "Transcode a SUPERSCRIPT object from Org to Texinfo.
  1217. CONTENTS is the contents of the object. INFO is a plist holding
  1218. contextual information."
  1219. (format "@math{^%s}" contents))
  1220. ;;;; Table
  1221. (defun org-texinfo-table (table contents info)
  1222. "Transcode a TABLE element from Org to Texinfo.
  1223. CONTENTS is the contents of the table. INFO is a plist holding
  1224. contextual information."
  1225. (if (eq (org-element-property :type table) 'table.el)
  1226. (format "@verbatim\n%s@end verbatim"
  1227. (org-element-normalize-string
  1228. (org-element-property :value table)))
  1229. (let* ((col-width (org-export-read-attribute :attr_texinfo table :columns))
  1230. (columns
  1231. (if col-width (format "@columnfractions %s" col-width)
  1232. (org-texinfo-table-column-widths table info))))
  1233. (format "@multitable %s\n%s@end multitable"
  1234. columns
  1235. contents))))
  1236. (defun org-texinfo-table-column-widths (table info)
  1237. "Determine the largest table cell in each column to process alignment.
  1238. TABLE is the table element to transcode. INFO is a plist used as
  1239. a communication channel."
  1240. (let ((widths (make-vector (cdr (org-export-table-dimensions table info)) 0)))
  1241. (org-element-map table 'table-row
  1242. (lambda (row)
  1243. (let ((idx 0))
  1244. (org-element-map row 'table-cell
  1245. (lambda (cell)
  1246. ;; Length of the cell in the original buffer is only an
  1247. ;; approximation of the length of the cell in the
  1248. ;; output. It can sometimes fail (e.g. it considers
  1249. ;; "/a/" being larger than "ab").
  1250. (let ((w (- (org-element-property :contents-end cell)
  1251. (org-element-property :contents-begin cell))))
  1252. (aset widths idx (max w (aref widths idx))))
  1253. (incf idx))
  1254. info)))
  1255. info)
  1256. (format "{%s}" (mapconcat (lambda (w) (make-string w ?a)) widths "} {"))))
  1257. ;;;; Table Cell
  1258. (defun org-texinfo-table-cell (table-cell contents info)
  1259. "Transcode a TABLE-CELL element from Org to Texinfo.
  1260. CONTENTS is the cell contents. INFO is a plist used as
  1261. a communication channel."
  1262. (concat
  1263. (let ((scientific-notation
  1264. (plist-get info :texinfo-table-scientific-notation)))
  1265. (if (and contents
  1266. scientific-notation
  1267. (string-match orgtbl-exp-regexp contents))
  1268. ;; Use appropriate format string for scientific notation.
  1269. (format scientific-notation
  1270. (match-string 1 contents)
  1271. (match-string 2 contents))
  1272. contents))
  1273. (when (org-export-get-next-element table-cell info) "\n@tab ")))
  1274. ;;;; Table Row
  1275. (defun org-texinfo-table-row (table-row contents info)
  1276. "Transcode a TABLE-ROW element from Org to Texinfo.
  1277. CONTENTS is the contents of the row. INFO is a plist used as
  1278. a communication channel."
  1279. ;; Rules are ignored since table separators are deduced from
  1280. ;; borders of the current row.
  1281. (when (eq (org-element-property :type table-row) 'standard)
  1282. (let ((rowgroup-tag
  1283. (if (and (= 1 (org-export-table-row-group table-row info))
  1284. (org-export-table-has-header-p
  1285. (org-export-get-parent-table table-row) info))
  1286. "@headitem "
  1287. "@item ")))
  1288. (concat rowgroup-tag contents "\n"))))
  1289. ;;;; Target
  1290. (defun org-texinfo-target (target contents info)
  1291. "Transcode a TARGET object from Org to Texinfo.
  1292. CONTENTS is nil. INFO is a plist holding contextual
  1293. information."
  1294. (format "@anchor{%s}"
  1295. (org-export-solidify-link-text (org-element-property :value target))))
  1296. ;;;; Timestamp
  1297. (defun org-texinfo-timestamp (timestamp contents info)
  1298. "Transcode a TIMESTAMP object from Org to Texinfo.
  1299. CONTENTS is nil. INFO is a plist holding contextual
  1300. information."
  1301. (let ((value (org-texinfo-plain-text
  1302. (org-timestamp-translate timestamp) info)))
  1303. (case (org-element-property :type timestamp)
  1304. ((active active-range)
  1305. (format (plist-get info :texinfo-active-timestamp-format) value))
  1306. ((inactive inactive-range)
  1307. (format (plist-get info :texinfo-inactive-timestamp-format) value))
  1308. (t (format (plist-get info :texinfo-diary-timestamp-format) value)))))
  1309. ;;;; Verbatim
  1310. (defun org-texinfo-verbatim (verbatim contents info)
  1311. "Transcode a VERBATIM object from Org to Texinfo.
  1312. CONTENTS is nil. INFO is a plist used as a communication
  1313. channel."
  1314. (org-texinfo--text-markup
  1315. (org-element-property :value verbatim) 'verbatim info))
  1316. ;;;; Verse Block
  1317. (defun org-texinfo-verse-block (verse-block contents info)
  1318. "Transcode a VERSE-BLOCK element from Org to Texinfo.
  1319. CONTENTS is verse block contents. INFO is a plist holding
  1320. contextual information."
  1321. (format "@display\n%s@end display" contents))
  1322. ;;; Interactive functions
  1323. (defun org-texinfo-export-to-texinfo
  1324. (&optional async subtreep visible-only body-only ext-plist)
  1325. "Export current buffer to a Texinfo file.
  1326. If narrowing is active in the current buffer, only export its
  1327. narrowed part.
  1328. If a region is active, export that region.
  1329. A non-nil optional argument ASYNC means the process should happen
  1330. asynchronously. The resulting file should be accessible through
  1331. the `org-export-stack' interface.
  1332. When optional argument SUBTREEP is non-nil, export the sub-tree
  1333. at point, extracting information from the headline properties
  1334. first.
  1335. When optional argument VISIBLE-ONLY is non-nil, don't export
  1336. contents of hidden elements.
  1337. When optional argument BODY-ONLY is non-nil, only write code
  1338. between \"\\begin{document}\" and \"\\end{document}\".
  1339. EXT-PLIST, when provided, is a property list with external
  1340. parameters overriding Org default settings, but still inferior to
  1341. file-local settings.
  1342. Return output file's name."
  1343. (interactive)
  1344. (let ((outfile (org-export-output-file-name ".texi" subtreep))
  1345. (org-export-coding-system org-texinfo-coding-system))
  1346. (org-export-to-file 'texinfo outfile
  1347. async subtreep visible-only body-only ext-plist)))
  1348. (defun org-texinfo-export-to-info
  1349. (&optional async subtreep visible-only body-only ext-plist)
  1350. "Export current buffer to Texinfo then process through to INFO.
  1351. If narrowing is active in the current buffer, only export its
  1352. narrowed part.
  1353. If a region is active, export that region.
  1354. A non-nil optional argument ASYNC means the process should happen
  1355. asynchronously. The resulting file should be accessible through
  1356. the `org-export-stack' interface.
  1357. When optional argument SUBTREEP is non-nil, export the sub-tree
  1358. at point, extracting information from the headline properties
  1359. first.
  1360. When optional argument VISIBLE-ONLY is non-nil, don't export
  1361. contents of hidden elements.
  1362. When optional argument BODY-ONLY is non-nil, only write code
  1363. between \"\\begin{document}\" and \"\\end{document}\".
  1364. EXT-PLIST, when provided, is a property list with external
  1365. parameters overriding Org default settings, but still inferior to
  1366. file-local settings.
  1367. When optional argument PUB-DIR is set, use it as the publishing
  1368. directory.
  1369. Return INFO file's name."
  1370. (interactive)
  1371. (let ((outfile (org-export-output-file-name ".texi" subtreep))
  1372. (org-export-coding-system org-texinfo-coding-system))
  1373. (org-export-to-file 'texinfo outfile
  1374. async subtreep visible-only body-only ext-plist
  1375. (lambda (file) (org-texinfo-compile file)))))
  1376. ;;;###autoload
  1377. (defun org-texinfo-publish-to-texinfo (plist filename pub-dir)
  1378. "Publish an org file to Texinfo.
  1379. FILENAME is the filename of the Org file to be published. PLIST
  1380. is the property list for the given project. PUB-DIR is the
  1381. publishing directory.
  1382. Return output file name."
  1383. (org-publish-org-to 'texinfo filename ".texi" plist pub-dir))
  1384. ;;;###autoload
  1385. (defun org-texinfo-convert-region-to-texinfo ()
  1386. "Assume the current region has org-mode syntax, and convert it to Texinfo.
  1387. This can be used in any buffer. For example, you can write an
  1388. itemized list in org-mode syntax in an Texinfo buffer and use
  1389. this command to convert it."
  1390. (interactive)
  1391. (org-export-replace-region-by 'texinfo))
  1392. (defun org-texinfo-compile (file)
  1393. "Compile a texinfo file.
  1394. FILE is the name of the file being compiled. Processing is
  1395. done through the command specified in `org-texinfo-info-process'.
  1396. Return INFO file name or an error if it couldn't be produced."
  1397. (let* ((base-name (file-name-sans-extension (file-name-nondirectory file)))
  1398. (full-name (file-truename file))
  1399. (out-dir (file-name-directory file))
  1400. ;; Properly set working directory for compilation.
  1401. (default-directory (if (file-name-absolute-p file)
  1402. (file-name-directory full-name)
  1403. default-directory))
  1404. errors)
  1405. (message (format "Processing Texinfo file %s..." file))
  1406. (save-window-excursion
  1407. (cond
  1408. ;; A function is provided: Apply it.
  1409. ((functionp org-texinfo-info-process)
  1410. (funcall org-texinfo-info-process (shell-quote-argument file)))
  1411. ;; A list is provided: Replace %b, %f and %o with appropriate
  1412. ;; values in each command before applying it. Output is
  1413. ;; redirected to "*Org INFO Texinfo Output*" buffer.
  1414. ((consp org-texinfo-info-process)
  1415. (let ((outbuf (get-buffer-create "*Org INFO Texinfo Output*")))
  1416. (mapc
  1417. (lambda (command)
  1418. (shell-command
  1419. (replace-regexp-in-string
  1420. "%b" (shell-quote-argument base-name)
  1421. (replace-regexp-in-string
  1422. "%f" (shell-quote-argument full-name)
  1423. (replace-regexp-in-string
  1424. "%o" (shell-quote-argument out-dir) command t t) t t) t t)
  1425. outbuf))
  1426. org-texinfo-info-process)
  1427. ;; Collect standard errors from output buffer.
  1428. (setq errors (org-texinfo-collect-errors outbuf))))
  1429. (t (error "No valid command to process to Info")))
  1430. (let ((infofile (concat out-dir base-name ".info")))
  1431. ;; Check for process failure. Provide collected errors if
  1432. ;; possible.
  1433. (if (not (file-exists-p infofile))
  1434. (error (concat (format "INFO file %s wasn't produced" infofile)
  1435. (when errors (concat ": " errors))))
  1436. ;; Else remove log files, when specified, and signal end of
  1437. ;; process to user, along with any error encountered.
  1438. (when org-texinfo-remove-logfiles
  1439. (dolist (ext org-texinfo-logfiles-extensions)
  1440. (let ((file (concat out-dir base-name "." ext)))
  1441. (when (file-exists-p file) (delete-file file)))))
  1442. (message (concat "Process completed"
  1443. (if (not errors) "."
  1444. (concat " with errors: " errors)))))
  1445. ;; Return output file name.
  1446. infofile))))
  1447. (defun org-texinfo-collect-errors (buffer)
  1448. "Collect some kind of errors from \"makeinfo\" command output.
  1449. BUFFER is the buffer containing output.
  1450. Return collected error types as a string, or nil if there was
  1451. none."
  1452. (with-current-buffer buffer
  1453. (save-excursion
  1454. (goto-char (point-min))
  1455. ;; Find final "makeinfo" run.
  1456. (when t
  1457. (let ((case-fold-search t)
  1458. (errors ""))
  1459. (when (save-excursion
  1460. (re-search-forward "perhaps incorrect sectioning?" nil t))
  1461. (setq errors (concat errors " [incorrect sectioning]")))
  1462. (when (save-excursion
  1463. (re-search-forward "missing close brace" nil t))
  1464. (setq errors (concat errors " [syntax error]")))
  1465. (when (save-excursion
  1466. (re-search-forward "Unknown command" nil t))
  1467. (setq errors (concat errors " [undefined @command]")))
  1468. (when (save-excursion
  1469. (re-search-forward "No matching @end" nil t))
  1470. (setq errors (concat errors " [block incomplete]")))
  1471. (when (save-excursion
  1472. (re-search-forward "requires a sectioning" nil t))
  1473. (setq errors (concat errors " [invalid section command]")))
  1474. (when (save-excursion
  1475. (re-search-forward "\\[unexpected\]" nil t))
  1476. (setq errors (concat errors " [unexpected error]")))
  1477. (when (save-excursion
  1478. (re-search-forward "misplaced " nil t))
  1479. (setq errors (concat errors " [syntax error]")))
  1480. (and (org-string-nw-p errors) (org-trim errors)))))))
  1481. (provide 'ox-texinfo)
  1482. ;; Local variables:
  1483. ;; generated-autoload-file: "org-loaddefs.el"
  1484. ;; End:
  1485. ;;; ox-texinfo.el ends here