[O] [PATCH] [BUG] org-table.el: Fix `org-table-eval-formula'

2015-12-03 Thread Piotr Gajewski
Hello,

I have found a little bug that results in formulas of a table being
computed incorrectly. When there are tabs in front of a data row (instead of 
spaces),
the list of values extracted from the row contains superfluous items.
All genuine values are shifted to the right. Consequently, when references
to fields are resolved, a formula gets the wrong values.

Example:

    |---+--+--+---++-|
    | ! |  sum |  | a |  b |   c |
    |---+--+--+---++-|
    | # | 1011 | 1000 | 1 | 10 | 100 |
    |---+--+--+---++-|
    #+TBLFM: $2=$a+$b+$c

The list of extracted values is ("\t" "#" "" "1000" "1" "10" "100").
Should be ("#" "" "1000" "1" "10" "100").

Piotr Gajewski

>From 1c943f1ea833b9cdaa172fd96cf6bf6d86c4d86e Mon Sep 17 00:00:00 2001
From: Piotr Gajewski 
Date: Thu, 3 Dec 2015 16:46:32 +0100
Subject: [PATCH] org-table.el: Fix `org-table-eval-formula'

* lisp/org-table.el (org-table-eval-formula): Fix regexp used for
  extracting values from fields of a table.

TINYCHANGE
---
 lisp/org-table.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/org-table.el b/lisp/org-table.el
index 17424be..9ed8b6e 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -2723,7 +2723,7 @@ not overwrite the stored one."
   (while (> ndown 0)
 (setq fields (org-split-string
       (buffer-substring-no-properties (point-at-bol) (point-at-eol))
-          " *| *"))
+          "[ \t]*|[ \t]*"))
 ;; replace fields with duration values if relevant
 (if duration
     (setq fields
-- 
1.9.5.msysgit.0



  


[O] [PATCH] org-table.el: Fix regexp used for splitting data rows when computing a formula

2015-12-07 Thread Piotr Gajewski
* lisp/org-table.el (org-table-eval-formula): Fix regexp
  used for splitting data rows.

* Explanation /root node/

*** Example 1: Spaces ' ' in front of a data row (OK)

    |---+-+--+---++-|
    | ! | sum |  | a |  b |   c |
    |---+-+--+---++-|
    | # | 111 | 1000 | 1 | 10 | 100 |
    |---+-+--+---++-|
    #+TBLFM: $2=$a+$b+$c

    List of values after splitting data row:
    ("#" "" "1000" "1" "10" "100")

    Formula is computed correctly.

*** Example 2: Tabulators '\t' in front of a data row (ERROR)

    |---+--+--+---++-|
    | ! |  sum |  | a |  b |   c |
    |---+--+--+---++-|
    | # | 1011 | 1000 | 1 | 10 | 100 |
    |---+--+--+---++-|
    #+TBLFM: $2=$a+$b+$c

    List of values after splitting data row:
    ("\t" "#" "" "1000" "1" "10" "100")

    There is an extra field containing '\t' character(s).
    All /genuine/ values are shifted to the right.
    Consequently, references to fields lookup the wrong values.

TINYCHANGE
---
 lisp/org-table.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/org-table.el b/lisp/org-table.el
index 17424be..9ed8b6e 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -2723,7 +2723,7 @@ not overwrite the stored one."
   (while (> ndown 0)
     (setq fields (org-split-string
           (buffer-substring-no-properties (point-at-bol) (point-at-eol))
-          " *| *"))
+          "[ \t]*|[ \t]*"))
     ;; replace fields with duration values if relevant
     (if duration
     (setq fields
-- 
1.9.5.msysgit.0