emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Orgmode] Re: [Feature Request] Cross headings in tables


From: Lawrence Mitchell
Subject: [Orgmode] Re: [Feature Request] Cross headings in tables
Date: Wed, 02 Feb 2011 12:30:12 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Achim Gratz wrote:

[...]

> The first header is still determined like it always was.  Headers inside
> table need to get a special "hline", the choice of "~" for this was
> dictated by most of the other characters already being used for various
> markup inside or outside tables.  When I say "halfway there", I mean
> that the export is working and the lines are recognized as hlines
> everywhere I could find (there may still be some regexpressions floating
> around that don't).  However, aligning tables will replace the wigglies
> with plain dashes since I have not yet found a way to inject the correct
> character for the currently hardcoded "-".  The HTML export for the
> above table looks like this:

[...]

> If somebody has an idea how to make the table alignment work, please
> lend me a hand.  Experimental patch is attached, comments are
> welcome.

How about the following two patches on top.  The first fixes
table alignment, the second fixes LaTeX export of these tables.


>From c555b7e15b617538490210a041bd4af45e51d752 Mon Sep 17 00:00:00 2001
From: Lawrence Mitchell <address@hidden>
Date: Wed, 2 Feb 2011 12:20:12 +0000
Subject: [PATCH 1/2] Correctly realign tables with internal headers
To: address@hidden

* lisp/org-table.el (org-table-align): Deal with internal headers
(specified by ?~) when realigning.
---
 lisp/org-table.el |   38 ++++++++++++++++++++++++--------------
 1 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/lisp/org-table.el b/lisp/org-table.el
index 9437ae1..498a6fc 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -632,7 +632,7 @@ When nil, simply write \"#ERROR\" in corrupted fields.")
         lines (new "") lengths l typenums ty fields maxfields i
         column
         (indent "") cnt frac
-        rfmt hfmt
+        rfmt hfmt tfmt
         (spaces '(1 . 1))
         (sp1 (car spaces))
         (sp2 (cdr spaces))
@@ -640,6 +640,8 @@ When nil, simply write \"#ERROR\" in corrupted fields.")
                 (make-string sp2 ?\ ) "%%%s%ds" (make-string sp1 ?\ ) "|"))
         (hfmt1 (concat
                 (make-string sp2 ?-) "%s" (make-string sp1 ?-) "+"))
+        (tfmt1 (concat
+                (make-string sp2 ?~) "%s" (make-string sp1 ?~) "+"))
         emptystrings links dates emph raise narrow
         falign falign1 fmax f1 len c e space)
     (untabify beg end)
@@ -680,17 +682,19 @@ When nil, simply write \"#ERROR\" in corrupted fields.")
     ;; Mark the hlines by setting the corresponding element to nil
     ;; At the same time, we remove trailing space.
     (setq lines (mapcar (lambda (l)
-                         (if (string-match "^ *|[-~]" l)
-                             nil
-                           (if (string-match "[ \t]+$" l)
-                               (substring l 0 (match-beginning 0))
-                             l)))
+                         (cond ((string-match "^ *|[-]" l)
+                                'dash)
+                               ((string-match "^ *|[~]" l)
+                                'tilde)
+                               ((string-match "[ \t]+$" l)
+                                (substring l 0 (match-beginning 0)))
+                               (t l)))
                        lines))
     ;; Get the data fields by splitting the lines.
     (setq fields (mapcar
                  (lambda (l)
                      (org-split-string l " *| *"))
-                 (delq nil (copy-sequence lines))))
+                 (delq 'dash (delq 'tilde (copy-sequence lines)))))
     ;; How many fields in the longest line?
     (condition-case nil
        (setq maxfields (apply 'max (mapcar 'length fields)))
@@ -770,19 +774,25 @@ When nil, simply write \"#ERROR\" in corrupted fields.")
                                    (concat (car c) space))))))))
 
     ;; Compute the formats needed for output of the table
