diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2018-01-07 10:56:02 +0100 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2018-01-07 10:56:02 +0100 |
commit | b65fe0f7a2664f1027778fea36fd1476fd3d06ca (patch) | |
tree | bfdd056ac5bb37fd5b3ac9308f5fecf4870e085b | |
parent | 34bb61bf819744ab5cff2e030dea52c6563323eb (diff) | |
parent | 0c93296f8362d6e81f9d8780e06fb341b0ab4fc7 (diff) | |
download | org-mode-b65fe0f7a2664f1027778fea36fd1476fd3d06ca.tar.gz |
Merge branch 'maint'
-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 3955526..ac0253f 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." @@ -3358,7 +3361,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 4f99427..750290d 100644 --- a/testing/lisp/test-org-table.el +++ b/testing/lisp/test-org-table.el @@ -1811,59 +1811,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." |