diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2018-01-07 10:45:29 +0100 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2018-01-07 10:55:30 +0100 |
commit | 0c93296f8362d6e81f9d8780e06fb341b0ab4fc7 (patch) | |
tree | 691c7b8259e3255afba081ea69bcd1012e0226e9 | |
parent | 3e1641ef0aa01ae39f90a3cb532136484de617bb (diff) | |
download | org-mode-0c93296f8362d6e81f9d8780e06fb341b0ab4fc7.tar.gz |
org-table: Obey to `org-table-formula-create-columns'
* lisp/org-table.el (org-table-recalculate): Return an error when the
formula cannot create a necessary column.
(org-table-formula-create-columns): Fix docstring.
* testing/lisp/test-org-table.el (test-org-table/field-formula-outside-table):
Fix tests.
-rw-r--r-- | lisp/org-table.el | 19 | ||||
-rw-r--r-- | testing/lisp/test-org-table.el | 73 |
2 files changed, 44 insertions, 48 deletions
diff --git a/lisp/org-table.el b/lisp/org-table.el index 3932671..6c6cf68 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -387,16 +387,19 @@ portability of tables." (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." + "Non-nil means evaluation of formula can add new columns. +When non-nil, evaluating an out-of-bounds field can insert as +many columns as needed. When set to `warn', issue a warning when +doing so. When set to `prompt', ask user before creating a new +column. Otherwise, throw an error." :group 'org-table-calculation :version "26.1" :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))) + (const :tag "Out-of-bounds field generates an error (default)" nil) + (const :tag "Out-of-bounds field silently adds columns as needed" t) + (const :tag "Out-of-bounds field adds columns, but issues a warning" warn) + (const :tag "Prompt user when setting an out-of-bounds field" prompt))) (defgroup org-table-import-export nil "Options concerning table import and export in Org mode." @@ -3327,7 +3330,9 @@ existing formula for column %s" t)) (and (eq org-table-formula-create-columns 'prompt) (yes-or-no-p - "Out-of-bounds formula. Add columns? "))))))) + "Out-of-bounds formula. Add columns? ")) + (user-error + "Missing columns in the table. Aborting")))))) (org-table-eval-formula nil formula t t t t)))) ;; Clean up markers and internal text property. (remove-text-properties (point-min) (point-max) '(org-untouchable t)) diff --git a/testing/lisp/test-org-table.el b/testing/lisp/test-org-table.el index 92960da..ea72ae5 100644 --- a/testing/lisp/test-org-table.el +++ b/testing/lisp/test-org-table.el @@ -1751,59 +1751,50 @@ See also `test-org-table/copy-field'." (buffer-string))))) (ert-deftest test-org-table/field-formula-outside-table () - "If `org-table-formula-create-columns' is nil, then a formula -that references an out-of-bounds column should do nothing. If it -is t, then new columns should be added as needed" - - (let ((org-table-formula-create-columns nil)) - - (should-error - (org-test-table-target-expect - " -| 2 | -| 4 | -| 8 | -" - " -| 2 | -| 4 | -| 8 | -" - 1 - "#+TBLFM: @1$2=5") - :type (list 'error 'user-error))) - - (let ((org-table-formula-create-columns t)) - - ;; make sure field formulas work - (org-test-table-target-expect - " + "Test `org-table-formula-create-columns' variable." + ;; Refuse to create column if variable is nil. + (should-error + (org-test-with-temp-text " | 2 | | 4 | | 8 | -" - " +<point>#+TBLFM: @1$2=5" + (let ((org-table-formula-create-columns nil)) + (org-table-calc-current-TBLFM)) + (buffer-string)) + :type (list 'error 'user-error)) + ;; If the variable is non-nil, field formulas and columns formulas + ;; can create tables. + (should + (equal + " | 2 | 5 | | 4 | | | 8 | | -" - 1 - "#+TBLFM: @1$2=5") - - ;; and make sure column formulas work too - (org-test-table-target-expect - " +#+TBLFM: @1$2=5" + (org-test-with-temp-text " | 2 | | 4 | | 8 | -" - " +<point>#+TBLFM: @1$2=5" + (let ((org-table-formula-create-columns t)) + (org-table-calc-current-TBLFM)) + (buffer-string)))) + (should + (equal + " | 2 | | 15 | | 4 | | 15 | | 8 | | 15 | -" - 1 - "#+TBLFM: $3=15"))) +#+TBLFM: $3=15" + (org-test-with-temp-text " +| 2 | +| 4 | +| 8 | +<point>#+TBLFM: $3=15" + (let ((org-table-formula-create-columns t)) + (org-table-calc-current-TBLFM)) + (buffer-string))))) (ert-deftest test-org-table/duration () "Test durations in table formulas." |