From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrea Rossetti Subject: trying to add hline refs ("@I$2") in lhs of formulae Date: Mon, 15 Sep 2014 02:51:34 +0200 Message-ID: <848ullu2nd.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:52403) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTKW9-0000O3-Fj for emacs-orgmode@gnu.org; Sun, 14 Sep 2014 20:51:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XTKW3-0002nb-GZ for emacs-orgmode@gnu.org; Sun, 14 Sep 2014 20:51:45 -0400 Received: from mail-wg0-x22d.google.com ([2a00:1450:400c:c00::22d]:45866) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTKW3-0002mv-8c for emacs-orgmode@gnu.org; Sun, 14 Sep 2014 20:51:39 -0400 Received: by mail-wg0-f45.google.com with SMTP id z12so3094615wgg.4 for ; Sun, 14 Sep 2014 17:51:37 -0700 (PDT) Received: from LAPTOP-ANDREA.laptop-andrea.trieste.it (net-93-144-105-140.cust.dsl.teletu.it. [93.144.105.140]) by mx.google.com with ESMTPSA id ga9sm12909442wjb.45.2014.09.14.17.51.35 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 14 Sep 2014 17:51:36 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Hello Org users, this example: --=-=-= Content-Type: text/x-org Content-Disposition: inline; filename=example-hline-refs.org | | | | |---+-----+---| | | | | |---+-----+---| | | | | #+TBLFM: @I$2='(random 1000) --=-=-= Content-Type: text/plain 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: --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=handle-hline-refs-in-expand-lhs.diff *** 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)) --=-=-= Content-Type: text/plain 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. --=-=-=--