From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:403:478a::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id 0IhcNpVMt2RGRgEASxT56A (envelope-from ) for ; Wed, 19 Jul 2023 04:38:13 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:478a::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id IOJENpVMt2Qs+QAA9RJhRA (envelope-from ) for ; Wed, 19 Jul 2023 04:38:13 +0200 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 842AD5F6F3 for ; Wed, 19 Jul 2023 04:38:13 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=runbox.com header.s=selector1 header.b=SHeiTssE; 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"; dmarc=pass (policy=quarantine) header.from=runbox.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1689734293; 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:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=rAyeu77FB+qgrpy/xdT1/SHKPET5P87vb0wusC8TNVI=; b=T49vlp+CBFddGwEhktjJX5wTr8pIfzCkC/Ceopjt4+rXTY2RDhS+9SJVi42UfePLeQz5y/ OITDdLZ2UtNawrwHx/+baKCXgako33r9iRnx1uyMWMieHyuhoHaAmkKjEAXZRTWcOnkj81 Ns53kB6TlZDveqnKBQuay2NGx4m9Hva8jCWji/G85UplJcbuZAyuReP62Xyf8seV2rAIs4 s5OrVjJcz6Nxzueo337RFdP0UjT1MOAEXPxwpWppmm1K+PDU0VUq0T7b5kbqfJxJLyCwO3 GhfGo3jHUUbYoyy+gJ08U6nH83P5e/DRqx9t1nEnXo/bKGjAV2x4qTeLGV/yCA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=runbox.com header.s=selector1 header.b=SHeiTssE; 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"; dmarc=pass (policy=quarantine) header.from=runbox.com ARC-Seal: i=1; s=key1; d=yhetil.org; t=1689734293; a=rsa-sha256; cv=none; b=dsRqTQXDFIwHS190yBizs+55LiA2a+/kK7Nv0HW1LOE0iAiLs5bwQgDggmA/FELySKJCEn S/dnAy8sqDD0yTUx3w+zAWrNuBbXGKQi6XoZtEO9TAWtg77PftroH00ZGqHLp/6KYpRFSx 56QXhPuxKnou03qXeSTi4u5GrkUr5PsSHHyDnmJT8dHNV3nGPAqeExNdhP34/PKiEISfwd 88WFVjTb+Xn66EeMP8cHfk4wuXOvB6GT0fEWa9CJT+1Xrlj5FEOhw5BYCl9S66UGWj0w10 4w9JOo4Ihco+FZHtXRAiHRajLkaZhwqA8EgxRGUgKU16wur3HW135BeaxRTvKw== Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qLx48-000596-El; Tue, 18 Jul 2023 22:37:24 -0400 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 1qLx46-00058u-El for emacs-orgmode@gnu.org; Tue, 18 Jul 2023 22:37:22 -0400 Received: from mailtransmit04.runbox.com ([2a0c:5a00:149::25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qLx43-0003dq-V7 for emacs-orgmode@gnu.org; Tue, 18 Jul 2023 22:37:22 -0400 Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit04.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1qLx3w-00FtdW-Mv for emacs-orgmode@gnu.org; Wed, 19 Jul 2023 04:37:12 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=runbox.com; s=selector1; h=Content-Type:MIME-Version:Message-ID:Date:Subject:To:From; bh=rAyeu77FB+qgrpy/xdT1/SHKPET5P87vb0wusC8TNVI=; b=SHeiTssEhVAPWdcjItprwr0Ub R+PPHr9ElE5K0My1l1FJfOCudBQfFJV0s8dhMX0KDjbZlr9eoI8+MToIWosgUKlwXfmYsbufwlCEc yz3+nM9/EfPwyEWMFiyFQ0PayliDVCXBE/9dMtf0zBcbWVL4JoRb3gigOCjOPHECL4IjsEZItGkHD Hp2rr4MNXw571tUcz9AqrviD4LN0jiaNB9N7Vs+M4RPV3U7pn2wd4Cq4qQAH5duJAajTEm0v+lSDM fihqZchb/mc23MDsTlautsYzD6UTCd+TGLKGBBEDuzB7IJC+yprIwsZZEN/G5efV0sq8Vn4+n+9Qq 0qhCfU9yA==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1qLx3w-0004HT-6x for emacs-orgmode@gnu.org; Wed, 19 Jul 2023 04:37:12 +0200 Received: by submission02.runbox with esmtpsa [Authenticated ID (946465)] (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) id 1qLx3g-0002f3-JJ for emacs-orgmode@gnu.org; Wed, 19 Jul 2023 04:36:56 +0200 User-agent: mu4e 1.10.4; emacs 29.0.92 From: Gavin Downard To: emacs-orgmode@gnu.org Subject: [PATCH] lisp/org-table.el: Allow named columns on lhs Date: Tue, 18 Jul 2023 19:36:02 -0700 Message-ID: <877cqwbpa2.fsf@runbox.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2a0c:5a00:149::25; envelope-from=gavin.downard@runbox.com; helo=mailtransmit04.runbox.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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-Spam-Score: -10.76 X-Migadu-Queue-Id: 842AD5F6F3 X-Migadu-Spam-Score: -10.76 X-Migadu-Scanner: mx0.migadu.com X-TUID: Hh7GObzMQP95 --=-=-= Content-Type: text/plain This patch does prioritize named columns over named fields, which can break compatibility in tables with a named column and named field with the same name. Alternatively, we could prioritize named fields to preserve compatibility, but since named columns are prioritized on the rhs, it could be pretty confusing. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-lisp-org-table.el-Allow-named-columns-on-lhs.patch >From c6ebbf02e0cb89839606338e8bbc4032810ea398 Mon Sep 17 00:00:00 2001 From: Gavin Downard Date: Sat, 1 Jul 2023 13:26:46 -0700 Subject: [PATCH] lisp/org-table.el: Allow named columns on lhs * lisp/org-table.el (org-table-recalculate): Add support for named columns on the lhs of spreadsheet formulas, prioritizing named columns over named fields if there is a conflict. (org-table-edit-formulas): Modify category name to include column formulas with field formulas. (org-table-get-stored-formulas): Remove comment mentioning lack of named columns in the lhs. * testing/lisp/test-org-table.el (test-org-table/named-column): Add test case for named columns. * etc/ORG-NEWS (Spreadsheets now support named columns on the lhs): Document the change This change breaks compatibility in tables with a named field and named column with the same name, when that name is used on the lhs of a formula. --- etc/ORG-NEWS | 4 ++++ lisp/org-table.el | 9 +++++---- testing/lisp/test-org-table.el | 9 +++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index a4725ae8c..42f39fd45 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -534,6 +534,10 @@ special repeaters ~++~ and ~.+~ are skipped. A capture template can target ~(here)~ which is the equivalent of invoking a capture template with a zero prefix. +*** Spreadsheets now support named columns on the lhs + +Spreadsheet formulas can now use named column references on the lhs. + ** New functions and changes in function arguments *** =TYPES= argument in ~org-element-lineage~ can now be a symbol diff --git a/lisp/org-table.el b/lisp/org-table.el index c5efe8f0c..34b0a562e 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -2253,8 +2253,7 @@ LOCATION is a buffer position, consider the formulas there." ((not (match-end 2)) m) ;; Is it a column reference? ((string-match-p "\\`\\$\\([0-9]+\\|[<>]+\\)\\'" m) m) - ;; Since named columns are not possible in - ;; LHS, assume this is a named field. + ;; This is either a named field or column. (t (match-string 2 string))))) (rhs (match-string 3 string))) (push (cons lhs rhs) eq-alist) @@ -2963,7 +2962,9 @@ existing formula for column %s" (t old-lhs))))) (if (string-match-p "\\`\\$[0-9]+\\'" lhs) (push (cons lhs rhs) eqlcol) - (push (cons lhs rhs) eqlfield)))) + (if-let ((named-column (assoc lhs org-table-column-names))) + (push (cons (concat "$" (cdr named-column)) rhs) eqlcol) + (push (cons lhs rhs) eqlfield))))) (setq eqlcol (nreverse eqlcol)) ;; Expand ranges in lhs of formulas (setq eqlfield (org-table-expand-lhs-ranges (nreverse eqlfield))) @@ -3355,7 +3356,7 @@ Parameters get priority." (sel-win (selected-window)) (titles '((column . "# Column Formulas\n") (field . "# Field and Range Formulas\n") - (named . "# Named Field Formulas\n")))) + (named . "# Named Field and Named Column Formulas\n")))) (org-switch-to-buffer-other-window "*Edit Formulas*") (erase-buffer) ;; Keep global-font-lock-mode from turning on font-lock-mode diff --git a/testing/lisp/test-org-table.el b/testing/lisp/test-org-table.el index 27aeb5ab3..8cd01049a 100644 --- a/testing/lisp/test-org-table.el +++ b/testing/lisp/test-org-table.el @@ -2158,6 +2158,15 @@ See also `test-org-table/copy-field'." | ! | name | | | | 1 | | #+TBLFM: @2$3=$name" + (org-table-calc-current-TBLFM) + (buffer-string)))) + (should + (string-match-p + "| +# +| +1 +| +1 +|" + (org-test-with-temp-text " +| ! | lhs | rhs | +| # | | 1 | +#+TBLFM: $lhs=$rhs" (org-table-calc-current-TBLFM) (buffer-string))))) -- 2.40.1 --=-=-=--