emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jambunathan K <kjambunathan@gmail.com>
To: Org Mode <emacs-orgmode@gnu.org>
Subject: [PATCH 2/2] org-odt.el: Put table style and col sizes under direct user control
Date: Mon, 29 Aug 2011 04:11:58 +0530	[thread overview]
Message-ID: <81ei05duq1.fsf_-_@gmail.com> (raw)
In-Reply-To: <81mxetdv47.fsf@gmail.com> (Jambunathan K.'s message of "Mon, 29 Aug 2011 04:03:28 +0530")

[-- Attachment #1: Type: text/plain, Size: 198 bytes --]


> I have worked up a patch which intends to give users more control over
> how tables are formatted. The patch modifies files that I don't own so
> the changes will take sometime to hit the repo.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-org-odt.el-Put-table-style-and-col-sizes-under-direc.patch --]
[-- Type: text/x-patch, Size: 8418 bytes --]

From 046a2d1793c50c99b5b58b3874540632513e4562 Mon Sep 17 00:00:00 2001
From: Jambunathan K <kjambunathan@gmail.com>
Date: Mon, 29 Aug 2011 02:33:17 +0530
Subject: [PATCH 2/2] org-odt.el: Put table style and col sizes under direct user control

* contrib/lisp/org-lparse.el
(org-lparse-table-get-colalign-info): Renamed
`org-forced-aligns' to `org-col-cookies'.  Renamed local
variable `forced-aligns' to `col-cookies'.
(org-lparse-format-table-row): With the introduction of
`org-col-cookies' property the internal structure of
`org-lparse-table-colalign-info' has changed.  Do the right
thing while setting up col alignment.  Pass on the colwidth
property as horiz-span arg of `TABLE-CELL' callback.
* contrib/lisp/org-odt.el (org-odt-begin-table): Let the table
style be settable throught #+ATTR_ODT line.  By default tables
are configured to occupy 90% of paper width.  This is too big
for smaller tables.  For aesthetic reasons, a user might
prefer that such tables of shorter width and thus specify a
different style.
(org-odt-end-table, org-odt-format-table-cell): Honor colwidth
specification.
* contrib/lisp/org-xhtml.el (org-xhtml-format-table-cell): Fix
signature as mandated by changes in TABLE-CELL callback.

See comments in the earlier patch. See also
http://lists.gnu.org/archive/html/emacs-orgmode/2011-08/msg01053.html
---
 contrib/lisp/org-lparse.el |   36 ++++++++++++---------
 contrib/lisp/org-odt.el    |   75 ++++++++++++++++++++++++++-----------------
 contrib/lisp/org-xhtml.el  |    2 +-
 3 files changed, 66 insertions(+), 47 deletions(-)

diff --git a/contrib/lisp/org-lparse.el b/contrib/lisp/org-lparse.el
index fd0488b..b176378 100755
--- a/contrib/lisp/org-lparse.el
+++ b/contrib/lisp/org-lparse.el
@@ -1301,13 +1301,12 @@ version."
 	(org-lparse-format-table-table lines))))
 
 (defun org-lparse-table-get-colalign-info (lines)
-  (let ((forced-aligns (org-find-text-property-in-string
-			'org-forced-aligns (car lines))))
-    (when (and forced-aligns org-table-clean-did-remove-column)
-      (setq forced-aligns
-	    (mapcar (lambda (x) (cons (1- (car x)) (cdr x))) forced-aligns)))
-
-    forced-aligns))
+  (let ((col-cookies (org-find-text-property-in-string
+			'org-col-cookies (car lines))))
+    (when (and col-cookies org-table-clean-did-remove-column)
+      (setq col-cookies
+	    (mapcar (lambda (x) (cons (1- (car x)) (cdr x))) col-cookies)))
+    col-cookies))
 
 (defvar org-lparse-table-style)
 (defvar org-lparse-table-ncols)
@@ -1945,12 +1944,13 @@ See `org-xhtml-entity-format-callbacks-alist' for more information."
 	    (make-vector org-lparse-table-ncols nil))
       (let ((c -1))
 	(while  (< (incf c) org-lparse-table-ncols)
-	  (let ((cookie (cdr (assoc (1+ c) org-lparse-table-colalign-info))))
+	  (let* ((col-cookie (cdr (assoc (1+ c) org-lparse-table-colalign-info)))
+		 (align (nth 0 col-cookie)))
 	    (setf (aref org-lparse-table-colalign-vector c)
 		  (cond
-		   ((string= cookie "l") "left")
-		   ((string= cookie "r") "right")
-		   ((string= cookie "c") "center")
+		   ((string= align "l") "left")
+		   ((string= align "r") "right")
+		   ((string= align "c") "center")
 		   (t nil))))))))
   (incf org-lparse-table-rownum)
   (let ((i -1))
@@ -1961,11 +1961,15 @@ See `org-xhtml-entity-format-callbacks-alist' for more information."
 	(when (and (string= x "") text-for-empty-fields)
 	  (setq x text-for-empty-fields))
 	(incf i)
-	(and org-lparse-table-is-styled
-	     (< i org-lparse-table-ncols)
-	     (string-match org-table-number-regexp x)
-	     (incf (aref org-lparse-table-num-numeric-items-per-column i)))
-	(org-lparse-format 'TABLE-CELL x org-lparse-table-rownum i))
+	(let (col-cookie horiz-span)
+	  (when org-lparse-table-is-styled
+	    (when (and (< i org-lparse-table-ncols)
+		       (string-match org-table-number-regexp x))
+	      (incf (aref org-lparse-table-num-numeric-items-per-column i)))
+	    (setq col-cookie (cdr (assoc (1+ i) org-lparse-table-colalign-info))
+		  horiz-span (nth 1 col-cookie)))
+	  (org-lparse-format
+	   'TABLE-CELL x org-lparse-table-rownum i (or horiz-span 0))))
       fields "\n"))))
 
 (defun org-lparse-get (what &optional opt-plist)
diff --git a/contrib/lisp/org-odt.el b/contrib/lisp/org-odt.el
index a5b2d96..491ed44 100644
--- a/contrib/lisp/org-odt.el
+++ b/contrib/lisp/org-odt.el
@@ -644,15 +644,22 @@ PUB-DIR is set, use this as the publishing directory."
 
   (org-lparse-insert-tag
    "<table:table table:name=\"%s\" table:style-name=\"%s\">"
-   (or label "") "OrgTable")
+   (or label "") (or attributes "OrgTable"))
   (setq org-lparse-table-begin-marker (point)))
 
 (defun org-odt-end-table ()
   (goto-char org-lparse-table-begin-marker)
   (loop for level from 0 below org-lparse-table-ncols
-	do (insert
-	    (org-odt-format-tags
-	     "<table:table-column table:style-name=\"OrgTableColumn\"/>"  "")))
+	do (let* ((col-cookie (and org-lparse-table-is-styled
+				   (cdr (assoc (1+ level)
+					       org-lparse-table-colalign-info))))
+		  (extra-columns (or (nth 1 col-cookie) 0)))
+	     (dotimes (i (1+ extra-columns))
+	       (insert
+		(org-odt-format-tags
+		 "\n<table:table-column table:style-name=\"OrgTableColumn\"/>"
+		 "")))
+	     (insert "\n")))
 
   ;; fill style attributes for table cells
   (when org-lparse-table-is-styled
@@ -708,32 +715,40 @@ PUB-DIR is set, use this as the publishing directory."
 (defun org-odt-get-paragraph-style-for-table-cell (r c)
   (capitalize (aref org-lparse-table-colalign-vector c)))
 
-(defun org-odt-format-table-cell (data r c)
-  (if (not org-lparse-table-is-styled)
-      (org-odt-format-tags
-       '("<table:table-cell>" . "</table:table-cell>")
-       (org-odt-format-stylized-paragraph
-	(cond
-	 (org-lparse-table-cur-rowgrp-is-hdr "OrgTableHeading")
-	 ((and (= c 0) (org-lparse-get 'TABLE-FIRST-COLUMN-AS-LABELS))
-	  "OrgTableHeading")
-	 (t "OrgTableContents"))
-	data))
-    (let* ((style-name-cookie
-	    (format "@@table-cell:style-name@@%03d@@%03d@@" r c))
-	   (paragraph-style-cookie
-	    (concat
-	     (cond
-	      (org-lparse-table-cur-rowgrp-is-hdr "OrgTableHeading")
-	      ((and (= c 0) (org-lparse-get 'TABLE-FIRST-COLUMN-AS-LABELS))
-	       "OrgTableHeading")
-	      (t "OrgTableContents"))
-	     (format "@@table-cell:p@@%03d@@%03d@@" r c))))
-      (org-odt-format-tags
-       '("<table:table-cell table:style-name=\"%s\">" .
-	 "</table:table-cell>")
-       (org-odt-format-stylized-paragraph paragraph-style-cookie data)
-       style-name-cookie))))
+(defun org-odt-format-table-cell (data r c horiz-span)
+  (concat
+   (if (not org-lparse-table-is-styled)
+       (org-odt-format-tags
+	'("<table:table-cell>" . "</table:table-cell>")
+	(org-odt-format-stylized-paragraph
+	 (cond
+	  (org-lparse-table-cur-rowgrp-is-hdr "OrgTableHeading")
+	  ((and (= c 0) (org-lparse-get 'TABLE-FIRST-COLUMN-AS-LABELS))
+	   "OrgTableHeading")
+	  (t "OrgTableContents"))
+	 data))
+     (let* ((style-name-cookie
+	     (format "@@table-cell:style-name@@%03d@@%03d@@" r c))
+	    (paragraph-style-cookie
+	     (concat
+	      (cond
+	       (org-lparse-table-cur-rowgrp-is-hdr "OrgTableHeading")
+	       ((and (= c 0) (org-lparse-get 'TABLE-FIRST-COLUMN-AS-LABELS))
+		"OrgTableHeading")
+	       (t "OrgTableContents"))
+	      (format "@@table-cell:p@@%03d@@%03d@@" r c)))
+	    (extra (concat (and (> horiz-span 0)
+				(format " table:number-columns-spanned=\"%d\""
+					(1+ horiz-span))))))
+       (org-odt-format-tags
+	'("<table:table-cell table:style-name=\"%s\"%s>" .
+	  "</table:table-cell>")
+	(org-odt-format-stylized-paragraph paragraph-style-cookie data)
+	style-name-cookie extra)))
+   (let (s)
+     (dotimes (i horiz-span)
+       (setq s (concat s "\n<table:covered-table-cell/>"))) s)
+   "\n"))
 
 (defun org-odt-begin-footnote-definition (n)
   (org-lparse-begin-paragraph 'footnote))
diff --git a/contrib/lisp/org-xhtml.el b/contrib/lisp/org-xhtml.el
index 8a8f4ca..07f9493 100644
--- a/contrib/lisp/org-xhtml.el
+++ b/contrib/lisp/org-xhtml.el
@@ -1558,7 +1558,7 @@ lang=\"%s\" xml:lang=\"%s\">
    (cons (eval (car org-export-table-row-tags))
 	 (eval (cdr org-export-table-row-tags))) row))
 
-(defun org-xhtml-format-table-cell (text r c)
+(defun org-xhtml-format-table-cell (text r c horiz-span)
   (let ((cell-style-cookie (or (and org-lparse-table-is-styled
 				    (format "@@class%03d@@" c)) "")))
     (cond
-- 
1.7.2.3


  parent reply	other threads:[~2011-08-28 22:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-25 15:12 org->odt/html table export: adjusting default behaviour? Matt Price
2011-08-25 15:36 ` Matt Price
2011-08-25 21:40 ` Jambunathan K
2011-08-26 14:24   ` Matt Price
2011-08-28 22:33     ` Jambunathan K
2011-08-28 22:40       ` [PATCH 1/2] Parse and store both col align and col width spec for later use Jambunathan K
2011-08-28 22:41       ` Jambunathan K [this message]
2011-09-14  9:56   ` [odt] Support for table templates (was Re: org->odt/html table export: adjusting default behaviour?) Jambunathan K
2011-08-25 22:01 ` org->odt/html table export: adjusting default behaviour? Jambunathan K
2011-08-26 14:13   ` Matt Price

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=81ei05duq1.fsf_-_@gmail.com \
    --to=kjambunathan@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).