ox.el (org-export-define-backend, org-export-define-derived-backend): Use defuns
[org-mode.git] / lisp / ox-ascii.el
blob37e1b039afd2363cca343f95071fdb7a4b5d88c9
1 ;;; ox-ascii.el --- ASCII Back-End for Org Export Engine
3 ;; Copyright (C) 2012, 2013 Free Software Foundation, Inc.
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; GNU Emacs 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 ;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
21 ;;; Commentary:
23 ;; This library implements an ASCII back-end for Org generic exporter.
25 ;; It provides two commands for export, depending on the desired
26 ;; output: `org-ascii-export-as-ascii' (temporary buffer) and
27 ;; `org-ascii-export-to-ascii' ("txt" file). Also, three publishing
28 ;; functions are available: `org-ascii-publish-to-ascii',
29 ;; `org-ascii-publish-to-latin1' and `org-ascii-publish-to-utf8'.
31 ;; Output encoding is specified through `org-ascii-charset' variable,
32 ;; among `ascii', `latin1' and `utf-8' symbols.
34 ;; By default, horizontal rules span over the full text with, but with
35 ;; a given width attribute (set though #+ATTR_ASCII: :width <num>)
36 ;; they can be shortened and centered.
38 ;;; Code:
40 (eval-when-compile (require 'cl))
41 (require 'ox)
42 (require 'ox-publish)
44 (declare-function aa2u "ext:ascii-art-to-unicode" ())
46 ;;; Define Back-End
48 ;; The following setting won't allow to modify preferred charset
49 ;; through a buffer keyword or an option item, but, since the property
50 ;; will appear in communication channel nonetheless, it allows to
51 ;; override `org-ascii-charset' variable on the fly by the ext-plist
52 ;; mechanism.
54 ;; We also install a filter for headlines and sections, in order to
55 ;; control blank lines separating them in output string.
57 (org-export-define-backend 'ascii
58 '((bold . org-ascii-bold)
59 (center-block . org-ascii-center-block)
60 (clock . org-ascii-clock)
61 (code . org-ascii-code)
62 (comment . (lambda (&rest args) ""))
63 (comment-block . (lambda (&rest args) ""))
64 (drawer . org-ascii-drawer)
65 (dynamic-block . org-ascii-dynamic-block)
66 (entity . org-ascii-entity)
67 (example-block . org-ascii-example-block)
68 (export-block . org-ascii-export-block)
69 (export-snippet . org-ascii-export-snippet)
70 (fixed-width . org-ascii-fixed-width)
71 (footnote-definition . org-ascii-footnote-definition)
72 (footnote-reference . org-ascii-footnote-reference)
73 (headline . org-ascii-headline)
74 (horizontal-rule . org-ascii-horizontal-rule)
75 (inline-src-block . org-ascii-inline-src-block)
76 (inlinetask . org-ascii-inlinetask)
77 (inner-template . org-ascii-inner-template)
78 (italic . org-ascii-italic)
79 (item . org-ascii-item)
80 (keyword . org-ascii-keyword)
81 (latex-environment . org-ascii-latex-environment)
82 (latex-fragment . org-ascii-latex-fragment)
83 (line-break . org-ascii-line-break)
84 (link . org-ascii-link)
85 (paragraph . org-ascii-paragraph)
86 (plain-list . org-ascii-plain-list)
87 (plain-text . org-ascii-plain-text)
88 (planning . org-ascii-planning)
89 (quote-block . org-ascii-quote-block)
90 (quote-section . org-ascii-quote-section)
91 (radio-target . org-ascii-radio-target)
92 (section . org-ascii-section)
93 (special-block . org-ascii-special-block)
94 (src-block . org-ascii-src-block)
95 (statistics-cookie . org-ascii-statistics-cookie)
96 (strike-through . org-ascii-strike-through)
97 (subscript . org-ascii-subscript)
98 (superscript . org-ascii-superscript)
99 (table . org-ascii-table)
100 (table-cell . org-ascii-table-cell)
101 (table-row . org-ascii-table-row)
102 (target . org-ascii-target)
103 (template . org-ascii-template)
104 (timestamp . org-ascii-timestamp)
105 (underline . org-ascii-underline)
106 (verbatim . org-ascii-verbatim)
107 (verse-block . org-ascii-verse-block))
108 :export-block "ASCII"
109 :menu-entry
110 '(?t "Export to Plain Text"
111 ((?A "As ASCII buffer"
112 (lambda (a s v b)
113 (org-ascii-export-as-ascii a s v b '(:ascii-charset ascii))))
114 (?a "As ASCII file"
115 (lambda (a s v b)
116 (org-ascii-export-to-ascii a s v b '(:ascii-charset ascii))))
117 (?L "As Latin1 buffer"
118 (lambda (a s v b)
119 (org-ascii-export-as-ascii a s v b '(:ascii-charset latin1))))
120 (?l "As Latin1 file"
121 (lambda (a s v b)
122 (org-ascii-export-to-ascii a s v b '(:ascii-charset latin1))))
123 (?U "As UTF-8 buffer"
124 (lambda (a s v b)
125 (org-ascii-export-as-ascii a s v b '(:ascii-charset utf-8))))
126 (?u "As UTF-8 file"
127 (lambda (a s v b)
128 (org-ascii-export-to-ascii a s v b '(:ascii-charset utf-8))))))
129 :filters-alist '((:filter-headline . org-ascii-filter-headline-blank-lines)
130 (:filter-parse-tree org-ascii-filter-paragraph-spacing
131 org-ascii-filter-comment-spacing)
132 (:filter-section . org-ascii-filter-headline-blank-lines))
133 :options-alist '((:ascii-charset nil nil org-ascii-charset)))
137 ;;; User Configurable Variables
139 (defgroup org-export-ascii nil
140 "Options for exporting Org mode files to ASCII."
141 :tag "Org Export ASCII"
142 :group 'org-export)
144 (defcustom org-ascii-text-width 72
145 "Maximum width of exported text.
146 This number includes margin size, as set in
147 `org-ascii-global-margin'."
148 :group 'org-export-ascii
149 :version "24.4"
150 :package-version '(Org . "8.0")
151 :type 'integer)
153 (defcustom org-ascii-global-margin 0
154 "Width of the left margin, in number of characters."
155 :group 'org-export-ascii
156 :version "24.4"
157 :package-version '(Org . "8.0")
158 :type 'integer)
160 (defcustom org-ascii-inner-margin 2
161 "Width of the inner margin, in number of characters.
162 Inner margin is applied between each headline."
163 :group 'org-export-ascii
164 :version "24.4"
165 :package-version '(Org . "8.0")
166 :type 'integer)
168 (defcustom org-ascii-quote-margin 6
169 "Width of margin used for quoting text, in characters.
170 This margin is applied on both sides of the text."
171 :group 'org-export-ascii
172 :version "24.4"
173 :package-version '(Org . "8.0")
174 :type 'integer)
176 (defcustom org-ascii-inlinetask-width 30
177 "Width of inline tasks, in number of characters.
178 This number ignores any margin."
179 :group 'org-export-ascii
180 :version "24.4"
181 :package-version '(Org . "8.0")
182 :type 'integer)
184 (defcustom org-ascii-headline-spacing '(1 . 2)
185 "Number of blank lines inserted around headlines.
187 This variable can be set to a cons cell. In that case, its car
188 represents the number of blank lines present before headline
189 contents whereas its cdr reflects the number of blank lines after
190 contents.
192 A nil value replicates the number of blank lines found in the
193 original Org buffer at the same place."
194 :group 'org-export-ascii
195 :version "24.4"
196 :package-version '(Org . "8.0")
197 :type '(choice
198 (const :tag "Replicate original spacing" nil)
199 (cons :tag "Set an uniform spacing"
200 (integer :tag "Number of blank lines before contents")
201 (integer :tag "Number of blank lines after contents"))))
203 (defcustom org-ascii-indented-line-width 'auto
204 "Additional indentation width for the first line in a paragraph.
205 If the value is an integer, indent the first line of each
206 paragraph by this number. If it is the symbol `auto' preserve
207 indentation from original document."
208 :group 'org-export-ascii
209 :version "24.4"
210 :package-version '(Org . "8.0")
211 :type '(choice
212 (integer :tag "Number of white spaces characters")
213 (const :tag "Preserve original width" auto)))
215 (defcustom org-ascii-paragraph-spacing 'auto
216 "Number of white lines between paragraphs.
217 If the value is an integer, add this number of blank lines
218 between contiguous paragraphs. If is it the symbol `auto', keep
219 the same number of blank lines as in the original document."
220 :group 'org-export-ascii
221 :version "24.4"
222 :package-version '(Org . "8.0")
223 :type '(choice
224 (integer :tag "Number of blank lines")
225 (const :tag "Preserve original spacing" auto)))
227 (defcustom org-ascii-charset 'ascii
228 "The charset allowed to represent various elements and objects.
229 Possible values are:
230 `ascii' Only use plain ASCII characters
231 `latin1' Include Latin-1 characters
232 `utf-8' Use all UTF-8 characters"
233 :group 'org-export-ascii
234 :version "24.4"
235 :package-version '(Org . "8.0")
236 :type '(choice
237 (const :tag "ASCII" ascii)
238 (const :tag "Latin-1" latin1)
239 (const :tag "UTF-8" utf-8)))
241 (defcustom org-ascii-underline '((ascii ?= ?~ ?-)
242 (latin1 ?= ?~ ?-)
243 (utf-8 ?═ ?─ ?╌ ?┄ ?┈))
244 "Characters for underlining headings in ASCII export.
246 Alist whose key is a symbol among `ascii', `latin1' and `utf-8'
247 and whose value is a list of characters.
249 For each supported charset, this variable associates a sequence
250 of underline characters. In a sequence, the characters will be
251 used in order for headlines level 1, 2, ... If no character is
252 available for a given level, the headline won't be underlined."
253 :group 'org-export-ascii
254 :version "24.4"
255 :package-version '(Org . "8.0")
256 :type '(list
257 (cons :tag "Underline characters sequence"
258 (const :tag "ASCII charset" ascii)
259 (repeat character))
260 (cons :tag "Underline characters sequence"
261 (const :tag "Latin-1 charset" latin1)
262 (repeat character))
263 (cons :tag "Underline characters sequence"
264 (const :tag "UTF-8 charset" utf-8)
265 (repeat character))))
267 (defcustom org-ascii-bullets '((ascii ?* ?+ ?-)
268 (latin1 ?§ ?¶)
269 (utf-8 ?◊))
270 "Bullet characters for headlines converted to lists in ASCII export.
272 Alist whose key is a symbol among `ascii', `latin1' and `utf-8'
273 and whose value is a list of characters.
275 The first character is used for the first level considered as low
276 level, and so on. If there are more levels than characters given
277 here, the list will be repeated.
279 Note that this variable doesn't affect plain lists
280 representation."
281 :group 'org-export-ascii
282 :version "24.4"
283 :package-version '(Org . "8.0")
284 :type '(list
285 (cons :tag "Bullet characters for low level headlines"
286 (const :tag "ASCII charset" ascii)
287 (repeat character))
288 (cons :tag "Bullet characters for low level headlines"
289 (const :tag "Latin-1 charset" latin1)
290 (repeat character))
291 (cons :tag "Bullet characters for low level headlines"
292 (const :tag "UTF-8 charset" utf-8)
293 (repeat character))))
295 (defcustom org-ascii-links-to-notes t
296 "Non-nil means convert links to notes before the next headline.
297 When nil, the link will be exported in place. If the line
298 becomes long in this way, it will be wrapped."
299 :group 'org-export-ascii
300 :version "24.4"
301 :package-version '(Org . "8.0")
302 :type 'boolean)
304 (defcustom org-ascii-table-keep-all-vertical-lines nil
305 "Non-nil means keep all vertical lines in ASCII tables.
306 When nil, vertical lines will be removed except for those needed
307 for column grouping."
308 :group 'org-export-ascii
309 :version "24.4"
310 :package-version '(Org . "8.0")
311 :type 'boolean)
313 (defcustom org-ascii-table-widen-columns t
314 "Non-nil means widen narrowed columns for export.
315 When nil, narrowed columns will look in ASCII export just like in
316 Org mode, i.e. with \"=>\" as ellipsis."
317 :group 'org-export-ascii
318 :version "24.4"
319 :package-version '(Org . "8.0")
320 :type 'boolean)
322 (defcustom org-ascii-table-use-ascii-art nil
323 "Non-nil means table.el tables are turned into ascii-art.
325 It only makes sense when export charset is `utf-8'. It is nil by
326 default since it requires ascii-art-to-unicode.el package. You
327 can download it here:
329 http://gnuvola.org/software/j/aa2u/ascii-art-to-unicode.el."
330 :group 'org-export-ascii
331 :version "24.4"
332 :package-version '(Org . "8.0")
333 :type 'boolean)
335 (defcustom org-ascii-caption-above nil
336 "When non-nil, place caption string before the element.
337 Otherwise, place it right after it."
338 :group 'org-export-ascii
339 :version "24.4"
340 :package-version '(Org . "8.0")
341 :type 'boolean)
343 (defcustom org-ascii-verbatim-format "`%s'"
344 "Format string used for verbatim text and inline code."
345 :group 'org-export-ascii
346 :version "24.4"
347 :package-version '(Org . "8.0")
348 :type 'string)
350 (defcustom org-ascii-format-drawer-function nil
351 "Function called to format a drawer in ASCII.
353 The function must accept three parameters:
354 NAME the drawer name, like \"LOGBOOK\"
355 CONTENTS the contents of the drawer.
356 WIDTH the text width within the drawer.
358 The function should return either the string to be exported or
359 nil to ignore the drawer.
361 For example, the variable could be set to the following function
362 in order to mimic default behaviour:
364 \(defun org-ascii-format-drawer-default (name contents width)
365 \"Format a drawer element for ASCII export.\"
366 contents)"
367 :group 'org-export-ascii
368 :version "24.4"
369 :package-version '(Org . "8.0")
370 :type 'function)
372 (defcustom org-ascii-format-inlinetask-function nil
373 "Function called to format an inlinetask in ASCII.
375 The function must accept six parameters:
376 TODO the todo keyword, as a string
377 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
378 PRIORITY the inlinetask priority, as a string
379 NAME the inlinetask name, as a string.
380 TAGS the inlinetask tags, as a list of strings.
381 CONTENTS the contents of the inlinetask, as a string.
383 The function should return either the string to be exported or
384 nil to ignore the inline task.
386 For example, the variable could be set to the following function
387 in order to mimic default behaviour:
389 \(defun org-ascii-format-inlinetask-default
390 \(todo type priority name tags contents\)
391 \"Format an inline task element for ASCII export.\"
392 \(let* \(\(utf8p \(eq \(plist-get info :ascii-charset\) 'utf-8\)\)
393 \(width org-ascii-inlinetask-width\)
394 \(org-ascii--indent-string
395 \(concat
396 ;; Top line, with an additional blank line if not in UTF-8.
397 \(make-string width \(if utf8p ?━ ?_\)\) \"\\n\"
398 \(unless utf8p \(concat \(make-string width ? \) \"\\n\"\)\)
399 ;; Add title. Fill it if wider than inlinetask.
400 \(let \(\(title \(org-ascii--build-title inlinetask info width\)\)\)
401 \(if \(<= \(length title\) width\) title
402 \(org-ascii--fill-string title width info\)\)\)
403 \"\\n\"
404 ;; If CONTENTS is not empty, insert it along with
405 ;; a separator.
406 \(when \(org-string-nw-p contents\)
407 \(concat \(make-string width \(if utf8p ?─ ?-\)\) \"\\n\" contents\)\)
408 ;; Bottom line.
409 \(make-string width \(if utf8p ?━ ?_\)\)\)
410 ;; Flush the inlinetask to the right.
411 \(- \(plist-get info :ascii-width\)
412 \(plist-get info :ascii-margin\)
413 \(plist-get info :ascii-inner-margin\)
414 \(org-ascii--current-text-width inlinetask info\)\)"
415 :group 'org-export-ascii
416 :version "24.4"
417 :package-version '(Org . "8.0")
418 :type 'function)
422 ;;; Internal Functions
424 ;; Internal functions fall into three categories.
426 ;; The first one is about text formatting. The core function is
427 ;; `org-ascii--current-text-width', which determines the current
428 ;; text width allowed to a given element. In other words, it helps
429 ;; keeping each line width within maximum text width defined in
430 ;; `org-ascii-text-width'. Once this information is known,
431 ;; `org-ascii--fill-string', `org-ascii--justify-string',
432 ;; `org-ascii--box-string' and `org-ascii--indent-string' can
433 ;; operate on a given output string.
435 ;; The second category contains functions handling elements listings,
436 ;; triggered by "#+TOC:" keyword. As such, `org-ascii--build-toc'
437 ;; returns a complete table of contents, `org-ascii--list-listings'
438 ;; returns a list of referenceable src-block elements, and
439 ;; `org-ascii--list-tables' does the same for table elements.
441 ;; The third category includes general helper functions.
442 ;; `org-ascii--build-title' creates the title for a given headline
443 ;; or inlinetask element. `org-ascii--build-caption' returns the
444 ;; caption string associated to a table or a src-block.
445 ;; `org-ascii--describe-links' creates notes about links for
446 ;; insertion at the end of a section. It uses
447 ;; `org-ascii--unique-links' to get the list of links to describe.
448 ;; Eventually, `org-ascii--translate' translates a string according
449 ;; to language and charset specification.
452 (defun org-ascii--fill-string (s text-width info &optional justify)
453 "Fill a string with specified text-width and return it.
455 S is the string being filled. TEXT-WIDTH is an integer
456 specifying maximum length of a line. INFO is the plist used as
457 a communication channel.
459 Optional argument JUSTIFY can specify any type of justification
460 among `left', `center', `right' or `full'. A nil value is
461 equivalent to `left'. For a justification that doesn't also fill
462 string, see `org-ascii--justify-string'.
464 Return nil if S isn't a string."
465 ;; Don't fill paragraph when break should be preserved.
466 (cond ((not (stringp s)) nil)
467 ((plist-get info :preserve-breaks) s)
468 (t (let ((double-space-p sentence-end-double-space))
469 (with-temp-buffer
470 (let ((fill-column text-width)
471 (use-hard-newlines t)
472 (sentence-end-double-space double-space-p))
473 (insert s)
474 (fill-region (point-min) (point-max) justify))
475 (buffer-string))))))
477 (defun org-ascii--justify-string (s text-width how)
478 "Justify string S.
479 TEXT-WIDTH is an integer specifying maximum length of a line.
480 HOW determines the type of justification: it can be `left',
481 `right', `full' or `center'."
482 (with-temp-buffer
483 (insert s)
484 (goto-char (point-min))
485 (let ((fill-column text-width)
486 ;; Disable `adaptive-fill-mode' so it doesn't prevent
487 ;; filling lines matching `adaptive-fill-regexp'.
488 (adaptive-fill-mode nil))
489 (while (< (point) (point-max))
490 (justify-current-line how)
491 (forward-line)))
492 (buffer-string)))
494 (defun org-ascii--indent-string (s width)
495 "Indent string S by WIDTH white spaces.
496 Empty lines are not indented."
497 (when (stringp s)
498 (replace-regexp-in-string
499 "\\(^\\)\\(?:.*\\S-\\)" (make-string width ? ) s nil nil 1)))
501 (defun org-ascii--box-string (s info)
502 "Return string S with a partial box to its left.
503 INFO is a plist used as a communicaton channel."
504 (let ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
505 (format (if utf8p "╭────\n%s\n╰────" ",----\n%s\n`----")
506 (replace-regexp-in-string
507 "^" (if utf8p "│ " "| ")
508 ;; Remove last newline character.
509 (replace-regexp-in-string "\n[ \t]*\\'" "" s)))))
511 (defun org-ascii--current-text-width (element info)
512 "Return maximum text width for ELEMENT's contents.
513 INFO is a plist used as a communication channel."
514 (case (org-element-type element)
515 ;; Elements with an absolute width: `headline' and `inlinetask'.
516 (inlinetask org-ascii-inlinetask-width)
517 ('headline
518 (- org-ascii-text-width
519 (let ((low-level-rank (org-export-low-level-p element info)))
520 (if low-level-rank (* low-level-rank 2) org-ascii-global-margin))))
521 ;; Elements with a relative width: store maximum text width in
522 ;; TOTAL-WIDTH.
523 (otherwise
524 (let* ((genealogy (cons element (org-export-get-genealogy element)))
525 ;; Total width is determined by the presence, or not, of an
526 ;; inline task among ELEMENT parents.
527 (total-width
528 (if (loop for parent in genealogy
529 thereis (eq (org-element-type parent) 'inlinetask))
530 org-ascii-inlinetask-width
531 ;; No inlinetask: Remove global margin from text width.
532 (- org-ascii-text-width
533 org-ascii-global-margin
534 (let ((parent (org-export-get-parent-headline element)))
535 ;; Inner margin doesn't apply to text before first
536 ;; headline.
537 (if (not parent) 0
538 (let ((low-level-rank
539 (org-export-low-level-p parent info)))
540 ;; Inner margin doesn't apply to contents of
541 ;; low level headlines, since they've got their
542 ;; own indentation mechanism.
543 (if low-level-rank (* low-level-rank 2)
544 org-ascii-inner-margin))))))))
545 (- total-width
546 ;; Each `quote-block', `quote-section' and `verse-block' above
547 ;; narrows text width by twice the standard margin size.
548 (+ (* (loop for parent in genealogy
549 when (memq (org-element-type parent)
550 '(quote-block quote-section verse-block))
551 count parent)
552 2 org-ascii-quote-margin)
553 ;; Text width within a plain-list is restricted by
554 ;; indentation of current item. If that's the case,
555 ;; compute it with the help of `:structure' property from
556 ;; parent item, if any.
557 (let ((parent-item
558 (if (eq (org-element-type element) 'item) element
559 (loop for parent in genealogy
560 when (eq (org-element-type parent) 'item)
561 return parent))))
562 (if (not parent-item) 0
563 ;; Compute indentation offset of the current item,
564 ;; that is the sum of the difference between its
565 ;; indentation and the indentation of the top item in
566 ;; the list and current item bullet's length. Also
567 ;; remove checkbox length, and tag length (for
568 ;; description lists) or bullet length.
569 (let ((struct (org-element-property :structure parent-item))
570 (beg-item (org-element-property :begin parent-item)))
571 (+ (- (org-list-get-ind beg-item struct)
572 (org-list-get-ind
573 (org-list-get-top-point struct) struct))
574 (length (org-ascii--checkbox parent-item info))
575 (length
576 (or (org-list-get-tag beg-item struct)
577 (org-list-get-bullet beg-item struct)))))))))))))
579 (defun org-ascii--build-title
580 (element info text-width &optional underline notags toc)
581 "Format ELEMENT title and return it.
583 ELEMENT is either an `headline' or `inlinetask' element. INFO is
584 a plist used as a communication channel. TEXT-WIDTH is an
585 integer representing the maximum length of a line.
587 When optional argument UNDERLINE is non-nil, underline title,
588 without the tags, according to `org-ascii-underline'
589 specifications.
591 If optional argument NOTAGS is non-nil, no tags will be added to
592 the title.
594 When optional argument TOC is non-nil, use optional title if
595 possible. It doesn't apply to `inlinetask' elements."
596 (let* ((headlinep (eq (org-element-type element) 'headline))
597 (numbers
598 ;; Numbering is specific to headlines.
599 (and headlinep (org-export-numbered-headline-p element info)
600 ;; All tests passed: build numbering string.
601 (concat
602 (mapconcat
603 'number-to-string
604 (org-export-get-headline-number element info) ".")
605 " ")))
606 (text
607 (org-trim
608 (org-export-data
609 (if (and toc headlinep) (org-export-get-alt-title element info)
610 (org-element-property :title element))
611 info)))
612 (todo
613 (and (plist-get info :with-todo-keywords)
614 (let ((todo (org-element-property :todo-keyword element)))
615 (and todo (concat (org-export-data todo info) " ")))))
616 (tags (and (not notags)
617 (plist-get info :with-tags)
618 (let ((tag-list (org-export-get-tags element info)))
619 (and tag-list
620 (format ":%s:"
621 (mapconcat 'identity tag-list ":"))))))
622 (priority
623 (and (plist-get info :with-priority)
624 (let ((char (org-element-property :priority element)))
625 (and char (format "(#%c) " char)))))
626 (first-part (concat numbers todo priority text)))
627 (concat
628 first-part
629 ;; Align tags, if any.
630 (when tags
631 (format
632 (format " %%%ds"
633 (max (- text-width (1+ (length first-part))) (length tags)))
634 tags))
635 ;; Maybe underline text, if ELEMENT type is `headline' and an
636 ;; underline character has been defined.
637 (when (and underline headlinep)
638 (let ((under-char
639 (nth (1- (org-export-get-relative-level element info))
640 (cdr (assq (plist-get info :ascii-charset)
641 org-ascii-underline)))))
642 (and under-char
643 (concat "\n"
644 (make-string (length first-part) under-char))))))))
646 (defun org-ascii--has-caption-p (element info)
647 "Non-nil when ELEMENT has a caption affiliated keyword.
648 INFO is a plist used as a communication channel. This function
649 is meant to be used as a predicate for `org-export-get-ordinal'."
650 (org-element-property :caption element))
652 (defun org-ascii--build-caption (element info)
653 "Return caption string for ELEMENT, if applicable.
655 INFO is a plist used as a communication channel.
657 The caption string contains the sequence number of ELEMENT along
658 with its real caption. Return nil when ELEMENT has no affiliated
659 caption keyword."
660 (let ((caption (org-export-get-caption element)))
661 (when caption
662 ;; Get sequence number of current src-block among every
663 ;; src-block with a caption.
664 (let ((reference
665 (org-export-get-ordinal
666 element info nil 'org-ascii--has-caption-p))
667 (title-fmt (org-ascii--translate
668 (case (org-element-type element)
669 (table "Table %d: %s")
670 (src-block "Listing %d: %s"))
671 info)))
672 (org-ascii--fill-string
673 (format title-fmt reference (org-export-data caption info))
674 (org-ascii--current-text-width element info) info)))))
676 (defun org-ascii--build-toc (info &optional n keyword)
677 "Return a table of contents.
679 INFO is a plist used as a communication channel.
681 Optional argument N, when non-nil, is an integer specifying the
682 depth of the table.
684 Optional argument KEYWORD specifies the TOC keyword, if any, from
685 which the table of contents generation has been initiated."
686 (let ((title (org-ascii--translate "Table of Contents" info)))
687 (concat
688 title "\n"
689 (make-string (length title)
690 (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))
691 "\n\n"
692 (let ((text-width
693 (if keyword (org-ascii--current-text-width keyword info)
694 (- org-ascii-text-width org-ascii-global-margin))))
695 (mapconcat
696 (lambda (headline)
697 (let* ((level (org-export-get-relative-level headline info))
698 (indent (* (1- level) 3)))
699 (concat
700 (unless (zerop indent) (concat (make-string (1- indent) ?.) " "))
701 (org-ascii--build-title
702 headline info (- text-width indent) nil
703 (or (not (plist-get info :with-tags))
704 (eq (plist-get info :with-tags) 'not-in-toc))
705 'toc))))
706 (org-export-collect-headlines info n) "\n")))))
708 (defun org-ascii--list-listings (keyword info)
709 "Return a list of listings.
711 KEYWORD is the keyword that initiated the list of listings
712 generation. INFO is a plist used as a communication channel."
713 (let ((title (org-ascii--translate "List of Listings" info)))
714 (concat
715 title "\n"
716 (make-string (length title)
717 (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))
718 "\n\n"
719 (let ((text-width
720 (if keyword (org-ascii--current-text-width keyword info)
721 (- org-ascii-text-width org-ascii-global-margin)))
722 ;; Use a counter instead of retreiving ordinal of each
723 ;; src-block.
724 (count 0))
725 (mapconcat
726 (lambda (src-block)
727 ;; Store initial text so its length can be computed. This is
728 ;; used to properly align caption right to it in case of
729 ;; filling (like contents of a description list item).
730 (let ((initial-text
731 (format (org-ascii--translate "Listing %d:" info)
732 (incf count))))
733 (concat
734 initial-text " "
735 (org-trim
736 (org-ascii--indent-string
737 (org-ascii--fill-string
738 ;; Use short name in priority, if available.
739 (let ((caption (or (org-export-get-caption src-block t)
740 (org-export-get-caption src-block))))
741 (org-export-data caption info))
742 (- text-width (length initial-text)) info)
743 (length initial-text))))))
744 (org-export-collect-listings info) "\n")))))
746 (defun org-ascii--list-tables (keyword info)
747 "Return a list of tables.
749 KEYWORD is the keyword that initiated the list of tables
750 generation. INFO is a plist used as a communication channel."
751 (let ((title (org-ascii--translate "List of Tables" info)))
752 (concat
753 title "\n"
754 (make-string (length title)
755 (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))
756 "\n\n"
757 (let ((text-width
758 (if keyword (org-ascii--current-text-width keyword info)
759 (- org-ascii-text-width org-ascii-global-margin)))
760 ;; Use a counter instead of retreiving ordinal of each
761 ;; src-block.
762 (count 0))
763 (mapconcat
764 (lambda (table)
765 ;; Store initial text so its length can be computed. This is
766 ;; used to properly align caption right to it in case of
767 ;; filling (like contents of a description list item).
768 (let ((initial-text
769 (format (org-ascii--translate "Table %d:" info)
770 (incf count))))
771 (concat
772 initial-text " "
773 (org-trim
774 (org-ascii--indent-string
775 (org-ascii--fill-string
776 ;; Use short name in priority, if available.
777 (let ((caption (or (org-export-get-caption table t)
778 (org-export-get-caption table))))
779 (org-export-data caption info))
780 (- text-width (length initial-text)) info)
781 (length initial-text))))))
782 (org-export-collect-tables info) "\n")))))
784 (defun org-ascii--unique-links (element info)
785 "Return a list of unique link references in ELEMENT.
787 ELEMENT is either a headline element or a section element. INFO
788 is a plist used as a communication channel."
789 (let* (seen
790 (unique-link-p
791 (function
792 ;; Return LINK if it wasn't referenced so far, or nil.
793 ;; Update SEEN links along the way.
794 (lambda (link)
795 (let ((footprint
796 (cons (org-element-property :raw-link link)
797 (org-element-contents link))))
798 ;; Ignore LINK if it hasn't been translated already.
799 ;; It can happen if it is located in an affiliated
800 ;; keyword that was ignored.
801 (when (and (org-string-nw-p
802 (gethash link (plist-get info :exported-data)))
803 (not (member footprint seen)))
804 (push footprint seen) link)))))
805 ;; If at a section, find parent headline, if any, in order to
806 ;; count links that might be in the title.
807 (headline
808 (if (eq (org-element-type element) 'headline) element
809 (or (org-export-get-parent-headline element) element))))
810 ;; Get all links in HEADLINE.
811 (org-element-map headline 'link
812 (lambda (l) (funcall unique-link-p l)) info nil nil t)))
814 (defun org-ascii--describe-links (links width info)
815 "Return a string describing a list of links.
817 LINKS is a list of link type objects, as returned by
818 `org-ascii--unique-links'. WIDTH is the text width allowed for
819 the output string. INFO is a plist used as a communication
820 channel."
821 (mapconcat
822 (lambda (link)
823 (let ((type (org-element-property :type link))
824 (anchor (let ((desc (org-element-contents link)))
825 (if desc (org-export-data desc info)
826 (org-element-property :raw-link link)))))
827 (cond
828 ;; Coderefs, radio links and fuzzy links are ignored.
829 ((member type '("coderef" "radio" "fuzzy")) nil)
830 ;; Id and custom-id links: Headlines refer to their numbering.
831 ((member type '("custom-id" "id"))
832 (let ((dest (org-export-resolve-id-link link info)))
833 (concat
834 (org-ascii--fill-string
835 (format
836 "[%s] %s"
837 anchor
838 (if (not dest) (org-ascii--translate "Unknown reference" info)
839 (format
840 (org-ascii--translate "See section %s" info)
841 (mapconcat 'number-to-string
842 (org-export-get-headline-number dest info) "."))))
843 width info) "\n\n")))
844 ;; Do not add a link that cannot be resolved and doesn't have
845 ;; any description: destination is already visible in the
846 ;; paragraph.
847 ((not (org-element-contents link)) nil)
849 (concat
850 (org-ascii--fill-string
851 (format "[%s] %s" anchor (org-element-property :raw-link link))
852 width info)
853 "\n\n")))))
854 links ""))
856 (defun org-ascii--checkbox (item info)
857 "Return checkbox string for ITEM or nil.
858 INFO is a plist used as a communication channel."
859 (let ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
860 (case (org-element-property :checkbox item)
861 (on (if utf8p "☑ " "[X] "))
862 (off (if utf8p "☐ " "[ ] "))
863 (trans (if utf8p "☒ " "[-] ")))))
867 ;;; Template
869 (defun org-ascii-template--document-title (info)
870 "Return document title, as a string.
871 INFO is a plist used as a communication channel."
872 (let* ((text-width org-ascii-text-width)
873 ;; Links in the title will not be resolved later, so we make
874 ;; sure their path is located right after them.
875 (org-ascii-links-to-notes nil)
876 (title (org-export-data (plist-get info :title) info))
877 (author (and (plist-get info :with-author)
878 (let ((auth (plist-get info :author)))
879 (and auth (org-export-data auth info)))))
880 (email (and (plist-get info :with-email)
881 (org-export-data (plist-get info :email) info)))
882 (date (and (plist-get info :with-date)
883 (org-export-data (plist-get info :date) info))))
884 ;; There are two types of title blocks depending on the presence
885 ;; of a title to display.
886 (if (string= title "")
887 ;; Title block without a title. DATE is positioned at the top
888 ;; right of the document, AUTHOR to the top left and EMAIL
889 ;; just below.
890 (cond
891 ((and (org-string-nw-p date) (org-string-nw-p author))
892 (concat
893 author
894 (make-string (- text-width (length date) (length author)) ? )
895 date
896 (when (org-string-nw-p email) (concat "\n" email))
897 "\n\n\n"))
898 ((and (org-string-nw-p date) (org-string-nw-p email))
899 (concat
900 email
901 (make-string (- text-width (length date) (length email)) ? )
902 date "\n\n\n"))
903 ((org-string-nw-p date)
904 (concat
905 (org-ascii--justify-string date text-width 'right)
906 "\n\n\n"))
907 ((and (org-string-nw-p author) (org-string-nw-p email))
908 (concat author "\n" email "\n\n\n"))
909 ((org-string-nw-p author) (concat author "\n\n\n"))
910 ((org-string-nw-p email) (concat email "\n\n\n")))
911 ;; Title block with a title. Document's TITLE, along with the
912 ;; AUTHOR and its EMAIL are both overlined and an underlined,
913 ;; centered. Date is just below, also centered.
914 (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8))
915 ;; Format TITLE. It may be filled if it is too wide,
916 ;; that is wider than the two thirds of the total width.
917 (title-len (min (length title) (/ (* 2 text-width) 3)))
918 (formatted-title (org-ascii--fill-string title title-len info))
919 (line
920 (make-string
921 (min (+ (max title-len (length author) (length email)) 2)
922 text-width) (if utf8p ?━ ?_))))
923 (org-ascii--justify-string
924 (concat line "\n"
925 (unless utf8p "\n")
926 (upcase formatted-title)
927 (cond
928 ((and (org-string-nw-p author) (org-string-nw-p email))
929 (concat (if utf8p "\n\n\n" "\n\n") author "\n" email))
930 ((org-string-nw-p author)
931 (concat (if utf8p "\n\n\n" "\n\n") author))
932 ((org-string-nw-p email)
933 (concat (if utf8p "\n\n\n" "\n\n") 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-ascii-inner-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-ascii--indent-string
944 (concat
945 ;; 1. Document's body.
946 contents
947 ;; 2. Footnote definitions.
948 (let ((definitions (org-export-collect-footnote-definitions
949 (plist-get info :parse-tree) info))
950 ;; Insert full links right inside the footnote definition
951 ;; as they have no chance to be inserted later.
952 (org-ascii-links-to-notes nil))
953 (when definitions
954 (concat
955 "\n\n\n"
956 (let ((title (org-ascii--translate "Footnotes" info)))
957 (concat
958 title "\n"
959 (make-string
960 (length title)
961 (if (eq (plist-get info :ascii-charset) 'utf-8) ?─ ?_))))
962 "\n\n"
963 (let ((text-width (- org-ascii-text-width org-ascii-global-margin)))
964 (mapconcat
965 (lambda (ref)
966 (let ((id (format "[%s] " (car ref))))
967 ;; Distinguish between inline definitions and
968 ;; full-fledged definitions.
969 (org-trim
970 (let ((def (nth 2 ref)))
971 (if (eq (org-element-type def) 'org-data)
972 ;; Full-fledged definition: footnote ID is
973 ;; inserted inside the first parsed paragraph
974 ;; (FIRST), if any, to be sure filling will
975 ;; take it into consideration.
976 (let ((first (car (org-element-contents def))))
977 (if (not (eq (org-element-type first) 'paragraph))
978 (concat id "\n" (org-export-data def info))
979 (push id (nthcdr 2 first))
980 (org-export-data def info)))
981 ;; Fill paragraph once footnote ID is inserted
982 ;; in order to have a correct length for first
983 ;; line.
984 (org-ascii--fill-string
985 (concat id (org-export-data def info))
986 text-width info))))))
987 definitions "\n\n"))))))
988 org-ascii-global-margin)))
990 (defun org-ascii-template (contents info)
991 "Return complete document string after ASCII conversion.
992 CONTENTS is the transcoded contents string. INFO is a plist
993 holding export options."
994 (concat
995 ;; 1. Build title block.
996 (org-ascii--indent-string
997 (concat (org-ascii-template--document-title info)
998 ;; 2. Table of contents.
999 (let ((depth (plist-get info :with-toc)))
1000 (when depth
1001 (concat
1002 (org-ascii--build-toc info (and (wholenump depth) depth))
1003 "\n\n\n"))))
1004 org-ascii-global-margin)
1005 ;; 3. Document's body.
1006 contents
1007 ;; 4. Creator. Ignore `comment' value as there are no comments in
1008 ;; ASCII. Justify it to the bottom right.
1009 (org-ascii--indent-string
1010 (let ((creator-info (plist-get info :with-creator))
1011 (text-width (- org-ascii-text-width org-ascii-global-margin)))
1012 (unless (or (not creator-info) (eq creator-info 'comment))
1013 (concat
1014 "\n\n\n"
1015 (org-ascii--fill-string
1016 (plist-get info :creator) text-width info 'right))))
1017 org-ascii-global-margin)))
1019 (defun org-ascii--translate (s info)
1020 "Translate string S according to specified language and charset.
1021 INFO is a plist used as a communication channel."
1022 (let ((charset (intern (format ":%s" (plist-get info :ascii-charset)))))
1023 (org-export-translate s charset info)))
1027 ;;; Transcode Functions
1029 ;;;; Bold
1031 (defun org-ascii-bold (bold contents info)
1032 "Transcode BOLD from Org to ASCII.
1033 CONTENTS is the text with bold markup. INFO is a plist holding
1034 contextual information."
1035 (format "*%s*" contents))
1038 ;;;; Center Block
1040 (defun org-ascii-center-block (center-block contents info)
1041 "Transcode a CENTER-BLOCK element from Org to ASCII.
1042 CONTENTS holds the contents of the block. INFO is a plist
1043 holding contextual information."
1044 (org-ascii--justify-string
1045 contents (org-ascii--current-text-width center-block info) 'center))
1048 ;;;; Clock
1050 (defun org-ascii-clock (clock contents info)
1051 "Transcode a CLOCK object from Org to ASCII.
1052 CONTENTS is nil. INFO is a plist holding contextual
1053 information."
1054 (concat org-clock-string " "
1055 (org-translate-time
1056 (org-element-property :raw-value
1057 (org-element-property :value clock)))
1058 (let ((time (org-element-property :duration clock)))
1059 (and time
1060 (concat " => "
1061 (apply 'format
1062 "%2s:%02s"
1063 (org-split-string time ":")))))))
1066 ;;;; Code
1068 (defun org-ascii-code (code contents info)
1069 "Return a CODE object from Org to ASCII.
1070 CONTENTS is nil. INFO is a plist holding contextual
1071 information."
1072 (format org-ascii-verbatim-format (org-element-property :value code)))
1075 ;;;; Drawer
1077 (defun org-ascii-drawer (drawer contents info)
1078 "Transcode a DRAWER element from Org to ASCII.
1079 CONTENTS holds the contents of the block. INFO is a plist
1080 holding contextual information."
1081 (let ((name (org-element-property :drawer-name drawer))
1082 (width (org-ascii--current-text-width drawer info)))
1083 (if (functionp org-ascii-format-drawer-function)
1084 (funcall org-ascii-format-drawer-function name contents width)
1085 ;; If there's no user defined function: simply
1086 ;; display contents of the drawer.
1087 contents)))
1090 ;;;; Dynamic Block
1092 (defun org-ascii-dynamic-block (dynamic-block contents info)
1093 "Transcode a DYNAMIC-BLOCK element from Org to ASCII.
1094 CONTENTS holds the contents of the block. INFO is a plist
1095 holding contextual information."
1096 contents)
1099 ;;;; Entity
1101 (defun org-ascii-entity (entity contents info)
1102 "Transcode an ENTITY object from Org to ASCII.
1103 CONTENTS are the definition itself. INFO is a plist holding
1104 contextual information."
1105 (org-element-property
1106 (intern (concat ":" (symbol-name (plist-get info :ascii-charset))))
1107 entity))
1110 ;;;; Example Block
1112 (defun org-ascii-example-block (example-block contents info)
1113 "Transcode a EXAMPLE-BLOCK element from Org to ASCII.
1114 CONTENTS is nil. INFO is a plist holding contextual information."
1115 (org-ascii--box-string
1116 (org-export-format-code-default example-block info) info))
1119 ;;;; Export Snippet
1121 (defun org-ascii-export-snippet (export-snippet contents info)
1122 "Transcode a EXPORT-SNIPPET object from Org to ASCII.
1123 CONTENTS is nil. INFO is a plist holding contextual information."
1124 (when (eq (org-export-snippet-backend export-snippet) 'ascii)
1125 (org-element-property :value export-snippet)))
1128 ;;;; Export Block
1130 (defun org-ascii-export-block (export-block contents info)
1131 "Transcode a EXPORT-BLOCK element from Org to ASCII.
1132 CONTENTS is nil. INFO is a plist holding contextual information."
1133 (when (string= (org-element-property :type export-block) "ASCII")
1134 (org-remove-indentation (org-element-property :value export-block))))
1137 ;;;; Fixed Width
1139 (defun org-ascii-fixed-width (fixed-width contents info)
1140 "Transcode a FIXED-WIDTH element from Org to ASCII.
1141 CONTENTS is nil. INFO is a plist holding contextual information."
1142 (org-ascii--box-string
1143 (org-remove-indentation
1144 (org-element-property :value fixed-width)) info))
1147 ;;;; Footnote Definition
1149 ;; Footnote Definitions are ignored. They are compiled at the end of
1150 ;; the document, by `org-ascii-template'.
1153 ;;;; Footnote Reference
1155 (defun org-ascii-footnote-reference (footnote-reference contents info)
1156 "Transcode a FOOTNOTE-REFERENCE element from Org to ASCII.
1157 CONTENTS is nil. INFO is a plist holding contextual information."
1158 (format "[%s]" (org-export-get-footnote-number footnote-reference info)))
1161 ;;;; Headline
1163 (defun org-ascii-headline (headline contents info)
1164 "Transcode a HEADLINE element from Org to ASCII.
1165 CONTENTS holds the contents of the headline. INFO is a plist
1166 holding contextual information."
1167 ;; Don't export footnote section, which will be handled at the end
1168 ;; of the template.
1169 (unless (org-element-property :footnote-section-p headline)
1170 (let* ((low-level-rank (org-export-low-level-p headline info))
1171 (width (org-ascii--current-text-width headline info))
1172 ;; Blank lines between headline and its contents.
1173 ;; `org-ascii-headline-spacing', when set, overwrites
1174 ;; original buffer's spacing.
1175 (pre-blanks
1176 (make-string
1177 (if org-ascii-headline-spacing (car org-ascii-headline-spacing)
1178 (org-element-property :pre-blank headline)) ?\n))
1179 ;; Even if HEADLINE has no section, there might be some
1180 ;; links in its title that we shouldn't forget to describe.
1181 (links
1182 (unless (or (eq (caar (org-element-contents headline)) 'section))
1183 (let ((title (org-element-property :title headline)))
1184 (when (consp title)
1185 (org-ascii--describe-links
1186 (org-ascii--unique-links title info) width info))))))
1187 ;; Deep subtree: export it as a list item.
1188 (if low-level-rank
1189 (concat
1190 ;; Bullet.
1191 (let ((bullets (cdr (assq (plist-get info :ascii-charset)
1192 org-ascii-bullets))))
1193 (char-to-string
1194 (nth (mod (1- low-level-rank) (length bullets)) bullets)))
1196 ;; Title.
1197 (org-ascii--build-title headline info width) "\n"
1198 ;; Contents, indented by length of bullet.
1199 pre-blanks
1200 (org-ascii--indent-string
1201 (concat contents
1202 (when (org-string-nw-p links) (concat "\n\n" links)))
1204 ;; Else: Standard headline.
1205 (concat
1206 (org-ascii--build-title headline info width 'underline)
1207 "\n" pre-blanks
1208 (concat (when (org-string-nw-p links) links) contents))))))
1211 ;;;; Horizontal Rule
1213 (defun org-ascii-horizontal-rule (horizontal-rule contents info)
1214 "Transcode an HORIZONTAL-RULE object from Org to ASCII.
1215 CONTENTS is nil. INFO is a plist holding contextual
1216 information."
1217 (let ((text-width (org-ascii--current-text-width horizontal-rule info))
1218 (spec-width
1219 (org-export-read-attribute :attr_ascii horizontal-rule :width)))
1220 (org-ascii--justify-string
1221 (make-string (if (and spec-width (string-match "^[0-9]+$" spec-width))
1222 (string-to-number spec-width)
1223 text-width)
1224 (if (eq (plist-get info :ascii-charset) 'utf-8) ?― ?-))
1225 text-width 'center)))
1228 ;;;; Inline Src Block
1230 (defun org-ascii-inline-src-block (inline-src-block contents info)
1231 "Transcode an INLINE-SRC-BLOCK element from Org to ASCII.
1232 CONTENTS holds the contents of the item. INFO is a plist holding
1233 contextual information."
1234 (format org-ascii-verbatim-format
1235 (org-element-property :value inline-src-block)))
1238 ;;;; Inlinetask
1240 (defun org-ascii-inlinetask (inlinetask contents info)
1241 "Transcode an INLINETASK element from Org to ASCII.
1242 CONTENTS holds the contents of the block. INFO is a plist
1243 holding contextual information."
1244 (let ((width (org-ascii--current-text-width inlinetask info)))
1245 ;; If `org-ascii-format-inlinetask-function' is provided, call it
1246 ;; with appropriate arguments.
1247 (if (functionp org-ascii-format-inlinetask-function)
1248 (funcall org-ascii-format-inlinetask-function
1249 ;; todo.
1250 (and (plist-get info :with-todo-keywords)
1251 (let ((todo (org-element-property
1252 :todo-keyword inlinetask)))
1253 (and todo (org-export-data todo info))))
1254 ;; todo-type
1255 (org-element-property :todo-type inlinetask)
1256 ;; priority
1257 (and (plist-get info :with-priority)
1258 (org-element-property :priority inlinetask))
1259 ;; title
1260 (org-export-data (org-element-property :title inlinetask) info)
1261 ;; tags
1262 (and (plist-get info :with-tags)
1263 (org-element-property :tags inlinetask))
1264 ;; contents and width
1265 contents width)
1266 ;; Otherwise, use a default template.
1267 (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
1268 (org-ascii--indent-string
1269 (concat
1270 ;; Top line, with an additional blank line if not in UTF-8.
1271 (make-string width (if utf8p ?━ ?_)) "\n"
1272 (unless utf8p (concat (make-string width ? ) "\n"))
1273 ;; Add title. Fill it if wider than inlinetask.
1274 (let ((title (org-ascii--build-title inlinetask info width)))
1275 (if (<= (length title) width) title
1276 (org-ascii--fill-string title width info)))
1277 "\n"
1278 ;; If CONTENTS is not empty, insert it along with
1279 ;; a separator.
1280 (when (org-string-nw-p contents)
1281 (concat (make-string width (if utf8p ?─ ?-)) "\n" contents))
1282 ;; Bottom line.
1283 (make-string width (if utf8p ?━ ?_)))
1284 ;; Flush the inlinetask to the right.
1285 (- org-ascii-text-width org-ascii-global-margin
1286 (if (not (org-export-get-parent-headline inlinetask)) 0
1287 org-ascii-inner-margin)
1288 (org-ascii--current-text-width inlinetask info)))))))
1291 ;;;; Italic
1293 (defun org-ascii-italic (italic contents info)
1294 "Transcode italic from Org to ASCII.
1295 CONTENTS is the text with italic markup. INFO is a plist holding
1296 contextual information."
1297 (format "/%s/" contents))
1300 ;;;; Item
1302 (defun org-ascii-item (item contents info)
1303 "Transcode an ITEM element from Org to ASCII.
1304 CONTENTS holds the contents of the item. INFO is a plist holding
1305 contextual information."
1306 (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8))
1307 (checkbox (org-ascii--checkbox item info))
1308 (list-type (org-element-property :type (org-export-get-parent item)))
1309 (bullet
1310 ;; First parent of ITEM is always the plain-list. Get
1311 ;; `:type' property from it.
1312 (org-list-bullet-string
1313 (case list-type
1314 (descriptive
1315 (concat checkbox
1316 (org-export-data (org-element-property :tag item) info)
1317 ": "))
1318 (ordered
1319 ;; Return correct number for ITEM, paying attention to
1320 ;; counters.
1321 (let* ((struct (org-element-property :structure item))
1322 (bul (org-element-property :bullet item))
1323 (num (number-to-string
1324 (car (last (org-list-get-item-number
1325 (org-element-property :begin item)
1326 struct
1327 (org-list-prevs-alist struct)
1328 (org-list-parents-alist struct)))))))
1329 (replace-regexp-in-string "[0-9]+" num bul)))
1330 (t (let ((bul (org-element-property :bullet item)))
1331 ;; Change bullets into more visible form if UTF-8 is active.
1332 (if (not utf8p) bul
1333 (replace-regexp-in-string
1334 "-" "•"
1335 (replace-regexp-in-string
1336 "+" "⁃"
1337 (replace-regexp-in-string "*" "‣" bul))))))))))
1338 (concat
1339 bullet
1340 (unless (eq list-type 'descriptive) checkbox)
1341 ;; Contents: Pay attention to indentation. Note: check-boxes are
1342 ;; already taken care of at the paragraph level so they don't
1343 ;; interfere with indentation.
1344 (let ((contents (org-ascii--indent-string contents (length bullet))))
1345 (if (eq (org-element-type (car (org-element-contents item))) 'paragraph)
1346 (org-trim contents)
1347 (concat "\n" contents))))))
1350 ;;;; Keyword
1352 (defun org-ascii-keyword (keyword contents info)
1353 "Transcode a KEYWORD element from Org to ASCII.
1354 CONTENTS is nil. INFO is a plist holding contextual
1355 information."
1356 (let ((key (org-element-property :key keyword))
1357 (value (org-element-property :value keyword)))
1358 (cond
1359 ((string= key "ASCII") value)
1360 ((string= key "TOC")
1361 (let ((value (downcase value)))
1362 (cond
1363 ((string-match "\\<headlines\\>" value)
1364 (let ((depth (or (and (string-match "[0-9]+" value)
1365 (string-to-number (match-string 0 value)))
1366 (plist-get info :with-toc))))
1367 (org-ascii--build-toc
1368 info (and (wholenump depth) depth) keyword)))
1369 ((string= "tables" value)
1370 (org-ascii--list-tables keyword info))
1371 ((string= "listings" value)
1372 (org-ascii--list-listings keyword info))))))))
1375 ;;;; Latex Environment
1377 (defun org-ascii-latex-environment (latex-environment contents info)
1378 "Transcode a LATEX-ENVIRONMENT element from Org to ASCII.
1379 CONTENTS is nil. INFO is a plist holding contextual
1380 information."
1381 (when (plist-get info :with-latex)
1382 (org-remove-indentation (org-element-property :value latex-environment))))
1385 ;;;; Latex Fragment
1387 (defun org-ascii-latex-fragment (latex-fragment contents info)
1388 "Transcode a LATEX-FRAGMENT object from Org to ASCII.
1389 CONTENTS is nil. INFO is a plist holding contextual
1390 information."
1391 (when (plist-get info :with-latex)
1392 (org-element-property :value latex-fragment)))
1395 ;;;; Line Break
1397 (defun org-ascii-line-break (line-break contents info)
1398 "Transcode a LINE-BREAK object from Org to ASCII.
1399 CONTENTS is nil. INFO is a plist holding contextual
1400 information." hard-newline)
1403 ;;;; Link
1405 (defun org-ascii-link (link desc info)
1406 "Transcode a LINK object from Org to ASCII.
1408 DESC is the description part of the link, or the empty string.
1409 INFO is a plist holding contextual information."
1410 (let ((raw-link (org-element-property :raw-link link))
1411 (type (org-element-property :type link)))
1412 (cond
1413 ((string= type "coderef")
1414 (let ((ref (org-element-property :path link)))
1415 (format (org-export-get-coderef-format ref desc)
1416 (org-export-resolve-coderef ref info))))
1417 ;; Do not apply a special syntax on radio links. Though, use
1418 ;; transcoded target's contents as output.
1419 ((string= type "radio")
1420 (let ((destination (org-export-resolve-radio-link link info)))
1421 (when destination
1422 (org-export-data (org-element-contents destination) info))))
1423 ;; Do not apply a special syntax on fuzzy links pointing to
1424 ;; targets.
1425 ((string= type "fuzzy")
1426 (let ((destination (org-export-resolve-fuzzy-link link info)))
1427 ;; Ignore invisible "#+TARGET: path".
1428 (unless (eq (org-element-type destination) 'keyword)
1429 (if (org-string-nw-p desc) desc
1430 (when destination
1431 (let ((number
1432 (org-export-get-ordinal
1433 destination info nil 'org-ascii--has-caption-p)))
1434 (when number
1435 (if (atom number) (number-to-string number)
1436 (mapconcat 'number-to-string number ".")))))))))
1438 (if (not (org-string-nw-p desc)) (format "[%s]" raw-link)
1439 (concat
1440 (format "[%s]" desc)
1441 (unless org-ascii-links-to-notes (format " (%s)" raw-link))))))))
1444 ;;;; Paragraph
1446 (defun org-ascii-paragraph (paragraph contents info)
1447 "Transcode a PARAGRAPH element from Org to ASCII.
1448 CONTENTS is the contents of the paragraph, as a string. INFO is
1449 the plist used as a communication channel."
1450 (let ((contents (if (not (wholenump org-ascii-indented-line-width)) contents
1451 (concat
1452 (make-string org-ascii-indented-line-width ? )
1453 (replace-regexp-in-string "\\`[ \t]+" "" contents)))))
1454 (org-ascii--fill-string
1455 contents (org-ascii--current-text-width paragraph info) info)))
1458 ;;;; Plain List
1460 (defun org-ascii-plain-list (plain-list contents info)
1461 "Transcode a PLAIN-LIST element from Org to ASCII.
1462 CONTENTS is the contents of the list. INFO is a plist holding
1463 contextual information."
1464 contents)
1467 ;;;; Plain Text
1469 (defun org-ascii-plain-text (text info)
1470 "Transcode a TEXT string from Org to ASCII.
1471 INFO is a plist used as a communication channel."
1472 (let ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
1473 (when (and utf8p (plist-get info :with-smart-quotes))
1474 (setq text (org-export-activate-smart-quotes text :utf-8 info)))
1475 (if (not (plist-get info :with-special-strings)) text
1476 (setq text (replace-regexp-in-string "\\\\-" "" text))
1477 (if (not utf8p) text
1478 ;; Usual replacements in utf-8 with proper option set.
1479 (replace-regexp-in-string
1480 "\\.\\.\\." "…"
1481 (replace-regexp-in-string
1482 "--" "–"
1483 (replace-regexp-in-string "---" "—" text)))))))
1486 ;;;; Planning
1488 (defun org-ascii-planning (planning contents info)
1489 "Transcode a PLANNING element from Org to ASCII.
1490 CONTENTS is nil. INFO is a plist used as a communication
1491 channel."
1492 (mapconcat
1493 'identity
1494 (delq nil
1495 (list (let ((closed (org-element-property :closed planning)))
1496 (when closed
1497 (concat org-closed-string " "
1498 (org-translate-time
1499 (org-element-property :raw-value closed)))))
1500 (let ((deadline (org-element-property :deadline planning)))
1501 (when deadline
1502 (concat org-deadline-string " "
1503 (org-translate-time
1504 (org-element-property :raw-value deadline)))))
1505 (let ((scheduled (org-element-property :scheduled planning)))
1506 (when scheduled
1507 (concat org-scheduled-string " "
1508 (org-translate-time
1509 (org-element-property :raw-value scheduled)))))))
1510 " "))
1513 ;;;; Quote Block
1515 (defun org-ascii-quote-block (quote-block contents info)
1516 "Transcode a QUOTE-BLOCK element from Org to ASCII.
1517 CONTENTS holds the contents of the block. INFO is a plist
1518 holding contextual information."
1519 (org-ascii--indent-string contents org-ascii-quote-margin))
1522 ;;;; Quote Section
1524 (defun org-ascii-quote-section (quote-section contents info)
1525 "Transcode a QUOTE-SECTION element from Org to ASCII.
1526 CONTENTS is nil. INFO is a plist holding contextual information."
1527 (let ((width (org-ascii--current-text-width quote-section info))
1528 (value
1529 (org-export-data
1530 (org-remove-indentation (org-element-property :value quote-section))
1531 info)))
1532 (org-ascii--indent-string
1533 value
1534 (+ org-ascii-quote-margin
1535 ;; Don't apply inner margin if parent headline is low level.
1536 (let ((headline (org-export-get-parent-headline quote-section)))
1537 (if (org-export-low-level-p headline info) 0
1538 org-ascii-inner-margin))))))
1541 ;;;; Radio Target
1543 (defun org-ascii-radio-target (radio-target contents info)
1544 "Transcode a RADIO-TARGET object from Org to ASCII.
1545 CONTENTS is the contents of the target. INFO is a plist holding
1546 contextual information."
1547 contents)
1550 ;;;; Section
1552 (defun org-ascii-section (section contents info)
1553 "Transcode a SECTION element from Org to ASCII.
1554 CONTENTS is the contents of the section. INFO is a plist holding
1555 contextual information."
1556 (org-ascii--indent-string
1557 (concat
1558 contents
1559 (when org-ascii-links-to-notes
1560 ;; Add list of links at the end of SECTION.
1561 (let ((links (org-ascii--describe-links
1562 (org-ascii--unique-links section info)
1563 (org-ascii--current-text-width section info) info)))
1564 ;; Separate list of links and section contents.
1565 (when (org-string-nw-p links) (concat "\n\n" links)))))
1566 ;; Do not apply inner margin if parent headline is low level.
1567 (let ((headline (org-export-get-parent-headline section)))
1568 (if (or (not headline) (org-export-low-level-p headline info)) 0
1569 org-ascii-inner-margin))))
1572 ;;;; Special Block
1574 (defun org-ascii-special-block (special-block contents info)
1575 "Transcode a SPECIAL-BLOCK element from Org to ASCII.
1576 CONTENTS holds the contents of the block. INFO is a plist
1577 holding contextual information."
1578 contents)
1581 ;;;; Src Block
1583 (defun org-ascii-src-block (src-block contents info)
1584 "Transcode a SRC-BLOCK element from Org to ASCII.
1585 CONTENTS holds the contents of the item. INFO is a plist holding
1586 contextual information."
1587 (let ((caption (org-ascii--build-caption src-block info))
1588 (code (org-export-format-code-default src-block info)))
1589 (if (equal code "") ""
1590 (concat
1591 (when (and caption org-ascii-caption-above) (concat caption "\n"))
1592 (org-ascii--box-string code info)
1593 (when (and caption (not org-ascii-caption-above))
1594 (concat "\n" caption))))))
1597 ;;;; Statistics Cookie
1599 (defun org-ascii-statistics-cookie (statistics-cookie contents info)
1600 "Transcode a STATISTICS-COOKIE object from Org to ASCII.
1601 CONTENTS is nil. INFO is a plist holding contextual information."
1602 (org-element-property :value statistics-cookie))
1605 ;;;; Subscript
1607 (defun org-ascii-subscript (subscript contents info)
1608 "Transcode a SUBSCRIPT object from Org to ASCII.
1609 CONTENTS is the contents of the object. INFO is a plist holding
1610 contextual information."
1611 (if (org-element-property :use-brackets-p subscript)
1612 (format "_{%s}" contents)
1613 (format "_%s" contents)))
1616 ;;;; Superscript
1618 (defun org-ascii-superscript (superscript contents info)
1619 "Transcode a SUPERSCRIPT object from Org to ASCII.
1620 CONTENTS is the contents of the object. INFO is a plist holding
1621 contextual information."
1622 (if (org-element-property :use-brackets-p superscript)
1623 (format "_{%s}" contents)
1624 (format "_%s" contents)))
1627 ;;;; Strike-through
1629 (defun org-ascii-strike-through (strike-through contents info)
1630 "Transcode STRIKE-THROUGH from Org to ASCII.
1631 CONTENTS is text with strike-through markup. INFO is a plist
1632 holding contextual information."
1633 (format "+%s+" contents))
1636 ;;;; Table
1638 (defun org-ascii-table (table contents info)
1639 "Transcode a TABLE element from Org to ASCII.
1640 CONTENTS is the contents of the table. INFO is a plist holding
1641 contextual information."
1642 (let ((caption (org-ascii--build-caption table info)))
1643 (concat
1644 ;; Possibly add a caption string above.
1645 (when (and caption org-ascii-caption-above) (concat caption "\n"))
1646 ;; Insert table. Note: "table.el" tables are left unmodified.
1647 (cond ((eq (org-element-property :type table) 'org) contents)
1648 ((and org-ascii-table-use-ascii-art
1649 (eq (plist-get info :ascii-charset) 'utf-8)
1650 (require 'ascii-art-to-unicode nil t))
1651 (with-temp-buffer
1652 (insert (org-remove-indentation
1653 (org-element-property :value table)))
1654 (goto-char (point-min))
1655 (aa2u)
1656 (goto-char (point-max))
1657 (skip-chars-backward " \r\t\n")
1658 (buffer-substring (point-min) (point))))
1659 (t (org-remove-indentation (org-element-property :value table))))
1660 ;; Possible add a caption string below.
1661 (when (and caption (not org-ascii-caption-above))
1662 (concat "\n" caption)))))
1665 ;;;; Table Cell
1667 (defun org-ascii--table-cell-width (table-cell info)
1668 "Return width of TABLE-CELL.
1670 INFO is a plist used as a communication channel.
1672 Width of a cell is determined either by a width cookie in the
1673 same column as the cell, or by the maximum cell's length in that
1674 column.
1676 When `org-ascii-table-widen-columns' is non-nil, width cookies
1677 are ignored."
1678 (or (and (not org-ascii-table-widen-columns)
1679 (org-export-table-cell-width table-cell info))
1680 (let* ((max-width 0)
1681 (table (org-export-get-parent-table table-cell))
1682 (specialp (org-export-table-has-special-column-p table))
1683 (col (cdr (org-export-table-cell-address table-cell info))))
1684 (org-element-map table 'table-row
1685 (lambda (row)
1686 (setq max-width
1687 (max (length
1688 (org-export-data
1689 (org-element-contents
1690 (elt (if specialp (cdr (org-element-contents row))
1691 (org-element-contents row))
1692 col))
1693 info))
1694 max-width)))
1695 info)
1696 max-width)))
1698 (defun org-ascii-table-cell (table-cell contents info)
1699 "Transcode a TABLE-CELL object from Org to ASCII.
1700 CONTENTS is the cell contents. INFO is a plist used as
1701 a communication channel."
1702 ;; Determine column width. When `org-ascii-table-widen-columns'
1703 ;; is nil and some width cookie has set it, use that value.
1704 ;; Otherwise, compute the maximum width among transcoded data of
1705 ;; each cell in the column.
1706 (let ((width (org-ascii--table-cell-width table-cell info)))
1707 ;; When contents are too large, truncate them.
1708 (unless (or org-ascii-table-widen-columns (<= (length contents) width))
1709 (setq contents (concat (substring contents 0 (- width 2)) "=>")))
1710 ;; Align contents correctly within the cell.
1711 (let* ((indent-tabs-mode nil)
1712 (data
1713 (when contents
1714 (org-ascii--justify-string
1715 contents width
1716 (org-export-table-cell-alignment table-cell info)))))
1717 (setq contents (concat data (make-string (- width (length data)) ? ))))
1718 ;; Return cell.
1719 (concat (format " %s " contents)
1720 (when (memq 'right (org-export-table-cell-borders table-cell info))
1721 (if (eq (plist-get info :ascii-charset) 'utf-8) "│" "|")))))
1724 ;;;; Table Row
1726 (defun org-ascii-table-row (table-row contents info)
1727 "Transcode a TABLE-ROW element from Org to ASCII.
1728 CONTENTS is the row contents. INFO is a plist used as
1729 a communication channel."
1730 (when (eq (org-element-property :type table-row) 'standard)
1731 (let ((build-hline
1732 (function
1733 (lambda (lcorner horiz vert rcorner)
1734 (concat
1735 (apply
1736 'concat
1737 (org-element-map table-row 'table-cell
1738 (lambda (cell)
1739 (let ((width (org-ascii--table-cell-width cell info))
1740 (borders (org-export-table-cell-borders cell info)))
1741 (concat
1742 ;; In order to know if CELL starts the row, do
1743 ;; not compare it with the first cell in the
1744 ;; row as there might be a special column.
1745 ;; Instead, compare it with first exportable
1746 ;; cell, obtained with `org-element-map'.
1747 (when (and (memq 'left borders)
1748 (eq (org-element-map table-row 'table-cell
1749 'identity info t)
1750 cell))
1751 lcorner)
1752 (make-string (+ 2 width) (string-to-char horiz))
1753 (cond
1754 ((not (memq 'right borders)) nil)
1755 ((eq (car (last (org-element-contents table-row))) cell)
1756 rcorner)
1757 (t vert)))))
1758 info)) "\n"))))
1759 (utf8p (eq (plist-get info :ascii-charset) 'utf-8))
1760 (borders (org-export-table-cell-borders
1761 (org-element-map table-row 'table-cell 'identity info t)
1762 info)))
1763 (concat (cond
1764 ((and (memq 'top borders) (or utf8p (memq 'above borders)))
1765 (if utf8p (funcall build-hline "┍" "━" "┯" "┑")
1766 (funcall build-hline "+" "-" "+" "+")))
1767 ((memq 'above borders)
1768 (if utf8p (funcall build-hline "├" "─" "┼" "┤")
1769 (funcall build-hline "+" "-" "+" "+"))))
1770 (when (memq 'left borders) (if utf8p "│" "|"))
1771 contents "\n"
1772 (when (and (memq 'bottom borders) (or utf8p (memq 'below borders)))
1773 (if utf8p (funcall build-hline "┕" "━" "┷" "┙")
1774 (funcall build-hline "+" "-" "+" "+")))))))
1777 ;;;; Timestamp
1779 (defun org-ascii-timestamp (timestamp contents info)
1780 "Transcode a TIMESTAMP object from Org to ASCII.
1781 CONTENTS is nil. INFO is a plist holding contextual information."
1782 (org-ascii-plain-text (org-timestamp-translate timestamp) info))
1785 ;;;; Underline
1787 (defun org-ascii-underline (underline contents info)
1788 "Transcode UNDERLINE from Org to ASCII.
1789 CONTENTS is the text with underline markup. INFO is a plist
1790 holding contextual information."
1791 (format "_%s_" contents))
1794 ;;;; Verbatim
1796 (defun org-ascii-verbatim (verbatim contents info)
1797 "Return a VERBATIM object from Org to ASCII.
1798 CONTENTS is nil. INFO is a plist holding contextual information."
1799 (format org-ascii-verbatim-format
1800 (org-element-property :value verbatim)))
1803 ;;;; Verse Block
1805 (defun org-ascii-verse-block (verse-block contents info)
1806 "Transcode a VERSE-BLOCK element from Org to ASCII.
1807 CONTENTS is verse block contents. INFO is a plist holding
1808 contextual information."
1809 (let ((verse-width (org-ascii--current-text-width verse-block info)))
1810 (org-ascii--indent-string
1811 (org-ascii--justify-string contents verse-width 'left)
1812 org-ascii-quote-margin)))
1816 ;;; Filters
1818 (defun org-ascii-filter-headline-blank-lines (headline back-end info)
1819 "Filter controlling number of blank lines after a headline.
1821 HEADLINE is a string representing a transcoded headline.
1822 BACK-END is symbol specifying back-end used for export. INFO is
1823 plist containing the communication channel.
1825 This function only applies to `ascii' back-end. See
1826 `org-ascii-headline-spacing' for information."
1827 (if (not org-ascii-headline-spacing) headline
1828 (let ((blanks (make-string (1+ (cdr org-ascii-headline-spacing)) ?\n)))
1829 (replace-regexp-in-string "\n\\(?:\n[ \t]*\\)*\\'" blanks headline))))
1831 (defun org-ascii-filter-paragraph-spacing (tree back-end info)
1832 "Filter controlling number of blank lines between paragraphs.
1834 TREE is the parse tree. BACK-END is the symbol specifying
1835 back-end used for export. INFO is a plist used as
1836 a communication channel.
1838 See `org-ascii-paragraph-spacing' for information."
1839 (when (wholenump org-ascii-paragraph-spacing)
1840 (org-element-map tree 'paragraph
1841 (lambda (p)
1842 (when (eq (org-element-type (org-export-get-next-element p info))
1843 'paragraph)
1844 (org-element-put-property
1845 p :post-blank org-ascii-paragraph-spacing)))))
1846 tree)
1848 (defun org-ascii-filter-comment-spacing (tree backend info)
1849 "Filter removing blank lines between comments.
1850 TREE is the parse tree. BACK-END is the symbol specifying
1851 back-end used for export. INFO is a plist used as
1852 a communication channel."
1853 (org-element-map tree '(comment comment-block)
1854 (lambda (c)
1855 (when (memq (org-element-type (org-export-get-next-element c info))
1856 '(comment comment-block))
1857 (org-element-put-property c :post-blank 0))))
1858 tree)
1862 ;;; End-user functions
1864 ;;;###autoload
1865 (defun org-ascii-export-as-ascii
1866 (&optional async subtreep visible-only body-only ext-plist)
1867 "Export current buffer to a text buffer.
1869 If narrowing is active in the current buffer, only export its
1870 narrowed part.
1872 If a region is active, export that region.
1874 A non-nil optional argument ASYNC means the process should happen
1875 asynchronously. The resulting buffer should be accessible
1876 through the `org-export-stack' interface.
1878 When optional argument SUBTREEP is non-nil, export the sub-tree
1879 at point, extracting information from the headline properties
1880 first.
1882 When optional argument VISIBLE-ONLY is non-nil, don't export
1883 contents of hidden elements.
1885 When optional argument BODY-ONLY is non-nil, strip title and
1886 table of contents from output.
1888 EXT-PLIST, when provided, is a property list with external
1889 parameters overriding Org default settings, but still inferior to
1890 file-local settings.
1892 Export is done in a buffer named \"*Org ASCII Export*\", which
1893 will be displayed when `org-export-show-temporary-export-buffer'
1894 is non-nil."
1895 (interactive)
1896 (if async
1897 (org-export-async-start
1898 (lambda (output)
1899 (with-current-buffer (get-buffer-create "*Org ASCII Export*")
1900 (erase-buffer)
1901 (insert output)
1902 (goto-char (point-min))
1903 (text-mode)
1904 (org-export-add-to-stack (current-buffer) 'ascii)))
1905 `(org-export-as 'ascii ,subtreep ,visible-only ,body-only
1906 ',ext-plist))
1907 (let ((outbuf (org-export-to-buffer
1908 'ascii "*Org ASCII Export*"
1909 subtreep visible-only body-only ext-plist)))
1910 (with-current-buffer outbuf (text-mode))
1911 (when org-export-show-temporary-export-buffer
1912 (switch-to-buffer-other-window outbuf)))))
1914 ;;;###autoload
1915 (defun org-ascii-export-to-ascii
1916 (&optional async subtreep visible-only body-only ext-plist)
1917 "Export current buffer to a text file.
1919 If narrowing is active in the current buffer, only export its
1920 narrowed part.
1922 If a region is active, export that region.
1924 A non-nil optional argument ASYNC means the process should happen
1925 asynchronously. The resulting file should be accessible through
1926 the `org-export-stack' interface.
1928 When optional argument SUBTREEP is non-nil, export the sub-tree
1929 at point, extracting information from the headline properties
1930 first.
1932 When optional argument VISIBLE-ONLY is non-nil, don't export
1933 contents of hidden elements.
1935 When optional argument BODY-ONLY is non-nil, strip title and
1936 table of contents from output.
1938 EXT-PLIST, when provided, is a property list with external
1939 parameters overriding Org default settings, but still inferior to
1940 file-local settings.
1942 Return output file's name."
1943 (interactive)
1944 (let ((outfile (org-export-output-file-name ".txt" subtreep)))
1945 (if async
1946 (org-export-async-start
1947 (lambda (f) (org-export-add-to-stack f 'ascii))
1948 `(expand-file-name
1949 (org-export-to-file
1950 'ascii ,outfile ,subtreep ,visible-only ,body-only ',ext-plist)))
1951 (org-export-to-file
1952 'ascii outfile subtreep visible-only body-only ext-plist))))
1954 ;;;###autoload
1955 (defun org-ascii-publish-to-ascii (plist filename pub-dir)
1956 "Publish an Org file to ASCII.
1958 FILENAME is the filename of the Org file to be published. PLIST
1959 is the property list for the given project. PUB-DIR is the
1960 publishing directory.
1962 Return output file name."
1963 (org-publish-org-to
1964 'ascii filename ".txt" `(:ascii-charset ascii ,@plist) pub-dir))
1966 ;;;###autoload
1967 (defun org-ascii-publish-to-latin1 (plist filename pub-dir)
1968 "Publish an Org file to Latin-1.
1970 FILENAME is the filename of the Org file to be published. PLIST
1971 is the property list for the given project. PUB-DIR is the
1972 publishing directory.
1974 Return output file name."
1975 (org-publish-org-to
1976 'ascii filename ".txt" `(:ascii-charset latin1 ,@plist) pub-dir))
1978 ;;;###autoload
1979 (defun org-ascii-publish-to-utf8 (plist filename pub-dir)
1980 "Publish an org file to UTF-8.
1982 FILENAME is the filename of the Org file to be published. PLIST
1983 is the property list for the given project. PUB-DIR is the
1984 publishing directory.
1986 Return output file name."
1987 (org-publish-org-to
1988 'ascii filename ".txt" `(:ascii-charset utf-8 ,@plist) pub-dir))
1991 (provide 'ox-ascii)
1993 ;; Local variables:
1994 ;; generated-autoload-file: "org-loaddefs.el"
1995 ;; coding: utf-8-emacs
1996 ;; End:
1998 ;;; ox-ascii.el ends here