From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jambunathan K 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 Message-ID: <81ei05duq1.fsf_-_@gmail.com> References: <81pqjtqife.fsf@gmail.com> <81mxetdv47.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([140.186.70.92]:48930) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qxo4G-00041k-4u for emacs-orgmode@gnu.org; Sun, 28 Aug 2011 18:43:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qxo4E-0002pI-KU for emacs-orgmode@gnu.org; Sun, 28 Aug 2011 18:43:04 -0400 Received: from mail-pz0-f44.google.com ([209.85.210.44]:36833) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qxo4E-0002pE-8g for emacs-orgmode@gnu.org; Sun, 28 Aug 2011 18:43:02 -0400 Received: by pzk36 with SMTP id 36so8673130pzk.17 for ; Sun, 28 Aug 2011 15:43:01 -0700 (PDT) In-Reply-To: <81mxetdv47.fsf@gmail.com> (Jambunathan K.'s message of "Mon, 29 Aug 2011 04:03:28 +0530") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Org Mode --=-=-= Content-Type: text/plain > 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. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-org-odt.el-Put-table-style-and-col-sizes-under-direc.patch >From 046a2d1793c50c99b5b58b3874540632513e4562 Mon Sep 17 00:00:00 2001 From: Jambunathan K 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 "" - (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 - "" ""))) + 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" + ""))) + (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 - '("" . "") - (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 - '("" . - "") - (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 + '("" . "") + (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 + '("" . + "") + (org-odt-format-stylized-paragraph paragraph-style-cookie data) + style-name-cookie extra))) + (let (s) + (dotimes (i horiz-span) + (setq s (concat s "\n"))) 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 --=-=-=--