emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] [BUG] org-table.el: Fix `org-table-eval-formula'
@ 2015-12-03 16:17 Piotr Gajewski
  2015-12-04 20:40 ` Nicolas Goaziou
  0 siblings, 1 reply; 2+ messages in thread
From: Piotr Gajewski @ 2015-12-03 16:17 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

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 <address@hidden>
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



 		 	   		  

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] [BUG] org-table.el: Fix `org-table-eval-formula'
  2015-12-03 16:17 [PATCH] [BUG] org-table.el: Fix `org-table-eval-formula' Piotr Gajewski
@ 2015-12-04 20:40 ` Nicolas Goaziou
  0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Goaziou @ 2015-12-04 20:40 UTC (permalink / raw)
  To: Piotr Gajewski; +Cc: emacs-orgmode@gnu.org, piotr.gajewski

Hello,

Piotr Gajewski <pg7@outlook.com> writes:

> 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 <address@hidden>
> 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

Thanks for the patch. 

However I eventually applied a slightly different one. In particular,
I don't think TAB should be a valid cell alignment character within
a table. IMO, it is only a special character when used in indentation.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-12-04 20:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-03 16:17 [PATCH] [BUG] org-table.el: Fix `org-table-eval-formula' Piotr Gajewski
2015-12-04 20:40 ` Nicolas Goaziou

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).