* trying to add hline refs ("@I$2") in lhs of formulae
@ 2014-09-15 0:51 Andrea Rossetti
0 siblings, 0 replies; only message in thread
From: Andrea Rossetti @ 2014-09-15 0:51 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 35 bytes --]
Hello Org users,
this example:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: example-hline-refs.org --]
[-- Type: text/x-org, Size: 109 bytes --]
| | | |
|---+-----+---|
| | | |
|---+-----+---|
| | | |
#+TBLFM: @I$2='(random 1000)
[-- Attachment #3: Type: text/plain, Size: 372 bytes --]
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:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: handle-hline-refs-in-expand-lhs.diff --]
[-- Type: text/x-patch, Size: 980 bytes --]
*** 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))
[-- Attachment #5: Type: text/plain, Size: 1337 bytes --]
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.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2014-09-15 0:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-15 0:51 trying to add hline refs ("@I$2") in lhs of formulae Andrea Rossetti
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).