Hello Org users,

  this example:

|   |     |   |
|---+-----+---|
|   |     |   |
|---+-----+---|
|   |     |   |
#+TBLFM: @I$2='(random 1000)
  works incorrectly for me (Org 8.2.7c from ELPA, Emacs 24.3,
Win7): C-c C-c on the #+TBLFM line updates four cells
(@2$1, @2$2, @3$1, @3$2) instead of one (expected response:
update of @2$2 only).

  I crafted a tiny change for my org-table.el to assign 1x1 cell
addresses "@I$2", "@III-2$4"... in the left-hand side of table formulae. 
The diff file is attached here:

*** c:/Users/andrea/AppData/Roaming/.emacs.d/elpa/org-20140908/org-table-original.el	Sat Sep 13 16:54:54 2014
--- c:/Users/andrea/AppData/Roaming/.emacs.d/elpa/org-20140908/org-table.el	Sun Sep 14 23:39:13 2014
***************
*** 3216,3221 ****
--- 3216,3231 ----
         ((string-match "^@-?[-+0-9]+\\$-?[0-9]+$" lhs)
  	;; This just refers to one fixed field
  	(push e res))
+        ((string-match "^@\\(I+\\)\\(\\([-+]\\)?\\([0-9]+\\)\\)?\\(\\$-?[0-9]+\\)$" lhs)
+ 	;;		   1	   2  3		 4		5
+ 	;; This just refers to one field with hline-based row fixed column
+ 	(let*
+ 	    (
+ 	     (m1       (match-string 1 lhs))
+ 	     (m2       (match-string 2 lhs))
+ 	     (m5       (match-string 5 lhs))
+ 	     (m1m2line (org-table-line-to-dline (org-table-get-descriptor-line (concat m1 m2)))))
+ 	  (push (cons (format "@%d%s" m1m2line m5) (cdr e)) res)))
         ((string-match "^[a-zA-Z][_a-zA-Z0-9]*$" lhs)
  	;; This just refers to one fixed named field
  	(push e res))
  May I please ask for some feedback to Org users who installed Org
from ELPA: if you apply the diff, does example-hline-refs.org work
properly (i.e. formula recalculation updates only cell @2$2)?
Does it work good also for other values like @II-1$2, @I+1$1 etc.?

  Thanks in advance for any feedback you may provide, kindest regards.

  Andrea


  PS1: 1xN ranges like "@I", "@I+1" aren't managed by the proposed
tiny change. Another (similar) tiny change would be needed in order
to support them.

  PS2: if you want to test the diff without messing your Org
installation, you might simply...

 - open org-table.el
 - copy&paste the additional code into function org-table-expand-lhs-ranges
 - reevaluate the (defun org-table-expand-lhs-ranges ...) statement with
   C-x C-e
 - kill the org-table.el buffer without saving the file
 - play again with example-hline-refs.org

  PS3: I believe the change will not work for Org versions
installed from git master, because at some point in org table
there's a code check forbidding hline refs:

(if (string-match "^@-?I+" (car x))
    (user-error "Can't assign to hline relative reference"))

  Motivations for that code check were discussed here:
http://thread.gmane.org/gmane.emacs.orgmode/71562 ,
I hope the proposed diff could make the check unnecessary
or less strict in the future.

Reply via email to