1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

Fix ses-select accordingly with changes for having ses-setq.

* lisp/ses.el (ses-select): Fix accordingly with new definition of
'ses-range'. 'ses-select' is no longer a macro, but a function,
and ranges are evaluated as list of values, not list of symbols.
Also the order of elements is not changed.
(ses-select): Add un extra optional argument to allow configure
the test function.
This commit is contained in:
Vincent Belaïche 2023-12-27 14:10:20 +01:00 committed by Vincent Belaïche
parent 053b05ae62
commit f77596e9b6

View file

@ -4078,22 +4078,24 @@ args are integers."
(setq list (apply #'ses-delete-blanks list))
(/ (float (apply #'+ list)) (length list)))
(defmacro ses-select (fromrange test torange)
(defun ses-select (fromrange test torange &optional test-fn)
"Select cells in FROMRANGE that are `equal' to TEST.
For each match, return the corresponding cell from TORANGE.
The ranges are macroexpanded but not evaluated so they should be
either (ses-range BEG END) or (list ...). The TEST is evaluated."
(setq fromrange (cdr (macroexpand fromrange))
torange (cdr (macroexpand torange))
test (eval test t))
For each match, return the corresponding cell from TORANGE. The
ranges must be lists of cells values, so they should be
either (ses-range BEG END) or (list CELL1 CELL2 CELL3), where
BEG, END, CELL1, CELL2 and CELL3 are cell symbols. When TEST-FN
is supplied it is used as a test function instead of `equal'. The
test is evaluated for value X from FROMRANGE as (TEST-FN X
TEST)."
(setq test-fn (or test-fn #'equal))
(or (= (length fromrange) (length torange))
(error "ses-select: Ranges not same length"))
(let (result)
(dolist (x fromrange)
(if (equal test (symbol-value x))
(if (funcall test-fn x test)
(push (car torange) result))
(setq torange (cdr torange)))
(cons 'list result)))
(nreverse result)))
;;All standard formulas are safe
(dolist (x '(ses-cell-value ses-range ses-delete-blanks ses+ ses-average