emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Piyush Srivastava <piyush.srivastava@tifr.res.in>
To: emacs-orgmode@gnu.org
Subject: Bug: Table update fails for named fields [9.1.13 (release_9.1.13)]
Date: Sun, 20 May 2018 20:10:24 +0530	[thread overview]
Message-ID: <874lj2z8yv.fsf@tifr.res.in> (raw)


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)

             reply	other threads:[~2018-05-20 14:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-20 14:40 Piyush Srivastava [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-05-20 14:39 Bug: Table update fails for named fields [9.1.13 (release_9.1.13)] Piyush Srivastava

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874lj2z8yv.fsf@tifr.res.in \
    --to=piyush.srivastava@tifr.res.in \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).