]> code.delx.au - gnu-emacs/blobdiff - lisp/org/org-ascii.el
Fix Org ChangeLog entries and remove arch-tag.
[gnu-emacs] / lisp / org / org-ascii.el
index 730f8bdfa4114c928f54bc3039163e1c411c0a6b..e139773d486ad4b89b5eb29a965f9c2e6d97407e 100644 (file)
@@ -6,7 +6,7 @@
 ;; Author: Carsten Dominik <carsten at orgmode dot org>
 ;; Keywords: outlines, hypermedia, calendar, wp
 ;; Homepage: http://orgmode.org
-;; Version: 7.01
+;; Version: 7.7
 ;;
 ;; This file is part of GNU Emacs.
 ;;
@@ -38,7 +38,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
@@ -96,29 +96,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))
@@ -176,7 +177,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)
@@ -188,7 +189,7 @@ in a window.  A non-interactive call will only return the buffer."
               nil 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)))
 
@@ -291,10 +292,12 @@ publishing directory."
          (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)
@@ -303,6 +306,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)
@@ -311,7 +315,7 @@ publishing directory."
                  :add-text (plist-get opt-plist :text))
                 "\n"))
         thetoc have-headings first-heading-pos
-        table-open table-buffer link-buffer link desc desc0 rpl wrap)
+        table-open table-buffer link-buffer link type path desc desc0 rpl wrap fnc)
     (let ((inhibit-read-only t))
       (org-unmodified
        (remove-text-properties (point-min) (point-max)
@@ -347,7 +351,7 @@ publishing directory."
 
       (if (and (or author email)
               org-export-author-info)
-         (insert(concat (nth 1 lang-words) ": " (or author "")
+         (insert (concat (nth 1 lang-words) ": " (or author "")
                          (if (and org-export-email-info
                                   email (string-match "\\S-" email))
                              (concat " <" email ">") "")
@@ -370,7 +374,7 @@ 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)
+         (mapc #'(lambda (line)
                   (if (string-match org-todo-line-regexp
                                     line)
                       ;; This is a headline
@@ -400,7 +404,7 @@ publishing directory."
 
                         (if (and (memq org-export-with-tags '(not-in-toc nil))
                                  (string-match
-                                  (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
+                                  (org-re "[ \t]+:[[:alnum:]_@#%:]+:[ \t]*$")
                                   txt))
                             (setq txt (replace-match "" t t txt)))
                         (if (string-match quote-re0 txt)
@@ -424,17 +428,19 @@ publishing directory."
 
     (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)
       ;; Remove the quoted HTML tags.
       (setq line (org-html-expand-for-ascii line))
       ;; Replace links with the description when possible
-      (while (string-match org-bracket-link-regexp line)
-       (setq link (match-string 1 line)
-             desc0 (match-string 3 line)
-             desc (or desc0 (match-string 1 line)))
+      (while (string-match org-bracket-link-analytic-regexp++ line)
+       (setq path (match-string 3 line)
+             link (concat (match-string 1 line) path)
+             type (match-string 2 line)
+             desc0 (match-string 5 line)
+             desc (or desc0 link))
        (if (and (> (length link) 8)
                 (equal (substring link 0 8) "coderef:"))
            (setq line (replace-match
@@ -443,15 +449,18 @@ publishing directory."
                                      (substring link 8)
                                      org-export-code-refs)))
                        t t line))
-         (setq rpl (concat "["
-                           (or (match-string 3 line) (match-string 1 line))
-                           "]"))
-         (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)))))
+         (setq rpl (concat "[" desc "]"))
+         (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))))))
          (setq line (replace-match rpl t t line))))
       (when custom-times
        (setq line (org-translate-time line)))
@@ -482,7 +491,8 @@ publishing directory."
                   (org-format-table-ascii table-buffer)
                   "\n") "\n")))
        (t
-       (if (string-match "^\\([ \t]*\\)\\([-+*][ \t]+\\)\\(.*?\\)\\( ::\\)" line)
+       (if (string-match "^\\([ \t]*\\)\\([-+*][ \t]+\\)\\(.*?\\)\\( ::\\)"
+                         line)
            (setq line (replace-match "\\1\\3:" t nil line)))
        (setq line (org-fix-indentation line org-ascii-current-indentation))
        ;; Remove forced line breaks
@@ -571,9 +581,12 @@ publishing directory."
       (replace-match "\\1\\2")))
   ;; Remove list start counters
   (goto-char (point-min))
-  (while (re-search-forward  "\\[@start:[0-9]+\\] ?" nil t)
-    (org-if-unprotected
-     (replace-match ""))))
+  (while (org-list-search-forward
+         "\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\][ \t]*" nil t)
+    (replace-match ""))
+  (remove-text-properties
+   (point-min) (point-max)
+   '(face nil font-lock-fontified nil font-lock-multiline nil line-prefix nil wrap-prefix nil)))
 
 (defun org-html-expand-for-ascii (line)
   "Handle quoted HTML for ASCII export."
@@ -586,7 +599,7 @@ publishing directory."
 (defun org-ascii-replace-entities ()
   "Replace entities with the ASCII representation."
   (let (e)
-    (while (re-search-forward "\\\\\\([a-zA-Z]+[0-9]*\\)" nil t)
+    (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))
@@ -616,7 +629,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"))
@@ -643,9 +658,10 @@ 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)
+       (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") title)
            (setq title (replace-match "" t t title))))
       (if org-export-with-section-numbers
          (setq title (concat (org-section-number level) " " title)))
@@ -710,5 +726,5 @@ publishing directory."
 
 (provide 'org-ascii)
 
-;; arch-tag: aa96f882-f477-4e13-86f5-70d43e7adf3c
+
 ;;; org-ascii.el ends here