-    (setq rfmt (concat indent "|") hfmt (concat indent "|"))
+    (setq rfmt (concat indent "|") hfmt (concat indent "|")
+         tfmt (concat indent "|"))
     (while (setq l (pop lengths))
       (setq ty (if (pop typenums) "" "-")) ; number types flushright
       (setq rfmt (concat rfmt (format rfmt1 ty l))
-           hfmt (concat hfmt (format hfmt1 (make-string l ?-)))))
+           hfmt (concat hfmt (format hfmt1 (make-string l ?-)))
+           tfmt (concat tfmt (format tfmt1 (make-string l ?~)))))
     (setq rfmt (concat rfmt "\n")
-         hfmt (concat (substring hfmt 0 -1) "|\n"))
-
+         hfmt (concat (substring hfmt 0 -1) "|\n")
+         tfmt (concat (substring tfmt 0 -1) "|\n"))
     (setq new (mapconcat
               (lambda (l)
-                (if l (apply 'format rfmt
-                             (append (pop fields) emptystrings))
-                  hfmt))
+                (cond ((eq l 'dash)
+                       hfmt)
+                      ((eq l 'tilde)
+                       tfmt)
+                      (t
+                       (apply 'format rfmt
+                              (append (pop fields) emptystrings)))))
               lines ""))
     (if (equal (char-before) ?\n)
        ;; This hack is for org-indent, to force redisplay of the


>From 306605c2f49710a80d47553cb9bdf318dadf4db7 Mon Sep 17 00:00:00 2001
From: Lawrence Mitchell <address@hidden>
Date: Wed, 2 Feb 2011 12:21:13 +0000
Subject: [PATCH 2/2] Correctly export internal table headers during LaTeX export
To: address@hidden

* lisp/org-latex.el (org-export-latex-tables): Allow for tildes in
table format (indicating internal headers).
(org-export-latex-content): Export tables before special characters to
deal with new tilde header style.
---
 lisp/org-latex.el |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/lisp/org-latex.el b/lisp/org-latex.el
index 9290c35..61dced4 100644
--- a/lisp/org-latex.el
+++ b/lisp/org-latex.el
@@ -1389,6 +1389,9 @@ links, keywords, lists, tables, fixed-width"
    (unless (memq 'emphasis exclude-list)
      (when (plist-get org-export-latex-options-plist :emphasize)
        (org-export-latex-fontify)))
+   (unless (memq 'tables exclude-list)
+     (org-export-latex-tables
+      (plist-get org-export-latex-options-plist :tables)))
    (unless (memq 'sub-superscript exclude-list)
      (org-export-latex-special-chars
       (plist-get org-export-latex-options-plist :sub-superscript)))
@@ -1398,9 +1401,6 @@ links, keywords, lists, tables, fixed-width"
      (org-export-latex-keywords))
    (unless (memq 'lists exclude-list)
      (org-export-latex-lists))
-   (unless (memq 'tables exclude-list)
-     (org-export-latex-tables
-      (plist-get org-export-latex-options-plist :tables)))
    (unless (memq 'fixed-width exclude-list)
      (org-export-latex-fixed-width
       (plist-get org-export-latex-options-plist :fixed-width)))
@@ -1804,7 +1804,7 @@ The conversion is made depending of STRING-BEFORE and 
STRING-AFTER."
             ;; make a formatting string to reflect alignment
             (setq olines lines)
             (while (and (not line-fmt) (setq line (pop olines)))
-              (unless (string-match "^[ \t]*|-" line)
+              (unless (string-match "^[ \t]*|[-~]" line)
                 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
                 (setq fnum (make-vector (length fields) 0))
                 (setq line-fmt
@@ -1839,7 +1839,7 @@ The conversion is made depending of STRING-BEFORE and 
STRING-AFTER."
             (setq lines
                   (mapcar
                    (lambda(elem)
-                     (or (and (string-match "[ \t]*|-+" elem) 'hline)
+                     (or (and (string-match "[ \t]*|[-~]+" elem) 'hline)
                          (org-split-string (org-trim elem) "|")))
                    lines))
             (when insert
-- 
1.7.4.rc2.18.gb20e9




reply via email to

[Prev in Thread] Current Thread [Next in Thread]