]> code.delx.au - gnu-emacs/blobdiff - lisp/org/org-ascii.el
Close bug#3992.
[gnu-emacs] / lisp / org / org-ascii.el
index 4ace1db5c7c405bc29b40c9ce6350183ac36fc5c..13603ce51340398705fa6cfdc6fc6a3456addd26 100644 (file)
@@ -1,12 +1,12 @@
 ;;; org-ascii.el --- ASCII export for Org-mode
 
-;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
+;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
 ;;   Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <carsten at orgmode dot org>
 ;; Keywords: outlines, hypermedia, calendar, wp
 ;; Homepage: http://orgmode.org
-;; Version: 6.29c
+;; Version: 6.33x
 ;;
 ;; This file is part of GNU Emacs.
 ;;
@@ -27,6 +27,8 @@
 ;;; Commentary:
 
 (require 'org-exp)
+(eval-when-compile
+  (require 'cl))
 
 (defgroup org-export-ascii nil
   "Options specific for ASCII export of Org-mode files."
@@ -56,6 +58,18 @@ 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.
+When nil, vertical lines will be removed except for those needed
+for column grouping."
+  :group 'org-export-ascii
+  :type 'boolean)
+
+;;; Hooks
+
+(defvar org-export-ascii-final-hook nil
+  "Hook run at the end of ASCII export, in the new buffer.")
+
 ;;; ASCII export
 
 (defvar org-ascii-current-indentation nil) ; For communication
@@ -113,7 +127,7 @@ in a window.  A non-interactive call will only return the buffer."
     (setq buffer "*Org ASCII Export*"))
   (let ((transient-mark-mode t) (zmacs-regions t)
        ext-plist rtn)
-    (setq ext-plist (plist-put ext-plist :ignore-subree-p t))
+    (setq ext-plist (plist-put ext-plist :ignore-subtree-p t))
     (goto-char end)
     (set-mark (point)) ;; to activate the region
     (goto-char beg)
@@ -150,7 +164,7 @@ publishing directory."
         (rbeg (and region-p (region-beginning)))
         (rend (and region-p (region-end)))
         (subtree-p
-         (if (plist-get opt-plist :ignore-subree-p)
+         (if (plist-get opt-plist :ignore-subtree-p)
              nil
            (when region-p
              (save-excursion
@@ -266,11 +280,13 @@ publishing directory."
 
     ;; File header
     (unless body-only
-      (if title (org-insert-centered title ?=))
-      (insert "\n")
+      (when (and title (not (string= "" title)))
+       (org-insert-centered title ?=)
+       (insert "\n"))
+
       (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 email (concat " <" email ">") "")
                          "\n")))
 
@@ -283,7 +299,8 @@ publishing directory."
       (if (and date org-export-time-stamp-file)
          (insert (concat (nth 2 lang-words) ": " date"\n")))
 
-      (insert "\n\n"))
+      (unless (= (point) (point-min))
+       (insert "\n\n")))
 
     (if (and org-export-with-toc (not body-only))
        (progn
@@ -452,6 +469,7 @@ publishing directory."
        (setq end (next-single-property-change beg 'org-cwidth))
        (delete-region beg end)
        (goto-char beg)))
+    (run-hooks 'org-export-ascii-final-hook)
     (or to-buffer (save-buffer))
     (goto-char (point-min))
     (or (org-export-push-to-kill-ring "ASCII")
@@ -574,18 +592,20 @@ publishing directory."
       ;; column and the special lines
       (setq lines (org-table-clean-before-export lines)))
     ;; Get rid of the vertical lines except for grouping
-    (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))))
+    (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)))))
 
 (defun org-colgroup-info-to-vline-list (info)
   (let (vl new last)