diff options
Diffstat (limited to 'lisp/org/org-ascii.el')
-rw-r--r-- | lisp/org/org-ascii.el | 106 |
1 files changed, 94 insertions, 12 deletions
diff --git a/lisp/org/org-ascii.el b/lisp/org/org-ascii.el index 13603ce5134..3d86e7a5230 100644 --- a/lisp/org/org-ascii.el +++ b/lisp/org/org-ascii.el @@ -6,7 +6,7 @@ ;; Author: Carsten Dominik <carsten at orgmode dot org> ;; Keywords: outlines, hypermedia, calendar, wp ;; Homepage: http://orgmode.org -;; Version: 6.33x +;; Version: 6.35i ;; ;; This file is part of GNU Emacs. ;; @@ -52,19 +52,34 @@ Org-mode file." :type '(repeat character)) (defcustom org-export-ascii-links-to-notes t - "Non-nil means, convert links to notes before the next headline. + "Non-nil means convert links to notes before the next headline. When nil, the link will be exported in place. If the line becomes long in this way, it will be wrapped." :group 'org-export-ascii :type 'boolean) (defcustom org-export-ascii-table-keep-all-vertical-lines nil - "Non-nil means, keep all vertical lines in ASCII tables. + "Non-nil means keep all vertical lines in ASCII tables. When nil, vertical lines will be removed except for those needed for column grouping." :group 'org-export-ascii :type 'boolean) +(defcustom org-export-ascii-table-widen-columns t + "Non-nil means widen narrowed columns for export. +When nil, narrowed columns will look in ASCII export just like in org-mode, +i.e. with \"=>\" as ellipsis." + :group 'org-export-ascii + :type 'boolean) + +(defvar org-export-ascii-entities 'ascii + "The ascii representation to be used during ascii export. +Possible values are: + +ascii Only use plain ASCII characters +latin1 Include Latin-1 character +utf8 Use all UTF-8 characters") + ;;; Hooks (defvar org-export-ascii-final-hook nil @@ -75,6 +90,41 @@ for column grouping." (defvar org-ascii-current-indentation nil) ; For communication ;;;###autoload +(defun org-export-as-latin1 (&rest args) + "Like `org-export-as-ascii', use latin1 encoding for special symbols." + (interactive) + (org-export-as-encoding 'org-export-as-ascii (interactive-p) + 'latin1 args)) + +;;;###autoload +(defun org-export-as-latin1-to-buffer (&rest args) + "Like `org-export-as-ascii-to-buffer', use latin1 encoding for symbols." + (interactive) + (org-export-as-encoding 'org-export-as-ascii-to-buffer (interactive-p) + 'latin1 args)) + +;;;###autoload +(defun org-export-as-utf8 (&rest args) + "Like `org-export-as-ascii', use use encoding for special symbols." + (interactive) + (org-export-as-encoding 'org-export-as-ascii (interactive-p) + 'utf8 args)) + +;;;###autoload +(defun org-export-as-utf8-to-buffer (&rest args) + "Like `org-export-as-ascii-to-buffer', use utf8 encoding for symbols." + (interactive) + (org-export-as-encoding 'org-export-as-ascii-to-buffer (interactive-p) + 'utf8 args)) + +(defun org-export-as-encoding (command interactivep encoding &rest args) + (let ((org-export-ascii-entities encoding)) + (if interactivep + (call-interactively command) + (apply command args)))) + + +;;;###autoload (defun org-export-as-ascii-to-buffer (arg) "Call `org-export-as-ascii` with output to a temporary buffer. No file is created. The prefix ARG is passed through to `org-export-as-ascii'." @@ -156,6 +206,7 @@ resulting ASCII as a string. When BODY-ONLY is set, don't produce the file header and footer. When PUB-DIR is set, use this as the publishing directory." (interactive "P") + (run-hooks 'org-export-first-hook) (setq-default org-todo-line-regexp org-todo-line-regexp) (let* ((opt-plist (org-combine-plists (org-default-export-plist) ext-plist @@ -181,6 +232,11 @@ publishing directory." (if subtree-p (org-export-add-subtree-options opt-plist rbeg) opt-plist))) + ;; The following two are dynamically scoped into other + ;; routines below. + (org-current-export-dir + (or pub-dir (org-export-directory :html opt-plist))) + (org-current-export-file buffer-file-name) (custom-times org-display-custom-times) (org-ascii-current-indentation '(0 . 0)) (level 0) line txt @@ -219,8 +275,10 @@ publishing directory." (and (not (plist-get opt-plist :skip-before-1st-heading)) (org-export-grab-title-from-buffer)) - (file-name-sans-extension - (file-name-nondirectory bfname)))) + (and (buffer-file-name) + (file-name-sans-extension + (file-name-nondirectory bfname))) + "UNTITLED")) (email (plist-get opt-plist :email)) (language (plist-get opt-plist :language)) (quote-re0 (concat "^[ \t]*" org-quote-string "\\>")) @@ -287,7 +345,9 @@ publishing directory." (if (and (or author email) org-export-author-info) (insert(concat (nth 1 lang-words) ": " (or author "") - (if email (concat " <" email ">") "") + (if (and org-export-email-info + email (string-match "\\S-" email)) + (concat " <" email ">") "") "\n"))) (cond @@ -482,18 +542,31 @@ publishing directory." (defun org-export-ascii-preprocess (parameters) "Do extra work for ASCII export" + ;; + ;; Realign tables to get rid of narrowing + (when org-export-ascii-table-widen-columns + (let ((org-table-do-narrow nil)) + (goto-char (point-min)) + (org-ascii-replace-entities) + (goto-char (point-min)) + (org-table-map-tables + (lambda () + (org-if-unprotected + (org-table-align)))))) ;; Put quotes around verbatim text (goto-char (point-min)) (while (re-search-forward org-verbatim-re nil t) - (goto-char (match-end 2)) - (backward-delete-char 1) (insert "'") - (goto-char (match-beginning 2)) - (delete-char 1) (insert "`") - (goto-char (match-end 2))) + (org-if-unprotected-at (match-beginning 4) + (goto-char (match-end 2)) + (backward-delete-char 1) (insert "'") + (goto-char (match-beginning 2)) + (delete-char 1) (insert "`") + (goto-char (match-end 2)))) ;; Remove target markers (goto-char (point-min)) (while (re-search-forward "<<<?\\([^<>]*\\)>>>?\\([ \t]*\\)" nil t) - (replace-match "\\1\\2"))) + (org-if-unprotected-at (match-beginning 1) + (replace-match "\\1\\2")))) (defun org-html-expand-for-ascii (line) "Handle quoted HTML for ASCII export." @@ -503,6 +576,15 @@ publishing directory." (setq line (replace-match "" nil nil line)))) line) +(defun org-ascii-replace-entities () + "Replace entities with the ASCII representation." + (let (e) + (while (re-search-forward "\\\\\\([a-zA-Z]+[0-9]*\\)" nil t) + (org-if-unprotected-at (match-beginning 1) + (setq e (org-entity-get-representation (match-string 1) + org-export-ascii-entities)) + (and e (replace-match e t t)))))) + (defun org-export-ascii-wrap (line where) "Wrap LINE at or before WHERE." (let ((ind (org-get-indentation line)) |