org-e-man.el 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300
  1. ;; org-e-man.el --- Man Back-End For Org Export Engine
  2. ;; Copyright (C) 2011-2013 Free Software Foundation, Inc.
  3. ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
  4. ;; Author: Luis R Anaya <papoanaya aroba hot mail punto com>
  5. ;; Keywords: outlines, hypermedia, calendar, wp
  6. ;;
  7. ;; This program 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. ;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;;
  19. ;; This library implements a Man back-end for Org generic exporter.
  20. ;;
  21. ;; To test it, run
  22. ;;
  23. ;; M-: (org-export-to-buffer 'e-man "*Test e-Man*") RET
  24. ;;
  25. ;; in an org-mode buffer then switch to the buffer to see the Man
  26. ;; export. See contrib/lisp/org-export.el for more details on how
  27. ;; this exporter works.
  28. ;;
  29. ;; It introduces one new buffer keywords:
  30. ;; "MAN_CLASS_OPTIONS".
  31. ;;; Code:
  32. (require 'org-export)
  33. (eval-when-compile (require 'cl))
  34. (defvar org-export-man-default-packages-alist)
  35. (defvar org-export-man-packages-alist)
  36. (defvar orgtbl-exp-regexp)
  37. ;;; Define Back-End
  38. (org-export-define-backend e-man
  39. ((babel-call . org-e-man-babel-call)
  40. (bold . org-e-man-bold)
  41. (center-block . org-e-man-center-block)
  42. (clock . org-e-man-clock)
  43. (code . org-e-man-code)
  44. (comment . org-e-man-comment)
  45. (comment-block . org-e-man-comment-block)
  46. (drawer . org-e-man-drawer)
  47. (dynamic-block . org-e-man-dynamic-block)
  48. (entity . org-e-man-entity)
  49. (example-block . org-e-man-example-block)
  50. (export-block . org-e-man-export-block)
  51. (export-snippet . org-e-man-export-snippet)
  52. (fixed-width . org-e-man-fixed-width)
  53. (footnote-definition . org-e-man-footnote-definition)
  54. (footnote-reference . org-e-man-footnote-reference)
  55. (headline . org-e-man-headline)
  56. (horizontal-rule . org-e-man-horizontal-rule)
  57. (inline-babel-call . org-e-man-inline-babel-call)
  58. (inline-src-block . org-e-man-inline-src-block)
  59. (inlinetask . org-e-man-inlinetask)
  60. (italic . org-e-man-italic)
  61. (item . org-e-man-item)
  62. (keyword . org-e-man-keyword)
  63. (man-environment . org-e-man-man-environment)
  64. (man-fragment . org-e-man-man-fragment)
  65. (line-break . org-e-man-line-break)
  66. (link . org-e-man-link)
  67. (paragraph . org-e-man-paragraph)
  68. (plain-list . org-e-man-plain-list)
  69. (plain-text . org-e-man-plain-text)
  70. (planning . org-e-man-planning)
  71. (property-drawer . org-e-man-property-drawer)
  72. (quote-block . org-e-man-quote-block)
  73. (quote-section . org-e-man-quote-section)
  74. (radio-target . org-e-man-radio-target)
  75. (section . org-e-man-section)
  76. (special-block . org-e-man-special-block)
  77. (src-block . org-e-man-src-block)
  78. (statistics-cookie . org-e-man-statistics-cookie)
  79. (strike-through . org-e-man-strike-through)
  80. (subscript . org-e-man-subscript)
  81. (superscript . org-e-man-superscript)
  82. (table . org-e-man-table)
  83. (table-cell . org-e-man-table-cell)
  84. (table-row . org-e-man-table-row)
  85. (target . org-e-man-target)
  86. (template . org-e-man-template)
  87. (timestamp . org-e-man-timestamp)
  88. (underline . org-e-man-underline)
  89. (verbatim . org-e-man-verbatim)
  90. (verse-block . org-e-man-verse-block))
  91. :export-block "MAN"
  92. :menu-entry
  93. (?m "Export to MAN"
  94. ((?m "As MAN file" org-e-man-export-to-man)
  95. (?p "As PDF file" org-e-man-export-to-pdf)
  96. (?o "As PDF file and open"
  97. (lambda (a s v b)
  98. (if a (org-e-man-export-to-pdf t s v b)
  99. (org-open-file (org-e-man-export-to-pdf nil s v b)))))))
  100. :options-alist
  101. ((:man-class "MAN_CLASS" nil nil t)
  102. (:man-class-options "MAN_CLASS_OPTIONS" nil nil t)
  103. (:man-header-extra "MAN_HEADER" nil nil newline)))
  104. ;;; User Configurable Variables
  105. (defgroup org-export-e-man nil
  106. "Options for exporting Org mode files to Man."
  107. :tag "Org Export Man"
  108. :group 'org-export)
  109. ;;; Tables
  110. (defcustom org-e-man-tables-centered t
  111. "When non-nil, tables are exported in a center environment."
  112. :group 'org-export-e-man
  113. :type 'boolean)
  114. (defcustom org-e-man-tables-verbatim nil
  115. "When non-nil, tables are exported verbatim."
  116. :group 'org-export-e-man
  117. :type 'boolean)
  118. (defcustom org-e-man-table-scientific-notation "%sE%s"
  119. "Format string to display numbers in scientific notation.
  120. The format should have \"%s\" twice, for mantissa and exponent
  121. \(i.e. \"%s\\\\times10^{%s}\").
  122. When nil, no transformation is made."
  123. :group 'org-export-e-man
  124. :type '(choice
  125. (string :tag "Format string")
  126. (const :tag "No formatting")))
  127. ;;; Inlinetasks
  128. ;; Src blocks
  129. (defcustom org-e-man-source-highlight nil
  130. "Use GNU source highlight to embellish source blocks "
  131. :group 'org-export-e-man
  132. :type 'boolean)
  133. (defcustom org-e-man-source-highlight-langs
  134. '((emacs-lisp "lisp") (lisp "lisp") (clojure "lisp")
  135. (scheme "scheme")
  136. (c "c") (cc "cpp") (csharp "csharp") (d "d")
  137. (fortran "fortran") (cobol "cobol") (pascal "pascal")
  138. (ada "ada") (asm "asm")
  139. (perl "perl") (cperl "perl")
  140. (python "python") (ruby "ruby") (tcl "tcl") (lua "lua")
  141. (java "java") (javascript "javascript")
  142. (tex "latex")
  143. (shell-script "sh") (awk "awk") (diff "diff") (m4 "m4")
  144. (ocaml "caml") (caml "caml")
  145. (sql "sql") (sqlite "sql")
  146. (html "html") (css "css") (xml "xml")
  147. (bat "bat") (bison "bison") (clipper "clipper")
  148. (ldap "ldap") (opa "opa")
  149. (php "php") (postscript "postscript") (prolog "prolog")
  150. (properties "properties") (makefile "makefile")
  151. (tml "tml") (vala "vala") (vbscript "vbscript") (xorg "xorg"))
  152. "Alist mapping languages to their listing language counterpart.
  153. The key is a symbol, the major mode symbol without the \"-mode\".
  154. The value is the string that should be inserted as the language
  155. parameter for the listings package. If the mode name and the
  156. listings name are the same, the language does not need an entry
  157. in this list - but it does not hurt if it is present."
  158. :group 'org-export-e-man
  159. :type '(repeat
  160. (list
  161. (symbol :tag "Major mode ")
  162. (string :tag "Listings language"))))
  163. (defvar org-e-man-custom-lang-environments nil
  164. "Alist mapping languages to language-specific Man environments.
  165. It is used during export of src blocks by the listings and
  166. man packages. For example,
  167. \(setq org-e-man-custom-lang-environments
  168. '\(\(python \"pythoncode\"\)\)\)
  169. would have the effect that if org encounters begin_src python
  170. during man export."
  171. )
  172. ;;; Compilation
  173. (defcustom org-e-man-pdf-process
  174. '("tbl %f | eqn | groff -man | ps2pdf - > %b.pdf"
  175. "tbl %f | eqn | groff -man | ps2pdf - > %b.pdf"
  176. "tbl %f | eqn | groff -man | ps2pdf - > %b.pdf")
  177. "Commands to process a Man file to a PDF file.
  178. This is a list of strings, each of them will be given to the
  179. shell as a command. %f in the command will be replaced by the
  180. full file name, %b by the file base name (i.e. without directory
  181. and extension parts) and %o by the base directory of the file.
  182. By default, Org uses 3 runs of to do the processing.
  183. Alternatively, this may be a Lisp function that does the
  184. processing. This function should accept the file name as
  185. its single argument."
  186. :group 'org-export-pdf
  187. :type '(choice
  188. (repeat :tag "Shell command sequence"
  189. (string :tag "Shell command"))
  190. (const :tag "2 runs of pdfgroff"
  191. ("tbl %f | eqn | groff -mm | ps2pdf - > %b.pdf"
  192. "tbl %f | eqn | groff -mm | ps2pdf - > %b.pdf" ))
  193. (const :tag "3 runs of pdfgroff"
  194. ("tbl %f | eqn | groff -mm | ps2pdf - > %b.pdf"
  195. "tbl %f | eqn | groff -mm | ps2pdf - > %b.pdf"
  196. "tbl %f | eqn | groff -mm | ps2pdf - > %b.pdf"))
  197. (function)))
  198. (defcustom org-e-man-logfiles-extensions
  199. '("log" "out" "toc")
  200. "The list of file extensions to consider as Man logfiles."
  201. :group 'org-export-e-man
  202. :type '(repeat (string :tag "Extension")))
  203. (defcustom org-e-man-remove-logfiles t
  204. "Non-nil means remove the logfiles produced by PDF production.
  205. These are the .aux, .log, .out, and .toc files."
  206. :group 'org-export-e-man
  207. :type 'boolean)
  208. ;;; Internal Functions
  209. (defun org-e-man--caption/label-string (element info)
  210. "Return caption and label Man string for ELEMENT.
  211. INFO is a plist holding contextual information. If there's no
  212. caption nor label, return the empty string.
  213. For non-floats, see `org-e-man--wrap-label'."
  214. (let ((label (org-element-property :label element))
  215. (main (org-export-get-caption element))
  216. (short (org-export-get-caption element t)))
  217. (cond ((and (not main) (not label)) "")
  218. ((not main) (format "\\fI%s\\fP" label))
  219. ;; Option caption format with short name.
  220. (short (format "\\fR%s\\fP - \\fI\\P - %s\n"
  221. (org-export-data short info)
  222. (org-export-data main info)))
  223. ;; Standard caption format.
  224. (t (format "\\fR%s\\fP" (org-export-data main info))))))
  225. (defun org-e-man--wrap-label (element output)
  226. "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
  227. This function shouldn't be used for floats. See
  228. `org-e-man--caption/label-string'."
  229. (let ((label (org-element-property :name element)))
  230. (if (or (not output) (not label) (string= output "") (string= label ""))
  231. output
  232. (concat (format "%s\n.br\n" label) output))))
  233. ;;; Template
  234. (defun org-e-man-template (contents info)
  235. "Return complete document string after Man conversion.
  236. CONTENTS is the transcoded contents string. INFO is a plist
  237. holding export options."
  238. (let* ((title (org-export-data (plist-get info :title) info))
  239. (attr (read (format "(%s)"
  240. (mapconcat
  241. #'identity
  242. (list (plist-get info :man-class-options))
  243. " "))))
  244. (section-item (plist-get attr :section-id)))
  245. (concat
  246. (cond
  247. ((and title (stringp section-item))
  248. (format ".TH \"%s\" \"%s\" \n" title section-item))
  249. ((and (string= "" title) (stringp section-item))
  250. (format ".TH \"%s\" \"%s\" \n" " " section-item))
  251. (title
  252. (format ".TH \"%s\" \"1\" \n" title))
  253. (t
  254. ".TH \" \" \"1\" "))
  255. contents)))
  256. ;;; Transcode Functions
  257. ;;; Babel Call
  258. ;;
  259. ;; Babel Calls are ignored.
  260. ;;; Bold
  261. (defun org-e-man-bold (bold contents info)
  262. "Transcode BOLD from Org to Man.
  263. CONTENTS is the text with bold markup. INFO is a plist holding
  264. contextual information."
  265. (format "\\fB%s\\fP" contents))
  266. ;;; Center Block
  267. (defun org-e-man-center-block (center-block contents info)
  268. "Transcode a CENTER-BLOCK element from Org to Man.
  269. CONTENTS holds the contents of the center block. INFO is a plist
  270. holding contextual information."
  271. (org-e-man--wrap-label
  272. center-block
  273. (format ".ce %d\n.nf\n%s\n.fi"
  274. (- (length (split-string contents "\n")) 1 )
  275. contents)))
  276. ;;; Clock
  277. (defun org-e-man-clock (clock contents info)
  278. "Transcode a CLOCK element from Org to Man.
  279. CONTENTS is nil. INFO is a plist holding contextual
  280. information."
  281. "" )
  282. ;;; Code
  283. (defun org-e-man-code (code contents info)
  284. "Transcode a CODE object from Org to Man.
  285. CONTENTS is nil. INFO is a plist used as a communication
  286. channel."
  287. (format "\\fC%s\\fP" code))
  288. ;;; Comment
  289. ;;
  290. ;; Comments are ignored.
  291. ;;; Comment Block
  292. ;;
  293. ;; Comment Blocks are ignored.
  294. ;;; Drawer
  295. (defun org-e-man-drawer (drawer contents info)
  296. "Transcode a DRAWER element from Org to Man.
  297. DRAWER holds the drawer information
  298. CONTENTS holds the contents of the block.
  299. INFO is a plist holding contextual information. "
  300. contents)
  301. ;;; Dynamic Block
  302. (defun org-e-man-dynamic-block (dynamic-block contents info)
  303. "Transcode a DYNAMIC-BLOCK element from Org to Man.
  304. CONTENTS holds the contents of the block. INFO is a plist
  305. holding contextual information. See `org-export-data'."
  306. (org-e-man--wrap-label dynamic-block contents))
  307. ;;; Entity
  308. (defun org-e-man-entity (entity contents info)
  309. "Transcode an ENTITY object from Org to Man.
  310. CONTENTS are the definition itself. INFO is a plist holding
  311. contextual information."
  312. (org-element-property :utf-8 entity))
  313. ;;; Example Block
  314. (defun org-e-man-example-block (example-block contents info)
  315. "Transcode an EXAMPLE-BLOCK element from Org to Man.
  316. CONTENTS is nil. INFO is a plist holding contextual
  317. information."
  318. (org-e-man--wrap-label
  319. example-block
  320. (format ".RS\n.nf\n%s\n.fi\n.RE"
  321. (org-export-format-code-default example-block info))))
  322. ;;; Export Block
  323. (defun org-e-man-export-block (export-block contents info)
  324. "Transcode a EXPORT-BLOCK element from Org to Man.
  325. CONTENTS is nil. INFO is a plist holding contextual information."
  326. (when (string= (org-element-property :type export-block) "MAN")
  327. (org-remove-indentation (org-element-property :value export-block))))
  328. ;;; Export Snippet
  329. (defun org-e-man-export-snippet (export-snippet contents info)
  330. "Transcode a EXPORT-SNIPPET object from Org to Man.
  331. CONTENTS is nil. INFO is a plist holding contextual information."
  332. (when (eq (org-export-snippet-backend export-snippet) 'e-man)
  333. (org-element-property :value export-snippet)))
  334. ;;; Fixed Width
  335. (defun org-e-man-fixed-width (fixed-width contents info)
  336. "Transcode a FIXED-WIDTH element from Org to Man.
  337. CONTENTS is nil. INFO is a plist holding contextual information."
  338. (org-e-man--wrap-label
  339. fixed-width
  340. (format "\\fC\n%s\\fP"
  341. (org-remove-indentation
  342. (org-element-property :value fixed-width)))))
  343. ;;; Footnote Definition
  344. ;;
  345. ;; Footnote Definitions are ignored.
  346. ;;; Footnote References
  347. ;;
  348. ;; Footnote References are Ignored
  349. ;;; Headline
  350. (defun org-e-man-headline (headline contents info)
  351. "Transcode an HEADLINE element from Org to Man.
  352. CONTENTS holds the contents of the headline. INFO is a plist
  353. holding contextual information."
  354. (let* ((level (org-export-get-relative-level headline info))
  355. (numberedp (org-export-numbered-headline-p headline info))
  356. ;; Section formatting will set two placeholders: one for the
  357. ;; title and the other for the contents.
  358. (section-fmt
  359. (case level
  360. (1 ".SH \"%s\"\n%s")
  361. (2 ".SS \"%s\"\n%s")
  362. (3 ".SS \"%s\"\n%s")
  363. (t nil)))
  364. (text (org-export-data (org-element-property :title headline) info)))
  365. (cond
  366. ;; Case 1: This is a footnote section: ignore it.
  367. ((org-element-property :footnote-section-p headline) nil)
  368. ;; Case 2. This is a deep sub-tree: export it as a list item.
  369. ;; Also export as items headlines for which no section
  370. ;; format has been found.
  371. ((or (not section-fmt) (org-export-low-level-p headline info))
  372. ;; Build the real contents of the sub-tree.
  373. (let ((low-level-body
  374. (concat
  375. ;; If the headline is the first sibling, start a list.
  376. (when (org-export-first-sibling-p headline info)
  377. (format "%s\n" ".RS"))
  378. ;; Itemize headline
  379. ".TP\n.ft I\n" text "\n.ft\n"
  380. contents ".RE")))
  381. ;; If headline is not the last sibling simply return
  382. ;; LOW-LEVEL-BODY. Otherwise, also close the list, before any
  383. ;; blank line.
  384. (if (not (org-export-last-sibling-p headline info)) low-level-body
  385. (replace-regexp-in-string
  386. "[ \t\n]*\\'" ""
  387. low-level-body))))
  388. ;; Case 3. Standard headline. Export it as a section.
  389. (t (format section-fmt text contents )))))
  390. ;;; Horizontal Rule
  391. ;; Not supported
  392. ;;; Inline Babel Call
  393. ;;
  394. ;; Inline Babel Calls are ignored.
  395. ;;; Inline Src Block
  396. (defun org-e-man-inline-src-block (inline-src-block contents info)
  397. "Transcode an INLINE-SRC-BLOCK element from Org to Man.
  398. CONTENTS holds the contents of the item. INFO is a plist holding
  399. contextual information."
  400. (let* ((code (org-element-property :value inline-src-block)))
  401. (cond
  402. (org-e-man-source-highlight
  403. (let* ((tmpdir (if (featurep 'xemacs)
  404. temp-directory
  405. temporary-file-directory ))
  406. (in-file (make-temp-name
  407. (expand-file-name "srchilite" tmpdir)))
  408. (out-file (make-temp-name
  409. (expand-file-name "reshilite" tmpdir)))
  410. (org-lang (org-element-property :language inline-src-block))
  411. (lst-lang (cadr (assq (intern org-lang)
  412. org-e-man-source-highlight-langs)))
  413. (cmd (concat (expand-file-name "source-highlight")
  414. " -s " lst-lang
  415. " -f groff_man"
  416. " -i " in-file
  417. " -o " out-file )))
  418. (if lst-lang
  419. (let ((code-block "" ))
  420. (with-temp-file in-file (insert code))
  421. (shell-command cmd)
  422. (setq code-block (org-file-contents out-file))
  423. (delete-file in-file)
  424. (delete-file out-file)
  425. code-block)
  426. (format ".RS\n.nf\n\\fC\\m[black]%s\\m[]\\fP\n.fi\n.RE\n"
  427. code))))
  428. ;; Do not use a special package: transcode it verbatim.
  429. (t
  430. (concat ".RS\n.nf\n" "\\fC" "\n" code "\n"
  431. "\\fP\n.fi\n.RE\n")))))
  432. ;;; Inlinetask
  433. ;;; Italic
  434. (defun org-e-man-italic (italic contents info)
  435. "Transcode ITALIC from Org to Man.
  436. CONTENTS is the text with italic markup. INFO is a plist holding
  437. contextual information."
  438. (format "\\fI%s\\fP" contents))
  439. ;;; Item
  440. (defun org-e-man-item (item contents info)
  441. "Transcode an ITEM element from Org to Man.
  442. CONTENTS holds the contents of the item. INFO is a plist holding
  443. contextual information."
  444. (let* ((bullet (org-element-property :bullet item))
  445. (type (org-element-property :type (org-element-property :parent item)))
  446. (checkbox (case (org-element-property :checkbox item)
  447. (on "\\o'\\(sq\\(mu'") ;;
  448. (off "\\(sq ") ;;
  449. (trans "\\o'\\(sq\\(mi'" ))) ;;
  450. (tag (let ((tag (org-element-property :tag item)))
  451. ;; Check-boxes must belong to the tag.
  452. (and tag (format "\\fB%s\\fP"
  453. (concat checkbox
  454. (org-export-data tag info)))))))
  455. (if (and (null tag )
  456. (null checkbox))
  457. (let* ((bullet (org-trim bullet))
  458. (marker (cond ((string= "-" bullet) "\\(em")
  459. ((string= "*" bullet) "\\(bu")
  460. ((eq type 'ordered)
  461. (format "%s " (org-trim bullet)))
  462. (t "\\(dg"))))
  463. (concat ".IP " marker " 4\n"
  464. (org-trim (or contents " " ))))
  465. ; else
  466. (concat ".TP\n" (or tag (concat " " checkbox)) "\n"
  467. (org-trim (or contents " " ))))))
  468. ;;; Keyword
  469. (defun org-e-man-keyword (keyword contents info)
  470. "Transcode a KEYWORD element from Org to Man.
  471. CONTENTS is nil. INFO is a plist holding contextual information."
  472. (let ((key (org-element-property :key keyword))
  473. (value (org-element-property :value keyword)))
  474. (cond
  475. ((string= key "MAN") value)
  476. ((string= key "INDEX") nil)
  477. ;; Invisible targets.
  478. ((string= key "TARGET") nil)
  479. ((string= key "TOC" ) nil))))
  480. ;;; Man Environment
  481. (defun org-e-man-man-environment (man-environment contents info)
  482. "Transcode a MAN-ENVIRONMENT element from Org to Man.
  483. CONTENTS is nil. INFO is a plist holding contextual information."
  484. (let ((label (org-element-property :name man-environment))
  485. (value (org-remove-indentation
  486. (org-element-property :value man-environment))))
  487. (if (not (org-string-nw-p label)) value
  488. ;; Environment is labelled: label must be within the environment
  489. ;; (otherwise, a reference pointing to that element will count
  490. ;; the section instead).
  491. (with-temp-buffer
  492. (insert value)
  493. (goto-char (point-min))
  494. (forward-line)
  495. (insert (format "%s\n" label))
  496. (buffer-string)))))
  497. ;;; Man Fragment
  498. (defun org-e-man-man-fragment (man-fragment contents info)
  499. "Transcode a MAN-FRAGMENT object from Org to Man.
  500. CONTENTS is nil. INFO is a plist holding contextual information."
  501. (org-element-property :value man-fragment))
  502. ;;; Line Break
  503. (defun org-e-man-line-break (line-break contents info)
  504. "Transcode a LINE-BREAK object from Org to Man.
  505. CONTENTS is nil. INFO is a plist holding contextual information."
  506. ".br\n")
  507. ;;; Link
  508. (defun org-e-man-link (link desc info)
  509. "Transcode a LINK object from Org to Man.
  510. DESC is the description part of the link, or the empty string.
  511. INFO is a plist holding contextual information. See
  512. `org-export-data'."
  513. (let* ((type (org-element-property :type link))
  514. (raw-path (org-element-property :path link))
  515. ;; Ensure DESC really exists, or set it to nil.
  516. (desc (and (not (string= desc "")) desc))
  517. (path (cond
  518. ((member type '("http" "https" "ftp" "mailto"))
  519. (concat type ":" raw-path))
  520. ((string= type "file")
  521. (when (string-match "\\(.+\\)::.+" raw-path)
  522. (setq raw-path (match-string 1 raw-path)))
  523. (if (file-name-absolute-p raw-path)
  524. (concat "file://" (expand-file-name raw-path))
  525. (concat "file://" raw-path)))
  526. (t raw-path)))
  527. protocol)
  528. (cond
  529. ;; External link with a description part.
  530. ((and path desc) (format "%s \\fBat\\fP \\fI%s\\fP" path desc))
  531. ;; External link without a description part.
  532. (path (format "\\fI%s\\fP" path))
  533. ;; No path, only description. Try to do something useful.
  534. (t (format "\\fI%s\\fP" desc)))))
  535. ;;; Paragraph
  536. (defun org-e-man-paragraph (paragraph contents info)
  537. "Transcode a PARAGRAPH element from Org to Man.
  538. CONTENTS is the contents of the paragraph, as a string. INFO is
  539. the plist used as a communication channel."
  540. (let ((parent (plist-get (nth 1 paragraph) :parent)))
  541. (when parent
  542. (let ((parent-type (car parent))
  543. (fixed-paragraph ""))
  544. (cond ((and (eq parent-type 'item)
  545. (plist-get (nth 1 parent) :bullet ))
  546. (setq fixed-paragraph (concat "" contents)))
  547. ((eq parent-type 'section)
  548. (setq fixed-paragraph (concat ".PP\n" contents)))
  549. ((eq parent-type 'footnote-definition)
  550. (setq fixed-paragraph contents))
  551. (t (setq fixed-paragraph (concat "" contents))))
  552. fixed-paragraph ))))
  553. ;;; Plain List
  554. (defun org-e-man-plain-list (plain-list contents info)
  555. "Transcode a PLAIN-LIST element from Org to Man.
  556. CONTENTS is the contents of the list. INFO is a plist holding
  557. contextual information."
  558. contents)
  559. ;;; Plain Text
  560. (defun org-e-man-plain-text (text info)
  561. "Transcode a TEXT string from Org to Man.
  562. TEXT is the string to transcode. INFO is a plist holding
  563. contextual information."
  564. (let ((output text))
  565. ;; Protect various chars.
  566. (setq output (replace-regexp-in-string
  567. "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
  568. "$\\" output nil t 1))
  569. ;; Activate smart quotes. Be sure to provide original TEXT string
  570. ;; since OUTPUT may have been modified.
  571. (when (plist-get info :with-smart-quotes)
  572. (setq output (org-export-activate-smart-quotes output :utf-8 info text)))
  573. ;; Handle break preservation if required.
  574. (when (plist-get info :preserve-breaks)
  575. (setq output (replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" ".br\n"
  576. output)))
  577. ;; Return value.
  578. output))
  579. ;;; Planning
  580. ;;; Property Drawer
  581. ;;; Quote Block
  582. (defun org-e-man-quote-block (quote-block contents info)
  583. "Transcode a QUOTE-BLOCK element from Org to Man.
  584. CONTENTS holds the contents of the block. INFO is a plist
  585. holding contextual information."
  586. (org-e-man--wrap-label
  587. quote-block
  588. (format ".RS\n%s\n.RE" contents)))
  589. ;;; Quote Section
  590. (defun org-e-man-quote-section (quote-section contents info)
  591. "Transcode a QUOTE-SECTION element from Org to Man.
  592. CONTENTS is nil. INFO is a plist holding contextual information."
  593. (let ((value (org-remove-indentation
  594. (org-element-property :value quote-section))))
  595. (when value (format ".RS\\fI%s\\fP\n.RE\n" value))))
  596. ;;; Radio Target
  597. (defun org-e-man-radio-target (radio-target text info)
  598. "Transcode a RADIO-TARGET object from Org to Man.
  599. TEXT is the text of the target. INFO is a plist holding
  600. contextual information."
  601. text )
  602. ;;; Section
  603. (defun org-e-man-section (section contents info)
  604. "Transcode a SECTION element from Org to Man.
  605. CONTENTS holds the contents of the section. INFO is a plist
  606. holding contextual information."
  607. contents)
  608. ;;; Special Block
  609. (defun org-e-man-special-block (special-block contents info)
  610. "Transcode a SPECIAL-BLOCK element from Org to Man.
  611. CONTENTS holds the contents of the block. INFO is a plist
  612. holding contextual information."
  613. (let ((type (downcase (org-element-property :type special-block))))
  614. (org-e-man--wrap-label
  615. special-block
  616. (format "%s\n" contents))))
  617. ;;; Src Block
  618. (defun org-e-man-src-block (src-block contents info)
  619. "Transcode a SRC-BLOCK element from Org to Man.
  620. CONTENTS holds the contents of the item. INFO is a plist holding
  621. contextual information."
  622. (let* ((lang (org-element-property :language src-block))
  623. (code (org-element-property :value src-block))
  624. (custom-env (and lang
  625. (cadr (assq (intern lang)
  626. org-e-man-custom-lang-environments))))
  627. (num-start (case (org-element-property :number-lines src-block)
  628. (continued (org-export-get-loc src-block info))
  629. (new 0)))
  630. (retain-labels (org-element-property :retain-labels src-block)))
  631. (cond
  632. ;; Case 1. No source fontification.
  633. ((not org-e-man-source-highlight)
  634. (format ".RS\n.nf\n\\fC%s\\fP\n.fi\n.RE\n\n"
  635. (org-export-format-code-default src-block info)))
  636. (org-e-man-source-highlight
  637. (let* ((tmpdir (if (featurep 'xemacs)
  638. temp-directory
  639. temporary-file-directory ))
  640. (in-file (make-temp-name
  641. (expand-file-name "srchilite" tmpdir)))
  642. (out-file (make-temp-name
  643. (expand-file-name "reshilite" tmpdir)))
  644. (org-lang (org-element-property :language src-block))
  645. (lst-lang (cadr (assq (intern org-lang)
  646. org-e-man-source-highlight-langs)))
  647. (cmd (concat "source-highlight"
  648. " -s " lst-lang
  649. " -f groff_man "
  650. " -i " in-file
  651. " -o " out-file)))
  652. (if lst-lang
  653. (let ((code-block ""))
  654. (with-temp-file in-file (insert code))
  655. (shell-command cmd)
  656. (setq code-block (org-file-contents out-file))
  657. (delete-file in-file)
  658. (delete-file out-file)
  659. code-block)
  660. (format ".RS\n.nf\n\\fC\\m[black]%s\\m[]\\fP\n.fi\n.RE" code)))))))
  661. ;;; Statistics Cookie
  662. (defun org-e-man-statistics-cookie (statistics-cookie contents info)
  663. "Transcode a STATISTICS-COOKIE object from Org to Man.
  664. CONTENTS is nil. INFO is a plist holding contextual information."
  665. (org-element-property :value statistics-cookie))
  666. ;;; Strike-Through
  667. (defun org-e-man-strike-through (strike-through contents info)
  668. "Transcode STRIKE-THROUGH from Org to Man.
  669. CONTENTS is the text with strike-through markup. INFO is a plist
  670. holding contextual information."
  671. (format "\\fI%s\\fP" contents))
  672. ;;; Subscript
  673. (defun org-e-man-subscript (subscript contents info)
  674. "Transcode a SUBSCRIPT object from Org to Man.
  675. CONTENTS is the contents of the object. INFO is a plist holding
  676. contextual information."
  677. (format "\\d\\s-2%s\\s+2\\u" contents))
  678. ;;; Superscript "^_%s$
  679. (defun org-e-man-superscript (superscript contents info)
  680. "Transcode a SUPERSCRIPT object from Org to Man.
  681. CONTENTS is the contents of the object. INFO is a plist holding
  682. contextual information."
  683. (format "\\u\\s-2%s\\s+2\\d" contents))
  684. ;;; Table
  685. ;;
  686. ;; `org-e-man-table' is the entry point for table transcoding. It
  687. ;; takes care of tables with a "verbatim" attribute. Otherwise, it
  688. ;; delegates the job to either `org-e-man-table--table.el-table' or
  689. ;; `org-e-man-table--org-table' functions, depending of the type of
  690. ;; the table.
  691. ;;
  692. ;; `org-e-man-table--align-string' is a subroutine used to build
  693. ;; alignment string for Org tables.
  694. (defun org-e-man-table (table contents info)
  695. "Transcode a TABLE element from Org to Man.
  696. CONTENTS is the contents of the table. INFO is a plist holding
  697. contextual information."
  698. (cond
  699. ;; Case 1: verbatim table.
  700. ((or org-e-man-tables-verbatim
  701. (let ((attr (read (format "(%s)"
  702. (mapconcat
  703. #'identity
  704. (org-element-property :attr_man table)
  705. " ")))))
  706. (and attr (plist-get attr :verbatim))))
  707. (format ".nf\n\\fC%s\\fP\n.fi"
  708. ;; Re-create table, without affiliated keywords.
  709. (org-trim
  710. (org-element-interpret-data
  711. `(table nil ,@(org-element-contents table))))))
  712. ;; Case 2: Standard table.
  713. (t (org-e-man-table--org-table table contents info))))
  714. (defun org-e-man-table--align-string (divider table info)
  715. "Return an appropriate Man alignment string.
  716. TABLE is the considered table. INFO is a plist used as
  717. a communication channel."
  718. (let (alignment)
  719. ;; Extract column groups and alignment from first (non-rule)
  720. ;; row.
  721. (org-element-map
  722. (org-element-map
  723. table 'table-row
  724. (lambda (row)
  725. (and (eq (org-element-property :type row) 'standard) row))
  726. info 'first-match)
  727. 'table-cell
  728. (lambda (cell)
  729. (let* ((borders (org-export-table-cell-borders cell info))
  730. (raw-width (org-export-table-cell-width cell info))
  731. (width-cm (when raw-width (/ raw-width 5)))
  732. (width (if raw-width (format "w(%dc)"
  733. (if (< width-cm 1) 1 width-cm)) "")))
  734. ;; Check left border for the first cell only.
  735. (when (and (memq 'left borders) (not alignment))
  736. (push "|" alignment))
  737. (push
  738. (case (org-export-table-cell-alignment cell info)
  739. (left (concat "l" width divider))
  740. (right (concat "r" width divider))
  741. (center (concat "c" width divider)))
  742. alignment)
  743. (when (memq 'right borders) (push "|" alignment))))
  744. info)
  745. (apply 'concat (reverse alignment))))
  746. (defun org-e-man-table--org-table (table contents info)
  747. "Return appropriate Man code for an Org table.
  748. TABLE is the table type element to transcode. CONTENTS is its
  749. contents, as a string. INFO is a plist used as a communication
  750. channel.
  751. This function assumes TABLE has `org' as its `:type' attribute."
  752. (let* ((attr (org-export-read-attribute :attr_man table))
  753. (label (org-element-property :name table))
  754. (caption (and (not (plist-get attr :disable-caption))
  755. (org-e-man--caption/label-string table info)))
  756. (divider (if (plist-get attr :divider) "|" " "))
  757. ;; Determine alignment string.
  758. (alignment (org-e-man-table--align-string divider table info))
  759. ;; Extract others display options.
  760. (lines (org-split-string contents "\n"))
  761. (attr-list
  762. (let ((result-list '()))
  763. (dolist (attr-item
  764. (list
  765. (if (plist-get attr :expand)
  766. "expand" nil)
  767. (case (plist-get attr :placement)
  768. ('center "center")
  769. ('left nil)
  770. (t
  771. (if org-e-man-tables-centered
  772. "center" "")))
  773. (case (plist-get attr :boxtype)
  774. ('box "box")
  775. ('doublebox "doublebox")
  776. ('allbox "allbox")
  777. ('none nil)
  778. (t "box"))))
  779. (if attr-item
  780. (add-to-list 'result-list attr-item)))
  781. result-list ))
  782. (title-line (plist-get attr :title-line))
  783. (long-cells (plist-get attr :long-cells))
  784. (table-format (concat
  785. (format "%s" (or (car attr-list) "" ))
  786. (or
  787. (let ((output-list '()))
  788. (when (cdr attr-list)
  789. (dolist (attr-item (cdr attr-list))
  790. (setq output-list (concat output-list (format ",%s" attr-item)))))
  791. output-list)
  792. "")))
  793. (first-line (when lines (org-split-string (car lines) "\t"))))
  794. ;; Prepare the final format string for the table.
  795. (cond
  796. ;; Others.
  797. (lines (concat ".TS\n " table-format ";\n"
  798. (format "%s.\n"
  799. (let ((final-line ""))
  800. (when title-line
  801. (dotimes (i (length first-line))
  802. (setq final-line (concat final-line "cb" divider))))
  803. (setq final-line (concat final-line "\n"))
  804. (if alignment
  805. (setq final-line (concat final-line alignment))
  806. (dotimes (i (length first-line))
  807. (setq final-line (concat final-line "c" divider))))
  808. final-line ))
  809. (format "%s.TE\n"
  810. (let ((final-line "")
  811. (long-line "")
  812. (lines (org-split-string contents "\n")))
  813. (dolist (line-item lines)
  814. (setq long-line "")
  815. (if long-cells
  816. (progn
  817. (if (string= line-item "_")
  818. (setq long-line (format "%s\n" line-item))
  819. ;; else string =
  820. (let ((cell-item-list (org-split-string line-item "\t")))
  821. (dolist (cell-item cell-item-list)
  822. (cond ((eq cell-item (car (last cell-item-list)))
  823. (setq long-line (concat long-line
  824. (format "T{\n%s\nT}\t\n" cell-item ))))
  825. (t
  826. (setq long-line (concat long-line
  827. (format "T{\n%s\nT}\t" cell-item ))))))
  828. long-line))
  829. ;; else long cells
  830. (setq final-line (concat final-line long-line )))
  831. (setq final-line (concat final-line line-item "\n"))))
  832. final-line))
  833. (and caption (format ".TB \"%s\"" caption)))))))
  834. ;;; Table Cell
  835. (defun org-e-man-table-cell (table-cell contents info)
  836. "Transcode a TABLE-CELL element from Org to Man
  837. CONTENTS is the cell contents. INFO is a plist used as
  838. a communication channel."
  839. (concat (if (and contents
  840. org-e-man-table-scientific-notation
  841. (string-match orgtbl-exp-regexp contents))
  842. ;; Use appropriate format string for scientific
  843. ;; notation.
  844. (format org-e-man-table-scientific-notation
  845. (match-string 1 contents)
  846. (match-string 2 contents))
  847. contents )
  848. (when (org-export-get-next-element table-cell info) "\t")))
  849. ;;; Table Row
  850. (defun org-e-man-table-row (table-row contents info)
  851. "Transcode a TABLE-ROW element from Org to Man
  852. CONTENTS is the contents of the row. INFO is a plist used as
  853. a communication channel."
  854. ;; Rules are ignored since table separators are deduced from
  855. ;; borders of the current row.
  856. (when (eq (org-element-property :type table-row) 'standard)
  857. (let* ((attr (mapconcat 'identity
  858. (org-element-property
  859. :attr_man (org-export-get-parent table-row))
  860. " "))
  861. ;; TABLE-ROW's borders are extracted from its first cell.
  862. (borders
  863. (org-export-table-cell-borders
  864. (car (org-element-contents table-row)) info)))
  865. (concat
  866. ;; Mark horizontal lines
  867. (cond ((and (memq 'top borders) (memq 'above borders)) "_\n"))
  868. contents
  869. (cond
  870. ;; When BOOKTABS are activated enforce bottom rule even when
  871. ;; no hline was specifically marked.
  872. ((and (memq 'bottom borders) (memq 'below borders)) "\n_")
  873. ((memq 'below borders) "\n_"))))))
  874. ;;; Target
  875. (defun org-e-man-target (target contents info)
  876. "Transcode a TARGET object from Org to Man.
  877. CONTENTS is nil. INFO is a plist holding contextual
  878. information."
  879. (format "\\fI%s\\fP"
  880. (org-export-solidify-link-text (org-element-property :value target))))
  881. ;;; Timestamp
  882. (defun org-e-man-timestamp (timestamp contents info)
  883. "Transcode a TIMESTAMP object from Org to Man.
  884. CONTENTS is nil. INFO is a plist holding contextual
  885. information."
  886. "" )
  887. ;;; Underline
  888. (defun org-e-man-underline (underline contents info)
  889. "Transcode UNDERLINE from Org to Man.
  890. CONTENTS is the text with underline markup. INFO is a plist
  891. holding contextual information."
  892. (format "\\fI%s\\fP" contents))
  893. ;;; Verbatim
  894. (defun org-e-man-verbatim (verbatim contents info)
  895. "Transcode a VERBATIM object from Org to Man.
  896. CONTENTS is nil. INFO is a plist used as a communication
  897. channel."
  898. (format ".nf\n%s\n.fi" contents))
  899. ;;; Verse Block
  900. (defun org-e-man-verse-block (verse-block contents info)
  901. "Transcode a VERSE-BLOCK element from Org to Man.
  902. CONTENTS is verse block contents. INFO is a plist holding
  903. contextual information."
  904. (format ".RS\n.ft I\n%s\n.ft\n.RE" contents))
  905. ;;; Interactive functions
  906. (defun org-e-man-export-to-man
  907. (&optional async subtreep visible-only body-only ext-plist)
  908. "Export current buffer to a Man file.
  909. If narrowing is active in the current buffer, only export its
  910. narrowed part.
  911. If a region is active, export that region.
  912. A non-nil optional argument ASYNC means the process should happen
  913. asynchronously. The resulting file should be accessible through
  914. the `org-export-stack' interface.
  915. When optional argument SUBTREEP is non-nil, export the sub-tree
  916. at point, extracting information from the headline properties
  917. first.
  918. When optional argument VISIBLE-ONLY is non-nil, don't export
  919. contents of hidden elements.
  920. When optional argument BODY-ONLY is non-nil, only the body
  921. without any markers.
  922. EXT-PLIST, when provided, is a property list with external
  923. parameters overriding Org default settings, but still inferior to
  924. file-local settings.
  925. Return output file's name."
  926. (interactive)
  927. (let ((outfile (org-export-output-file-name ".man" subtreep)))
  928. (if async
  929. (org-export-async-start
  930. (lambda (f) (org-export-add-to-stack f 'e-man))
  931. `(expand-file-name
  932. (org-export-to-file
  933. 'e-man ,outfile ,subtreep ,visible-only ,body-only ',ext-plist)))
  934. (org-export-to-file
  935. 'e-man outfile subtreep visible-only body-only ext-plist))))
  936. (defun org-e-man-export-to-pdf
  937. (&optional async subtreep visible-only body-only ext-plist)
  938. "Export current buffer to Groff then process through to PDF.
  939. If narrowing is active in the current buffer, only export its
  940. narrowed part.
  941. If a region is active, export that region.
  942. A non-nil optional argument ASYNC means the process should happen
  943. asynchronously. The resulting file should be accessible through
  944. the `org-export-stack' interface.
  945. When optional argument SUBTREEP is non-nil, export the sub-tree
  946. at point, extracting information from the headline properties
  947. first.
  948. When optional argument VISIBLE-ONLY is non-nil, don't export
  949. contents of hidden elements.
  950. When optional argument BODY-ONLY is non-nil, only write between
  951. markers.
  952. EXT-PLIST, when provided, is a property list with external
  953. parameters overriding Org default settings, but still inferior to
  954. file-local settings.
  955. Return PDF file's name."
  956. (interactive)
  957. (if async
  958. (let ((outfile (org-export-output-file-name ".man" subtreep)))
  959. (org-export-async-start
  960. (lambda (f) (org-export-add-to-stack f 'e-man))
  961. `(expand-file-name
  962. (org-e-man-compile
  963. (org-export-to-file
  964. 'e-man ,outfile ,subtreep ,visible-only ,body-only
  965. ',ext-plist)))))
  966. (org-e-man-compile
  967. (org-e-man-export-to-man nil subtreep visible-only body-only ext-plist))))
  968. (defun org-e-man-compile (file)
  969. "Compile a Groff file.
  970. FILE is the name of the file being compiled. Processing is done
  971. through the command specified in `org-e-man-pdf-process'.
  972. Return PDF file name or an error if it couldn't be produced."
  973. (let* ((base-name (file-name-sans-extension (file-name-nondirectory file)))
  974. (full-name (file-truename file))
  975. (out-dir (file-name-directory file))
  976. ;; Make sure `default-directory' is set to FILE directory,
  977. ;; not to whatever value the current buffer may have.
  978. (default-directory (file-name-directory full-name))
  979. errors)
  980. (message (format "Processing Groff file %s ..." file))
  981. (save-window-excursion
  982. (cond
  983. ;; A function is provided: Apply it.
  984. ((functionp org-e-man-pdf-process)
  985. (funcall org-e-man-pdf-process (shell-quote-argument file)))
  986. ;; A list is provided: Replace %b, %f and %o with appropriate
  987. ;; values in each command before applying it. Output is
  988. ;; redirected to "*Org PDF Groff Output*" buffer.
  989. ((consp org-e-man-pdf-process)
  990. (let ((outbuf (get-buffer-create "*Org PDF Groff Output*")))
  991. (mapc
  992. (lambda (command)
  993. (shell-command
  994. (replace-regexp-in-string
  995. "%b" (shell-quote-argument base-name)
  996. (replace-regexp-in-string
  997. "%f" (shell-quote-argument full-name)
  998. (replace-regexp-in-string
  999. "%o" (shell-quote-argument out-dir) command t t) t t) t t)
  1000. outbuf))
  1001. org-e-man-pdf-process)
  1002. ;; Collect standard errors from output buffer.
  1003. (setq errors (org-e-man-collect-errors outbuf))))
  1004. (t (error "No valid command to process to PDF")))
  1005. (let ((pdffile (concat out-dir base-name ".pdf")))
  1006. ;; Check for process failure. Provide collected errors if
  1007. ;; possible.
  1008. (if (not (file-exists-p pdffile))
  1009. (error (concat (format "PDF file %s wasn't produced" pdffile)
  1010. (when errors (concat ": " errors))))
  1011. ;; Else remove log files, when specified, and signal end of
  1012. ;; process to user, along with any error encountered.
  1013. (when org-e-man-remove-logfiles
  1014. (dolist (ext org-e-man-logfiles-extensions)
  1015. (let ((file (concat out-dir base-name "." ext)))
  1016. (when (file-exists-p file) (delete-file file)))))
  1017. (message (concat "Process completed"
  1018. (if (not errors) "."
  1019. (concat " with errors: " errors)))))
  1020. ;; Return output file name.
  1021. pdffile))))
  1022. (defun org-e-man-collect-errors (buffer)
  1023. "Collect some kind of errors from \"groff\" output
  1024. BUFFER is the buffer containing output.
  1025. Return collected error types as a string, or nil if there was
  1026. none."
  1027. (with-current-buffer buffer
  1028. (save-excursion
  1029. (goto-char (point-max))
  1030. ;; Find final run
  1031. nil )))
  1032. (provide 'org-e-man)
  1033. ;;; org-e-man.el ends here