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 "/".
This commit is contained in:
Carsten Dominik 2010-04-27 12:13:27 +02:00
parent 9822a6799a
commit ce6caec446
5 changed files with 69 additions and 36 deletions

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)