2009-04-07 13:08:24 -04:00
|
|
|
;;; org-ascii.el --- ASCII export for Org-mode
|
2009-04-07 12:40:16 -04:00
|
|
|
|
2012-04-01 18:53:28 -04:00
|
|
|
;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
|
2009-04-07 12:40:16 -04:00
|
|
|
|
|
|
|
;; Author: Carsten Dominik <carsten at orgmode dot org>
|
|
|
|
;; Keywords: outlines, hypermedia, calendar, wp
|
|
|
|
;; Homepage: http://orgmode.org
|
|
|
|
;;
|
|
|
|
;; 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
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;
|
|
|
|
;;; Commentary:
|
|
|
|
|
2010-07-15 16:26:51 -04:00
|
|
|
;;; Code:
|
|
|
|
|
2009-04-07 12:40:16 -04:00
|
|
|
(require 'org-exp)
|
2010-07-15 16:26:51 -04:00
|
|
|
|
2009-09-17 12:54:52 -04:00
|
|
|
(eval-when-compile
|
|
|
|
(require 'cl))
|
2009-04-07 12:40:16 -04:00
|
|
|
|
|
|
|
(defgroup org-export-ascii nil
|
|
|
|
"Options specific for ASCII export of Org-mode files."
|
|
|
|
:tag "Org Export ASCII"
|
|
|
|
:group 'org-export)
|
|
|
|
|
2012-04-11 02:49:49 -04:00
|
|
|
(defcustom org-export-ascii-underline '(?\= ?\- ?\~ ?\^ ?\. ?\# ?\$)
|
2009-04-07 12:40:16 -04:00
|
|
|
"Characters for underlining headings in ASCII export.
|
|
|
|
In the given sequence, these characters will be used for level 1, 2, ..."
|
|
|
|
:group 'org-export-ascii
|
|
|
|
:type '(repeat character))
|
|
|
|
|
|
|
|
(defcustom org-export-ascii-bullets '(?* ?+ ?-)
|
|
|
|
"Bullet characters for headlines converted to lists in ASCII export.
|
|
|
|
The first character is used for the first lest level generated in this
|
|
|
|
way, and so on. If there are more levels than characters given here,
|
|
|
|
the list will be repeated.
|
|
|
|
Note that plain lists will keep the same bullets as the have in the
|
|
|
|
Org-mode file."
|
|
|
|
:group 'org-export-ascii
|
|
|
|
:type '(repeat character))
|
|
|
|
|
|
|
|
(defcustom org-export-ascii-links-to-notes t
|
2010-01-21 10:15:40 -05:00
|
|
|
"Non-nil means convert links to notes before the next headline.
|
2009-04-07 12:40:16 -04:00
|
|
|
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)
|
|
|
|
|
2009-10-23 06:35:24 -04:00
|
|
|
(defcustom org-export-ascii-table-keep-all-vertical-lines nil
|
2010-01-21 10:15:40 -05:00
|
|
|
"Non-nil means keep all vertical lines in ASCII tables.
|
2009-10-23 06:35:24 -04:00
|
|
|
When nil, vertical lines will be removed except for those needed
|
|
|
|
for column grouping."
|
|
|
|
:group 'org-export-ascii
|
|
|
|
:type 'boolean)
|
|
|
|
|
2010-02-12 12:48:16 -05:00
|
|
|
(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)
|
|
|
|
|
2010-03-29 09:10:56 -04:00
|
|
|
(defvar org-export-ascii-entities 'ascii
|
2010-03-28 03:48:03 -04:00
|
|
|
"The ascii representation to be used during ascii export.
|
|
|
|
Possible values are:
|
|
|
|
|
2010-03-29 09:10:56 -04:00
|
|
|
ascii Only use plain ASCII characters
|
|
|
|
latin1 Include Latin-1 character
|
|
|
|
utf8 Use all UTF-8 characters")
|
|
|
|
|
2009-09-29 01:07:36 -04:00
|
|
|
;;; Hooks
|
|
|
|
|
|
|
|
(defvar org-export-ascii-final-hook nil
|
|
|
|
"Hook run at the end of ASCII export, in the new buffer.")
|
|
|
|
|
2009-04-07 12:40:16 -04:00
|
|
|
;;; ASCII export
|
|
|
|
|
|
|
|
(defvar org-ascii-current-indentation nil) ; For communication
|
|
|
|
|
2010-03-29 09:10:56 -04:00
|
|
|
;;;###autoload
|
|
|
|
(defun org-export-as-latin1 (&rest args)
|
|
|
|
"Like `org-export-as-ascii', use latin1 encoding for special symbols."
|
|
|
|
(interactive)
|
2011-06-29 18:25:09 -04:00
|
|
|
(org-export-as-encoding 'org-export-as-ascii (org-called-interactively-p 'any)
|
2010-03-29 09:10:56 -04:00
|
|
|
'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)
|
2011-06-29 18:25:09 -04:00
|
|
|
(org-export-as-encoding 'org-export-as-ascii-to-buffer
|
|
|
|
(org-called-interactively-p 'any) 'latin1 args))
|
2010-03-29 09:10:56 -04:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun org-export-as-utf8 (&rest args)
|
2011-07-08 05:56:24 -04:00
|
|
|
"Like `org-export-as-ascii', use encoding for special symbols."
|
2010-03-29 09:10:56 -04:00
|
|
|
(interactive)
|
2012-03-27 20:05:36 -04:00
|
|
|
(org-export-as-encoding 'org-export-as-ascii
|
2011-07-08 05:56:24 -04:00
|
|
|
(org-called-interactively-p 'any)
|
2010-03-29 09:10:56 -04:00
|
|
|
'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)
|
2011-06-29 18:25:09 -04:00
|
|
|
(org-export-as-encoding 'org-export-as-ascii-to-buffer
|
|
|
|
(org-called-interactively-p 'any) 'utf8 args))
|
2010-03-29 09:10:56 -04:00
|
|
|
|
|
|
|
(defun org-export-as-encoding (command interactivep encoding &rest args)
|
|
|
|
(let ((org-export-ascii-entities encoding))
|
|
|
|
(if interactivep
|
|
|
|
(call-interactively command)
|
|
|
|
(apply command args))))
|
2010-04-01 07:11:54 -04:00
|
|
|
|
2010-03-29 09:10:56 -04:00
|
|
|
|
2009-04-07 12:40:16 -04:00
|
|
|
;;;###autoload
|
2009-05-04 12:26:42 -04:00
|
|
|
(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'."
|
|
|
|
(interactive "P")
|
|
|
|
(org-export-as-ascii arg nil nil "*Org ASCII Export*")
|
2009-05-21 03:14:33 -04:00
|
|
|
(when org-export-show-temporary-export-buffer
|
|
|
|
(switch-to-buffer-other-window "*Org ASCII Export*")))
|
2009-05-04 12:26:42 -04:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun org-replace-region-by-ascii (beg end)
|
|
|
|
"Assume the current region has org-mode syntax, and convert it to plain ASCII.
|
|
|
|
This can be used in any buffer. For example, you could write an
|
|
|
|
itemized list in org-mode syntax in a Mail buffer and then use this
|
|
|
|
command to convert it."
|
|
|
|
(interactive "r")
|
|
|
|
(let (reg ascii buf pop-up-frames)
|
|
|
|
(save-window-excursion
|
Use (derived-mode-p 'org-mode) instead of (eq major-mode 'org-mode).
* org.el (org-show-hierarchy-above, org-cycle)
(org-global-cycle, org-files-list, org-store-link)
(org-link-search, org-open-file, org-display-outline-path)
(org-refile-get-location, org-update-all-dblocks)
(org-change-tag-in-region, org-entry-properties)
(org-save-all-org-buffers, org-revert-all-org-buffers)
(org-buffer-list, org-cdlatex-mode)
(org-install-agenda-files-menu, org-end-of-subtree)
(org-speedbar-set-agenda-restriction): Use (derived-mode-p
'org-mode) instead of (eq major-mode 'org-mode).
* org-timer.el (org-timer-set-timer): Ditto.
* org-table.el (orgtbl-mode, org-table-align, orgtbl-mode): Ditto.
* org-src.el (org-edit-src-exit, org-edit-src-code)
(org-edit-fixed-width-region, org-edit-src-exit): Ditto.
* org-remember.el (org-remember-handler): Ditto.
* org-mouse.el (dnd-open-file, org-mouse-insert-item): Ditto.
* org-macs.el (org-get-limited-outline-regexp): Ditto.
* org-lparse.el (org-replace-region-by): Ditto.
* org-latex.el (org-latex-to-pdf-process)
(org-replace-region-by-latex): Ditto.
* org-indent.el (org-indent-indent-buffer): Ditto.
* org-id.el (org-id-store-link, org-id-update-id-locations)
(org-id-store-link): Ditto.
* org-html.el (org-export-html-preprocess)
(org-replace-region-by-html): Ditto.
* org-footnote.el (org-footnote-normalize)
(org-footnote-goto-definition)
(org-footnote-create-definition, org-footnote-normalize): Ditto.
* org-docbook.el (org-replace-region-by-docbook): Ditto.
* org-ctags.el (find-tag): Ditto.
* org-colview.el (org-columns-redo)
(org-columns-display-here, org-columns-edit-value)
(org-columns-redo): Ditto.
* org-colview-xemacs.el (org-columns-redo)
(org-columns-display-here, org-columns-edit-value)
(org-columns-redo): Ditto.
* org-capture.el (org-capture-insert-template-here)
(org-capture, org-capture-finalize)
(org-capture-set-target-location)
(org-capture-insert-template-here): Ditto.
* org-ascii.el (org-replace-region-by-ascii): Ditto.
* org-archive.el (org-archive-subtree): Ditto.
* org-agenda.el (org-agenda)
(org-agenda-get-restriction-and-command)
(org-agenda-get-some-entry-text, org-search-view)
(org-tags-view, org-agenda-get-day-entries)
(org-agenda-format-item, org-agenda-goto, org-agenda-kill)
(org-agenda-archive-with, org-agenda-switch-to): Ditto.
2012-04-20 14:03:45 -04:00
|
|
|
(if (derived-mode-p 'org-mode)
|
2009-05-04 12:26:42 -04:00
|
|
|
(setq ascii (org-export-region-as-ascii
|
2012-08-11 13:10:44 -04:00
|
|
|
beg end t 'string))
|
2009-05-04 12:26:42 -04:00
|
|
|
(setq reg (buffer-substring beg end)
|
|
|
|
buf (get-buffer-create "*Org tmp*"))
|
|
|
|
(with-current-buffer buf
|
|
|
|
(erase-buffer)
|
|
|
|
(insert reg)
|
|
|
|
(org-mode)
|
|
|
|
(setq ascii (org-export-region-as-ascii
|
2012-08-11 13:10:44 -04:00
|
|
|
(point-min) (point-max) t 'string)))
|
2009-05-04 12:26:42 -04:00
|
|
|
(kill-buffer buf)))
|
|
|
|
(delete-region beg end)
|
|
|
|
(insert ascii)))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun org-export-region-as-ascii (beg end &optional body-only buffer)
|
|
|
|
"Convert region from BEG to END in org-mode buffer to plain ASCII.
|
|
|
|
If prefix arg BODY-ONLY is set, omit file header, footer, and table of
|
|
|
|
contents, and only produce the region of converted text, useful for
|
|
|
|
cut-and-paste operations.
|
|
|
|
If BUFFER is a buffer or a string, use/create that buffer as a target
|
|
|
|
of the converted ASCII. If BUFFER is the symbol `string', return the
|
|
|
|
produced ASCII as a string and leave not buffer behind. For example,
|
|
|
|
a Lisp program could call this function in the following way:
|
|
|
|
|
|
|
|
(setq ascii (org-export-region-as-ascii beg end t 'string))
|
|
|
|
|
|
|
|
When called interactively, the output buffer is selected, and shown
|
|
|
|
in a window. A non-interactive call will only return the buffer."
|
|
|
|
(interactive "r\nP")
|
2011-06-29 18:25:09 -04:00
|
|
|
(when (org-called-interactively-p 'any)
|
2009-05-04 12:26:42 -04:00
|
|
|
(setq buffer "*Org ASCII Export*"))
|
|
|
|
(let ((transient-mark-mode t) (zmacs-regions t)
|
|
|
|
ext-plist rtn)
|
2009-11-12 11:50:31 -05:00
|
|
|
(setq ext-plist (plist-put ext-plist :ignore-subtree-p t))
|
2009-05-04 12:26:42 -04:00
|
|
|
(goto-char end)
|
|
|
|
(set-mark (point)) ;; to activate the region
|
|
|
|
(goto-char beg)
|
|
|
|
(setq rtn (org-export-as-ascii
|
|
|
|
nil nil ext-plist
|
|
|
|
buffer body-only))
|
|
|
|
(if (fboundp 'deactivate-mark) (deactivate-mark))
|
2011-06-29 18:25:09 -04:00
|
|
|
(if (and (org-called-interactively-p 'any) (bufferp rtn))
|
2009-05-04 12:26:42 -04:00
|
|
|
(switch-to-buffer-other-window rtn)
|
|
|
|
rtn)))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun org-export-as-ascii (arg &optional hidden ext-plist
|
2012-08-11 13:10:44 -04:00
|
|
|
to-buffer body-only pub-dir)
|
2009-04-07 12:40:16 -04:00
|
|
|
"Export the outline as a pretty ASCII file.
|
|
|
|
If there is an active region, export only the region.
|
|
|
|
The prefix ARG specifies how many levels of the outline should become
|
2009-05-04 12:26:42 -04:00
|
|
|
underlined headlines, default is 3. Lower levels will become bulleted
|
|
|
|
lists. When HIDDEN is non-nil, don't display the ASCII buffer.
|
|
|
|
EXT-PLIST is a property list with external parameters overriding
|
|
|
|
org-mode's default settings, but still inferior to file-local
|
|
|
|
settings. When TO-BUFFER is non-nil, create a buffer with that
|
|
|
|
name and export to that buffer. If TO-BUFFER is the symbol
|
|
|
|
`string', don't leave any buffer behind but just return the
|
|
|
|
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."
|
2009-04-07 12:40:16 -04:00
|
|
|
(interactive "P")
|
2009-12-11 02:40:19 -05:00
|
|
|
(run-hooks 'org-export-first-hook)
|
2009-04-07 12:40:16 -04:00
|
|
|
(setq-default org-todo-line-regexp org-todo-line-regexp)
|
|
|
|
(let* ((opt-plist (org-combine-plists (org-default-export-plist)
|
2009-05-04 12:26:42 -04:00
|
|
|
ext-plist
|
2009-04-07 12:40:16 -04:00
|
|
|
(org-infile-export-plist)))
|
|
|
|
(region-p (org-region-active-p))
|
|
|
|
(rbeg (and region-p (region-beginning)))
|
|
|
|
(rend (and region-p (region-end)))
|
|
|
|
(subtree-p
|
2009-11-12 11:50:31 -05:00
|
|
|
(if (plist-get opt-plist :ignore-subtree-p)
|
2009-05-04 12:26:42 -04:00
|
|
|
nil
|
|
|
|
(when region-p
|
|
|
|
(save-excursion
|
|
|
|
(goto-char rbeg)
|
|
|
|
(and (org-at-heading-p)
|
|
|
|
(>= (org-end-of-subtree t t) rend))))))
|
2009-04-07 12:40:16 -04:00
|
|
|
(level-offset (if subtree-p
|
|
|
|
(save-excursion
|
|
|
|
(goto-char rbeg)
|
|
|
|
(+ (funcall outline-level)
|
|
|
|
(if org-odd-levels-only 1 0)))
|
|
|
|
0))
|
|
|
|
(opt-plist (setq org-export-opt-plist
|
|
|
|
(if subtree-p
|
|
|
|
(org-export-add-subtree-options opt-plist rbeg)
|
|
|
|
opt-plist)))
|
2010-02-25 01:31:29 -05:00
|
|
|
;; 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)
|
2009-04-07 12:40:16 -04:00
|
|
|
(custom-times org-display-custom-times)
|
|
|
|
(org-ascii-current-indentation '(0 . 0))
|
|
|
|
(level 0) line txt
|
|
|
|
(umax nil)
|
|
|
|
(umax-toc nil)
|
|
|
|
(case-fold-search nil)
|
|
|
|
(bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
|
2009-05-04 12:26:42 -04:00
|
|
|
(filename (if to-buffer
|
|
|
|
nil
|
|
|
|
(concat (file-name-as-directory
|
|
|
|
(or pub-dir
|
|
|
|
(org-export-directory :ascii opt-plist)))
|
|
|
|
(file-name-sans-extension
|
|
|
|
(or (and subtree-p
|
|
|
|
(org-entry-get (region-beginning)
|
|
|
|
"EXPORT_FILE_NAME" t))
|
|
|
|
(file-name-nondirectory bfname)))
|
|
|
|
".txt")))
|
|
|
|
(filename (and filename
|
|
|
|
(if (equal (file-truename filename)
|
|
|
|
(file-truename bfname))
|
|
|
|
(concat filename ".txt")
|
|
|
|
filename)))
|
|
|
|
(buffer (if to-buffer
|
|
|
|
(cond
|
|
|
|
((eq to-buffer 'string)
|
|
|
|
(get-buffer-create "*Org ASCII Export*"))
|
|
|
|
(t (get-buffer-create to-buffer)))
|
|
|
|
(find-file-noselect filename)))
|
2009-04-07 12:40:16 -04:00
|
|
|
(org-levels-open (make-vector org-level-max nil))
|
|
|
|
(odd org-odd-levels-only)
|
|
|
|
(date (plist-get opt-plist :date))
|
2009-05-04 12:26:42 -04:00
|
|
|
(author (plist-get opt-plist :author))
|
|
|
|
(title (or (and subtree-p (org-export-get-title-from-subtree))
|
|
|
|
(plist-get opt-plist :title)
|
|
|
|
(and (not
|
|
|
|
(plist-get opt-plist :skip-before-1st-heading))
|
|
|
|
(org-export-grab-title-from-buffer))
|
2010-03-25 03:36:37 -04:00
|
|
|
(and (buffer-file-name)
|
|
|
|
(file-name-sans-extension
|
|
|
|
(file-name-nondirectory bfname)))
|
|
|
|
"UNTITLED"))
|
2009-05-04 12:26:42 -04:00
|
|
|
(email (plist-get opt-plist :email))
|
|
|
|
(language (plist-get opt-plist :language))
|
2011-08-24 19:58:29 -04:00
|
|
|
(quote-re0 (concat "^\\(" org-quote-string "\\)\\( +\\|[ \t]*$\\)"))
|
2009-04-07 12:40:16 -04:00
|
|
|
(todo nil)
|
|
|
|
(lang-words nil)
|
|
|
|
(region
|
|
|
|
(buffer-substring
|
|
|
|
(if (org-region-active-p) (region-beginning) (point-min))
|
|
|
|
(if (org-region-active-p) (region-end) (point-max))))
|
2011-06-26 12:51:28 -04:00
|
|
|
(org-export-footnotes-seen nil)
|
2011-05-11 12:02:15 -04:00
|
|
|
(org-export-footnotes-data (org-footnote-all-labels 'with-defs))
|
2009-04-07 12:40:16 -04:00
|
|
|
(lines (org-split-string
|
|
|
|
(org-export-preprocess-string
|
|
|
|
region
|
2011-02-15 05:07:46 -05:00
|
|
|
:for-backend 'ascii
|
2009-04-07 12:40:16 -04:00
|
|
|
:skip-before-1st-heading
|
|
|
|
(plist-get opt-plist :skip-before-1st-heading)
|
|
|
|
:drawers (plist-get opt-plist :drawers)
|
|
|
|
:tags (plist-get opt-plist :tags)
|
|
|
|
:priority (plist-get opt-plist :priority)
|
|
|
|
:footnotes (plist-get opt-plist :footnotes)
|
|
|
|
:timestamps (plist-get opt-plist :timestamps)
|
|
|
|
:todo-keywords (plist-get opt-plist :todo-keywords)
|
2011-03-29 18:48:29 -04:00
|
|
|
:tasks (plist-get opt-plist :tasks)
|
2009-04-07 12:40:16 -04:00
|
|
|
:verbatim-multiline t
|
|
|
|
:select-tags (plist-get opt-plist :select-tags)
|
|
|
|
:exclude-tags (plist-get opt-plist :exclude-tags)
|
|
|
|
:archived-trees
|
|
|
|
(plist-get opt-plist :archived-trees)
|
|
|
|
:add-text (plist-get opt-plist :text))
|
|
|
|
"\n"))
|
|
|
|
thetoc have-headings first-heading-pos
|
2010-09-07 14:04:35 -04:00
|
|
|
table-open table-buffer link-buffer link type path desc desc0 rpl wrap fnc)
|
2009-04-07 12:40:16 -04:00
|
|
|
(let ((inhibit-read-only t))
|
|
|
|
(org-unmodified
|
|
|
|
(remove-text-properties (point-min) (point-max)
|
|
|
|
'(:org-license-to-kill t))))
|
|
|
|
|
|
|
|
(setq org-min-level (org-get-min-level lines level-offset))
|
|
|
|
(setq org-last-level org-min-level)
|
|
|
|
(org-init-section-numbers)
|
|
|
|
(setq lang-words (or (assoc language org-export-language-setup)
|
|
|
|
(assoc "en" org-export-language-setup)))
|
2009-05-19 02:12:56 -04:00
|
|
|
(set-buffer buffer)
|
2009-04-07 12:40:16 -04:00
|
|
|
(erase-buffer)
|
|
|
|
(fundamental-mode)
|
2009-07-06 11:00:03 -04:00
|
|
|
(org-install-letbind)
|
2009-04-07 12:40:16 -04:00
|
|
|
;; create local variables for all options, to make sure all called
|
|
|
|
;; functions get the correct information
|
|
|
|
(mapc (lambda (x)
|
|
|
|
(set (make-local-variable (nth 2 x))
|
|
|
|
(plist-get opt-plist (car x))))
|
|
|
|
org-export-plist-vars)
|
|
|
|
(org-set-local 'org-odd-levels-only odd)
|
|
|
|
(setq umax (if arg (prefix-numeric-value arg)
|
|
|
|
org-export-headline-levels))
|
|
|
|
(setq umax-toc (if (integerp org-export-with-toc)
|
|
|
|
(min org-export-with-toc umax)
|
|
|
|
umax))
|
|
|
|
|
|
|
|
;; File header
|
2009-05-04 12:26:42 -04:00
|
|
|
(unless body-only
|
2009-08-09 07:20:50 -04:00
|
|
|
(when (and title (not (string= "" title)))
|
|
|
|
(org-insert-centered title ?=)
|
|
|
|
(insert "\n"))
|
|
|
|
|
2009-05-04 12:26:42 -04:00
|
|
|
(if (and (or author email)
|
|
|
|
org-export-author-info)
|
2010-09-06 07:14:36 -04:00
|
|
|
(insert (concat (nth 1 lang-words) ": " (or author "")
|
2010-03-26 02:59:10 -04:00
|
|
|
(if (and org-export-email-info
|
|
|
|
email (string-match "\\S-" email))
|
|
|
|
(concat " <" email ">") "")
|
2009-05-04 12:26:42 -04:00
|
|
|
"\n")))
|
|
|
|
|
|
|
|
(cond
|
|
|
|
((and date (string-match "%" date))
|
|
|
|
(setq date (format-time-string date)))
|
|
|
|
(date)
|
|
|
|
(t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
|
2009-06-08 02:00:46 -04:00
|
|
|
|
2009-05-04 12:26:42 -04:00
|
|
|
(if (and date org-export-time-stamp-file)
|
|
|
|
(insert (concat (nth 2 lang-words) ": " date"\n")))
|
2009-06-08 02:00:46 -04:00
|
|
|
|
2009-08-09 07:20:50 -04:00
|
|
|
(unless (= (point) (point-min))
|
|
|
|
(insert "\n\n")))
|
2009-05-04 12:26:42 -04:00
|
|
|
|
|
|
|
(if (and org-export-with-toc (not body-only))
|
2009-04-07 12:40:16 -04:00
|
|
|
(progn
|
|
|
|
(push (concat (nth 3 lang-words) "\n") thetoc)
|
|
|
|
(push (concat (make-string (string-width (nth 3 lang-words)) ?=)
|
|
|
|
"\n") thetoc)
|
2011-06-14 15:01:04 -04:00
|
|
|
(mapc #'(lambda (line)
|
2012-08-11 13:10:44 -04:00
|
|
|
(if (string-match org-todo-line-regexp
|
|
|
|
line)
|
|
|
|
;; This is a headline
|
|
|
|
(progn
|
|
|
|
(setq have-headings t)
|
|
|
|
(setq level (- (match-end 1) (match-beginning 1)
|
|
|
|
level-offset)
|
|
|
|
level (org-tr-level level)
|
|
|
|
txt (match-string 3 line)
|
|
|
|
todo
|
|
|
|
(or (and org-export-mark-todo-in-toc
|
|
|
|
(match-beginning 2)
|
|
|
|
(not (member (match-string 2 line)
|
|
|
|
org-done-keywords)))
|
2009-04-07 12:40:16 -04:00
|
|
|
; TODO, not DONE
|
2012-08-11 13:10:44 -04:00
|
|
|
(and org-export-mark-todo-in-toc
|
|
|
|
(= level umax-toc)
|
|
|
|
(org-search-todo-below
|
|
|
|
line lines level))))
|
|
|
|
(setq txt (org-html-expand-for-ascii txt))
|
|
|
|
|
|
|
|
(while (string-match org-bracket-link-regexp txt)
|
|
|
|
(setq txt
|
|
|
|
(replace-match
|
|
|
|
(match-string (if (match-end 2) 3 1) txt)
|
|
|
|
t t txt)))
|
|
|
|
|
|
|
|
(if (and (memq org-export-with-tags '(not-in-toc nil))
|
|
|
|
(string-match
|
|
|
|
(org-re "[ \t]+:[[:alnum:]_@#%:]+:[ \t]*$")
|
|
|
|
txt))
|
|
|
|
(setq txt (replace-match "" t t txt)))
|
|
|
|
(if (string-match quote-re0 txt)
|
|
|
|
(setq txt (replace-match "" t t txt 1)))
|
|
|
|
|
|
|
|
(if org-export-with-section-numbers
|
|
|
|
(setq txt (concat (org-section-number level)
|
|
|
|
" " txt)))
|
|
|
|
(if (<= level umax-toc)
|
|
|
|
(progn
|
|
|
|
(push
|
|
|
|
(concat
|
|
|
|
(make-string
|
|
|
|
(* (max 0 (- level org-min-level)) 4) ?\ )
|
|
|
|
(format (if todo "%s (*)\n" "%s\n") txt))
|
|
|
|
thetoc)
|
|
|
|
(setq org-last-level level))
|
|
|
|
))))
|
2009-04-07 12:40:16 -04:00
|
|
|
lines)
|
|
|
|
(setq thetoc (if have-headings (nreverse thetoc) nil))))
|
|
|
|
|
|
|
|
(org-init-section-numbers)
|
|
|
|
(while (setq line (pop lines))
|
Don't use `outline-regexp' anymore.
Use `org-outline-regexp' instead or `outline-regexp'. Also use the
new defconst `org-outline-regexp-bol' to match `org-outline-regexp'
at the beginning of line.
* org.el (org-outline-regexp-bol): New defconst.
(org-outline-level, org-set-font-lock-defaults, org-cycle)
(org-overview, org-content, org-flag-drawer)
(org-first-headline-recenter, org-insert-todo-heading)
(org-map-region, org-move-subtree-down, org-paste-subtree)
(org-kill-is-subtree-p, org-context-p, org-refile)
(org-refile-new-child, org-toggle-comment, org-todo)
(org-add-planning-info, org-add-log-setup, org-scan-tags)
(org-set-tags, org-insert-property-drawer)
(org-prepare-agenda-buffers, org-preview-latex-fragment)
(org-speed-command-default-hook, org-check-for-hidden)
(org-toggle-item, org-toggle-heading)
(org-indent-line-function, org-set-autofill-regexps)
(org-fill-paragraph, org-toggle-fixed-width-section)
(org-yank-generic, org-yank-folding-would-swallow-text)
(org-first-sibling-p, org-goto-sibling)
(org-goto-first-child, org-show-entry): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
* org-remember.el (org-remember-handler): Use
`org-outline-regexp-bol'.
* org-mouse.el (org-mouse-match-todo-keyword, org-mode-hook)
(org-mouse-move-tree, org-mouse-transform-to-outline): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
* org-macs.el (org-with-limited-levels)
(org-get-limited-outline-regexp): Use `org-outline-regexp'.
* org-indent.el (org-indent-outline-re)
(org-indent-refresh-section, org-indent-refresh-to): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
* org-html.el (org-export-as-html): Use
`org-outline-regexp-bol'.
* org-footnote.el (org-footnote-at-definition-p)
(org-footnote-normalize): Use `org-outline-regexp' and
`org-outline-regexp-bol'.
* org-exp.el (org-export-preprocess-string): Don't redefine
`outline-regexp'.
* org-docbook.el (org-export-as-docbook): Use
`org-outline-regexp-bol'.
* org-colview.el (org-columns, org-columns-compute): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
* org-colview-xemacs.el (org-columns, org-columns-compute):
Use `org-outline-regexp-bol'.
* org-clock.el (org-clock-insert-selection-line)
(org-clock-in, org-clock-out, org-dblock-write:clocktable):
Use `org-outline-regexp' and `org-outline-regexp-bol'.
* org-ascii.el (org-export-as-ascii)
(org-export-ascii-push-links): Use `org-outline-regexp' and
`org-outline-regexp-bol'.
* org-archive.el (org-archive-to-archive-sibling)
(org-archive-all-done): Use `org-outline-regexp' and
`org-outline-regexp-bol'.
* org-agenda.el (org-agenda, org-search-view)
(org-agenda-list-stuck-projects, org-agenda-get-timestamps)
(org-agenda-get-progress, org-agenda-get-blocks): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
2011-07-17 15:17:08 -04:00
|
|
|
(when (and link-buffer (string-match org-outline-regexp-bol line))
|
2009-04-07 12:40:16 -04:00
|
|
|
(org-export-ascii-push-links (nreverse link-buffer))
|
|
|
|
(setq link-buffer nil))
|
|
|
|
(setq wrap nil)
|
|
|
|
;; Remove the quoted HTML tags.
|
|
|
|
(setq line (org-html-expand-for-ascii line))
|
|
|
|
;; Replace links with the description when possible
|
2010-09-06 07:14:36 -04:00
|
|
|
(while (string-match org-bracket-link-analytic-regexp++ line)
|
2010-09-07 14:04:35 -04:00
|
|
|
(setq path (match-string 3 line)
|
|
|
|
link (concat (match-string 1 line) path)
|
2010-09-30 15:55:25 -04:00
|
|
|
type (match-string 2 line)
|
2010-09-06 07:14:36 -04:00
|
|
|
desc0 (match-string 5 line)
|
2012-03-27 19:44:41 -04:00
|
|
|
desc0 (replace-regexp-in-string "\\\\_" "_" desc0)
|
|
|
|
desc (or desc0 link)
|
|
|
|
desc (replace-regexp-in-string "\\\\_" "_" desc))
|
2009-04-07 12:40:16 -04:00
|
|
|
(if (and (> (length link) 8)
|
|
|
|
(equal (substring link 0 8) "coderef:"))
|
|
|
|
(setq line (replace-match
|
|
|
|
(format (org-export-get-coderef-format (substring link 8) desc)
|
|
|
|
(cdr (assoc
|
|
|
|
(substring link 8)
|
|
|
|
org-export-code-refs)))
|
|
|
|
t t line))
|
2010-09-06 07:14:36 -04:00
|
|
|
(setq rpl (concat "[" desc "]"))
|
2010-09-05 10:25:08 -04:00
|
|
|
(if (functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
|
|
|
|
(setq rpl (or (save-match-data
|
|
|
|
(funcall fnc (org-link-unescape path)
|
|
|
|
desc0 'ascii))
|
|
|
|
rpl))
|
|
|
|
(when (and desc0 (not (equal desc0 link)))
|
|
|
|
(if org-export-ascii-links-to-notes
|
|
|
|
(push (cons desc0 link) link-buffer)
|
|
|
|
(setq rpl (concat rpl " (" link ")")
|
|
|
|
wrap (+ (length line) (- (length (match-string 0 line)))
|
|
|
|
(length desc))))))
|
2009-04-07 12:40:16 -04:00
|
|
|
(setq line (replace-match rpl t t line))))
|
|
|
|
(when custom-times
|
|
|
|
(setq line (org-translate-time line)))
|
|
|
|
(cond
|
|
|
|
((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
|
|
|
|
;; a Headline
|
|
|
|
(setq first-heading-pos (or first-heading-pos (point)))
|
|
|
|
(setq level (org-tr-level (- (match-end 1) (match-beginning 1)
|
|
|
|
level-offset))
|
|
|
|
txt (match-string 2 line))
|
|
|
|
(org-ascii-level-start level txt umax lines))
|
|
|
|
|
|
|
|
((and org-export-with-tables
|
|
|
|
(string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
|
|
|
|
(if (not table-open)
|
|
|
|
;; New table starts
|
|
|
|
(setq table-open t table-buffer nil))
|
|
|
|
;; Accumulate lines
|
|
|
|
(setq table-buffer (cons line table-buffer))
|
|
|
|
(when (or (not lines)
|
|
|
|
(not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
|
|
|
|
(car lines))))
|
|
|
|
(setq table-open nil
|
|
|
|
table-buffer (nreverse table-buffer))
|
|
|
|
(insert (mapconcat
|
|
|
|
(lambda (x)
|
|
|
|
(org-fix-indentation x org-ascii-current-indentation))
|
|
|
|
(org-format-table-ascii table-buffer)
|
|
|
|
"\n") "\n")))
|
|
|
|
(t
|
2010-09-05 10:25:08 -04:00
|
|
|
(if (string-match "^\\([ \t]*\\)\\([-+*][ \t]+\\)\\(.*?\\)\\( ::\\)"
|
|
|
|
line)
|
2009-04-07 12:40:16 -04:00
|
|
|
(setq line (replace-match "\\1\\3:" t nil line)))
|
|
|
|
(setq line (org-fix-indentation line org-ascii-current-indentation))
|
|
|
|
;; Remove forced line breaks
|
|
|
|
(if (string-match "\\\\\\\\[ \t]*$" line)
|
|
|
|
(setq line (replace-match "" t t line)))
|
|
|
|
(if (and org-export-with-fixed-width
|
|
|
|
(string-match "^\\([ \t]*\\)\\(:\\( \\|$\\)\\)" line))
|
|
|
|
(setq line (replace-match "\\1" nil nil line))
|
|
|
|
(if wrap (setq line (org-export-ascii-wrap line wrap))))
|
|
|
|
(insert line "\n"))))
|
|
|
|
|
|
|
|
(org-export-ascii-push-links (nreverse link-buffer))
|
|
|
|
|
|
|
|
(normal-mode)
|
|
|
|
|
|
|
|
;; insert the table of contents
|
|
|
|
(when thetoc
|
|
|
|
(goto-char (point-min))
|
|
|
|
(if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
|
|
|
|
(progn
|
|
|
|
(goto-char (match-beginning 0))
|
|
|
|
(replace-match ""))
|
|
|
|
(goto-char first-heading-pos))
|
|
|
|
(mapc 'insert thetoc)
|
|
|
|
(or (looking-at "[ \t]*\n[ \t]*\n")
|
|
|
|
(insert "\n\n")))
|
|
|
|
|
|
|
|
;; Convert whitespace place holders
|
|
|
|
(goto-char (point-min))
|
|
|
|
(let (beg end)
|
|
|
|
(while (setq beg (next-single-property-change (point) 'org-whitespace))
|
|
|
|
(setq end (next-single-property-change beg 'org-whitespace))
|
|
|
|
(goto-char beg)
|
|
|
|
(delete-region beg end)
|
|
|
|
(insert (make-string (- end beg) ?\ ))))
|
|
|
|
|
|
|
|
;; remove display and invisible chars
|
|
|
|
(let (beg end)
|
|
|
|
(goto-char (point-min))
|
|
|
|
(while (setq beg (next-single-property-change (point) 'display))
|
|
|
|
(setq end (next-single-property-change beg 'display))
|
|
|
|
(delete-region beg end)
|
|
|
|
(goto-char beg)
|
|
|
|
(insert "=>"))
|
|
|
|
(goto-char (point-min))
|
|
|
|
(while (setq beg (next-single-property-change (point) 'org-cwidth))
|
|
|
|
(setq end (next-single-property-change beg 'org-cwidth))
|
|
|
|
(delete-region beg end)
|
|
|
|
(goto-char beg)))
|
2009-09-29 01:07:36 -04:00
|
|
|
(run-hooks 'org-export-ascii-final-hook)
|
2009-05-04 12:26:42 -04:00
|
|
|
(or to-buffer (save-buffer))
|
|
|
|
(goto-char (point-min))
|
2009-05-21 03:14:33 -04:00
|
|
|
(or (org-export-push-to-kill-ring "ASCII")
|
|
|
|
(message "Exporting... done"))
|
2009-05-19 02:12:56 -04:00
|
|
|
;; Return the buffer or a string, according to how this function was called
|
|
|
|
(if (eq to-buffer 'string)
|
|
|
|
(prog1 (buffer-substring (point-min) (point-max))
|
|
|
|
(kill-buffer (current-buffer)))
|
|
|
|
(current-buffer))))
|
2009-04-07 12:40:16 -04:00
|
|
|
|
2009-04-07 13:08:24 -04:00
|
|
|
(defun org-export-ascii-preprocess (parameters)
|
2010-07-15 16:26:51 -04:00
|
|
|
"Do extra work for ASCII export."
|
2010-02-12 12:48:16 -05:00
|
|
|
;;
|
|
|
|
;; Realign tables to get rid of narrowing
|
|
|
|
(when org-export-ascii-table-widen-columns
|
|
|
|
(let ((org-table-do-narrow nil))
|
2010-03-28 03:48:03 -04:00
|
|
|
(goto-char (point-min))
|
|
|
|
(org-ascii-replace-entities)
|
2010-02-12 12:48:16 -05:00
|
|
|
(goto-char (point-min))
|
|
|
|
(org-table-map-tables
|
2010-04-25 07:57:39 -04:00
|
|
|
(lambda () (org-if-unprotected (org-table-align)))
|
|
|
|
'quietly)))
|
2009-04-07 12:40:16 -04:00
|
|
|
;; Put quotes around verbatim text
|
|
|
|
(goto-char (point-min))
|
|
|
|
(while (re-search-forward org-verbatim-re nil t)
|
2010-01-08 03:41:16 -05:00
|
|
|
(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))))
|
2009-04-07 12:40:16 -04:00
|
|
|
;; Remove target markers
|
|
|
|
(goto-char (point-min))
|
|
|
|
(while (re-search-forward "<<<?\\([^<>]*\\)>>>?\\([ \t]*\\)" nil t)
|
2010-01-08 03:37:00 -05:00
|
|
|
(org-if-unprotected-at (match-beginning 1)
|
2010-04-26 10:35:23 -04:00
|
|
|
(replace-match "\\1\\2")))
|
|
|
|
;; Remove list start counters
|
|
|
|
(goto-char (point-min))
|
org-list: implement alphabetical lists
* lisp/org-list.el (org-alphabetical-lists): new variable
(org-item-re, org-list-full-item, org-cycle-list-bullet,
org-list-struct-fix-bul, org-list-inc-bullet-maybe): reflect
introduction of the new variable.
(org-item-beginning-re): changed into a function, so any modification
of `org-alphabetical-lists' will not require reloading Org.
(org-at-item-p, org-toggle-checkbox, org-update-checkbox-count,
org-list-parse-list, org-list-send-list): reflect changes to
`org-item-beginning-re'.
(org-list-use-alpha-bul-p): new function.
* lisp/org.el (org-check-for-hidden): reflect changes to
`org-item-beginning-re'.
* lisp/org-capture.el (org-capture-place-item): reflect changes to
`org-item-beginning-re'.
* lisp/org-docbook.el (org-export-docbook-list-line): handle new type
of items.
* lisp/org-exp.el (org-export-mark-list-end,
org-export-mark-list-properties): reflect changes to
`org-item-beginning-re'.
* lisp/org-html.el (org-html-export-list-line): handle new type of
items.
* lisp/org-latex.el (org-export-latex-lists): handle new type of items
and reflect changes to `org-item-beginning-re'.
* lisp/org-ascii.el (org-export-ascii-preprocess): handle new counters.
Modified from a patch by Nathaniel Flath.
2011-01-13 17:25:55 -05:00
|
|
|
(while (org-list-search-forward
|
|
|
|
"\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\][ \t]*" nil t)
|
2010-08-02 06:37:56 -04:00
|
|
|
(replace-match ""))
|
2010-08-27 03:27:59 -04:00
|
|
|
(remove-text-properties
|
|
|
|
(point-min) (point-max)
|
|
|
|
'(face nil font-lock-fontified nil font-lock-multiline nil line-prefix nil wrap-prefix nil)))
|
2009-04-07 12:40:16 -04:00
|
|
|
|
|
|
|
(defun org-html-expand-for-ascii (line)
|
|
|
|
"Handle quoted HTML for ASCII export."
|
|
|
|
(if org-export-html-expand
|
|
|
|
(while (string-match "@<[^<>\n]*>" line)
|
|
|
|
;; We just remove the tags for now.
|
|
|
|
(setq line (replace-match "" nil nil line))))
|
|
|
|
line)
|
|
|
|
|
2010-03-28 03:48:03 -04:00
|
|
|
(defun org-ascii-replace-entities ()
|
|
|
|
"Replace entities with the ASCII representation."
|
|
|
|
(let (e)
|
2010-10-15 03:39:42 -04:00
|
|
|
(while (re-search-forward "\\\\\\([a-zA-Z]+[0-9]*\\)\\({}\\)?" nil t)
|
2010-03-28 03:48:03 -04:00
|
|
|
(org-if-unprotected-at (match-beginning 1)
|
2010-04-04 16:26:27 -04:00
|
|
|
(setq e (org-entity-get-representation (match-string 1)
|
2010-03-28 03:48:03 -04:00
|
|
|
org-export-ascii-entities))
|
|
|
|
(and e (replace-match e t t))))))
|
|
|
|
|
2009-04-07 12:40:16 -04:00
|
|
|
(defun org-export-ascii-wrap (line where)
|
|
|
|
"Wrap LINE at or before WHERE."
|
|
|
|
(let ((ind (org-get-indentation line))
|
|
|
|
pos)
|
|
|
|
(catch 'found
|
|
|
|
(loop for i from where downto (/ where 2) do
|
|
|
|
(and (equal (aref line i) ?\ )
|
|
|
|
(setq pos i)
|
|
|
|
(throw 'found t))))
|
|
|
|
(if pos
|
|
|
|
(concat (substring line 0 pos) "\n"
|
|
|
|
(make-string ind ?\ )
|
|
|
|
(substring line (1+ pos)))
|
|
|
|
line)))
|
2009-06-08 02:00:46 -04:00
|
|
|
|
2009-04-07 12:40:16 -04:00
|
|
|
(defun org-export-ascii-push-links (link-buffer)
|
|
|
|
"Push out links in the buffer."
|
|
|
|
(when link-buffer
|
|
|
|
;; We still have links to push out.
|
|
|
|
(insert "\n")
|
|
|
|
(let ((ind ""))
|
|
|
|
(save-match-data
|
|
|
|
(if (save-excursion
|
|
|
|
(re-search-backward
|
Don't use `outline-regexp' anymore.
Use `org-outline-regexp' instead or `outline-regexp'. Also use the
new defconst `org-outline-regexp-bol' to match `org-outline-regexp'
at the beginning of line.
* org.el (org-outline-regexp-bol): New defconst.
(org-outline-level, org-set-font-lock-defaults, org-cycle)
(org-overview, org-content, org-flag-drawer)
(org-first-headline-recenter, org-insert-todo-heading)
(org-map-region, org-move-subtree-down, org-paste-subtree)
(org-kill-is-subtree-p, org-context-p, org-refile)
(org-refile-new-child, org-toggle-comment, org-todo)
(org-add-planning-info, org-add-log-setup, org-scan-tags)
(org-set-tags, org-insert-property-drawer)
(org-prepare-agenda-buffers, org-preview-latex-fragment)
(org-speed-command-default-hook, org-check-for-hidden)
(org-toggle-item, org-toggle-heading)
(org-indent-line-function, org-set-autofill-regexps)
(org-fill-paragraph, org-toggle-fixed-width-section)
(org-yank-generic, org-yank-folding-would-swallow-text)
(org-first-sibling-p, org-goto-sibling)
(org-goto-first-child, org-show-entry): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
* org-remember.el (org-remember-handler): Use
`org-outline-regexp-bol'.
* org-mouse.el (org-mouse-match-todo-keyword, org-mode-hook)
(org-mouse-move-tree, org-mouse-transform-to-outline): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
* org-macs.el (org-with-limited-levels)
(org-get-limited-outline-regexp): Use `org-outline-regexp'.
* org-indent.el (org-indent-outline-re)
(org-indent-refresh-section, org-indent-refresh-to): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
* org-html.el (org-export-as-html): Use
`org-outline-regexp-bol'.
* org-footnote.el (org-footnote-at-definition-p)
(org-footnote-normalize): Use `org-outline-regexp' and
`org-outline-regexp-bol'.
* org-exp.el (org-export-preprocess-string): Don't redefine
`outline-regexp'.
* org-docbook.el (org-export-as-docbook): Use
`org-outline-regexp-bol'.
* org-colview.el (org-columns, org-columns-compute): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
* org-colview-xemacs.el (org-columns, org-columns-compute):
Use `org-outline-regexp-bol'.
* org-clock.el (org-clock-insert-selection-line)
(org-clock-in, org-clock-out, org-dblock-write:clocktable):
Use `org-outline-regexp' and `org-outline-regexp-bol'.
* org-ascii.el (org-export-as-ascii)
(org-export-ascii-push-links): Use `org-outline-regexp' and
`org-outline-regexp-bol'.
* org-archive.el (org-archive-to-archive-sibling)
(org-archive-all-done): Use `org-outline-regexp' and
`org-outline-regexp-bol'.
* org-agenda.el (org-agenda, org-search-view)
(org-agenda-list-stuck-projects, org-agenda-get-timestamps)
(org-agenda-get-progress, org-agenda-get-blocks): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
2011-07-17 15:17:08 -04:00
|
|
|
(concat "^\\(\\([ \t]*\\)\\|\\("
|
|
|
|
org-outline-regexp
|
|
|
|
"\\)\\)[^ \t\n]") nil t))
|
2009-04-07 12:40:16 -04:00
|
|
|
(setq ind (or (match-string 2)
|
|
|
|
(make-string (length (match-string 3)) ?\ )))))
|
|
|
|
(mapc (lambda (x) (insert ind "[" (car x) "]: " (cdr x) "\n"))
|
|
|
|
link-buffer))
|
|
|
|
(insert "\n")))
|
|
|
|
|
|
|
|
(defun org-ascii-level-start (level title umax &optional lines)
|
|
|
|
"Insert a new level in ASCII export."
|
|
|
|
(let (char (n (- level umax 1)) (ind 0))
|
|
|
|
(if (> level umax)
|
|
|
|
(progn
|
|
|
|
(insert (make-string (* 2 n) ?\ )
|
|
|
|
(char-to-string (nth (% n (length org-export-ascii-bullets))
|
|
|
|
org-export-ascii-bullets))
|
|
|
|
" " title "\n")
|
|
|
|
;; find the indentation of the next non-empty line
|
|
|
|
(catch 'stop
|
|
|
|
(while lines
|
|
|
|
(if (string-match "^\\* " (car lines)) (throw 'stop nil))
|
|
|
|
(if (string-match "^\\([ \t]*\\)\\S-" (car lines))
|
|
|
|
(throw 'stop (setq ind (org-get-indentation (car lines)))))
|
|
|
|
(pop lines)))
|
|
|
|
(setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
|
|
|
|
(if (or (not (equal (char-before) ?\n))
|
|
|
|
(not (equal (char-before (1- (point))) ?\n)))
|
|
|
|
(insert "\n"))
|
2011-02-14 23:30:00 -05:00
|
|
|
(setq char (or (nth (1- level) org-export-ascii-underline)
|
2011-02-15 04:47:26 -05:00
|
|
|
(car (last org-export-ascii-underline))))
|
2009-04-07 12:40:16 -04:00
|
|
|
(unless org-export-with-tags
|
2010-08-20 20:30:31 -04:00
|
|
|
(if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") title)
|
2009-04-07 12:40:16 -04:00
|
|
|
(setq title (replace-match "" t t title))))
|
|
|
|
(if org-export-with-section-numbers
|
|
|
|
(setq title (concat (org-section-number level) " " title)))
|
|
|
|
(insert title "\n" (make-string (string-width title) char) "\n")
|
|
|
|
(setq org-ascii-current-indentation '(0 . 0)))))
|
|
|
|
|
|
|
|
(defun org-insert-centered (s &optional underline)
|
|
|
|
"Insert the string S centered and underline it with character UNDERLINE."
|
|
|
|
(let ((ind (max (/ (- fill-column (string-width s)) 2) 0)))
|
|
|
|
(insert (make-string ind ?\ ) s "\n")
|
|
|
|
(if underline
|
|
|
|
(insert (make-string ind ?\ )
|
|
|
|
(make-string (string-width s) underline)
|
|
|
|
"\n"))))
|
|
|
|
|
|
|
|
(defvar org-table-colgroup-info nil)
|
|
|
|
(defun org-format-table-ascii (lines)
|
|
|
|
"Format a table for ascii export."
|
|
|
|
(if (stringp lines)
|
|
|
|
(setq lines (org-split-string lines "\n")))
|
|
|
|
(if (not (string-match "^[ \t]*|" (car lines)))
|
|
|
|
;; Table made by table.el - test for spanning
|
|
|
|
lines
|
|
|
|
|
|
|
|
;; A normal org table
|
|
|
|
;; Get rid of hlines at beginning and end
|
|
|
|
(if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
|
|
|
|
(setq lines (nreverse lines))
|
|
|
|
(if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
|
|
|
|
(setq lines (nreverse lines))
|
|
|
|
(when org-export-table-remove-special-lines
|
|
|
|
;; Check if the table has a marking column. If yes remove the
|
|
|
|
;; column and the special lines
|
|
|
|
(setq lines (org-table-clean-before-export lines)))
|
|
|
|
;; Get rid of the vertical lines except for grouping
|
2009-10-23 06:35:24 -04:00
|
|
|
(if org-export-ascii-table-keep-all-vertical-lines
|
|
|
|
lines
|
|
|
|
(let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
|
|
|
|
rtn line vl1 start)
|
|
|
|
(while (setq line (pop lines))
|
|
|
|
(if (string-match org-table-hline-regexp line)
|
|
|
|
(and (string-match "|\\(.*\\)|" line)
|
|
|
|
(setq line (replace-match " \\1" t nil line)))
|
|
|
|
(setq start 0 vl1 vl)
|
|
|
|
(while (string-match "|" line start)
|
|
|
|
(setq start (match-end 0))
|
|
|
|
(or (pop vl1) (setq line (replace-match " " t t line)))))
|
|
|
|
(push line rtn))
|
|
|
|
(nreverse rtn)))))
|
2009-04-07 12:40:16 -04:00
|
|
|
|
|
|
|
(defun org-colgroup-info-to-vline-list (info)
|
|
|
|
(let (vl new last)
|
|
|
|
(while info
|
|
|
|
(setq last new new (pop info))
|
|
|
|
(if (or (memq last '(:end :startend))
|
|
|
|
(memq new '(:start :startend)))
|
|
|
|
(push t vl)
|
|
|
|
(push nil vl)))
|
|
|
|
(setq vl (nreverse vl))
|
|
|
|
(and vl (setcar vl nil))
|
|
|
|
vl))
|
|
|
|
|
|
|
|
(provide 'org-ascii)
|
|
|
|
|
2012-10-02 02:50:46 -04:00
|
|
|
;; Local variables:
|
|
|
|
;; generated-autoload-file: "org-loaddefs.el"
|
|
|
|
;; End:
|
|
|
|
|
2009-04-07 12:40:16 -04:00
|
|
|
;;; org-ascii.el ends here
|