From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id 8HXVKCLjW2dkJgAAqHPOHw:P1 (envelope-from ) for ; Fri, 13 Dec 2024 07:32:50 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id 8HXVKCLjW2dkJgAAqHPOHw (envelope-from ) for ; Fri, 13 Dec 2024 08:32:50 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=meSgzLrT; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1734075170; a=rsa-sha256; cv=none; b=UeoZ3xMp3Esk1VdOY+cRkSRmxURcRe8SxpLpAv/hxB8OatlTvcgAaul2KKXcqEX7nt6K9q GjMt94lTmev+VbO6I4w+LJXIFeYknEjRZKs/NG7pKZkqpqgsbRYHc5MDlNlBQZ31Z2Hbp9 J38WO2TvqOAlGXAegeI3j4rT2vAJ+u8eefiFlrCnvZwjvheCIox1V68TIiBPbfzGptwhuG Zsvt7KGabrfMXqOs20vtB0IevcS82AgV1U0W2AyT8oHzpwBBkn1Eq21aS+3TI2SihYEmzV IOFNSI8v5D+vWxG5lwqY8h2zalIggbQQ7pN/VUwgYj5GnJjZVM717je/tJ8VUw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=meSgzLrT; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1734075170; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=qLLiCNsAebr3JpiPGmSvUl+5okE9DVUCvd6RYOKrkEI=; b=d1K2Qbwp0efEoMsFddGrxYPm89Cq9nKal7m+R8IrdzfZx/eRiiFAHBLFBTt4IIIve7Mgq9 Bgk5PCTPbDcplHbNcLc88FW4MRrRXFu6lrUFlnce+7Z7w8vOP2HUcvlUwLEiJKe67QhIfx sduU/JWx3SVFinmHiYsLFQ8cy7KBlDq5zz0CzMKz6sznGVzAs+FX+CqCyAcFy4b0KN2FTZ 1ohu6AfNl3U6CN/4MHC6pchOn9tWZdmHpPaZfshALj38mHO17kLEuACWLYWG8j3F/YUBYB 3hUrsrEZF2cPp3GhH5p4IiCfkABd0x9Xwm388UhhFM0u3qlKRaBjDMZzGysfOw== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D71F2555AE for ; Fri, 13 Dec 2024 08:32:49 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tM09M-0002as-WE; Fri, 13 Dec 2024 02:31:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tM09K-0002ag-QF for emacs-orgmode@gnu.org; Fri, 13 Dec 2024 02:31:46 -0500 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tM09J-0002mw-4j for emacs-orgmode@gnu.org; Fri, 13 Dec 2024 02:31:46 -0500 Received: by mail-pj1-x1044.google.com with SMTP id 98e67ed59e1d1-2ee50ffcf14so2143178a91.0 for ; Thu, 12 Dec 2024 23:31:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734075103; x=1734679903; darn=gnu.org; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qLLiCNsAebr3JpiPGmSvUl+5okE9DVUCvd6RYOKrkEI=; b=meSgzLrTltV8FLFO+PrSfRSEvJrxra4eZXhVl+tC7L81VlSqLNqj4X1ftKpuLiB6WR XjN0wS0yNiVapoJeqpAa2js00CwrP49WJujgIuKCFSr/ydQKNzNLRsD5TEHEV7daF6WU NrqDF8mvAR006q5iPqmeT3048rCsT/TmCjdL1M+5EgCyyAQTp9Z3V1hEyF380ATX0LGF SvDE+3nPakjFQsTblTCThpoI44hB8yC9lWBgolH2iD6rxjZ4Avs6tJruVCPlj6mdqdoo aE81M8GpDfm/KT4CAtD/0reZuvtAYGN3TAW1ZsmM7pl6/rGeqK1RiDnYxlXPnvxRkssv rfQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734075103; x=1734679903; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:to:from:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=qLLiCNsAebr3JpiPGmSvUl+5okE9DVUCvd6RYOKrkEI=; b=FwtAVn5tLf5FLMWETG5F/EEpd06MqBIeCjb6udqO9aH2QUXQO2h4sEhoHVRvygGNFE t6v99dkpQoenIyyBubqpzjgxDp9Ak8ECBhUhe7/QfXfDFZsnXkJUN2WhNE/o9yDw+zMV fQ5KIOBOuC5hur8AlakpJuYjTEX0xydfx8aPCtfd1BeLkEQzEcS8JwnztxyPvO1oCR9B bhGBTyw8gH4WxTJK5I3MbT3G9Zafch8htJ5QpSy+Cmd2zP6YMLzSMdFLkTRXh9+uywUS J2IAQeo0PAbJu7GkfTvUiz9ABh31uJF3kAgvE5vxzp1HonZYdsxgGmVuGhDuCz7CuVxI kTXA== X-Gm-Message-State: AOJu0YyIKmtYebHlG22lKFYSJcomo9iCVxor4FNuoyACuN4VGOTZPTD4 OvyP3Q5O+S47kLYfHizW/CHe+W9WfA2aUS5AW8rCpN/WekxlOgI+cwrORb/1 X-Gm-Gg: ASbGncu7jhIG4+f9jZqF4rYX7qrjjDyDjaAGfxnPH53XV3CcMEXnFCsBlFK/Kku5SLX C2QmqNP2rjIXjeF8esNy7fC8E8JcKiaDrMGFZfwM+YXQfgWFbXbVUmZZxY4loeuWfsDgQ+rrdSO 7LEUDVk2T720E3REzwRJGYi5u2Uct9wMwSme0tLkaRrEFmwGok1jXy5eQzfaqs2fsBsHCnyPYkQ RW8EELtFTqnxgBIiw+lLXqksck4Nx6pMc6AygjJMmwzIaaWKEuClw== X-Google-Smtp-Source: AGHT+IGwgR2uRtu29+YcXtBE05ZuRvzgVyfXzi83ivyjQuls0V+nXyvwYRSMyru22j+0UKV84HvklQ== X-Received: by 2002:a17:90b:3141:b0:2ef:949c:6f6b with SMTP id 98e67ed59e1d1-2f13ac546dfmr9671676a91.13.1734075102569; Thu, 12 Dec 2024 23:31:42 -0800 (PST) Received: from localhost ([115.240.90.130]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f142d9199esm2531552a91.10.2024.12.12.23.31.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Dec 2024 23:31:42 -0800 (PST) From: Visuwesh To: Org Mode List Subject: Re: [PATCH] Add support for tables in Calc src block :var In-Reply-To: <87sf0239bm.fsf@ucl.ac.uk> (Eric Fraga's message of "Wed, 3 Apr 2024 12:43:58 +0000") References: <877ci2261h.fsf@gmail.com> <87y1aiijv3.fsf@localhost> <8734sq1k70.fsf@gmail.com> <87bk7eid26.fsf@localhost> <87y1aiz76v.fsf@gmail.com> <87jzlzhfiw.fsf@ucl.ac.uk> <87cyrbeure.fsf@gmail.com> <87sf0239bm.fsf@ucl.ac.uk> Date: Fri, 13 Dec 2024 13:01:38 +0530 Message-ID: <87pllw2g4l.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=2607:f8b0:4864:20::1044; envelope-from=visuweshm@gmail.com; helo=mail-pj1-x1044.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Queue-Id: D71F2555AE X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: -9.41 X-Spam-Score: -9.41 X-TUID: 0OSLLL+WvXa7 Sorry for getting back after so long! [=E0=AE=AA=E0=AF=81=E0=AE=A4=E0=AE=A9=E0=AF=8D =E0=AE=8F=E0=AE=AA=E0=AF=8D= =E0=AE=B0=E0=AE=B2=E0=AF=8D 03, 2024] Fraga, Eric wrote: > On Saturday, 30 Mar 2024 at 18:34, Visuwesh wrote: >>> Specifically, I would love to make reference to calc variables, >>> especially those defined using embedded calc, in org tables. >> >> Can you please provide a minimal example for me to play around with? I >> realise I would like something like this too [*] but I don't know >> concretely what this would/should look like. > > So, embedded calc processes expressions in any buffer, including org > mode, which might look like this: > > x :=3D 3 > > y :=3D 5 > > z :=3D 3 x - y =3D> 4 > > where, in this case, the value of z has been determined by calc and the > answer given after the =3D> in the line. The beauty of embedded calc is > you can change the value of x and the subsequent expressions will be > updated automatically (well, with C-x * u). > > I would then love to be able to have a table that would allow me to > include the value of any variable, e.g. z above, something like > > | var | value | > |-----+-------| > | x | 3 | > | z | 4 | > > where the values in the second column are obtained by querying Calc. Here's a hack I cooked up: (defun vz/calc-embedded-get-var (var) "Return the value of active `calc-embedded' VAR in current buffer." (let* ((info (cdr (assq (current-buffer) calc-embedded-active))) (var-info (seq-find (lambda (x) ;; 9 is the variable name: (var XXX var-XXX) (eq var (nth 1 (aref x 9)))) info)) old-val) (when (and info var-info) ;; This is called the `old-val' in `calc-embedded-update'. ;; This can be nil when the formula isn't evaled I think? ;; (aref VAR-INFO 8) is again repeated in 11th slot when the ;; variable is simply as assignment. (or (if (consp (setq old-val (aref var-info 11))) (car (last old-val)) old-val) ;; 8 is the eval form: (calcFun-evalto ...) or ;; (calcFun-assign ...) (car (last (aref var-info 8))))))) (define-advice org-table-get-constant (:around (oldfun name) vz/conside= r-calc-embedded-var) "Check if NAME is a `calc-embedded' at last." (let ((val (funcall oldfun name))) (if (equal val "#UNDEFINED_NAME") (or (number-to-string (vz/calc-embedded-get-var (intern name))) val) val))) Some caveats: 1. You need to ensure that all the calc-embedded variables that you use in the formula need to be active and evaluated beforehand. 2. The calc-embedded var is considered at last after everything else in org-table-get-constant in the advice. This would be the best way to go forward. It would be nice to lift the restrict in (1) but I think it would be better to leave it to the user to ensure everything stays updated since the user may want to use the old value. However, ensuring all the vars are active and eval-ed would be a royal pain when you're quickly evaluating a table formula. Here's the case I used to test this hack: x :=3D 3 y :=3D 5 z :=3D 5 x - y =3D> 10 | 1 | 20 | #+TBLFM: $2=3D$z*2