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: Tue, 30 Sep 2014 22:44:29 -0700 Message-ID: <87egusgx72.fsf@secretsauce.net> References: <87k34mgvup.fsf@secretsauce.net> <87fvf8hpqw.fsf@secretsauce.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55126) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZCjC-0000dt-Aj for emacs-orgmode@gnu.org; Wed, 01 Oct 2014 01:45:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XZCj6-0002Nh-TC for emacs-orgmode@gnu.org; Wed, 01 Oct 2014 01:45:30 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:52864) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZCj6-0002Na-I6 for emacs-orgmode@gnu.org; Wed, 01 Oct 2014 01:45:24 -0400 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by gateway2.nyi.internal (Postfix) with ESMTP id B5BD320851 for ; Wed, 1 Oct 2014 01:45:23 -0400 (EDT) In-reply-to: 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: Subhan Michael Tindall Cc: "emacs-orgmode@gnu.org" --=-=-= Content-Type: text/plain >> Dima Kogan writes: >> >> > Suppose I have this .org file: >> > >> > | | >> > #+TBLFM: @1$2=5 >> > >> > It's a 1x1 table with a formula. The formula sets a cell that's out of >> > bounds in the table, so evaluating this formula results in an error. >> > How set-in-stone is this behavior? I haven't dug too deeply into the >> > code, but are there fundamental assumptions here? Would a patch that >> > extends the table before applying such a formula be too naive in some >> way? > > Subhan Michael Tindall writes: > > I would include a customization variable to control this behavior, defaulting to whatever the current behavior is: > IE: > (setq org-calc-extend-file nil) default system behavior > (setq org-calc-extend-file t) always silently extend rows > (setq org-calc-extend-file "warn") issue warning in message buffer that line was extended > (setq org-calc-extend-file "prompt") prompt user y/n on whether or not to extend column OK. Patch attached. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Field-formulas-can-now-add-columns-as-needed.patch >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 --- lisp/org-table.el | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/lisp/org-table.el b/lisp/org-table.el index 7607ead..f2933ed 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -354,6 +354,16 @@ portability of tables." (const :tag "Stick to hline" nil) (const :tag "Error on attempt to cross" error))) +(defcustom org-table-formula-make-new-cols 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 + :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 +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) + (or (eq org-table-formula-make-new-cols t) + (and + (eq org-table-formula-make-new-cols 'warn) + (progn + (org-display-warning "Out-of-bounds formula added columns") + t)) + (and + (eq org-table-formula-make-new-cols '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 --=-=-=--