From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jason Riedy Subject: [PATCH 2/4] Support last-line specializers. Date: Wed, 16 Apr 2008 14:39:52 -0700 Message-ID: <1208381994-7893-3-git-send-email-jason@acm.org> References: <1208381994-7893-1-git-send-email-jason@acm.org> Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JmFMP-0000IF-Op for emacs-orgmode@gnu.org; Wed, 16 Apr 2008 17:40:10 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JmFMK-0000Fu-C3 for emacs-orgmode@gnu.org; Wed, 16 Apr 2008 17:40:06 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JmFMJ-0000Fc-Rn for emacs-orgmode@gnu.org; Wed, 16 Apr 2008 17:40:03 -0400 Received: from a.mail.sonic.net ([64.142.16.245]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JmFMI-0007er-QJ for emacs-orgmode@gnu.org; Wed, 16 Apr 2008 17:40:03 -0400 Received: from localhost.localdomain (209-204-163-7.vpn.sonic.net [209.204.163.7]) (authenticated bits=0) by a.mail.sonic.net (8.13.8.Beta0-Sonic/8.13.7) with ESMTP id m3GLduO5002451 for ; Wed, 16 Apr 2008 14:40:00 -0700 In-Reply-To: <1208381994-7893-1-git-send-email-jason@acm.org> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Each of lstart, lend, and lfmt permits a last-line specialization called llstart, etc. with corresponding heading versions. Signed-off-by: Jason Riedy --- ChangeLog | 10 ++++++++++ lisp/org-table.el | 32 ++++++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4569d3a..13980bf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2008-04-15 Jason Riedy + * lisp/org-table.el (*orgtbl-llfmt*, *orgtbl-llstart*) + (*orgtbl-llend*): Dynamic variables for last-line formatting. + (orgtbl-format-section): Shift formatting to support detecting the + last line and formatting it specially. + (orgtbl-to-generic): Document :ll* formats. Set to the non-ll + formats unless overridden. + (orgtbl-to-latex): Suggest using :llend to suppress the final \\. + +2008-04-15 Jason Riedy + * lisp/org-table.el (*orgtbl-table*, *orgtbl-rtn*): Dynamically bound variables to hold the input collection of lines and output formatted text. diff --git a/lisp/org-table.el b/lisp/org-table.el index 3cc70c1..2eb9938 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -3613,8 +3613,11 @@ First element has index 0, or I0 if given." (defvar *orgtbl-fmt* nil "Format for each entry") (defvar *orgtbl-efmt* nil "Format for numbers") (defvar *orgtbl-lfmt* nil "Format for an entire line, overrides fmt") +(defvar *orgtbl-llfmt* nil "Specializes lfmt for the last row") (defvar *orgtbl-lstart* nil "Text starting a row") +(defvar *orgtbl-llstart* nil "Specializes lstart for the last row") (defvar *orgtbl-lend* nil "Text ending a row") +(defvar *orgtbl-llend* nil "Specializes lend for the last row") (defun orgtbl-format-line (line) "Format LINE as a table row." @@ -3644,9 +3647,15 @@ First element has index 0, or I0 if given." (defun orgtbl-format-section (section-stopper) "Format lines until the first occurrence of SECTION-STOPPER." - (progn - (while (not (eq (car *orgtbl-table*) section-stopper)) - (orgtbl-format-line (pop *orgtbl-table*))))) + (let (prevline) + (progn + (while (not (eq (car *orgtbl-table*) section-stopper)) + (if prevline (orgtbl-format-line prevline)) + (setq prevline (pop *orgtbl-table*))) + (if prevline (let ((*orgtbl-lstart* *orgtbl-llstart*) + (*orgtbl-lend* *orgtbl-llend*) + (*orgtbl-lfmt* *orgtbl-llfmt*)) + (orgtbl-format-line prevline)))))) (defun orgtbl-to-generic (table params) "Convert the orgtbl-mode TABLE to some other format. @@ -3670,17 +3679,20 @@ Valid parameters are May be nil to ignore hlines. :lstart String to start a new table line. +:llstart String to start the last table line, defaults to :lstart. :lend String to end a table line +:llend String to end the last table line, defaults to :lend. :sep Separator between two fields :lfmt Format for entire line, with enough %s to capture all fields. If this is present, :lstart, :lend, and :sep are ignored. +:llfmt Format for the entire last line, defaults to :lfmt. :fmt A format to be used to wrap the field, should contain %s for the original field value. For example, to wrap everything in dollars, you could use :fmt \"$%s$\". This may also be a property list with column numbers and formats. For example :fmt (2 \"$%s$\" 4 \"%s%%\") -:hlstart :hlend :hlsep :hlfmt :hfmt +:hlstart :hllstart :hlend :hllend :hlsep :hlfmt :hllfmt :hfmt Same as above, specific for the header lines in the table. All lines before the first hline are treated as header. If any of these is not present, the data line value is used. @@ -3700,8 +3712,11 @@ directly by `orgtbl-send-table'. See manual." (*orgtbl-sep* (plist-get params :sep)) (*orgtbl-efmt* (plist-get params :efmt)) (*orgtbl-lstart* (plist-get params :lstart)) + (*orgtbl-llstart* (or (plist-get params :llstart) *orgtbl-lstart*)) (*orgtbl-lend* (plist-get params :lend)) + (*orgtbl-llend* (or (plist-get params :llend) *orgtbl-lend*)) (*orgtbl-lfmt* (plist-get params :lfmt)) + (*orgtbl-llfmt* (or (plist-get params :llfmt) *orgtbl-lfmt*)) (*orgtbl-fmt* (plist-get params :fmt)) *orgtbl-rtn*) @@ -3716,8 +3731,14 @@ directly by `orgtbl-send-table'. See manual." (progn (let* ((*orgtbl-lstart* (or (plist-get params :hlstart) *orgtbl-lstart*)) + (*orgtbl-llstart* (or (plist-get params :hllstart) + *orgtbl-llstart*)) (*orgtbl-lend* (or (plist-get params :hlend) *orgtbl-lend*)) + (*orgtbl-llend* (or (plist-get params :hllend) + (plist-get params :hlend) *orgtbl-llend*)) (*orgtbl-lfmt* (or (plist-get params :hlfmt) *orgtbl-lfmt*)) + (*orgtbl-llfmt* (or (plist-get params :hllfmt) + (plist-get params :hlfmt) *orgtbl-llfmt*)) (*orgtbl-sep* (or (plist-get params :hlsep) *orgtbl-sep*)) (*orgtbl-fmt* (or (plist-get params :hfmt) *orgtbl-fmt*))) (orgtbl-format-section 'hline)) @@ -3753,6 +3774,9 @@ LaTeX are: example \"%s\\\\times10^{%s}\". LaTeX default is \"%s\\\\,(%s)\". This may also be a property list with column numbers and formats. +:llend If you find too much space below the last line of a table, + pass a value of \"\" for :llend to suppress the final \\\\. + The general parameters :skip and :skipcols have already been applied when this function is called." (let* ((alignment (mapconcat (lambda (x) (if x "r" "l")) -- 1.5.5.rc1.121.g1594