summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Belaïche <vincentb1@users.sourceforge.net>2016-05-26 11:03:21 +0200
committerVincent Belaïche <vincentb1@users.sourceforge.net>2016-05-26 11:03:21 +0200
commita4d882cd09507fa1f891984fc7435923de3566fe (patch)
tree4af595dd471ead3f053e62a6f8546170fd10bd53
parent6c12c53949acafbfcad2e08b1ac5cbe283d71597 (diff)
downloademacs-a4d882cd09507fa1f891984fc7435923de3566fe.tar.gz
Correct old cell name unbinding when renaming cell.
Bug is to unbind old cell names when renaming a cell with 'makunbound'. when the old cell name is of A1 type, then 'kill-local-variable' must be used instead, so that only the current spreadsheet is affected. When the old cell name is a renamed cell, then 'ses--unbind-cell-name' must be used in order to remove the old name from the name hashmap. * ses.el (ses-rename-cell): check consistency of cell symbol from text-property and from array object. Instead of 'makunbound', use either 'ses--unbind-cell-name' or 'kill-local-variable' depending on whether the cell old name is a named cell or an A1 type cell
-rw-r--r--lisp/ses.el20
1 files changed, 16 insertions, 4 deletions
diff --git a/lisp/ses.el b/lisp/ses.el
index 50101945f34..ab9f0715fd8 100644
--- a/lisp/ses.el
+++ b/lisp/ses.el
@@ -3454,9 +3454,18 @@ highlighted range in the spreadsheet."
(setq cell (or cell (ses-get-cell row col))
old-name (ses-cell-symbol cell)
new-rowcol (ses-decode-cell-symbol (symbol-name new-name)))
+ ;; when ses-rename-cell is called interactively, then 'sym' is the
+ ;; 'cursor-intangible' property of text at cursor position, while
+ ;; 'old-name' is the symbol stored in array cell at coordinate
+ ;; 'rowcol' corresponding to 'ses-cell' property of symbol
+ ;; 'sym'. Both must be the same.
+ (unless (eq sym old-name)
+ (error "Spreadsheet is broken, both symbols %S and %S refering to cell (%d,%d)" sym old-name row col))
(if new-rowcol
+ ;; the new name is of A1 type, so we test that the coordinate
+ ;; inferred from new name
(if (equal new-rowcol rowcol)
- (put new-name 'ses-cell rowcol)
+ (put new-name 'ses-cell rowcol)
(error "Not a valid name for this cell location"))
(setq ses--named-cell-hashmap
(or ses--named-cell-hashmap (make-hash-table :test 'eq)))
@@ -3470,7 +3479,7 @@ highlighted range in the spreadsheet."
(setf (ses-cell-formula xcell)
(ses-replace-name-in-formula
(ses-cell-formula xcell)
- sym
+ old-name
new-name))))
;; Replace name by new name in reference list of cells to which renamed
;; cell refers to.
@@ -3478,11 +3487,14 @@ highlighted range in the spreadsheet."
(let* ((x (ses-sym-rowcol ref))
(xcell (ses-get-cell (car x) (cdr x))))
(setf (ses-cell-references xcell)
- (cons new-name (delq sym
+ (cons new-name (delq old-name
(ses-cell-references xcell))))))
(set (make-local-variable new-name) (symbol-value sym))
(setf (ses-cell--symbol cell) new-name)
- (makunbound sym)
+ ;; Unbind old name
+ (if (eq (get old-name 'ses-cell) :ses-named)
+ (ses--unbind-cell-name old-name)
+ (kill-local-variable old-name))
(and curcell (setq ses--curcell new-name))
(save-excursion
(or curcell (ses-goto-print row col))