Browse Source

org-table.el (org-table-eval-formula): Better error throwing

* org-table.el (org-table-eval-formula): Throw an error when
trying to replace a wrong formula specifier.

Thanks to Alejandro Suarez for reporting this.
Bastien Guerry 10 years ago
parent
commit
d4799ebfc1
1 changed files with 11 additions and 9 deletions
  1. 11 9
      lisp/org-table.el

+ 11 - 9
lisp/org-table.el

@@ -2758,15 +2758,17 @@ not overwrite the stored one."
 	(while (string-match "\\$\\(\\([-+]\\)?[0-9]+\\)" form)
 	  (setq n (+ (string-to-number (match-string 1 form))
 		     (if (match-end 2) n0 0))
-		x (nth (1- (if (= n 0) n0 (max n 1))) fields))
-	  (unless x (user-error "Invalid field specifier \"%s\""
-			   (match-string 0 form)))
-	  (setq form (replace-match
-		      (save-match-data
-			(org-table-make-reference
-			 x keep-empty numbers lispp))
-		      t t form)))
-
+		x (nth (1- (if (= n 0) n0 (max n 1))) fields)
+		formrpl (save-match-data
+			  (org-table-make-reference
+			   x keep-empty numbers lispp)))
+	  (when (or (not x)
+		    (save-match-data
+		      (string-match (regexp-quote formula) formrpl)))
+	    (user-error "Invalid field specifier \"%s\""
+			(match-string 0 form)))
+	  (setq form (replace-match repl t t form)))
+	
 	(if lispp
 	    (setq ev (condition-case nil
 			 (eval (eval (read form)))