aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Belaïche2011-06-27 08:11:36 +0200
committerVincent Belaïche2011-06-27 08:11:36 +0200
commit5e5d49b6d4b736e96be98d8e392c846bbc803142 (patch)
tree6be4a5f46e5c73a632c5b1c9611847cd2d51157f
parent90ca8b4908934c72a5a6cec8cda73694278f4362 (diff)
downloademacs-5e5d49b6d4b736e96be98d8e392c846bbc803142.tar.gz
emacs-5e5d49b6d4b736e96be98d8e392c846bbc803142.zip
(ses-repair-cell-reference-all): New function.
(ses-cell-symbol): Set macro as safe, so that it can be used in formulas.
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/ses.el70
2 files changed, 76 insertions, 0 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index c0833592e7e..f7b1a336c88 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,11 @@
12011-06-27 Vincent Belaïche <vincentb1@users.sourceforge.net> 12011-06-27 Vincent Belaïche <vincentb1@users.sourceforge.net>
2 2
3 * ses.el (ses-repair-cell-reference-all): New function.
4 (ses-cell-symbol): Set macro as safe, so that it can be used in
5 formulas.
6
72011-06-27 Vincent Belaïche <vincentb1@users.sourceforge.net>
8
3 * ses.el: Update cycle detection algorithm. 9 * ses.el: Update cycle detection algorithm.
4 (ses-localvars): Add ses--Dijkstra-attempt-nb and 10 (ses-localvars): Add ses--Dijkstra-attempt-nb and
5 ses--Dijkstra-weight-bound, and initial values thereof when 11 ses--Dijkstra-weight-bound, and initial values thereof when
diff --git a/lisp/ses.el b/lisp/ses.el
index b54a7519093..2e6c24ab5e8 100644
--- a/lisp/ses.el
+++ b/lisp/ses.el
@@ -348,6 +348,7 @@ when to emit a progress message.")
348(defmacro ses-cell-symbol (row &optional col) 348(defmacro ses-cell-symbol (row &optional col)
349 "From a CELL or a pair (ROW,COL), get the symbol that names the local-variable holding its value. (0,0) => A1." 349 "From a CELL or a pair (ROW,COL), get the symbol that names the local-variable holding its value. (0,0) => A1."
350 `(aref ,(if col `(ses-get-cell ,row ,col) row) 0)) 350 `(aref ,(if col `(ses-get-cell ,row ,col) row) 0))
351(put 'ses-cell-symbol 'safe-function t)
351 352
352(defmacro ses-cell-formula (row &optional col) 353(defmacro ses-cell-formula (row &optional col)
353 "From a CELL or a pair (ROW,COL), get the function that computes its value." 354 "From a CELL or a pair (ROW,COL), get the function that computes its value."
@@ -755,6 +756,75 @@ means Emacs will crash if FORMULA contains a circular list."
755 (ses-formula-record formula) 756 (ses-formula-record formula)
756 (ses-set-cell row col 'formula formula)))) 757 (ses-set-cell row col 'formula formula))))
757 758
759
760(defun ses-repair-cell-reference-all ()
761 "Repair cell reference and warn if there was some reference corruption."
762 (interactive "*")
763 (let (errors)
764 ;; Step 1, reset :ses-repair-reference cell property in the whole sheet.
765 (dotimes (row ses--numrows)
766 (dotimes (col ses--numcols)
767 (let ((references (ses-cell-property-pop :ses-repair-reference
768 row col)))
769 (when references
770 (push (list
771 (ses-cell-symbol row col)
772 :corrupt-property
773 references) errors)))))
774
775 ;; Step 2, build new.
776 (dotimes (row ses--numrows)
777 (dotimes (col ses--numcols)
778 (let* ((cell (ses-get-cell row col))
779 (sym (ses-cell-symbol cell))
780 (formula (ses-cell-formula cell))
781 (new-ref (ses-formula-references formula)))
782 (dolist (ref new-ref)
783 (let* ((rowcol (ses-sym-rowcol ref))
784 (h (ses-cell-property-get-handle :ses-repair-reference
785 (car rowcol) (cdr rowcol))))
786 (unless (memq ref (ses-cell-property-handle-car h))
787 (ses-cell-property-handle-setcar
788 h
789 (cons sym
790 (ses-cell-property-handle-car h)))))))))
791
792 ;; Step 3, overwrite with check.
793 (dotimes (row ses--numrows)
794 (dotimes (col ses--numcols)
795 (let* ((cell (ses-get-cell row col))
796 (irrelevant (ses-cell-references cell))
797 (new-ref (ses-cell-property-pop :ses-repair-reference cell))
798 missing)
799 (dolist (ref new-ref)
800 (if (memq ref irrelevant)
801 (setq irrelevant (delq ref irrelevant))
802 (push ref missing)))
803 (ses-set-cell row col 'references new-ref)
804 (when (or missing irrelevant)
805 (push `( ,(ses-cell-symbol cell)
806 ,@(and missing (list :missing missing))
807 ,@(and irrelevant (list :irrelevant irrelevant)))
808 errors)))))
809 (if errors
810 (warn "----------------------------------------------------------------
811Some reference where corrupted.
812
813The following is a list of where each element ELT is such
814that (car ELT) is the reference of cell CELL with corruption,
815and (cdr ELT) is a property list where
816
817* property `:corrupt-property' means that
818 property `:ses-repair-reference' of cell CELL was initially non
819 nil,
820
821* property `:missing' is a list of missing references
822
823* property `:irrelevant' is a list of non needed references
824
825%S" errors)
826 (message "No reference corruption found"))))
827
758(defun ses-calculate-cell (row col force) 828(defun ses-calculate-cell (row col force)
759 "Calculate and print the value for cell (ROW,COL) using the cell's formula 829 "Calculate and print the value for cell (ROW,COL) using the cell's formula
760function and print functions, if any. Result is nil for normal operation, or 830function and print functions, if any. Result is nil for normal operation, or