Browse Source

Fix relative column references

* lisp/org-table.el (org-table-eval-formula): Treat relative column refs.

I cannot believe this did not work and nobody complained about this.
$-1 is supposed to refer to the value in the column to the left.  Now
this does work.
Carsten Dominik 9 years ago
parent
commit
4161d85da8
1 changed files with 7 additions and 3 deletions
  1. 7 3
      lisp/org-table.el

+ 7 - 3
lisp/org-table.el

@@ -2394,9 +2394,13 @@ not overwrite the stored one."
 		 t t form)))
 	(setq form0 form)
 	;; Insert the references to fields in same row
-	(while (string-match "\\$\\([0-9]+\\)" form)
-	  (setq n (string-to-number (match-string 1 form))
-		x (nth (1- (if (= n 0) n0 n)) fields))
+	(while (string-match "\\$\\([-+]?[0-9]+\\)" form)
+	  (setq n (+ (string-to-number (match-string 1 form))
+		     (if (member (substring form (match-beginning 1)
+					    (1+ (match-beginning 1)))
+				 '("+" "-"))
+			 n0 0))
+		x (nth (1- (if (= n 0) n0 (max n 1))) fields))
 	  (unless x (error "Invalid field specifier \"%s\""
 			   (match-string 0 form)))
 	  (setq form (replace-match