summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Dominik <carsten.dominik@gmail.com>2010-04-27 12:13:27 +0200
committerCarsten Dominik <carsten.dominik@gmail.com>2010-04-28 08:49:35 +0200
commitce6caec4467595f8c0bb1085aebe260edd189507 (patch)
tree394f9eefdb370f8097d6ba2941053ea26e324441
parent9822a6799a45d8f8efa0bad624c99994b2bd41a6 (diff)
downloadorg-mode-ce6caec4467595f8c0bb1085aebe260edd189507.tar.gz
Automatically remove lines with formatting cookies when exporting tables
Lines that only contain formatting cookies like <l20> or <10> will now be removed automatically. Optionally, the first field in a row can also be "/".
-rw-r--r--ChangeLog5
-rw-r--r--doc/org.texi19
-rwxr-xr-xlisp/ChangeLog8
-rw-r--r--lisp/org-exp.el21
-rw-r--r--lisp/org-table.el52
5 files changed, 69 insertions, 36 deletions
diff --git a/ChangeLog b/ChangeLog
index 6338d10..f60aa11 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2010-04-28 Carsten Dominik <carsten.dominik@gmail.com>
+
+ * Document that lines with formatting cookies will be removed
+ automatically.
+
2010-04-18 Carsten Dominik <carsten.dominik@gmail.com>
* Makefile (BATCH): Write the BATCH command a bit more compact.
diff --git a/doc/org.texi b/doc/org.texi
index d36f495..381c45c 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -1881,6 +1881,9 @@ to the right and of string-rich column to the left, you and use @samp{<r>} or
@samp{<l>} in a similar fashion. You may also combine alignment and field
width like this: @samp{<l10>}.
+Lines which only contain these formatting cookies will be removed
+automatically.
+
@node Column groups, Orgtbl mode, Column width and alignment, Tables
@section Column groups
@cindex grouping columns in tables
@@ -1897,14 +1900,14 @@ a group of its own. Boundaries between column groups will upon export be
marked with vertical lines. Here is an example:
@example
-| | N | N^2 | N^3 | N^4 | sqrt(n) | sqrt[4](N) |
-|---+----+-----+-----+-----+---------+------------|
-| / | <> | < | | > | < | > |
-| # | 1 | 1 | 1 | 1 | 1 | 1 |
-| # | 2 | 4 | 8 | 16 | 1.4142 | 1.1892 |
-| # | 3 | 9 | 27 | 81 | 1.7321 | 1.3161 |
-|---+----+-----+-----+-----+---------+------------|
-#+TBLFM: $3=$2^2::$4=$2^3::$5=$2^4::$6=sqrt($2)::$7=sqrt(sqrt(($2)))
+| N | N^2 | N^3 | N^4 | sqrt(n) | sqrt[4](N) |
+|---+-----+-----+-----+---------+------------|
+| / | < | | > | < | > |
+| 1 | 1 | 1 | 1 | 1 | 1 |
+| 2 | 4 | 8 | 16 | 1.4142 | 1.1892 |
+| 3 | 9 | 27 | 81 | 1.7321 | 1.3161 |
+|---+-----+-----+-----+---------+------------|
+#+TBLFM: $2=$1^2::$3=$1^3::$4=$1^4::$5=sqrt($1)::$6=sqrt(sqrt(($1)))
@end example
It is also sufficient to just insert the column group starters after
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 21bbbcc..5a3aa4c 100755
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
+2010-04-28 Carsten Dominik <carsten.dominik@gmail.com>
+
+ * org-table.el (org-table-colgroup-line-p)
+ (org-table-cookie-line-p): New functions.
+
+ * org-exp.el (org-table-clean-before-export): Better tests for
+ colgroup and cookie lines.
+
2010-04-27 Carsten Dominik <carsten.dominik@gmail.com>
* org-agenda.el (org-agenda-goto): Push a mark before changing
diff --git a/lisp/org-exp.el b/lisp/org-exp.el
index f467d57..59a0703 100644
--- a/lisp/org-exp.el
+++ b/lisp/org-exp.el
@@ -42,6 +42,8 @@
(declare-function org-export-htmlize-region-for-paste "org-html" (beg end))
(declare-function htmlize-buffer "ext:htmlize" (&optional buffer))
(declare-function org-inlinetask-remove-END-maybe "org-inlinetask" ())
+(declare-function org-table-cookie-line-p "org-table" (line))
+(declare-function org-table-colgroup-line-p "org-table" (line))
(autoload 'org-export-generic "org-export-generic" "Export using the generic exporter" t)
(defgroup org-export nil
"Options for exporting org-listings."
@@ -2660,13 +2662,16 @@ If yes remove the column and the special lines."
"^[ \t]*| *\\([\#!$*_^ /]\\) *|")
x)))
lines))
+ ;; No special marking column
(progn
(setq org-table-clean-did-remove-column nil)
(delq nil
(mapcar
(lambda (x)
(cond
- ((string-match "^[ \t]*| */ *|" x)
+ ((org-table-colgroup-line-p x)
+ ;; This line contains colgroup info, extract it
+ ;; and then discard the line
(setq org-table-colgroup-info
(mapcar (lambda (x)
(cond ((member x '("<" "&lt;")) :start)
@@ -2675,14 +2680,20 @@ If yes remove the column and the special lines."
(t nil)))
(org-split-string x "[ \t]*|[ \t]*")))
nil)
+ ((org-table-cookie-line-p x)
+ ;; This line contains formatting cookies, discard it
+ nil)
(t x)))
lines)))
+ ;; there is a special marking column
(setq org-table-clean-did-remove-column t)
(delq nil
(mapcar
(lambda (x)
(cond
- ((string-match "^[ \t]*| */ *|" x)
+ ((org-table-colgroup-line-p x)
+ ;; This line contains colgroup info, extract it
+ ;; and then discard the line
(setq org-table-colgroup-info
(mapcar (lambda (x)
(cond ((member x '("<" "&lt;")) :start)
@@ -2691,8 +2702,12 @@ If yes remove the column and the special lines."
(t nil)))
(cdr (org-split-string x "[ \t]*|[ \t]*"))))
nil)
+ ((org-table-cookie-line-p x)
+ ;; This line contains formatting cookies, discard it
+ nil)
((string-match "^[ \t]*| *[!_^/] *|" x)
- nil) ; ignore this line
+ ;; ignore this line
+ nil)
((or (string-match "^\\([ \t]*\\)|-+\\+" x)
(string-match "^\\([ \t]*\\)|[^|]*|" x))
;; remove the first column
diff --git a/lisp/org-table.el b/lisp/org-table.el
index 4309759..0e6995b 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -327,6 +327,33 @@ outside the table.")
"\\(" "@?[-0-9I$&]+" "\\|" "[a-zA-Z]\\{1,2\\}\\([0-9]+\\|&\\)" "\\|" "\\$[a-zA-Z0-9]+" "\\)")
"Match a range for reference display.")
+(defun org-table-colgroup-line-p (line)
+ "Is this a table line colgroup information?"
+ (save-match-data
+ (and (string-match "[<>]\\|&[lg]t;" line)
+ (string-match "\\`[ \t]*|[ \t]*/[ \t]*\\(|[ \t<>0-9|lgt&;]+\\)\\'"
+ line)
+ (not (delq
+ nil
+ (mapcar
+ (lambda (s)
+ (not (member s '("" "<" ">" "<>" "&lt;" "&gt;" "&lt;&gt;"))))
+ (org-split-string (match-string 1 line) "[ \t]*|[ \t]*")))))))
+
+(defun org-table-cookie-line-p (line)
+ "Is this a table line with only alignment/width cookies?"
+
+ (save-match-data
+ (and (string-match "[<>]\\|&[lg]t;" line)
+ (or (string-match "\\`[ \t]*|[ \t]*/[ \t]*\\(|[ \t<>0-9|lgt&;]+\\)\\'" line)
+ (string-match "\\(\\`[ \t<>lr0-9|gt&;]+\\'\\)" line))
+ (not (delq nil (mapcar
+ (lambda (s)
+ (not (or (equal s "")
+ (string-match "\\`<\\([lr]?[0-9]+\\|[lr]\\)>\\'" s)
+ (string-match "\\`&lt;\\([lr]?[0-9]+\\|[lr]\\)&gt;\\'" s))))
+ (org-split-string (match-string 1 line) "[ \t]*|[ \t]*")))))))
+
(defconst org-table-translate-regexp
(concat "\\(" "@[-0-9I$]+" "\\|" "[a-zA-Z]\\{1,2\\}\\([0-9]+\\|&\\)" "\\)")
"Match a reference that needs translation, for reference display.")
@@ -764,14 +791,6 @@ When nil, simply write \"#ERROR\" in corrupted fields.")
(setq org-table-may-need-update nil)
))
-
-
-
-
-
-
-
-
(defun org-table-begin (&optional table-type)
"Find the beginning of the table and return its position.
With argument TABLE-TYPE, go to the beginning of a table.el-type table."
@@ -1730,23 +1749,6 @@ the table and kill the editing buffer."
(org-table-align)
(message "New field value inserted")))
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
(defvar org-timecnt) ; dynamically scoped parameter
(defun org-table-sum (&optional beg end nlast)