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: Wed, 01 Oct 2014 12:38:23 -0700 Message-ID: <87bnpvh8kb.fsf@secretsauce.net> References: <87k34mgvup.fsf@secretsauce.net> <87fvf8hpqw.fsf@secretsauce.net> <87egusgx72.fsf@secretsauce.net> <8738b78tt0.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:45495) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZPwc-0008L0-6f for emacs-orgmode@gnu.org; Wed, 01 Oct 2014 15:52:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XZPwX-00016m-85 for emacs-orgmode@gnu.org; Wed, 01 Oct 2014 15:52:14 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:52478) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZPwW-00014o-VF for emacs-orgmode@gnu.org; Wed, 01 Oct 2014 15:52:09 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by gateway2.nyi.internal (Postfix) with ESMTP id 1589E20B77 for ; Wed, 1 Oct 2014 15:52:07 -0400 (EDT) In-reply-to: <8738b78tt0.fsf@nicolasgoaziou.fr> 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: Nicolas Goaziou Cc: "emacs-orgmode@gnu.org" --=-=-= Content-Type: text/plain Hi. Thanks for replying. Nicolas Goaziou writes: > Thanks for your patch. Some comments follow. > >> From 3b6581c647cb87f0d3e8cee94ce2fb1fb122d3fd Mon Sep 17 00:00:00 2001 >> From: Dima Kogan >> Date: Tue, 30 Sep 2014 22:36:21 -0700 >> Subject: [PATCH] Field formulas can now add columns as needed >> >> The org-table-formula-make-new-cols customization controls whether and how this >> is done > > Your commit message is missing information and "TINYCHANGE" at its end. > See http://orgmode.org/worg/org-contribute.html#sec-5 OK. Added. By the way, I signed the copyright-assignment paperwork for Emacs itself. Would I need to do this again for org-mode? >> +(defcustom org-table-formula-make-new-cols nil > > What about `org-table-formula-create-columns'? Sure, why not. >> + "Non-nil means that evaluation of a field formula can add new >> +columns if an out-of-bounds field is being set." > > First line needs to be complete. E.g., > > "Non-nil means a field formula can create a new column." > >> + :group 'org-table-calculation >> + :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))) > > You need to add :version and :package-version keywords. OK. I'm not sure what those values should be, so please double-check. >> (defgroup org-table-import-export nil >> "Options concerning table import and export in Org-mode." >> :tag "Org Table Import Export" >> @@ -3125,7 +3135,22 @@ 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)) >> + (let* ((column-target (nth 2 eq)) >> + (column-count (progn (end-of-line) >> + (1- (org-table-current-column)))) >> + (create-new-column >> + (and (> column-target column-count) > > Is this check really necessary? Doesn't `org-table-goto-column' already > figures it out before creating a new column? This is necessary if we want to be able to warn the user or to prompt them ONLY if a new column has to be made. I.e. if we're not looking past the bounds of the table the user should never be pestered. If the customization variable is only t/nil then this can be dramatically simplified, as you have observed. By the way, is (org-display-warning) the preferred way to produce a warning? It does into a new buffer, not into *Messages*. Tweaked patch attached. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-org-table.el-field-formulas-can-now-create-columns-a.patch >From 7b3ab8eeffb2047b966c624707766ec29a416583 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 | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lisp/org-table.el b/lisp/org-table.el index 7607ead..090bb75 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,7 +3137,22 @@ 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)) + (let* ((column-target (nth 2 eq)) + (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)) -- 2.0.0 --=-=-=--