From 8bae4b059a3063a866260ed2958e6c1e05365901 Mon Sep 17 00:00:00 2001 From: Jambunathan K Date: Mon, 29 Aug 2011 02:00:24 +0530 Subject: [PATCH 1/2] Parse and store both col align and col width spec for later use * lisp/org-exp.el (org-store-forced-table-alignment): Parse the column cookie for both alignment and width specification. Store the resulting value in `org-col-cookies' property. Retire the previously used `org-forced-aligns' property for consistency. Renamed local variable `aligns' to `cookies'. * lisp/org-html.el (org-format-org-table-html): Use `org-col-cookies'. Renamed local variable forced-aligns to col-cookies. This is a preparatory patch. A backend can look at the colwidth specification and (at it's discretion) use it to control relative sizes of individual columns in a table. At this moment, it is unclear whether the widths used to control the display of table in Org buffer can be overloaded to also control the formatting of table in a backend. Refer following discussion with Matt Price: http://lists.gnu.org/archive/html/emacs-orgmode/2011-08/msg01053.html --- lisp/org-exp.el | 17 +++++++++++------ lisp/org-html.el | 14 +++++++------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lisp/org-exp.el b/lisp/org-exp.el index f795fbd..7d6bd38 100644 --- a/lisp/org-exp.el +++ b/lisp/org-exp.el @@ -1995,23 +1995,28 @@ When it is nil, all comments will be removed." (defun org-store-forced-table-alignment () "Find table lines which force alignment, store the results in properties." - (let (line cnt aligns) + (let (line cnt cookies) (goto-char (point-min)) - (while (re-search-forward "|[ \t]*<[lrc][0-9]*>[ \t]*|" nil t) + (while (re-search-forward "|[ \t]*<\\([lrc]?[0-9]+\\|[lrc]\\)>[ \t]*|" + nil t) ;; OK, this looks like a table line with an alignment cookie (org-if-unprotected (setq line (buffer-substring (point-at-bol) (point-at-eol))) (when (and (org-at-table-p) (org-table-cookie-line-p line)) - (setq cnt 0 aligns nil) + (setq cnt 0 cookies nil) (mapc (lambda (x) (setq cnt (1+ cnt)) - (if (string-match "\\`<\\([lrc]\\)" x) - (push (cons cnt (downcase (match-string 1 x))) aligns))) + (when (string-match "\\`<\\([lrc]\\)?\\([0-9]+\\)?>\\'" x) + (let ((align (and (match-end 1) + (downcase (match-string 1 x)))) + (width (and (match-end 2) + (string-to-number (match-string 2 x))))) + (push (cons cnt (list align width)) cookies)))) (org-split-string line "[ \t]*|[ \t]*")) (add-text-properties (org-table-begin) (org-table-end) - (list 'org-forced-aligns aligns)))) + (list 'org-col-cookies cookies)))) (goto-char (point-at-eol))))) (defun org-export-remove-special-table-lines () diff --git a/lisp/org-html.el b/lisp/org-html.el index 28a0e8f..a6e748a 100644 --- a/lisp/org-html.el +++ b/lisp/org-html.el @@ -1979,8 +1979,8 @@ for formatting. This is required for the DocBook exporter." (let* ((caption (org-find-text-property-in-string 'org-caption (car lines))) (label (org-find-text-property-in-string 'org-label (car lines))) - (forced-aligns (org-find-text-property-in-string 'org-forced-aligns - (car lines))) + (col-cookies (org-find-text-property-in-string 'org-col-cookies + (car lines))) (attributes (org-find-text-property-in-string 'org-attributes (car lines))) (html-table-tag (org-export-splice-attributes @@ -1993,9 +1993,9 @@ for formatting. This is required for the DocBook exporter." tbopen line fields html gr colgropen rowstart rowend ali align aligns n) (setq caption (and caption (org-html-do-expand caption))) - (when (and forced-aligns org-table-clean-did-remove-column) - (setq forced-aligns - (mapcar (lambda (x) (cons (1- (car x)) (cdr x))) forced-aligns))) + (when (and col-cookies org-table-clean-did-remove-column) + (setq col-cookies + (mapcar (lambda (x) (cons (1- (car x)) (cdr x))) col-cookies))) (if splice (setq head nil)) (unless splice (push (if head "" "") html)) (setq tbopen t) @@ -2056,8 +2056,8 @@ for formatting. This is required for the DocBook exporter." (lambda (x) (setq gr (pop org-table-colgroup-info) i (1+ i) - align (if (assoc i forced-aligns) - (cdr (assoc (cdr (assoc i forced-aligns)) + align (if (nth 1 (assoc i col-cookies)) + (cdr (assoc (nth 1 (assoc i col-cookies)) '(("l" . "left") ("r" . "right") ("c" . "center")))) (if (> (/ (float x) nline) -- 1.7.2.3