From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dima Kogan Subject: Re: Adding new table rows/cols in a formula update Date: Fri, 03 Oct 2014 11:07:07 -0700 Message-ID: <8761g16n8c.fsf@secretsauce.net> References: <87k34mgvup.fsf@secretsauce.net> <87fvf8hpqw.fsf@secretsauce.net> <87egusgx72.fsf@secretsauce.net> <8738b78tt0.fsf@nicolasgoaziou.fr> <87iok3h7d4.fsf@alphaville.bos.redhat.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:57245) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xa7GW-0007TE-BS for emacs-orgmode@gnu.org; Fri, 03 Oct 2014 14:07:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xa7GR-0008Hv-9l for emacs-orgmode@gnu.org; Fri, 03 Oct 2014 14:07:40 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:43679) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xa7GR-0008Hk-0L for emacs-orgmode@gnu.org; Fri, 03 Oct 2014 14:07:35 -0400 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by gateway2.nyi.internal (Postfix) with ESMTP id 3A54F204EB for ; Fri, 3 Oct 2014 14:07:33 -0400 (EDT) Received: from shorty.local (unknown [23.243.192.221]) by mail.messagingengine.com (Postfix) with ESMTPA id EC6DFC0000A for ; Fri, 3 Oct 2014 14:07:32 -0400 (EDT) Received: from dima by shorty.local with local (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1Xa7GN-0006bf-Qm for emacs-orgmode@gnu.org; Fri, 03 Oct 2014 11:07:31 -0700 In-reply-to: <87iok3h7d4.fsf@alphaville.bos.redhat.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Nick Dokos writes: > Nicolas Goaziou writes: > > Does it need sanity checking? A typo in a formula can create "billions > and billions"[fn:1] of columns inadvertently. Sure. Updated patch attached. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-org-table.el-field-formulas-can-now-create-columns-a.patch >From 06f09e58a0f8b62429dda2faa913e297218b67b2 Mon Sep 17 00:00:00 2001 From: Dima Kogan Date: Tue, 30 Sep 2014 22:36:21 -0700 Subject: [PATCH] org-table.el: field formulas can now create columns as needed (org-table-recalculate): use the new org-table-formula-make-new-cols customization to control whether org creates new columns when a formula explicitly targets them TINYCHANGE --- lisp/org-table.el | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/lisp/org-table.el b/lisp/org-table.el index 7607ead..14c68d6 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -354,6 +354,18 @@ portability of tables." (const :tag "Stick to hline" nil) (const :tag "Error on attempt to cross" error))) +(defcustom org-table-formula-create-columns nil + "Non-nil means that evaluation of a field formula can add new +columns if an out-of-bounds field is being set." + :group 'org-table-calculation + :version "24.5" + :package-version '(Org . "8.3") + :type '(choice + (const :tag "Setting an out-of-bounds field generates an error (default)" nil) + (const :tag "Setting an out-of-bounds field silently adds columns as needed" t) + (const :tag "Setting an out-of-bounds field adds columns as needed, but issues a warning message" warn) + (const :tag "When setting an out-of-bounds field, the user is prompted" prompt))) + (defgroup org-table-import-export nil "Options concerning table import and export in Org-mode." :tag "Org Table Import Export" @@ -3125,9 +3137,26 @@ known that the table will be realigned a little later anyway." (while (setq eq (pop eqlname1)) (message "Re-applying formula to field: %s" (car eq)) (org-goto-line (nth 1 eq)) - (org-table-goto-column (nth 2 eq)) - (org-table-eval-formula nil (nth 3 eq) 'noalign 'nocst - 'nostore 'noanalysis)) + (let ((column-target (nth 2 eq))) + (when (> column-target 1000) + (user-error "Formula column target too large")) + (let* ((column-count (progn (end-of-line) + (1- (org-table-current-column)))) + (create-new-column + (and (> column-target column-count) + (or (eq org-table-formula-create-columns t) + (and + (eq org-table-formula-create-columns 'warn) + (progn + (org-display-warning "Out-of-bounds formula added columns") + t)) + (and + (eq org-table-formula-create-columns 'prompt) + (yes-or-no-p "Out-of-bounds formula. Add columns?")))))) + (org-table-goto-column column-target nil create-new-column)) + + (org-table-eval-formula nil (nth 3 eq) 'noalign 'nocst + 'nostore 'noanalysis))) (org-goto-line thisline) (org-table-goto-column thiscol) -- 2.0.0 --=-=-=--