Browse Source

Add `orgtbl-to-table.el' and `orgtbl-to-unicode'.

* org-table.el (orgtbl-radio-table-templates): Add a template
for org-mode.
(orgtbl-to-orgtbl): Complete and align the table created with
orgtbl-to-orgtbl, in case the user use the function for radio
tables.
(orgtbl-to-table.el): New function to export a table to
another one using the table.el format.
(orgtbl-to-unicode): New function to export a table using
unicode characters.
Bastien Guerry 12 years ago
parent
commit
e3f30e12d2
1 changed files with 38 additions and 4 deletions
  1. 38 4
      lisp/org-table.el

+ 38 - 4
lisp/org-table.el

@@ -85,7 +85,13 @@ this variable requires a restart of Emacs to become effective."
 <!--
 #+ORGTBL: SEND %n orgtbl-to-html :splice nil :skip 0
 | | |
--->\n"))
+-->\n")
+    (org-mode "#+ BEGIN RECEIVE ORGTBL %n
+#+ END RECEIVE ORGTBL %n
+
+#+ORGTBL: SEND %n orgtbl-to-orgtbl :splice nil :skip 0
+| | |
+"))
   "Templates for radio tables in different major modes.
 All occurrences of %n in a template will be replaced with the name of the
 table, obtained by prompting the user."
@@ -4526,8 +4532,6 @@ This may be either a string or a function of two arguments:
 
 In addition to this, the parameters :skip and :skipcols are always handled
 directly by `orgtbl-send-table'.  See manual."
-  (interactive)
-
   (let* ((splicep (plist-get params :splice))
 	 (hline (plist-get params :hline))
 	 (skipheadrule (plist-get params :skipheadrule))
@@ -4726,7 +4730,37 @@ provide ORGTBL directives for the generated table."
 	   :lstart "| "
 	   :lend " |"))
 	 (params (org-combine-plists params2 params)))
-    (orgtbl-to-generic table params)))
+    (with-temp-buffer
+      (insert (orgtbl-to-generic table params))
+      (goto-char (point-min))
+      (while (re-search-forward org-table-hline-regexp nil t)
+	(org-table-align))
+      (buffer-substring 1 (buffer-size)))))
+
+(defun orgtbl-to-table.el (table params)
+  "Convert the orgtbl-mode TABLE into a table.el table."
+  (with-temp-buffer
+    (insert (orgtbl-to-orgtbl table params))
+    (org-table-align)
+    (replace-regexp-in-string
+     "-|" "-+"
+     (replace-regexp-in-string "|-" "+-" (buffer-substring 1 (buffer-size))))))
+
+(defun orgtbl-to-unicode (table params)
+  "Convert the orgtbl-mode TABLE into a table with unicode characters.
+You need the ascii-art-to-unicode.el package for this.  You can download
+it here: http://gnuvola.org/software/j/aa2u/ascii-art-to-unicode.el."
+  (with-temp-buffer
+    (insert (orgtbl-to-table.el table params))
+    (goto-char (point-min))
+    (if (or (featurep 'ascii-art-to-unicode)
+	    (require 'ascii-art-to-unicode nil t))
+	(aa2u)
+      (unless (delq nil (mapcar (lambda (l) (string-match "aa2u" (car l))) org-stored-links))
+	(push '("http://gnuvola.org/software/j/aa2u/ascii-art-to-unicode.el"
+		"Link to ascii-art-to-unicode.el") org-stored-links))
+      (error "Please download ascii-art-to-unicode.el (use C-c C-l to insert the link to it)"))
+    (buffer-string)))
 
 (defun org-table-get-remote-range (name-or-id form)
   "Get a field value or a list of values in a range from table at ID.