summaryrefslogtreecommitdiff
path: root/lisp/ox-ascii.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/ox-ascii.el')
-rw-r--r--lisp/ox-ascii.el185
1 files changed, 72 insertions, 113 deletions
diff --git a/lisp/ox-ascii.el b/lisp/ox-ascii.el
index 74a7c64..55bda83 100644
--- a/lisp/ox-ascii.el
+++ b/lisp/ox-ascii.el
@@ -1,10 +1,12 @@
;;; ox-ascii.el --- ASCII Back-End for Org Export Engine
-;; Copyright (C) 2012, 2013 Free Software Foundation, Inc.
+;; Copyright (C) 2012-2013 Free Software Foundation, Inc.
;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
;; Keywords: outlines, hypermedia, calendar, wp
+;; This file is part of GNU Emacs.
+
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
@@ -21,19 +23,7 @@
;;; Commentary:
;;
;; This library implements an ASCII back-end for Org generic exporter.
-;;
-;; It provides two commands for export, depending on the desired
-;; output: `org-ascii-export-as-ascii' (temporary buffer) and
-;; `org-ascii-export-to-ascii' ("txt" file). Also, three publishing
-;; functions are available: `org-ascii-publish-to-ascii',
-;; `org-ascii-publish-to-latin1' and `org-ascii-publish-to-utf8'.
-;;
-;; Output encoding is specified through `org-ascii-charset' variable,
-;; among `ascii', `latin1' and `utf-8' symbols.
-;;
-;; By default, horizontal rules span over the full text with, but with
-;; a given width attribute (set though #+ATTR_ASCII: :width <num>)
-;; they can be shortened and centered.
+;; See Org manual for more information.
;;; Code:
@@ -346,7 +336,8 @@ Otherwise, place it right after it."
:package-version '(Org . "8.0")
:type 'string)
-(defcustom org-ascii-format-drawer-function nil
+(defcustom org-ascii-format-drawer-function
+ (lambda (name contents width) contents)
"Function called to format a drawer in ASCII.
The function must accept three parameters:
@@ -357,63 +348,32 @@ The function must accept three parameters:
The function should return either the string to be exported or
nil to ignore the drawer.
-For example, the variable could be set to the following function
-in order to mimic default behaviour:
-
-\(defun org-ascii-format-drawer-default (name contents width)
- \"Format a drawer element for ASCII export.\"
- contents)"
+The default value simply returns the value of CONTENTS."
:group 'org-export-ascii
:version "24.4"
:package-version '(Org . "8.0")
:type 'function)
-(defcustom org-ascii-format-inlinetask-function nil
+(defcustom org-ascii-format-inlinetask-function
+ 'org-ascii-format-inlinetask-default
"Function called to format an inlinetask in ASCII.
-The function must accept six parameters:
- TODO the todo keyword, as a string
- TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
- PRIORITY the inlinetask priority, as a string
- NAME the inlinetask name, as a string.
- TAGS the inlinetask tags, as a list of strings.
- CONTENTS the contents of the inlinetask, as a string.
+The function must accept nine parameters:
+ TODO the todo keyword, as a string
+ TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
+ PRIORITY the inlinetask priority, as a string
+ NAME the inlinetask name, as a string.
+ TAGS the inlinetask tags, as a list of strings.
+ CONTENTS the contents of the inlinetask, as a string.
+ WIDTH the width of the inlinetask, as a number.
+ INLINETASK the inlinetask itself.
+ INFO the info channel.
The function should return either the string to be exported or
-nil to ignore the inline task.
-
-For example, the variable could be set to the following function
-in order to mimic default behaviour:
-
-\(defun org-ascii-format-inlinetask-default
- \(todo type priority name tags contents\)
- \"Format an inline task element for ASCII export.\"
- \(let* \(\(utf8p \(eq \(plist-get info :ascii-charset\) 'utf-8\)\)
- \(width org-ascii-inlinetask-width\)
- \(org-ascii--indent-string
- \(concat
- ;; Top line, with an additional blank line if not in UTF-8.
- \(make-string width \(if utf8p ?━ ?_\)\) \"\\n\"
- \(unless utf8p \(concat \(make-string width ? \) \"\\n\"\)\)
- ;; Add title. Fill it if wider than inlinetask.
- \(let \(\(title \(org-ascii--build-title inlinetask info width\)\)\)
- \(if \(<= \(length title\) width\) title
- \(org-ascii--fill-string title width info\)\)\)
- \"\\n\"
- ;; If CONTENTS is not empty, insert it along with
- ;; a separator.
- \(when \(org-string-nw-p contents\)
- \(concat \(make-string width \(if utf8p ?─ ?-\)\) \"\\n\" contents\)\)
- ;; Bottom line.
- \(make-string width \(if utf8p ?━ ?_\)\)\)
- ;; Flush the inlinetask to the right.
- \(- \(plist-get info :ascii-width\)
- \(plist-get info :ascii-margin\)
- \(plist-get info :ascii-inner-margin\)
- \(org-ascii--current-text-width inlinetask info\)\)"
+nil to ignore the inline task."
:group 'org-export-ascii
:version "24.4"
- :package-version '(Org . "8.0")
+ :package-version '(Org . "8.3")
:type 'function)
@@ -499,7 +459,7 @@ Empty lines are not indented."
(defun org-ascii--box-string (s info)
"Return string S with a partial box to its left.
-INFO is a plist used as a communicaton channel."
+INFO is a plist used as a communication channel."
(let ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
(format (if utf8p "╭────\n%s\n╰────" ",----\n%s\n`----")
(replace-regexp-in-string
@@ -720,7 +680,7 @@ generation. INFO is a plist used as a communication channel."
(let ((text-width
(if keyword (org-ascii--current-text-width keyword info)
(- org-ascii-text-width org-ascii-global-margin)))
- ;; Use a counter instead of retreiving ordinal of each
+ ;; Use a counter instead of retrieving ordinal of each
;; src-block.
(count 0))
(mapconcat
@@ -758,7 +718,7 @@ generation. INFO is a plist used as a communication channel."
(let ((text-width
(if keyword (org-ascii--current-text-width keyword info)
(- org-ascii-text-width org-ascii-global-margin)))
- ;; Use a counter instead of retreiving ordinal of each
+ ;; Use a counter instead of retrieving ordinal of each
;; src-block.
(count 0))
(mapconcat
@@ -1081,11 +1041,7 @@ CONTENTS holds the contents of the block. INFO is a plist
holding contextual information."
(let ((name (org-element-property :drawer-name drawer))
(width (org-ascii--current-text-width drawer info)))
- (if (functionp org-ascii-format-drawer-function)
- (funcall org-ascii-format-drawer-function name contents width)
- ;; If there's no user defined function: simply
- ;; display contents of the drawer.
- contents)))
+ (funcall org-ascii-format-drawer-function name contents width)))
;;;; Dynamic Block
@@ -1238,55 +1194,58 @@ contextual information."
;;;; Inlinetask
+(defun org-ascii-format-inlinetask-default
+ (todo type priority name tags contents width inlinetask info)
+ "Format an inline task element for ASCII export.
+See `org-ascii-format-inlinetask-function' for a description
+of the paramaters."
+ (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8))
+ (width (or width org-ascii-inlinetask-width)))
+ (org-ascii--indent-string
+ (concat
+ ;; Top line, with an additional blank line if not in UTF-8.
+ (make-string width (if utf8p ?━ ?_)) "\n"
+ (unless utf8p (concat (make-string width ? ) "\n"))
+ ;; Add title. Fill it if wider than inlinetask.
+ (let ((title (org-ascii--build-title inlinetask info width)))
+ (if (<= (length title) width) title
+ (org-ascii--fill-string title width info)))
+ "\n"
+ ;; If CONTENTS is not empty, insert it along with
+ ;; a separator.
+ (when (org-string-nw-p contents)
+ (concat (make-string width (if utf8p ?─ ?-)) "\n" contents))
+ ;; Bottom line.
+ (make-string width (if utf8p ?━ ?_)))
+ ;; Flush the inlinetask to the right.
+ (- org-ascii-text-width org-ascii-global-margin
+ (if (not (org-export-get-parent-headline inlinetask)) 0
+ org-ascii-inner-margin)
+ (org-ascii--current-text-width inlinetask info)))))
+
(defun org-ascii-inlinetask (inlinetask contents info)
"Transcode an INLINETASK element from Org to ASCII.
CONTENTS holds the contents of the block. INFO is a plist
holding contextual information."
(let ((width (org-ascii--current-text-width inlinetask info)))
- ;; If `org-ascii-format-inlinetask-function' is provided, call it
- ;; with appropriate arguments.
- (if (functionp org-ascii-format-inlinetask-function)
- (funcall org-ascii-format-inlinetask-function
- ;; todo.
- (and (plist-get info :with-todo-keywords)
- (let ((todo (org-element-property
- :todo-keyword inlinetask)))
- (and todo (org-export-data todo info))))
- ;; todo-type
- (org-element-property :todo-type inlinetask)
- ;; priority
- (and (plist-get info :with-priority)
- (org-element-property :priority inlinetask))
- ;; title
- (org-export-data (org-element-property :title inlinetask) info)
- ;; tags
- (and (plist-get info :with-tags)
- (org-element-property :tags inlinetask))
- ;; contents and width
- contents width)
- ;; Otherwise, use a default template.
- (let* ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
- (org-ascii--indent-string
- (concat
- ;; Top line, with an additional blank line if not in UTF-8.
- (make-string width (if utf8p ?━ ?_)) "\n"
- (unless utf8p (concat (make-string width ? ) "\n"))
- ;; Add title. Fill it if wider than inlinetask.
- (let ((title (org-ascii--build-title inlinetask info width)))
- (if (<= (length title) width) title
- (org-ascii--fill-string title width info)))
- "\n"
- ;; If CONTENTS is not empty, insert it along with
- ;; a separator.
- (when (org-string-nw-p contents)
- (concat (make-string width (if utf8p ?─ ?-)) "\n" contents))
- ;; Bottom line.
- (make-string width (if utf8p ?━ ?_)))
- ;; Flush the inlinetask to the right.
- (- org-ascii-text-width org-ascii-global-margin
- (if (not (org-export-get-parent-headline inlinetask)) 0
- org-ascii-inner-margin)
- (org-ascii--current-text-width inlinetask info)))))))
+ (funcall org-ascii-format-inlinetask-function
+ ;; todo.
+ (and (plist-get info :with-todo-keywords)
+ (let ((todo (org-element-property
+ :todo-keyword inlinetask)))
+ (and todo (org-export-data todo info))))
+ ;; todo-type
+ (org-element-property :todo-type inlinetask)
+ ;; priority
+ (and (plist-get info :with-priority)
+ (org-element-property :priority inlinetask))
+ ;; title
+ (org-export-data (org-element-property :title inlinetask) info)
+ ;; tags
+ (and (plist-get info :with-tags)
+ (org-element-property :tags inlinetask))
+ ;; contents and width
+ contents width inlinetask info)))
;;;; Italic