From 44622297420c16676b11dfa8b306098ded0081e7 Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Sat, 24 Apr 2010 10:22:49 +0200 Subject: [PATCH] Fix table formula bug with negative result numbers Willian Henney writes: > The following is using today's git trunk of org-mode with emacs > 23.1.94.1 (aquamacs 2.0preview5) > > Consider the following table > > | -8 | > | | > | | > | | > #+TBLFM: $1=@-1 - 1::@1$1=-8 > > Evaluate formulas once (C-u C-c *): > > | -8 | > | -9 | > |----| > | -1 | > > Evaluate formulas again (C-u C-c *): > > | -8 | > | -9 | > |----| > |----| > > What I expected: > > | -8 | > | -9 | > | -10 | > | -11 | > > The problem always seems to start at -10. When I turn on table > debugging, it first calculates the -10 value correctly, but then fails > to recognise the -10 cell as a number when calculating the next row, > using 0 instead, which results in -1. This is because during the > intermediate formatting of the cell the minus sign in -10 abuts the > column separator: "|-10 |", and the "|-" part is then interpreted as > the beginning of an hline. --- lisp/ChangeLog | 5 +++++ lisp/org-table.el | 1 + 2 files changed, 6 insertions(+) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index fa5703ae5..f4800f05c 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2010-04-24 Carsten Dominik + + * org-table.el (org-table-justify-field-maybe): Make sure that + inserting a value does not turn a line into a hline. + 2010-04-23 Carsten Dominik * org-clock.el (org-clock-sum): New argument HEADLINE-FILTER. diff --git a/lisp/org-table.el b/lisp/org-table.el index c2df70626..430975986 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -830,6 +830,7 @@ Optional argument NEW may specify text to replace the current field content." (if (<= (length new) l) ;; FIXME: length -> str-width? (setq n (format f new)) (setq n (concat new "|") org-table-may-need-update t))) + (if (equal (string-to-char n) ?-) (setq n (concat " " n))) (or (equal n o) (let (org-table-may-need-update) (replace-match n t t))))