From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 4Aw5L3dakF+HFAAA0tVLHw (envelope-from ) for ; Wed, 21 Oct 2020 15:57:43 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id gOoFK3dakF+PdAAAbx9fmQ (envelope-from ) for ; Wed, 21 Oct 2020 15:57:43 +0000 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 069E09403C6 for ; Wed, 21 Oct 2020 15:57:42 +0000 (UTC) Received: from localhost ([::1]:39860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVGUf-0004w1-Qe for larch@yhetil.org; Wed, 21 Oct 2020 11:57:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49738) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVGUB-0004tp-Cg for emacs-orgmode@gnu.org; Wed, 21 Oct 2020 11:57:11 -0400 Received: from grinta.net ([109.74.203.128]:47848) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVGU7-0000MK-5I for emacs-orgmode@gnu.org; Wed, 21 Oct 2020 11:57:10 -0400 Received: from black.local (unknown [46.165.233.56]) (Authenticated sender: daniele) by grinta.net (Postfix) with ESMTPSA id E78C0E13DA for ; Wed, 21 Oct 2020 15:57:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=grinta.net; s=2020; t=1603295823; bh=OfTci79s0y7mREK9kL1D9TEd8pMO3os97eB1BSWx8QU=; h=Subject:To:References:From:Date:In-Reply-To:From; b=ed8K1Ybn6X1voLWzJVSfq9T21BzIjBc8TX+V6a0Dc7XUHcQ0WyT1Qq/Z4qnVI6BjM TbzUQo/NX3aquOFa2XPCDQx+Y+JuNgFFxnRvbiajogSBNosRrYfGEObJt24QZrMr3O voht/LhkPMhjx1BJzYWWxlHDjqHjTGOLOeuchxURRqc1Hecz4+IYRGzMw9kS8rEd0o baqNsGF8dJZIv08xfTSc9Jda0fLUbOP7A648ZZPEBr88eplZhKcu0aOJHXH8M2FPsr P+F0mKdAr0NWXwKrC7KE4fSKwYAXYBXKFx5tFs+ZFEBnomy4kwndq3sijm62EHFMQl Y0QmJZhIfn3fg== Subject: Re: [PATCH] org-table: Add mode flag to enable Calc units simplification mode To: emacs-orgmode@gnu.org References: <6d8c15c2-d1b0-d913-df39-c60381cff70b@grinta.net> <33143b05-a298-8277-313b-3a1deb69ad27@grinta.net> From: Daniele Nicolodi Message-ID: <5379f64a-e82c-ca75-0fe4-de14aea010ac@grinta.net> Date: Wed, 21 Oct 2020 17:57:01 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.12.1 MIME-Version: 1.0 In-Reply-To: <33143b05-a298-8277-313b-3a1deb69ad27@grinta.net> Content-Type: multipart/mixed; boundary="------------7C3113B46C7EF6E2037ABABD" Content-Language: en-US Received-SPF: pass client-ip=109.74.203.128; envelope-from=daniele@grinta.net; helo=grinta.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/21 11:57:03 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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, NICE_REPLY_A=-0.001, SPF_HELO_PASS=-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.23 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" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=fail (rsa verify failed) header.d=grinta.net header.s=2020 header.b=ed8K1Ybn; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: 2.09 X-TUID: WTCZG+z/ksmY This is a multi-part message in MIME format. --------------7C3113B46C7EF6E2037ABABD Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Hello, after working on this I realized that the org-tbl-calc-modes variables is used only locally despite being declare globally. Maybe a remnant from pre-lexical-binding times. Attached is a patch (on top of the others one in this thread) that simplifies things a little. Cheers, Dan On 20/10/2020 15:30, Daniele Nicolodi wrote: > Hello, > > attached there are a few patches reworking the code, fixing the bug, and > introducing a new mode flag to enable Calc's units simplification mode > as discussed in a recent thread on the mailing list. I haven't updated > the documentation. I can do it once we agree that this feature is a > good idea. > > Cheers, > Dan > > > On 19/10/2020 17:38, Daniele Nicolodi wrote: >> Hello, >> >> I am hacking org-table-eval-formula (see thread about monetary values in >> org-tables) which uses this inline function: >> >> (defsubst org-table--set-calc-mode (var &optional value) >> (if (stringp var) >> (setq var (assoc var '(("D" calc-angle-mode deg) >> ("R" calc-angle-mode rad) >> ("F" calc-prefer-frac t) >> ("S" calc-symbolic-mode t))) >> value (nth 2 var) var (nth 1 var))) >> (if (memq var org-tbl-calc-modes) >> (setcar (cdr (memq var org-tbl-calc-modes)) value) >> (cons var (cons value org-tbl-calc-modes))) >> org-tbl-calc-modes) >> >> which I am not able to understand or which is not correct. >> >> The first (if ...) does some value substitutions, however, IIUC the >> second (if ...) sets a new value for an entry in the org-tbl-calc-modes >> plist if the entry is already present and builds a new plist with the >> entry prepended if the entry is not there. However, the original plist >> is returned and not the one with the new entry prepended. >> >> It does not seem to be the intended behavior. >> >> Shouldn't this be simply: >> >> (defsubst org-table--set-calc-mode (var &optional value) >> (if (stringp var) >> (setq var (assoc var '(("D" calc-angle-mode deg) >> ("R" calc-angle-mode rad) >> ("F" calc-prefer-frac t) >> ("S" calc-symbolic-mode t))) >> value (nth 2 var) var (nth 1 var))) >> (plist-put org-tbl-calc-modes var value)) >> >> or, better, the code refactored to do not use this function? >> >> Cheers, >> Dan >> > --------------7C3113B46C7EF6E2037ABABD Content-Type: text/plain; charset=UTF-8; x-mac-type="0"; x-mac-creator="0"; name="0004-org-table-Remove-unused-org-tbl-calc-modes-variable.patch" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename*0="0004-org-table-Remove-unused-org-tbl-calc-modes-variable.pat"; filename*1="ch" RnJvbSAyZDQ1MjFhMDMyZWMzZTQxNzRjOTdiMmIyZTlhMDg0OTFlOTg3MGZiIE1vbiBTZXAg MTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBEYW5pZWxlIE5pY29sb2RpIDxkYW5pZWxlQGdyaW50 YS5uZXQ+CkRhdGU6IFdlZCwgMjEgT2N0IDIwMjAgMTc6NDc6MTUgKzAyMDAKU3ViamVjdDog W1BBVENIIDQvNF0gb3JnLXRhYmxlOiBSZW1vdmUgdW51c2VkIG9yZy10YmwtY2FsYy1tb2Rl cyB2YXJpYWJsZQoKKiBvcmctdGFibGUuZWwgKG9yZy10YmwtY2FsYy1tb2Rlcyk6IFJlbW92 ZSB0aGUgdmFyaWFibGUgZGVjbGFyYXRpb24KYXMgdGhlIHZhcmlhbGJsZSBpcyBvbmx5IHVz ZWQgYXMgYSBsb2NhbCB2YXJpYWJsZSBpbiBgb3JnLXRhYmxlLWV2YWwtZm9ybXVsYScuCgoq IG9yZy10YWJsZS5lbCAob3JnLX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