Merge branch 'master' of orgmode.org:org-mode
[org-mode.git] / EXPERIMENTAL / org-e-ascii.el
blobab81205c7b218cd2897bc08d35a0e3180cea37f5
1 ;;; org-e-ascii.el --- ASCII Back-End For Org Export Engine
3 ;; Copyright (C) 2012 Free Software Foundation, Inc.
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ;;; Commentary:
23 ;; This library implements an ASCII back-end for Org generic exporter.
25 ;; To test it, run
27 ;; M-: (org-export-to-buffer 'e-ascii "*Test e-ASCII*") RET
29 ;; in an Org mode buffer then switch to that buffer to see the ASCII
30 ;; export. See contrib/lisp/org-export.el for more details on how
31 ;; this exporter works.
33 ;;; Code:
35 (eval-when-compile (require 'cl))
37 (declare-function org-element-get-contents "org-element" (element))
38 (declare-function org-element-get-property "org-element" (property element))
39 (declare-function org-element-normalize-string "org-element" (s))
40 (declare-function org-element-map "org-element"
41 (data types fun &optional info first-match))
42 (declare-function org-element-time-stamp-interpreter
43 "org-element" (time-stamp contents))
45 (declare-function org-export-clean-table "org-export" (table specialp))
46 (declare-function org-export-collect-footnote-definitions
47 "org-export" (data info))
48 (declare-function org-export-collect-headlines "org-export" (info &optional n))
49 (declare-function org-export-collect-listings "org-export" (info))
50 (declare-function org-export-collect-tables "org-export" (info))
51 (declare-function org-export-data "org-export" (data backend info))
52 (declare-function org-export-expand-macro "org-export" (macro info))
53 (declare-function org-export-get-coderef-format "org-export" (path desc))
54 (declare-function org-export-get-footnote-number "org-export" (footnote info))
55 (declare-function org-export-get-headline-number "org-export" (headline info))
56 (declare-function org-export-get-ordinal "org-export"
57 (element info &optional types within-section predicate))
58 (declare-function org-export-get-parent-headline "org-export" (blob info))
59 (declare-function org-export-get-relative-level "org-export" (headline info))
60 (declare-function org-export-handle-code
61 "org-export" (element info &optional num-fmt ref-fmt delayed))
62 (declare-function org-export-included-file "org-export" (keyword backend info))
63 (declare-function org-export-low-level-p "org-export" (headline info))
64 (declare-function org-export-output-file-name "org-export"
65 (extension &optional subtreep pub-dir))
66 (declare-function org-export-resolve-coderef "org-export" (ref info))
67 (declare-function org-export-resolve-fuzzy-link "org-export" (link info))
68 (declare-function org-export-resolve-id-link "org-export" (link info))
69 (declare-function org-export-secondary-string
70 "org-export" (secondary backend info))
71 (declare-function org-export-table-format-info "org-export" (table))
72 (declare-function
73 org-export-to-file "org-export"
74 (backend file &optional subtreep visible-only body-only ext-plist))
78 ;;; Internal Variables
80 ;; The following setting won't allow to modify preferred charset
81 ;; through a buffer keyword or an option item, but, since the property
82 ;; will appear in communication channel nonetheless, it allows to
83 ;; override `org-e-ascii-charset' variable on the fly by the ext-plist
84 ;; mechanism.
86 ;; We also install a developer filter for headlines, in order to
87 ;; control blank lines in output string.
89 (defconst org-e-ascii-option-alist
90 '((:ascii-charset nil nil org-e-ascii-charset)
91 (:filter-headline nil nil (cons
92 'org-e-ascii-filter-headline-blank-lines
93 org-export-filter-headline-functions)))
94 "Alist between ASCII export properties and ways to set them.
95 See `org-export-option-alist' for more information on the
96 structure or the values.")
98 (defconst org-e-ascii-dictionary
99 '(("Footnotes\n"
100 ("en"
101 :ascii "Footnotes\n"
102 :latin1 "Footnotes\n"
103 :utf-8 "Footnotes\n")
104 ("fr"
105 :ascii "Notes de bas de page\n"
106 :latin1 "Notes de bas de page\n"
107 :utf-8 "Notes de bas de page\n"))
108 ("Listing %d: %s"
109 ("en"
110 :ascii "Listing %d: %s"
111 :latin1 "Listing %d: %s"
112 :utf-8 "Listing %d: %s")
113 ("fr"
114 :ascii "Programme %d : %s"
115 :latin1 "Programme %d : %s"
116 :utf-8 "Programme nº %d : %s"))
117 ("List Of Listings\n"
118 ("en"
119 :ascii "List Of Listings\n"
120 :latin1 "List Of Listings\n"
121 :utf-8 "List Of Listings\n")
122 ("fr"
123 :ascii "Liste des programmes\n"
124 :latin1 "Liste des programmes\n"
125 :utf-8 "Liste des programmes\n"))
126 ("List Of Tables\n"
127 ("en"
128 :ascii "List Of Tables\n"
129 :latin1 "List Of Tables\n"
130 :utf-8 "List Of Tables\n")
131 ("fr"
132 :ascii "Liste des tableaux\n"
133 :latin1 "Liste des tableaux\n"
134 :utf-8 "Liste des tableaux\n"))
135 ("Listing %d: "
136 ("en"
137 :ascii "Listing %d: "
138 :latin1 "Listing %d: "
139 :utf-8 "Listing %d: ")
140 ("fr"
141 :ascii "Programme %d : "
142 :latin1 "Programme %d : "
143 :utf-8 "Programme nº %d : "))
144 ("Table Of Contents\n"
145 ("en"
146 :ascii "Table Of Contents\n"
147 :latin1 "Table Of Contents\n"
148 :utf-8 "Table Of Contents\n")
149 ("fr"
150 :ascii "Sommaire\n"
151 :latin1 "Table des matières\n"
152 :utf-8 "Table des matières\n"))
153 ("Table %d: %s"
154 ("en"
155 :ascii "Table %d: %s"
156 :latin1 "Table %d: %s"
157 :utf-8 "Table %d: %s")
158 ("fr"
159 :ascii "Tableau %d : %s"
160 :latin1 "Tableau %d : %s"
161 :utf-8 "Tableau nº %d : %s"))
162 ("See section %s"
163 ("en"
164 :ascii "See section %s"
165 :latin1 "See section %s"
166 :utf-8 "See section %s")
167 ("fr"
168 :ascii "cf. section %s"
169 :latin1 "cf. section %s"
170 :utf-8 "cf. section %s"))
171 ("Table %d: "
172 ("en"
173 :ascii "Table %d: "
174 :latin1 "Table %d: "
175 :utf-8 "Table %d: ")
176 ("fr"
177 :ascii "Tableau %d : "
178 :latin1 "Tableau %d : "
179 :utf-8 "Tableau nº %d : "))
180 ("Unknown reference"
181 ("en"
182 :ascii "Unknown reference"
183 :latin1 "Unknown reference"
184 :utf-8 "Unknown reference")
185 ("fr"
186 :ascii "Destination inconnue"
187 :latin1 "Référence inconnue"
188 :utf-8 "Référence inconnue")))
189 "Dictionary for ASCII back-end.
191 Alist whose car is the string to translate and cdr is an alist
192 whose car is the language string and cdr is a plist whose
193 properties are possible charsets and value the translated term.
195 It is used as a database for `org-e-ascii--translate'.")
199 ;;; User Configurable Variables
201 (defgroup org-export-e-ascii nil
202 "Options for exporting Org mode files to ASCII."
203 :tag "Org Export ASCII"
204 :group 'org-export)
206 (defcustom org-e-ascii-text-width 72
207 "Maximum width of exported text.
208 This number includes margin size, as set in
209 `org-e-ascii-global-margin'."
210 :group 'org-export-e-ascii
211 :type 'integer)
213 (defcustom org-e-ascii-global-margin 0
214 "Width of the left margin, in number of characters."
215 :group 'org-export-e-ascii
216 :type 'integer)
218 (defcustom org-e-ascii-inner-margin 2
219 "Width of the inner margin, in number of characters.
220 Inner margin is applied between each headline."
221 :group 'org-export-e-ascii
222 :type 'integer)
224 (defcustom org-e-ascii-quote-margin 6
225 "Width of margin used for quoting text, in characters.
226 This margin is applied on both sides of the text."
227 :group 'org-export-e-ascii
228 :type 'integer)
230 (defcustom org-e-ascii-inlinetask-width 30
231 "Width of inline tasks, in number of characters.
232 This number ignores any margin."
233 :group 'org-export-e-ascii
234 :type 'integer)
236 (defcustom org-e-ascii-headline-spacing '(1 . 2)
237 "Number of blank lines inserted around headlines.
239 This variable can be set to a cons cell. In that case, its car
240 represents the number of blank lines present before headline
241 contents whereas its cdr reflects the number of blank lines after
242 contents.
244 A nil value replicates the number of blank lines found in the
245 original Org buffer at the same place."
246 :group 'org-export-e-ascii
247 :type '(choice
248 (const :tag "Replicate original spacing" nil)
249 (cons :tag "Set an uniform spacing"
250 (integer :tag "Number of blank lines before contents")
251 (integer :tag "Number of blank lines after contents"))))
253 (defcustom org-e-ascii-charset 'ascii
254 "The charset allowed to represent various elements and objects.
255 Possible values are:
256 `ascii' Only use plain ASCII characters
257 `latin1' Include Latin-1 characters
258 `utf-8' Use all UTF-8 characters"
259 :group 'org-export-e-ascii
260 :type '(choice
261 (const :tag "ASCII" ascii)
262 (const :tag "Latin-1" latin1)
263 (const :tag "UTF-8" utf-8)))
265 (defcustom org-e-ascii-underline '((ascii ?= ?~ ?-)
266 (latin1 ?= ?~ ?-)
267 (utf-8 ?═ ?─ ?╌ ?┄ ?┈))
268 "Characters for underlining headings in ASCII export.
270 Alist whose key is a symbol among `ascii', `latin1' and `utf-8'
271 and whose value is a list of characters.
273 For each supported charset, this variable associates a sequence
274 of underline characters. In a sequence, the characters will be
275 used in order for headlines level 1, 2, ... If no character is
276 available for a given level, the headline won't be underlined."
277 :group 'org-export-e-ascii
278 :type '(list
279 (cons :tag "Underline characters sequence"
280 (const :tag "ASCII charset" ascii)
281 (repeat character))
282 (cons :tag "Underline characters sequence"
283 (const :tag "Latin-1 charset" latin1)
284 (repeat character))
285 (cons :tag "Underline characters sequence"
286 (const :tag "UTF-8 charset" utf-8)
287 (repeat character))))
289 (defcustom org-e-ascii-bullets '((ascii ?* ?+ ?-)
290 (latin1 ?§ ?¶)
291 (utf-8 ?◊))
292 "Bullet characters for headlines converted to lists in ASCII export.
294 Alist whose key is a symbol among `ascii', `latin1' and `utf-8'
295 and whose value is a list of characters.
297 The first character is used for the first level considered as low
298 level, and so on. If there are more levels than characters given
299 here, the list will be repeated.
301 Note that this variable doesn't affect plain lists
302 representation."
303 :group 'org-export-e-ascii
304 :type '(list
305 (cons :tag "Bullet characters for low level headlines"
306 (const :tag "ASCII charset" ascii)
307 (repeat character))
308 (cons :tag "Bullet characters for low level headlines"
309 (const :tag "Latin-1 charset" latin1)
310 (repeat character))
311 (cons :tag "Bullet characters for low level headlines"
312 (const :tag "UTF-8 charset" utf-8)
313 (repeat character))))
315 (defcustom org-e-ascii-links-to-notes t
316 "Non-nil means convert links to notes before the next headline.
317 When nil, the link will be exported in place. If the line
318 becomes long in this way, it will be wrapped."
319 :group 'org-export-e-ascii
320 :type 'boolean)
322 (defcustom org-e-ascii-table-keep-all-vertical-lines nil
323 "Non-nil means keep all vertical lines in ASCII tables.
324 When nil, vertical lines will be removed except for those needed
325 for column grouping."
326 :group 'org-export-e-ascii
327 :type 'boolean)
329 (defcustom org-e-ascii-table-widen-columns t
330 "Non-nil means widen narrowed columns for export.
331 When nil, narrowed columns will look in ASCII export just like in
332 Org mode, i.e. with \"=>\" as ellipsis."
333 :group 'org-export-e-ascii
334 :type 'boolean)
336 (defcustom org-e-ascii-caption-above nil
337 "When non-nil, place caption string before the element.
338 Otherwise, place it right after it."
339 :group 'org-export-e-ascii
340 :type 'boolean)
342 (defcustom org-e-ascii-verbatim-format "`%s'"
343 "Format string used for verbatim text and inline code."
344 :group 'org-export-e-ascii
345 :type 'string)
347 (defcustom org-e-ascii-format-drawer-function nil
348 "Function called to format a drawer in ASCII.
350 The function must accept two parameters:
351 NAME the drawer name, like \"LOGBOOK\"
352 CONTENTS the contents of the drawer.
353 WIDTH the text width within the drawer.
355 The function should return either the string to be exported or
356 nil to ignore the drawer.
358 For example, the variable could be set to the following function
359 in order to mimic default behaviour:
361 \(defun org-e-ascii-format-drawer-default \(name contents width\)
362 \"Format a drawer element for ASCII export.\"
363 contents\)"
364 :group 'org-export-e-ascii
365 :type 'function)
367 (defcustom org-e-ascii-format-inlinetask-function nil
368 "Function called to format an inlinetask in ASCII.
370 The function must accept six parameters:
371 TODO the todo keyword, as a string
372 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
373 PRIORITY the inlinetask priority, as a string
374 NAME the inlinetask name, as a string.
375 TAGS the inlinetask tags, as a string.
376 CONTENTS the contents of the inlinetask, as a string.
378 The function should return either the string to be exported or
379 nil to ignore the inline task.
381 For example, the variable could be set to the following function
382 in order to mimic default behaviour:
384 \(defun org-e-ascii-format-inlinetask-default
385 \(todo type priority name tags contents\)
386 \"Format an inline task element for ASCII export.\"
387 \(let* \(\(utf8p \(eq \(plist-get info :ascii-charset\) 'utf-8\)\)
388 \(width org-e-ascii-inlinetask-width\)
389 \(org-e-ascii--indent-string
390 \(concat
391 ;; Top line, with an additional blank line if not in UTF-8.
392 \(make-string width \(if utf8p ?━ ?_\)\) \"\\n\"
393 \(unless utf8p \(concat \(make-string width ? \) \"\\n\"\)\)
394 ;; Add title. Fill it if wider than inlinetask.
395 \(let \(\(title \(org-e-ascii--build-title inlinetask info width\)\)\)
396 \(if \(<= \(length title\) width\) title
397 \(org-e-ascii--fill-string title width info\)\)\)
398 \"\\n\"
399 ;; If CONTENTS is not empty, insert it along with
400 ;; a separator.
401 \(when \(org-string-nw-p contents\)
402 \(concat \(make-string width \(if utf8p ?─ ?-\)\) \"\\n\" contents\)\)
403 ;; Bottom line.
404 \(make-string width \(if utf8p ?━ ?_\)\)\)
405 ;; Flush the inlinetask to the right.
406 \(- \(plist-get info :ascii-width\)
407 \(plist-get info :ascii-margin\)
408 \(plist-get info :ascii-inner-margin\)
409 \(org-e-ascii--current-text-width inlinetask info\)\)"
410 :group 'org-export-e-ascii
411 :type 'function)
415 ;;; Internal Functions
417 ;; Internal functions fall into three categories.
419 ;; The first one is about text formatting. The core function is
420 ;; `org-e-ascii--current-text-width', which determines the current
421 ;; text width allowed to a given element. In other words, it helps
422 ;; keeping each line width within maximum text width defined in
423 ;; `org-e-ascii-text-width'. Once this information is known,
424 ;; `org-e-ascii--fill-string', `org-e-ascii--justify-string',
425 ;; `org-e-ascii--box-string' and `org-e-ascii--indent-string' can
426 ;; operate on a given output string.
428 ;; The second category contains functions handling elements listings,
429 ;; triggered by "#+TOC:" keyword. As such, `org-e-ascii--build-toc'
430 ;; returns a complete table of contents, `org-e-ascii--list-listings'
431 ;; returns a list of referenceable src-block elements, and
432 ;; `org-e-ascii--list-tables' does the same for table elements.
434 ;; The third category includes general helper functions.
435 ;; `org-e-ascii--build-title' creates the title for a given headline
436 ;; or inlinetask element. `org-e-ascii--build-caption' returns the
437 ;; caption string associated to a table or a src-block.
438 ;; `org-e-ascii--describe-links' creates notes about links for
439 ;; insertion at the end of a section. It uses
440 ;; `org-e-ascii--unique-links' to get the list of links to describe.
441 ;; Eventually, `org-e-ascii--translate' reads `org-e-ascii-dictionary'
442 ;; to internationalize output.
445 (defun org-e-ascii--fill-string (s text-width info &optional justify)
446 "Fill a string with specified text-width and return it.
448 S is the string being filled. TEXT-WIDTH is an integer
449 specifying maximum length of a line. INFO is the plist used as
450 a communication channel.
452 Optional argument JUSTIFY can specify any type of justification
453 among `left', `center', `right' or `full'. A nil value is
454 equivalent to `left'. For a justification that doesn't also fill
455 string, see `org-e-ascii--justify-string'.
457 Return nil if S isn't a string."
458 ;; Don't fill paragraph when break should be preserved.
459 (cond ((not (stringp s)) nil)
460 ((plist-get info :preserve-breaks) s)
461 (t (with-temp-buffer
462 (let ((fill-column text-width)
463 (use-hard-newlines t))
464 (insert s)
465 (fill-region (point-min) (point-max) justify))
466 (buffer-string)))))
468 (defun org-e-ascii--justify-string (s text-width how)
469 "Justify string S.
470 TEXT-WIDTH is an integer specifying maximum length of a line.
471 HOW determines the type of justification: it can be `left',
472 `right', `full' or `center'."
473 (with-temp-buffer
474 (insert s)
475 (goto-char (point-min))
476 (let ((fill-column text-width))
477 (while (< (point) (point-max))
478 (justify-current-line how)
479 (forward-line)))
480 (buffer-string)))
482 (defun org-e-ascii--indent-string (s width)
483 "Indent string S by WIDTH white spaces.
484 Empty lines are not indented."
485 (when (stringp s)
486 (replace-regexp-in-string
487 "\\(^\\)\\(?:.*\\S-\\)" (make-string width ? ) s nil nil 1)))
489 (defun org-e-ascii--box-string (s info)
490 "Return string S with a partial box to its left.
491 INFO is a plist used as a communicaton channel."
492 (let ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
493 (format (if utf8p "╭────\n%s\n╰────" ",----\n%s\n`----")
494 (replace-regexp-in-string
495 "^" (if utf8p "│ " "| ")
496 ;; Remove last newline character.
497 (replace-regexp-in-string "\n[ \t]*\\'" "" s)))))
499 (defun org-e-ascii--current-text-width (element info)
500 "Return maximum text width for ELEMENT's contents.
501 INFO is a plist used as a communication channel."
502 (cond
503 ;; Elements with an absolute width: `headline' and `inlinetask'.
504 ((eq (car element) 'inlinetask) org-e-ascii-inlinetask-width)
505 ((eq (car element) 'headline)
506 (- org-e-ascii-text-width
507 (let ((low-level-rank (org-export-low-level-p element info)))
508 (if low-level-rank (* low-level-rank 2) org-e-ascii-global-margin))))
509 ;; Elements with a relative width: store maximum text width in
510 ;; TOTAL-WIDTH.
512 (let* ((genealogy (cons element (plist-get info :genealogy)))
513 ;; Total width is determined by the presence, or not, of an
514 ;; inline task among ELEMENT parents.
515 (total-width
516 (if (loop for parent in genealogy
517 thereis (eq (car parent) 'inlinetask))
518 org-e-ascii-inlinetask-width
519 ;; No inlinetask: Remove global margin from text width.
520 (- org-e-ascii-text-width
521 org-e-ascii-global-margin
522 (let ((parent (org-export-get-parent-headline element info)))
523 ;; Inner margin doesn't apply to text before first
524 ;; headline.
525 (if (not parent) 0
526 (let ((low-level-rank
527 (org-export-low-level-p parent info)))
528 ;; Inner margin doesn't apply to contents of
529 ;; low level headlines, since they've got their
530 ;; own indentation mechanism.
531 (if low-level-rank (* low-level-rank 2)
532 org-e-ascii-inner-margin))))))))
533 (- total-width
534 ;; Each `quote-block', `quote-section' and `verse-block' above
535 ;; narrows text width by twice the standard margin size.
536 (+ (* (loop for parent in genealogy
537 when (memq (car parent)
538 '(quote-block quote-section verse-block))
539 count parent)
540 2 org-e-ascii-quote-margin)
541 ;; Text width within a plain-list is restricted by
542 ;; indentation of current item. If that's the case,
543 ;; compute it with the help of `:structure' property from
544 ;; parent item, if any.
545 (let ((parent-item
546 (if (eq (car element) 'item) element
547 (loop for parent in genealogy
548 when (eq (car parent) 'item)
549 return parent))))
550 (if (not parent-item) 0
551 ;; Compute indentation offset of the current item,
552 ;; that is the sum of the difference between its
553 ;; indentation and the indentation of the top item in
554 ;; the list and current item bullet's length. Also
555 ;; remove tag length (for description lists) or bullet
556 ;; length.
557 (let ((struct (org-element-get-property :structure parent-item))
558 (beg-item (org-element-get-property :begin parent-item)))
559 (+ (- (org-list-get-ind beg-item struct)
560 (org-list-get-ind
561 (org-list-get-top-point struct) struct))
562 (length
563 (or (org-list-get-tag beg-item struct)
564 (org-list-get-bullet beg-item struct)))))))))))))
566 (defun org-e-ascii--build-title
567 (element info text-width &optional underline notags)
568 "Format ELEMENT title and return it.
570 ELEMENT is either an `headline' or `inlinetask' element. INFO is
571 a plist used as a communication channel. TEXT-WIDTH is an
572 integer representing the maximum length of a line.
574 When optional argument UNDERLINE is non-nil, underline title,
575 without the tags, according to `org-e-ascii-underline'
576 specifications.
578 if optional argument NOTAGS is nil, no tags will be added to the
579 title."
580 (let* ((headlinep (eq (car element) 'headline))
581 (numbers
582 ;; Numbering is specific to headlines.
583 (and headlinep
584 ;; Section numbering must be active, and headline's
585 ;; level should be above specified limit, if any.
586 (let ((sec-num (plist-get info :section-numbers)))
587 (if (not (wholenump sec-num)) sec-num
588 (<= (org-export-get-relative-level headline info) sec-num)))
589 ;; All tests passed: build numbering string.
590 (concat
591 (mapconcat
592 #'number-to-string
593 (org-export-get-headline-number element info) ".")
594 " ")))
595 (text (org-export-secondary-string
596 (org-element-get-property :title element) 'e-ascii info))
597 (todo
598 (and (plist-get info :with-todo-keywords)
599 (let ((todo (org-element-get-property :todo-keyword element)))
600 (and todo
601 (concat (org-export-secondary-string todo 'e-ascii info)
602 " ")))))
603 (tags (and (not notags)
604 (plist-get info :with-tags)
605 (org-element-get-property :tags element)))
606 (priority
607 (and (plist-get info :with-priority)
608 (concat (org-element-get-property :priority element) " ")))
609 (first-part (concat numbers todo priority text)))
610 (concat
611 first-part
612 ;; Align tags, if any.
613 (when tags
614 (format
615 (format " %%%ds"
616 (max (- text-width (1+ (length first-part))) (length tags)))
617 tags))
618 ;; Maybe underline text, if ELEMENT type is `headline' and an
619 ;; underline character has been defined.
620 (when (and underline headlinep)
621 (let ((under-char
622 (nth (1- (org-export-get-relative-level element info))
623 (cdr (assq (plist-get info :ascii-charset)
624 org-e-ascii-underline)))))
625 (and under-char
626 (concat "\n"
627 (make-string (length first-part) under-char))))))))
629 (defun org-e-ascii--build-caption (element info)
630 "Return caption string for ELEMENT, if applicable.
632 INFO is a plist used as a communication channel.
634 The caption string contains the sequence number of ELEMENT if it
635 has a name affiliated keyword, along with the real caption, if
636 any. Return nil when ELEMENT has no affiliated caption or name
637 keyword."
638 (let ((caption (org-element-get-property :caption element))
639 (name (org-element-get-property :name element)))
640 (when (or caption name)
641 ;; Get sequence number of current src-block among every
642 ;; src-block with either a caption or a name.
643 (let ((reference
644 (org-export-get-ordinal
645 element info nil nil
646 (lambda (el) (or (org-element-get-property :caption el)
647 (org-element-get-property :name el)))))
648 (title-fmt (org-e-ascii--translate
649 (case (car element)
650 (table "Table %d: %s")
651 (src-block "Listing %d: %s")) info)))
652 (org-e-ascii--fill-string
653 (format
654 title-fmt reference
655 (if (not caption) name
656 (org-export-secondary-string (car caption) 'e-ascii info)))
657 (org-e-ascii--current-text-width element info) info)))))
659 (defun org-e-ascii--build-toc (info &optional n keyword)
660 "Return a table of contents.
662 INFO is a plist used as a communication channel.
664 Optional argument N, when non-nil, is an integer specifying the
665 depth of the table.
667 Optional argument KEYWORD specifies the TOC keyword, if any, from
668 which the table of contents generation has been initiated."
669 (let ((title (org-e-ascii--translate "Table Of Contents\n" info)))
670 (concat
671 title
672 (make-string (1- (length title))
673 (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))
674 "\n\n"
675 (let ((text-width
676 (if keyword (org-e-ascii--current-text-width keyword info)
677 (- org-e-ascii-text-width org-e-ascii-global-margin))))
678 (mapconcat
679 (lambda (headline)
680 (let* ((level (org-export-get-relative-level headline info))
681 (indent (* (1- level) 3)))
682 (concat
683 (unless (zerop indent) (concat (make-string (1- indent) ?.) " "))
684 (org-e-ascii--build-title
685 headline info (- text-width indent) nil
686 (eq (plist-get info :with-tags) 'not-in-toc)))))
687 (org-export-collect-headlines info n) "\n")))))
689 (defun org-e-ascii--list-listings (keyword info)
690 "Return a list of listings.
692 KEYWORD is the keyword that initiated the list of listings
693 generation. INFO is a plist used as a communication channel."
694 (let ((title (org-e-ascii--translate "List Of Listings\n" info)))
695 (concat
696 title
697 (make-string (1- (length title))
698 (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))
699 "\n\n"
700 (let ((text-width
701 (if keyword (org-e-ascii--current-text-width keyword info)
702 (- org-e-ascii-text-width org-e-ascii-global-margin)))
703 ;; Use a counter instead of retreiving ordinal of each
704 ;; src-block.
705 (count 0))
706 (mapconcat
707 (lambda (src-block)
708 ;; Store initial text so its length can be computed. This is
709 ;; used to properly align caption right to it in case of
710 ;; filling (like contents of a description list item).
711 (let ((initial-text
712 (format (org-e-ascii--translate "Listing %d: " info)
713 (incf count))))
714 (concat
715 initial-text
716 (org-trim
717 (org-e-ascii--indent-string
718 (org-e-ascii--fill-string
719 (let ((caption (org-element-get-property :caption src-block)))
720 (if (not caption) (org-element-get-property :name src-block)
721 (org-export-secondary-string
722 ;; Use short name in priority, if available.
723 (or (cdr caption) (car caption)) 'e-ascii info)))
724 (- text-width (length initial-text)) info)
725 (length initial-text))))))
726 (org-export-collect-listings info) "\n")))))
728 (defun org-e-ascii--list-tables (keyword info)
729 "Return a list of listings.
731 KEYWORD is the keyword that initiated the list of listings
732 generation. INFO is a plist used as a communication channel."
733 (let ((title (org-e-ascii--translate "List Of Tables\n" info)))
734 (concat
735 title
736 (make-string (1- (length title))
737 (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))
738 "\n\n"
739 (let ((text-width
740 (if keyword (org-e-ascii--current-text-width keyword info)
741 (- org-e-ascii-text-width org-e-ascii-global-margin)))
742 ;; Use a counter instead of retreiving ordinal of each
743 ;; src-block.
744 (count 0))
745 (mapconcat
746 (lambda (table)
747 ;; Store initial text so its length can be computed. This is
748 ;; used to properly align caption right to it in case of
749 ;; filling (like contents of a description list item).
750 (let ((initial-text
751 (format (org-e-ascii--translate "Table %d: " info)
752 (incf count))))
753 (concat
754 initial-text
755 (org-trim
756 (org-e-ascii--indent-string
757 (org-e-ascii--fill-string
758 (let ((caption (org-element-get-property :caption table)))
759 (if (not caption) (org-element-get-property :name table)
760 ;; Use short name in priority, if available.
761 (org-export-secondary-string
762 (or (cdr caption) (car caption)) 'e-ascii info)))
763 (- text-width (length initial-text)) info)
764 (length initial-text))))))
765 (org-export-collect-tables info) "\n")))))
767 (defun org-e-ascii--unique-links (element info)
768 "Return a list of unique link references in ELEMENT.
770 ELEMENT is either an headline element or a section element. INFO
771 is a plist used as a communication channel.
773 It covers links that may be found current headline's title, in
774 the following section and in any inlinetask's title there."
775 (let* (seen
776 (unique-link-p
777 (function
778 ;; Return LINK if it wasn't referenced so far, or nil.
779 ;; Update SEEN links along the way.
780 (lambda (link)
781 (let ((footprint
782 (cons (org-element-get-property :raw-link link)
783 (org-element-get-contents link))))
784 (unless (member footprint seen)
785 (push footprint seen) link)))))
786 (harvest-links-in-title
787 (function
788 ;; Return a list of all unique links in ELEMENT. ELEMENT
789 ;; may be an headline or an inlinetask element.
790 (lambda (element)
791 (let (acc)
792 (dolist (obj (org-element-get-property :title element) acc)
793 (when (and (listp obj) (eq (car obj) 'link))
794 (let ((link (funcall unique-link-p obj)))
795 (and link (push link acc)))))))))
796 ;; Retrieve headline's section, if it exists.
797 (section (if (eq (car element) 'section) element
798 (let ((sec (car (org-element-get-contents element))))
799 (and (eq (car sec) 'section) sec))))
800 (headline (if (eq (car element) 'headline) element
801 (org-export-get-parent-headline element info))))
802 (append
803 ;; Links that may be in HEADLINE's title.
804 (funcall harvest-links-in-title headline)
805 ;; Get all links in SECTION.
806 (org-element-map
807 section 'link (lambda (link local) (funcall unique-link-p link)) info)
808 ;; Links that may be in inlinetasks titles within SECTION.
809 (let (acc)
810 (org-element-map
811 section 'inlinetask
812 (lambda (inlinetask local)
813 (push (funcall harvest-links-in-title inlinetask) acc))
814 info)
815 (delq nil acc)))))
817 (defun org-e-ascii--describe-links (links width info)
818 "Return a string describing a list of links.
820 LINKS is a list of link type objects, as returned by
821 `org-e-ascii--unique-links'. WIDTH is the text width allowed for
822 the output string. INFO is a plist used as a communication
823 channel."
824 (mapconcat
825 (lambda (link)
826 (let ((type (org-element-get-property :type link))
827 (anchor (let ((desc (org-element-get-contents link)))
828 (if (not desc)
829 (org-element-get-property :raw-link link)
830 (org-export-secondary-string desc 'e-ascii info)))))
831 (cond
832 ;; Coderefs and radio links are ignored.
833 ((member type '("coderef" "radio")) nil)
834 ;; Id, custom-id and fuzzy links (with the exception of
835 ;; targets): Headlines refer to their numbering.
836 ((member type '("custom-id" "fuzzy" "id"))
837 (let ((destination (if (string= type "fuzzy")
838 (org-export-resolve-fuzzy-link link info)
839 (org-export-resolve-id-link link info))))
840 (unless (eq (car destination) 'target)
841 (concat
842 (org-e-ascii--fill-string
843 (format
844 "[%s] %s"
845 anchor
846 (if (not destination)
847 (org-e-ascii--translate "Unknown reference" info)
848 (format
849 (org-e-ascii--translate "See section %s" info)
850 (mapconcat 'number-to-string
851 (org-export-get-headline-number destination info)
852 "."))))
853 width info) "\n\n"))))
854 ;; Do not add a link that cannot be resolved and doesn't have
855 ;; any description: destination is already visible in the
856 ;; paragraph.
857 ((not (org-element-get-contents link)) nil)
859 (concat
860 (org-e-ascii--fill-string
861 (format "[%s] %s" anchor (org-element-get-property :raw-link link))
862 width info)
863 "\n\n")))))
864 links ""))
868 ;;; Template
870 (defun org-e-ascii-template--document-title (info)
871 "Return document title, as a string.
872 INFO is a plist used as a communication channel."
873 (let ((text-width org-e-ascii-text-width)
874 (title (org-export-secondary-string
875 (plist-get info :title) 'e-ascii info))
876 (author
877 (and (plist-get info :with-author)
878 (let ((auth (plist-get info :author)))
879 (and auth (org-export-secondary-string auth 'e-ascii info)))))
880 (email
881 (and (plist-get info :with-email)
882 (org-export-secondary-string
883 (plist-get info :email) 'e-ascii info)))
884 (date (plist-get info :date)))
885 ;; There are two types of title blocks depending on the presence
886 ;; of a title to display.
887 (if (string= title "")
888 ;; Title block without a title. DATE is positioned at the top
889 ;; right of the document, AUTHOR to the top left and EMAIL
890 ;; just below.
891 (cond
892 ((and (org-string-nw-p date) (org-string-nw-p author))
893 (concat
894 author
895 (make-string (- text-width (length date) (length author)) ? )
896 date
897 (when (org-string-nw-p email) (concat "\n" email))
898 "\n\n\n"))
899 ((and (org-string-nw-p date) (org-string-nw-p email))
900 (concat
901 email
902 (make-string (- text-width (length date) (length email)) ? )
903 date "\n\n\n"))
904 ((org-string-nw-p date)
905 (concat
906 (org-e-ascii--justify-string date text-width 'right)
907 "\n\n\n"))
908 ((and (org-string-nw-p author) (org-string-nw-p email))
909 (concat author "\n" email "\n\n\n"))
910 ((org-string-nw-p author) (concat author "\n\n\n"))
911 ((org-string-nw-p email) (concat email "\n\n\n")))
912 ;; Title block with a title. Document's TITLE, along with the
913 ;; AUTHOR and its EMAIL are both overlined and an underlined,
914 ;; centered. Date is just below, also centered.
915 (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8))
916 ;; Format TITLE. It may be filled if it is too wide,
917 ;; that is wider than the two thirds of the total width.
918 (title-len (min (length title) (/ (* 2 text-width) 3)))
919 (formatted-title (org-e-ascii--fill-string title title-len info))
920 (line
921 (make-string
922 (min (+ (max title-len (length author) (length email)) 2)
923 text-width) (if utf8p ?━ ?_))))
924 (org-e-ascii--justify-string
925 (concat line "\n"
926 (unless utf8p "\n")
927 (upcase formatted-title)
928 (if utf8p "\n\n\n" "\n\n")
929 (cond
930 ((and (org-string-nw-p author) (org-string-nw-p email))
931 (concat author "\n" email))
932 ((org-string-nw-p author) author)
933 ((org-string-nw-p email) email))
934 "\n" line
935 (when (org-string-nw-p date) (concat "\n\n\n" date))
936 "\n\n\n") text-width 'center)))))
938 (defun org-e-ascii-template (contents info)
939 "Return complete document string after ASCII conversion.
940 CONTENTS is the transcoded contents string. INFO is a plist
941 holding export options."
942 (org-element-normalize-string
943 (org-e-ascii--indent-string
944 (let ((text-width (- org-e-ascii-text-width org-e-ascii-global-margin)))
945 ;; 1. Build title block.
946 (concat
947 (org-e-ascii-template--document-title info)
948 ;; 2. Table of contents.
949 (let ((depth (plist-get info :with-toc)))
950 (when depth
951 (concat
952 (org-e-ascii--build-toc info (and (wholenump depth) depth))
953 "\n\n\n")))
954 ;; 3. Document's body.
955 contents
956 ;; 4. Footnote definitions.
957 (let ((definitions (org-export-collect-footnote-definitions
958 (plist-get info :parse-tree) info))
959 ;; Insert full links right inside the footnote definition
960 ;; as they have no chance to be inserted later.
961 (org-e-ascii-links-to-notes nil))
962 (when definitions
963 (concat
964 "\n\n\n"
965 (let ((title (org-e-ascii--translate "Footnotes\n" info)))
966 (concat
967 title
968 (make-string
969 (1- (length title))
970 (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))))
971 "\n\n"
972 (mapconcat
973 (lambda (ref)
974 (let ((id (format "[%s] " (car ref))))
975 ;; Distinguish between inline definitions and
976 ;; full-fledged definitions.
977 (org-trim
978 (let ((def (nth 2 ref)))
979 (if (eq (car def) 'org-data)
980 ;; Full-fledged definition: footnote ID is
981 ;; inserted inside the first parsed paragraph
982 ;; (FIRST), if any, to be sure filling will
983 ;; take it into consideration.
984 (let ((first (car (org-element-get-contents def))))
985 (if (not (eq (car first) 'paragraph))
986 (concat id "\n" (org-export-data def 'e-ascii info))
987 (push id (nthcdr 2 first))
988 (org-export-data def 'e-ascii info)))
989 ;; Fill paragraph once footnote ID is inserted in
990 ;; order to have a correct length for first line.
991 (org-e-ascii--fill-string
992 (concat id (org-export-secondary-string def 'e-ascii info))
993 text-width info))))))
994 definitions "\n\n"))))
995 ;; 5. Creator. Ignore `comment' value as there are no comments in
996 ;; ASCII. Justify it to the bottom right.
997 (let ((creator-info (plist-get info :with-creator)))
998 (unless (or (not creator-info) (eq creator-info 'comment))
999 (concat
1000 "\n\n\n"
1001 (org-e-ascii--fill-string
1002 (plist-get info :creator) text-width info 'right))))))
1003 org-e-ascii-global-margin)))
1005 (defun org-e-ascii--translate (s info)
1006 "Translate string S.
1008 INFO is a plist used as a communication channel.
1010 Translation depends on `:language' property and allowed charset.
1011 If no translation in found for a given language and a given
1012 charset, fall-back to S."
1013 (let* ((charset (intern (format ":%s" (plist-get info :ascii-charset))))
1014 (lang (plist-get info :language))
1015 (translations (cdr (assoc s org-e-ascii-dictionary))))
1016 (or (plist-get (cdr (assoc lang translations)) charset) s)))
1020 ;;; Transcode Functions
1022 ;;;; Babel Call
1024 ;; Babel Calls are ignored.
1027 ;;;; Center Block
1029 (defun org-e-ascii-center-block (center-block contents info)
1030 "Transcode a CENTER-BLOCK element from Org to ASCII.
1031 CONTENTS holds the contents of the block. INFO is a plist
1032 holding contextual information."
1033 (org-e-ascii--justify-string
1034 contents (org-e-ascii--current-text-width center-block info) 'center))
1037 ;;;; Comment
1039 ;; Comments are ignored.
1042 ;;;; Comment Block
1044 ;; Comment Blocks are ignored.
1047 ;;;; Drawer
1049 (defun org-e-ascii-drawer (drawer contents info)
1050 "Transcode a DRAWER element from Org to ASCII.
1051 CONTENTS holds the contents of the block. INFO is a plist
1052 holding contextual information."
1053 (let ((name (org-element-get-property :drawer-name drawer))
1054 (width (org-e-ascii--current-text-width drawer info)))
1055 (if (functionp org-e-ascii-format-drawer-function)
1056 (funcall org-e-ascii-format-drawer-function name contents width)
1057 ;; If there's no user defined function: simply
1058 ;; display contents of the drawer.
1059 contents)))
1062 ;;;; Dynamic Block
1064 (defun org-e-ascii-dynamic-block (dynamic-block contents info)
1065 "Transcode a DYNAMIC-BLOCK element from Org to ASCII.
1066 CONTENTS holds the contents of the block. INFO is a plist
1067 holding contextual information. See
1068 `org-export-data'."
1069 contents)
1072 ;;;; Emphasis
1074 (defun org-e-ascii-emphasis (emphasis contents info)
1075 "Transcode EMPHASIS from Org to ASCII.
1076 CONTENTS is the contents of the emphasized text. INFO is a plist
1077 holding contextual information.."
1078 (let ((marker (org-element-get-property :marker emphasis)))
1079 ;; Leave emphasis markers as-is.
1080 (concat marker contents marker)))
1083 ;;;; Entity
1085 (defun org-e-ascii-entity (entity contents info)
1086 "Transcode an ENTITY object from Org to ASCII.
1087 CONTENTS are the definition itself. INFO is a plist holding
1088 contextual information."
1089 (org-element-get-property
1090 (intern (concat ":" (symbol-name (plist-get info :ascii-charset))))
1091 entity))
1094 ;;;; Example Block
1096 (defun org-e-ascii-example-block (example-block contents info)
1097 "Transcode a EXAMPLE-BLOCK element from Org to ASCII.
1098 CONTENTS is nil. INFO is a plist holding contextual information."
1099 (org-e-ascii--box-string (org-export-handle-code example-block info) info))
1102 ;;;; Export Snippet
1104 (defun org-e-ascii-export-snippet (export-snippet contents info)
1105 "Transcode a EXPORT-SNIPPET object from Org to ASCII.
1106 CONTENTS is nil. INFO is a plist holding contextual information."
1107 (org-element-get-property :value export-snippet))
1110 ;;;; Export Block
1112 (defun org-e-ascii-export-block (export-block contents info)
1113 "Transcode a EXPORT-BLOCK element from Org to ASCII.
1114 CONTENTS is nil. INFO is a plist holding contextual information."
1115 (when (string= (org-element-get-property :type export-block) "ascii")
1116 (org-remove-indentation (org-element-get-property :value export-block))))
1119 ;;;; Fixed Width
1121 (defun org-e-ascii-fixed-width (fixed-width contents info)
1122 "Transcode a FIXED-WIDTH element from Org to ASCII.
1123 CONTENTS is nil. INFO is a plist holding contextual information."
1124 (org-e-ascii--box-string
1125 (replace-regexp-in-string
1126 "^[ \t]*: ?" "" (org-element-get-property :value fixed-width)) info))
1129 ;;;; Footnote Definition
1131 ;; Footnote Definitions are ignored. They are compiled at the end of
1132 ;; the document, by `org-e-ascii-template'.
1135 ;;;; Footnote Reference
1137 (defun org-e-ascii-footnote-reference (footnote-reference contents info)
1138 "Transcode a FOOTNOTE-REFERENCE element from Org to ASCII.
1139 CONTENTS is nil. INFO is a plist holding contextual information."
1140 (format "[%s]" (org-export-get-footnote-number footnote-reference info)))
1143 ;;;; Headline
1145 (defun org-e-ascii-headline (headline contents info)
1146 "Transcode an HEADLINE element from Org to ASCII.
1147 CONTENTS holds the contents of the headline. INFO is a plist
1148 holding contextual information."
1149 ;; Don't export footnote section, which will be handled at the end
1150 ;; of the template.
1151 (unless (org-element-get-property :footnote-section-p headline)
1152 (let* ((low-level-rank (org-export-low-level-p headline info))
1153 (width (org-e-ascii--current-text-width headline info))
1154 ;; Blank lines between headline and its contents.
1155 ;; `org-e-ascii-headline-spacing', when set, overwrites
1156 ;; original buffer's spacing.
1157 (pre-blanks
1158 (make-string
1159 (if org-e-ascii-headline-spacing (car org-e-ascii-headline-spacing)
1160 (org-element-get-property :pre-blank headline)) ?\n))
1161 ;; Even if HEADLINE has no section, there might be some
1162 ;; links in its title that we shouldn't forget to describe.
1163 (links
1164 (unless (eq (caar (org-element-get-contents headline)) 'section)
1165 (org-e-ascii--describe-links
1166 (org-e-ascii--unique-links headline info) width info))))
1167 ;; Deep subtree: export it as a list item.
1168 (if low-level-rank
1169 (concat
1170 ;; Bullet.
1171 (let ((bullets (cdr (assq (plist-get info :ascii-charset)
1172 org-e-ascii-bullets))))
1173 (char-to-string
1174 (nth (mod (1- low-level-rank) (length bullets)) bullets)))
1176 ;; Title.
1177 (org-e-ascii--build-title headline info width) "\n"
1178 ;; Contents, indented by length of bullet.
1179 pre-blanks
1180 (org-e-ascii--indent-string
1181 (concat contents
1182 (when (org-string-nw-p links) (concat "\n\n" links)))
1184 ;; Else: Standard headline.
1185 (concat
1186 (org-e-ascii--build-title headline info width 'underline)
1187 "\n" pre-blanks
1188 (concat (when (org-string-nw-p links) links) contents))))))
1191 ;;;; Horizontal Rule
1193 (defun org-e-ascii-horizontal-rule (horizontal-rule contents info)
1194 "Transcode an HORIZONTAL-RULE object from Org to ASCII.
1195 CONTENTS is nil. INFO is a plist holding contextual
1196 information."
1197 (let ((attr
1198 (read
1199 (format
1200 "(%s)"
1201 (mapconcat
1202 #'identity
1203 (org-element-get-property :attr_ascii horizontal-rule)
1204 " ")))))
1205 (make-string (or (and (wholenump (plist-get attr :width))
1206 (plist-get attr :width))
1207 (org-e-ascii--current-text-width horizontal-rule info))
1208 (if (eq (plist-get info :ascii-charset) 'utf-8) ?― ?-))))
1211 ;;;; Inline Babel Call
1213 ;; Inline Babel Calls are ignored.
1216 ;;;; Inline Src Block
1218 (defun org-e-ascii-inline-src-block (inline-src-block contents info)
1219 "Transcode an INLINE-SRC-BLOCK element from Org to ASCII.
1220 CONTENTS holds the contents of the item. INFO is a plist holding
1221 contextual information."
1222 (format org-e-ascii-verbatim-format
1223 (org-element-get-property :value inline-src-block)))
1226 ;;;; Inlinetask
1228 (defun org-e-ascii-inlinetask (inlinetask contents info)
1229 "Transcode an INLINETASK element from Org to ASCII.
1230 CONTENTS holds the contents of the block. INFO is a plist
1231 holding contextual information."
1232 (let ((width (org-e-ascii--current-text-width inlinetask info))
1233 (title (org-export-secondary-string
1234 (org-element-get-property :title inlinetask) 'e-ascii info))
1235 (todo (and (plist-get info :with-todo-keywords)
1236 (let ((todo (org-element-get-property
1237 :todo-keyword inlinetask)))
1238 (and todo
1239 (org-export-secondary-string todo 'e-ascii info)))))
1240 (todo-type (org-element-get-property :todo-type inlinetask))
1241 (tags (and (plist-get info :with-tags)
1242 (org-element-get-property :tags inlinetask)))
1243 (priority (and (plist-get info :with-priority)
1244 (org-element-get-property :priority inlinetask))))
1245 ;; If `org-e-ascii-format-inlinetask-function' is provided, call it
1246 ;; with appropriate arguments.
1247 (if (functionp org-e-ascii-format-inlinetask-function)
1248 (funcall org-e-ascii-format-inlinetask-function
1249 todo todo-type priority title tags contents width)
1250 ;; Otherwise, use a default template.
1251 (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
1252 (org-e-ascii--indent-string
1253 (concat
1254 ;; Top line, with an additional blank line if not in UTF-8.
1255 (make-string width (if utf8p ?━ ?_)) "\n"
1256 (unless utf8p (concat (make-string width ? ) "\n"))
1257 ;; Add title. Fill it if wider than inlinetask.
1258 (let ((title (org-e-ascii--build-title inlinetask info width)))
1259 (if (<= (length title) width) title
1260 (org-e-ascii--fill-string title width info)))
1261 "\n"
1262 ;; If CONTENTS is not empty, insert it along with
1263 ;; a separator.
1264 (when (org-string-nw-p contents)
1265 (concat (make-string width (if utf8p ?─ ?-)) "\n" contents))
1266 ;; Bottom line.
1267 (make-string width (if utf8p ?━ ?_)))
1268 ;; Flush the inlinetask to the right.
1269 (- org-e-ascii-text-width org-e-ascii-global-margin
1270 (if (not (org-export-get-parent-headline inlinetask info)) 0
1271 org-e-ascii-inner-margin)
1272 (org-e-ascii--current-text-width inlinetask info)))))))
1275 ;;;; Item
1277 (defun org-e-ascii-item (item contents info)
1278 "Transcode an ITEM element from Org to ASCII.
1279 CONTENTS holds the contents of the item. INFO is a plist holding
1280 contextual information."
1281 (let ((bullet
1282 ;; First parent of ITEM is always the plain-list. Get
1283 ;; `:type' property from it.
1284 (let ((type (org-element-get-property
1285 :type (car (plist-get info :genealogy)))))
1286 (if (eq type 'descriptive)
1287 (concat
1288 (org-export-secondary-string
1289 (org-element-get-property :tag item) 'e-ascii info) ": ")
1290 (org-element-get-property :bullet item)))))
1291 (concat
1292 ;; Change bullets into more visible form if UTF-8 is active.
1293 (if (not (eq (plist-get info :ascii-charset) 'utf-8)) bullet
1294 (replace-regexp-in-string
1295 "-" "•"
1296 (replace-regexp-in-string
1297 "+" "⁃"
1298 (replace-regexp-in-string
1299 "*" "‣" bullet))))
1300 ;; Contents: Pay attention to indentation. Note: check-boxes are
1301 ;; already taken care of at the paragraph level so they don't
1302 ;; interfere with indentation.
1303 (let ((contents (org-e-ascii--indent-string contents (length bullet))))
1304 (if (eq (caar (org-element-get-contents item)) 'paragraph)
1305 (org-trim contents)
1306 (concat "\n" contents))))))
1309 ;;;; Keyword
1311 (defun org-e-ascii-keyword (keyword contents info)
1312 "Transcode a KEYWORD element from Org to ASCII.
1313 CONTENTS is nil. INFO is a plist holding contextual
1314 information."
1315 (let ((key (downcase (org-element-get-property :key keyword)))
1316 (value (org-element-get-property :value keyword)))
1317 (cond
1318 ((string= key "ascii") value)
1319 ((string= key "toc")
1320 (let ((value (downcase value)))
1321 (cond
1322 ((string-match "\\<headlines\\>" value)
1323 (let ((depth (or (and (string-match "[0-9]+" value)
1324 (string-to-number (match-string 0 value)))
1325 (plist-get info :with-toc))))
1326 (org-e-ascii--build-toc
1327 info (and (wholenump depth) depth) keyword)))
1328 ((string= "tables" value)
1329 (org-e-ascii--list-tables keyword info))
1330 ((string= "listings" value)
1331 (org-e-ascii--list-listings keyword info)))))
1332 ((string= key "include")
1333 (org-export-included-file keyword 'e-ascii info)))))
1336 ;;;; Latex Environment
1338 (defun org-e-ascii-latex-environment (latex-environment contents info)
1339 "Transcode a LATEX-ENVIRONMENT element from Org to ASCII.
1340 CONTENTS is nil. INFO is a plist holding contextual
1341 information."
1342 (org-remove-indentation (org-element-get-property :value latex-environment)))
1345 ;;;; Latex Fragment
1347 (defun org-e-ascii-latex-fragment (latex-fragment contents info)
1348 "Transcode a LATEX-FRAGMENT object from Org to ASCII.
1349 CONTENTS is nil. INFO is a plist holding contextual
1350 information."
1351 (org-element-get-property :value latex-fragment))
1354 ;;;; Line Break
1356 (defun org-e-ascii-line-break (line-break contents info)
1357 "Transcode a LINE-BREAK object from Org to ASCII.
1358 CONTENTS is nil. INFO is a plist holding contextual
1359 information." hard-newline)
1362 ;;;; Link
1364 (defun org-e-ascii-link (link desc info)
1365 "Transcode a LINK object from Org to ASCII.
1367 DESC is the description part of the link, or the empty string.
1368 INFO is a plist holding contextual information."
1369 (let ((raw-link (org-element-get-property :raw-link link))
1370 (type (org-element-get-property :type link)))
1371 (cond
1372 ((string= type "coderef")
1373 (let ((ref (org-element-get-property :path link)))
1374 (format (org-export-get-coderef-format ref desc)
1375 (org-export-resolve-coderef ref info))))
1376 ;; Do not apply a special syntax on radio links.
1377 ((string= type "radio") desc)
1378 ;; Do not apply a special syntax on fuzzy links pointing to
1379 ;; targets.
1380 ((and (string= type "fuzzy")
1381 (let ((path (org-element-get-property :path link)))
1382 (loop for target in (plist-get info :target-list)
1383 thereis (string=
1384 (org-element-get-property :raw-value target)
1385 path))))
1386 (if (org-string-nw-p desc) desc raw-link))
1388 (concat (format "[%s]" (if (org-string-nw-p desc) desc raw-link))
1389 (unless org-e-ascii-links-to-notes (format " (%s)" raw-link)))))))
1392 ;;;; Macro
1394 (defun org-e-ascii-macro (macro contents info)
1395 "Transcode a MACRO element from Org to ASCII.
1396 CONTENTS is nil. INFO is a plist holding contextual
1397 information."
1398 (org-export-expand-macro macro info))
1401 ;;;; Paragraph
1403 (defun org-e-ascii-paragraph (paragraph contents info)
1404 "Transcode a PARAGRAPH element from Org to ASCII.
1405 CONTENTS is the contents of the paragraph, as a string. INFO is
1406 the plist used as a communication channel."
1407 (org-e-ascii--fill-string
1408 (let ((parent (car (plist-get info :genealogy))))
1409 ;; If PARAGRAPH is the first one in a list element, be sure to
1410 ;; add the check-box in front of it, before any filling. Later,
1411 ;; it would interfere with line width.
1412 (if (and (eq (car parent) 'item)
1413 (equal (car (org-element-get-contents parent)) paragraph))
1414 (let ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
1415 (concat (case (org-element-get-property :checkbox parent)
1416 (on (if utf8p "☑ " "[X] "))
1417 (off (if utf8p "☐ " "[ ] "))
1418 (trans (if utf8p "☒ " "[-] ")))
1419 contents))
1420 contents))
1421 (org-e-ascii--current-text-width paragraph info) info))
1424 ;;;; Plain List
1426 (defun org-e-ascii-plain-list (plain-list contents info)
1427 "Transcode a PLAIN-LIST element from Org to ASCII.
1428 CONTENTS is the contents of the list. INFO is a plist holding
1429 contextual information."
1430 contents)
1433 ;;;; Plain Text
1435 (defun org-e-ascii-plain-text (text info)
1436 "Transcode a TEXT string from Org to ASCII.
1437 INFO is a plist used as a communication channel."
1438 (if (not (and (eq (plist-get info :ascii-charset) 'utf-8)
1439 (plist-get info :with-special-strings)))
1440 text
1441 ;; Usual replacements in utf-8 with proper option set.
1442 (replace-regexp-in-string
1443 "\\.\\.\\." "…"
1444 (replace-regexp-in-string
1445 "--" "–"
1446 (replace-regexp-in-string "---" "—" text)))))
1449 ;;;; Property Drawer
1451 (defun org-e-ascii-property-drawer (property-drawer contents info)
1452 "Transcode a PROPERTY-DRAWER element from Org to ASCII.
1453 CONTENTS is nil. INFO is a plist used as a communication
1454 channel."
1455 ;; The property drawer isn't exported but we want separating blank
1456 ;; lines nonetheless.
1460 ;;;; Quote Block
1462 (defun org-e-ascii-quote-block (quote-block contents info)
1463 "Transcode a QUOTE-BLOCK element from Org to ASCII.
1464 CONTENTS holds the contents of the block. INFO is a plist
1465 holding contextual information."
1466 (let ((width (org-e-ascii--current-text-width quote-block info)))
1467 (org-e-ascii--indent-string
1468 (org-remove-indentation
1469 (org-e-ascii--fill-string contents width info))
1470 org-e-ascii-quote-margin)))
1473 ;;;; Quote Section
1475 (defun org-e-ascii-quote-section (quote-section contents info)
1476 "Transcode a QUOTE-SECTION element from Org to ASCII.
1477 CONTENTS is nil. INFO is a plist holding contextual information."
1478 (let ((width (org-e-ascii--current-text-width quote-section info))
1479 (value
1480 (org-export-secondary-string
1481 (org-remove-indentation
1482 (org-element-get-property :value quote-section)) 'e-ascii info)))
1483 (org-e-ascii--indent-string
1484 value
1485 (+ org-e-ascii-quote-margin
1486 ;; Don't apply inner margin if parent headline is low level.
1487 (let ((headline (org-export-get-parent-headline quote-section info)))
1488 (if (org-export-low-level-p headline info) 0
1489 org-e-ascii-inner-margin))))))
1492 ;;;; Radio Target
1494 (defun org-e-ascii-radio-target (radio-target contents info)
1495 "Transcode a RADIO-TARGET object from Org to ASCII.
1496 CONTENTS is the contents of the target. INFO is a plist holding
1497 contextual information."
1498 contents)
1500 ;;;; Section
1502 (defun org-e-ascii-section (section contents info)
1503 "Transcode a SECTION element from Org to ASCII.
1504 CONTENTS is the contents of the section. INFO is a plist holding
1505 contextual information."
1506 (org-e-ascii--indent-string
1507 (concat
1508 contents
1509 (when org-e-ascii-links-to-notes
1510 ;; Add list of links at the end of SECTION.
1511 (let ((links (org-e-ascii--describe-links
1512 (org-e-ascii--unique-links section info)
1513 (org-e-ascii--current-text-width section info) info)))
1514 ;; Separate list of links and section contents.
1515 (when (org-string-nw-p links) (concat "\n\n" links)))))
1516 ;; Do not apply inner margin if parent headline is low level.
1517 (let ((headline (org-export-get-parent-headline section info)))
1518 (if (or (not headline) (org-export-low-level-p headline info)) 0
1519 org-e-ascii-inner-margin))))
1522 ;;;; Special Block
1524 (defun org-e-ascii-special-block (special-block contents info)
1525 "Transcode a SPECIAL-BLOCK element from Org to ASCII.
1526 CONTENTS holds the contents of the block. INFO is a plist
1527 holding contextual information."
1528 contents)
1531 ;;;; Src Block
1533 (defun org-e-ascii-src-block (src-block contents info)
1534 "Transcode a SRC-BLOCK element from Org to ASCII.
1535 CONTENTS holds the contents of the item. INFO is a plist holding
1536 contextual information."
1537 (let ((caption (org-e-ascii--build-caption src-block info)))
1538 (concat
1539 (when (and caption org-e-ascii-caption-above) (concat caption "\n"))
1540 (org-e-ascii--box-string (org-export-handle-code src-block info) info)
1541 (when (and caption (not org-e-ascii-caption-above))
1542 (concat "\n" caption)))))
1544 ;;;; Statistics Cookie
1546 (defun org-e-ascii-statistics-cookie (statistics-cookie contents info)
1547 "Transcode a STATISTICS-COOKIE object from Org to ASCII.
1548 CONTENTS is nil. INFO is a plist holding contextual information."
1549 (org-element-get-property :value statistics-cookie))
1552 ;;;; Subscript
1554 (defun org-e-ascii-subscript (subscript contents info)
1555 "Transcode a SUBSCRIPT object from Org to ASCII.
1556 CONTENTS is the contents of the object. INFO is a plist holding
1557 contextual information."
1558 (if (org-element-get-property :use-brackets-p subscript)
1559 (format "_{%s}" contents)
1560 (format "_%s" contents)))
1563 ;;;; Superscript
1565 (defun org-e-ascii-superscript (superscript contents info)
1566 "Transcode a SUPERSCRIPT object from Org to ASCII.
1567 CONTENTS is the contents of the object. INFO is a plist holding
1568 contextual information."
1569 (if (org-element-get-property :use-brackets-p superscript)
1570 (format "_{%s}" contents)
1571 (format "_%s" contents)))
1574 ;;;; Table
1576 ;; While `org-e-ascii-table' is the callback function expected by
1577 ;; org-export mechanism, it requires four subroutines to display
1578 ;; tables accordingly to chosen charset, alignment and width
1579 ;; specifications.
1581 ;; Thus, `org-e-ascii-table--column-width' computes the display width
1582 ;; for each column in the table,
1583 ;; `org-e-ascii-table--vertical-separators' returns a vector
1584 ;; containing separators (or lack thereof),
1585 ;; `org-e-ascii-table--build-hline' creates various hline strings,
1586 ;; depending on charset, separators and position within the tabl and
1587 ;; `org-e-ascii-table--format-cell' properly aligns contents within
1588 ;; a given cell and width.
1590 (defun org-e-ascii-table (table contents info)
1591 "Transcode a TABLE element from Org to ASCII.
1592 CONTENTS is nil. INFO is a plist holding contextual information."
1593 (let ((raw-table (org-element-get-property :raw-table table))
1594 (caption (org-e-ascii--build-caption table info)))
1595 (concat
1596 ;; Possibly add a caption string above.
1597 (when (and caption org-e-ascii-caption-above) (concat caption "\n"))
1598 ;; Insert table. Note: "table.el" tables are left unmodified.
1599 (if (eq (org-element-get-property :type table) 'table.el) raw-table
1600 (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8))
1601 ;; Extract information out of the raw table (TABLE-INFO)
1602 ;; and clean it (CLEAN-TABLE).
1603 (table-info (org-export-table-format-info raw-table))
1604 (special-col-p (plist-get table-info :special-column-p))
1605 (alignment (plist-get table-info :alignment))
1606 (clean-table (org-export-clean-table raw-table special-col-p))
1607 ;; Change table into lisp, much like `org-table-to-lisp',
1608 ;; being more careful about keeping the exact length of
1609 ;; cells, for alignment purpose.
1610 (lisp-table
1611 (mapcar
1612 (lambda (line)
1613 (if (string-match org-table-hline-regexp line) 'hline
1614 (org-split-string (org-trim line) "\\s-?|\\s-?")))
1615 (org-split-string clean-table "[ \t]*\n[ \t]*")))
1616 ;; Compute real column widths.
1617 (column-widths
1618 (org-e-ascii-table--column-width lisp-table table-info))
1619 ;; Construct separators according to column groups.
1620 (separators (org-e-ascii-table--vertical-separators table-info))
1621 ;; Build different `hline' strings, depending on
1622 ;; separators, column widths and position.
1623 (hline-standard
1624 (org-e-ascii-table--build-hline
1625 nil separators column-widths info))
1626 (hline-top
1627 (and utf8p (org-e-ascii-table--build-hline
1628 'top separators column-widths info)))
1629 (hline-bottom
1630 (and utf8p (org-e-ascii-table--build-hline
1631 'bottom separators column-widths info))))
1632 ;; Now build table back, with correct alignment, considering
1633 ;; columns widths and separators.
1634 (mapconcat
1635 (lambda (line)
1636 (cond
1637 ((eq line 'hline) hline-standard)
1638 ((eq line 'hline-bottom) hline-bottom)
1639 ((eq line 'hline-top) hline-top)
1640 (t (loop for cell in line
1641 for col from 0 to (length line)
1642 concat
1643 (concat
1644 (let ((sep (aref separators col)))
1645 (if (and utf8p (not (string= sep ""))) "│" sep))
1646 (org-e-ascii-table--format-cell
1647 cell col column-widths alignment info)) into l
1648 finally return
1649 (concat l
1650 (let ((sep (aref separators col)))
1651 (if (and utf8p (not (string= sep ""))) "│"
1652 sep)))))))
1653 ;; If charset is `utf-8', make sure lisp-table always starts
1654 ;; with `hline-top' and ends with `hline-bottom'.
1655 (if (not utf8p) lisp-table
1656 (setq lisp-table
1657 (cons 'hline-top
1658 (if (eq (car lisp-table) 'hline) (cdr lisp-table)
1659 lisp-table)))
1660 (setq lisp-table
1661 (nconc
1662 (if (eq (car (last lisp-table)) 'hline) (butlast lisp-table)
1663 lisp-table)
1664 '(hline-bottom)))) "\n")))
1665 ;; Possible add a caption string below.
1666 (when (and caption (not org-e-ascii-caption-above))
1667 (concat "\n" caption)))))
1669 (defun org-e-ascii-table--column-width (table table-info)
1670 "Return vector of TABLE columns width.
1672 TABLE is the Lisp representation of the Org table considered.
1673 TABLE-INFO holds information about the table. See
1674 `org-export-table-format-info'.
1676 Unlike to `:width' property from `org-export-table-format-info',
1677 the return value contains width of every column, not only those
1678 with a width cookie."
1679 (let* ((cookies (plist-get table-info :width))
1680 (width (make-vector (length cookies) 0)))
1681 (mapc
1682 (lambda (line)
1683 (let ((idx 0))
1684 (unless (eq line 'hline)
1685 (mapc (lambda (cell)
1686 (let ((len (length cell)))
1687 (when (> len (aref width idx)) (aset width idx len)))
1688 (incf idx))
1689 line))))
1690 table)
1691 (unless org-e-ascii-table-widen-columns
1692 ;; When colums are not widened, width cookies have precedence
1693 ;; over string lengths. Thus, overwrite the latter with the
1694 ;; former.
1695 (loop for w across cookies
1696 for idx from 0 to (length cookies)
1697 when w do (aset width idx w)))
1698 ;; Return value.
1699 width))
1701 (defun org-e-ascii-table--vertical-separators (table-info)
1702 "Return a vector of strings for vertical separators.
1704 TABLE-INFO holds information about considered table. See
1705 `org-export-table-format-info'.
1707 Return value is a vector whose length is one more than the number
1708 of columns in the table. Special column, if any, is ignored."
1709 (let* ((colgroups (plist-get table-info :column-groups))
1710 (separators (make-vector (1+ (length colgroups)) "")))
1711 (if org-e-ascii-table-keep-all-vertical-lines
1712 (make-vector (length separators) "|")
1713 (let ((column 0))
1714 (mapc (lambda (group)
1715 (when (memq group '(start start-end))
1716 (aset separators column "|"))
1717 (when (memq group '(end start-end))
1718 (aset separators (1+ column) "|"))
1719 (incf column))
1720 colgroups)
1721 ;; Remove unneeded special column.
1722 (if (not (plist-get table-info :special-column-p)) separators
1723 (substring separators 1))))))
1725 (defun org-e-ascii-table--format-cell (cell col width alignment info)
1726 "Format CELL with column width and alignment constraints.
1728 CELL is the contents of the cell, as a string.
1730 COL is the column containing the cell considered.
1732 WIDTH is a vector holding every column width, as returned by
1733 `org-e-ascii-table--column-width'.
1735 ALIGNMENT is a vector containing alignment strings for every
1736 column.
1738 INFO is a plist used as a communication channel."
1739 (let ((col-width (if org-e-ascii-table-widen-columns (aref width col)
1740 (or (aref width col) (length cell)))))
1741 ;; When CELL is too large, it has to be truncated.
1742 (unless (or org-e-ascii-table-widen-columns (<= (length cell) col-width))
1743 (setq cell (concat (substring cell 0 (- col-width 2)) "=>")))
1744 (let* ((indent-tabs-mode nil)
1745 (align (aref alignment col))
1746 (aligned-cell
1747 (org-e-ascii--justify-string
1748 (org-trim cell) col-width
1749 (cond ((string= align "c") 'center)
1750 ((string= align "r") 'right)))))
1751 ;; Return aligned cell, with missing white spaces added and
1752 ;; space separators between columns.
1753 (format
1754 " %s "
1755 (concat aligned-cell
1756 (make-string (- col-width (length aligned-cell)) ? ))))))
1758 (defun org-e-ascii-table--build-hline (position separators column-widths info)
1759 "Return string used as an horizontal line in tables.
1761 POSITION is a symbol among `top', `bottom' and nil, which
1762 specifies position of the horizontal line within the table.
1764 SEPARATORS is a vector strings specifying separators used in the
1765 table, as returned by `org-e-ascii-table--vertical-separators'.
1767 COLUMN-WIDTHS is a vector of numbers specifying widths of all
1768 columns in the table, as returned by
1769 `org-e-ascii-table--column-width'.
1771 INFO is a plist used as a communication channel."
1772 (let ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
1773 (loop for idx from 0 to (length separators)
1774 for width across column-widths
1775 concat
1776 (concat
1777 (cond ((string= (aref separators idx) "") nil)
1778 ((and utf8p (zerop idx))
1779 (cond ((eq position 'top) "┍")
1780 ((eq position 'bottom) "┕")
1781 (t "├")))
1782 (utf8p
1783 (cond ((eq position 'top) "┯")
1784 ((eq position 'bottom) "┷")
1785 (t "┼")))
1786 (t "+"))
1787 ;; Hline has to cover all the cell and
1788 ;; both white spaces between columns.
1789 (make-string (+ width 2)
1790 (cond ((not utf8p) ?-)
1791 ((not position) ?─)
1792 (t ?━))))
1793 into hline
1794 finally return
1795 (concat
1796 hline
1797 (cond
1798 ((string= (aref separators idx) "") nil)
1799 (utf8p (cond ((eq position 'top) "┑")
1800 ((eq position 'bottom) "┙")
1801 (t "┤")))
1802 (t "+"))))))
1805 ;;;; Target
1807 (defun org-e-ascii-target (target contents info)
1808 "Transcode a TARGET object from Org to ASCII.
1809 CONTENTS is the contents of the target. INFO is a plist holding
1810 contextual information."
1811 contents)
1814 ;;;; Time-stamp
1816 (defun org-e-ascii-time-stamp (time-stamp contents info)
1817 "Transcode a TIME-STAMP object from Org to ASCII.
1818 CONTENTS is nil. INFO is a plist holding contextual information."
1819 ;; Return time-stamps as-is.
1820 (org-element-time-stamp-interpreter time-stamp contents))
1823 ;;;; Verbatim
1825 (defun org-e-ascii-verbatim (verbatim contents info)
1826 "Return a VERBATIM object from Org to ASCII.
1827 CONTENTS is nil. INFO is a plist holding contextual information."
1828 (format org-e-ascii-verbatim-format
1829 (org-element-get-property :value verbatim)))
1832 ;;;; Verse Block
1834 (defun org-e-ascii-verse-block (verse-block contents info)
1835 "Transcode a VERSE-BLOCK element from Org to ASCII.
1836 CONTENTS is nil. INFO is a plist holding contextual information."
1837 (let ((verse-width (org-e-ascii--current-text-width verse-block info)))
1838 (org-e-ascii--indent-string
1839 (org-e-ascii--justify-string
1840 (org-export-secondary-string
1841 (org-element-get-property :value verse-block) 'e-ascii info)
1842 verse-width 'left)
1843 org-e-ascii-quote-margin)))
1846 ;;; Filter
1848 (defun org-e-ascii-filter-headline-blank-lines (headline back-end)
1849 "Filter controlling number of blank lines after an headline.
1851 HEADLINE is a string representing a transcoded headline.
1852 BACK-END is symbol specifying back-end used for export.
1854 This function only applies to `e-ascii' back-end. See
1855 `org-e-ascii-headline-spacing' for information.
1857 For any other back-end, HEADLINE is returned as-is."
1858 (if (not (and (eq back-end 'e-ascii) org-e-ascii-headline-spacing)) headline
1859 (let ((blanks (make-string (1+ (cdr org-e-ascii-headline-spacing)) ?\n)))
1860 (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" blanks headline))))
1864 ;;; Interactive function
1866 (defun org-e-ascii-export-to-ascii
1867 (&optional subtreep visible-only body-only ext-plist pub-dir)
1868 "Export current buffer to a text file.
1870 If narrowing is active in the current buffer, only export its
1871 narrowed part.
1873 If a region is active, export that region.
1875 When optional argument SUBTREEP is non-nil, export the sub-tree
1876 at point, extracting information from the headline properties
1877 first.
1879 When optional argument VISIBLE-ONLY is non-nil, don't export
1880 contents of hidden elements.
1882 When optional argument BODY-ONLY is non-nil, strip title, table
1883 of contents and footnote definitions from output.
1885 EXT-PLIST, when provided, is a property list with external
1886 parameters overriding Org default settings, but still inferior to
1887 file-local settings.
1889 When optional argument PUB-DIR is set, use it as the publishing
1890 directory.
1892 Return output file's name."
1893 (interactive)
1894 (let ((outfile (org-export-output-file-name ".txt" subtreep pub-dir)))
1895 (org-export-to-file
1896 'e-ascii outfile subtreep visible-only body-only ext-plist)))
1899 (provide 'org-e-ascii)
1900 ;;; org-e-ascii.el ends here