Merge Org 7.9.3 (commit 31c1aea)
[bpt/emacs.git] / lisp / org / org-ascii.el
index d596453..c5a4b37 100644 (file)
@@ -1,11 +1,10 @@
 ;;; org-ascii.el --- ASCII export for Org-mode
 
-;; Copyright (C) 2004-201 Free Software Foundation, Inc.
+;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <carsten at orgmode dot org>
 ;; Keywords: outlines, hypermedia, calendar, wp
 ;; Homepage: http://orgmode.org
-;; Version: 7.4
 ;;
 ;; This file is part of GNU Emacs.
 ;;
@@ -37,7 +36,7 @@
   :tag "Org Export ASCII"
   :group 'org-export)
 
-(defcustom org-export-ascii-underline '(?\$ ?\# ?^ ?\~ ?\= ?\-)
+(defcustom org-export-ascii-underline '(?\= ?\- ?\~ ?\^ ?\. ?\# ?\$)
   "Characters for underlining headings in ASCII export.
 In the given sequence, these characters will be used for level 1, 2, ..."
   :group 'org-export-ascii
@@ -95,29 +94,30 @@ utf8      Use all UTF-8 characters")
 (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)
+  (org-export-as-encoding 'org-export-as-ascii (org-called-interactively-p 'any)
                          '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))
+  (org-export-as-encoding 'org-export-as-ascii-to-buffer
+                         (org-called-interactively-p 'any) 'latin1 args))
 
 ;;;###autoload
 (defun org-export-as-utf8 (&rest args)
-  "Like `org-export-as-ascii', use use encoding for special symbols."
+  "Like `org-export-as-ascii', use encoding for special symbols."
   (interactive)
-  (org-export-as-encoding 'org-export-as-ascii (interactive-p)
+  (org-export-as-encoding 'org-export-as-ascii
+                         (org-called-interactively-p 'any)
                          '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))
+  (org-export-as-encoding 'org-export-as-ascii-to-buffer
+                         (org-called-interactively-p 'any) 'utf8 args))
 
 (defun org-export-as-encoding (command interactivep encoding &rest args)
   (let ((org-export-ascii-entities encoding))
@@ -131,7 +131,7 @@ utf8      Use all UTF-8 characters")
   "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*")
+  (org-export-as-ascii arg nil "*Org ASCII Export*")
   (when org-export-show-temporary-export-buffer
     (switch-to-buffer-other-window "*Org ASCII Export*")))
 
@@ -144,9 +144,9 @@ command to convert it."
   (interactive "r")
   (let (reg ascii buf pop-up-frames)
     (save-window-excursion
-      (if (org-mode-p)
+      (if (derived-mode-p 'org-mode)
          (setq ascii (org-export-region-as-ascii
-                     beg end t 'string))
+                      beg end t 'string))
        (setq reg (buffer-substring beg end)
              buf (get-buffer-create "*Org tmp*"))
        (with-current-buffer buf
@@ -154,7 +154,7 @@ command to convert it."
          (insert reg)
          (org-mode)
          (setq ascii (org-export-region-as-ascii
-                     (point-min) (point-max) t 'string)))
+                      (point-min) (point-max) t 'string)))
        (kill-buffer buf)))
     (delete-region beg end)
     (insert ascii)))
@@ -175,7 +175,7 @@ a Lisp program could call this function in the following way:
 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")
-  (when (interactive-p)
+  (when (org-called-interactively-p 'any)
     (setq buffer "*Org ASCII Export*"))
   (let ((transient-mark-mode t) (zmacs-regions t)
        ext-plist rtn)
@@ -183,23 +183,19 @@ in a window.  A non-interactive call will only return the buffer."
     (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))
+    (setq rtn (org-export-as-ascii nil ext-plist buffer body-only))
     (if (fboundp 'deactivate-mark) (deactivate-mark))
-    (if (and (interactive-p) (bufferp rtn))
+    (if (and (org-called-interactively-p 'any) (bufferp rtn))
        (switch-to-buffer-other-window rtn)
       rtn)))
 
 ;;;###autoload
-(defun org-export-as-ascii (arg &optional hidden ext-plist
-                              to-buffer body-only pub-dir)
+(defun org-export-as-ascii (arg &optional ext-plist to-buffer body-only pub-dir)
   "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
 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
+lists.  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
@@ -283,17 +279,19 @@ publishing directory."
                    "UNTITLED"))
         (email (plist-get opt-plist :email))
         (language (plist-get opt-plist :language))
-        (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
+        (quote-re0 (concat "^\\(" org-quote-string "\\)\\( +\\|[ \t]*$\\)"))
         (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))))
+        (org-export-footnotes-seen nil)
+        (org-export-footnotes-data (org-footnote-all-labels 'with-defs))
         (lines (org-split-string
                 (org-export-preprocess-string
                  region
-                 :for-ascii t
+                 :for-backend 'ascii
                  :skip-before-1st-heading
                  (plist-get opt-plist :skip-before-1st-heading)
                  :drawers (plist-get opt-plist :drawers)
@@ -302,6 +300,7 @@ publishing directory."
                  :footnotes (plist-get opt-plist :footnotes)
                  :timestamps (plist-get opt-plist :timestamps)
                  :todo-keywords (plist-get opt-plist :todo-keywords)
+                 :tasks (plist-get opt-plist :tasks)
                  :verbatim-multiline t
                  :select-tags (plist-get opt-plist :select-tags)
                  :exclude-tags (plist-get opt-plist :exclude-tags)
@@ -369,61 +368,61 @@ publishing directory."
          (push (concat (nth 3 lang-words) "\n") thetoc)
          (push (concat (make-string (string-width (nth 3 lang-words)) ?=)
                        "\n") thetoc)
-         (mapc '(lambda (line)
-                  (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)))
+         (mapc #'(lambda (line)
+                   (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)))
                                        ; TODO, not DONE
-                                  (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)))
-
-                        (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))
-                          ))))
+                                   (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))
+                           ))))
                lines)
          (setq thetoc (if have-headings (nreverse thetoc) nil))))
 
     (org-init-section-numbers)
     (while (setq line (pop lines))
-      (when (and link-buffer (string-match "^\\*+ " line))
+      (when (and link-buffer (string-match org-outline-regexp-bol line))
        (org-export-ascii-push-links (nreverse link-buffer))
        (setq link-buffer nil))
       (setq wrap nil)
@@ -435,7 +434,9 @@ publishing directory."
              link (concat (match-string 1 line) path)
              type (match-string 2 line)
              desc0 (match-string 5 line)
-             desc (or desc0 link))
+             desc0 (replace-regexp-in-string "\\\\_" "_" desc0)
+             desc (or desc0 link)
+             desc (replace-regexp-in-string "\\\\_" "_" desc))
        (if (and (> (length link) 8)
                 (equal (substring link 0 8) "coderef:"))
            (setq line (replace-match
@@ -548,6 +549,7 @@ publishing directory."
          (kill-buffer (current-buffer)))
       (current-buffer))))
 
+;;;###autoload
 (defun org-export-ascii-preprocess (parameters)
   "Do extra work for ASCII export."
   ;;
@@ -576,8 +578,8 @@ publishing directory."
       (replace-match "\\1\\2")))
   ;; Remove list start counters
   (goto-char (point-min))
-  (while (org-search-forward-unenclosed
-         "\\[@\\(?:start:\\)?[0-9]+\\][ \t]*" nil t)
+  (while (org-list-search-forward
+         "\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\][ \t]*" nil t)
     (replace-match ""))
   (remove-text-properties
    (point-min) (point-max)
@@ -624,7 +626,9 @@ publishing directory."
       (save-match-data
        (if (save-excursion
              (re-search-backward
-              "^\\(\\([ \t]*\\)\\|\\(\\*+ \\)\\)[^ \t\n]" nil t))
+              (concat "^\\(\\([ \t]*\\)\\|\\("
+                      org-outline-regexp
+                      "\\)\\)[^ \t\n]") nil t))
            (setq ind (or (match-string 2)
                          (make-string (length (match-string 3)) ?\ )))))
       (mapc (lambda (x) (insert ind "[" (car x) "]: " (cdr x) "\n"))
@@ -651,7 +655,8 @@ publishing directory."
       (if (or (not (equal (char-before) ?\n))
              (not (equal (char-before (1- (point))) ?\n)))
          (insert "\n"))
-      (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
+      (setq char (or (nth (1- level) org-export-ascii-underline)
+                    (car (last org-export-ascii-underline))))
       (unless org-export-with-tags
        (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") title)
            (setq title (replace-match "" t t title))))
@@ -718,4 +723,8 @@ publishing directory."
 
 (provide 'org-ascii)
 
+;; Local variables:
+;; generated-autoload-file: "org-loaddefs.el"
+;; End:
+
 ;;; org-ascii.el ends here