From mboxrd@z Thu Jan 1 00:00:00 1970 From: Piyush Srivastava Subject: Bug: Table update fails for named fields [9.1.13 (release_9.1.13)] Date: Sun, 20 May 2018 20:09:46 +0530 Message-ID: <87603iz8zx.fsf@tifr.res.in> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43314) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKPVF-0004Ry-5o for emacs-orgmode@gnu.org; Sun, 20 May 2018 10:40:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fKPVB-0001zP-A0 for emacs-orgmode@gnu.org; Sun, 20 May 2018 10:40:05 -0400 Received: from mailhost.tifr.res.in ([2406:f00:1:1::6c]:55791) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fKPVA-0001vn-To for emacs-orgmode@gnu.org; Sun, 20 May 2018 10:40:01 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by mailhost.tifr.res.in (Postfix) with ESMTP id 73A1741F7 for ; Sun, 20 May 2018 20:09:55 +0530 (IST) Received: from mailhost.tifr.res.in ([127.0.0.1]) by localhost (mailhost.tifr.res.in [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GxO8HUzyWVdQ for ; Sun, 20 May 2018 20:09:50 +0530 (IST) Received: from vyom (unknown [158.144.106.131]) by mailhost.tifr.res.in (Postfix) with ESMTPSA id 22C9841F9 for ; Sun, 20 May 2018 20:09:49 +0530 (IST) 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" To: emacs-orgmode@gnu.org In the current org mode version (release_9.1.13), when a named cell formula is stored using C-u C-c =, the #+TBLFM line stores the name of the cell without a prefix '$' sign, as in the following table (notice that is the #+TBLFM row, there is no '$' sign before the 'sum' variable): | | c | |---+-----| | | 3 | | | 10 | |---+-----| | # | 14 | | ^ | sum | |---+-----| #+TBLFM: sum=vsum(@-II$0..@-I$0) With this storage, pressing TAB in the row after changing some entries does not update the filed referred to by 'sum', contrary to the description in the manual. However, if I manually prefix a '$; to the variable 'sum' as in the table below, then TAB update work as described in the manual (notice the $sum variable in the #+TBLFM row): | | c | |---+-----| | | 3 | | | 12 | |---+-----| | # | 15 | | ^ | sum | |---+-----| #+TBLFM: $sum=vsum(@-II$0..@-I$0) A fix is to ensure that if the LHS of a field formula being inserted is a field name rather than a numerical reference, then a '$' is prefixed to it. I have the following patch with implements this: diff --git a/lisp/org-table.el b/lisp/org-table.el --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -2301,7 +2301,13 @@ LOCATION instead." (org-indent-line) (insert (or (match-string 2) "#+TBLFM:"))) (insert " " - (mapconcat (lambda (x) (concat (car x) "=" (cdr x))) + (mapconcat (lambda (x) + (let* ((name (car x)) + (first (substring-no-properties name 0 1)) + (test (or (string= first "@") (string= first "$"))) + ) + (concat (if test name (concat "$" name)) + "=" (cdr x)))) (sort alist #'org-table-formula-less-p) "::") "\n")))) What this patch does is the following: if the reference being inserted does not begin with an '@' or a '$', then it is assumed to be a named reference, and a '$' is prefixed to it. This will work *provided* no named references themselves start with a '$'. I am happy to assign copyright for the patch, if that is needed and if the patch if found suitable, for it to be included in org-mode code. Thanks, -- Piyush. Emacs : GNU Emacs 25.3.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.26) of 2018-02-09 Package: Org mode version 9.1.13 (release_9.1.13)