diff options
| author | Vincent Belaïche | 2016-05-26 11:03:21 +0200 |
|---|---|---|
| committer | Vincent Belaïche | 2016-05-26 11:03:21 +0200 |
| commit | a4d882cd09507fa1f891984fc7435923de3566fe (patch) | |
| tree | 4af595dd471ead3f053e62a6f8546170fd10bd53 | |
| parent | 6c12c53949acafbfcad2e08b1ac5cbe283d71597 (diff) | |
| download | emacs-a4d882cd09507fa1f891984fc7435923de3566fe.tar.gz emacs-a4d882cd09507fa1f891984fc7435923de3566fe.zip | |
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.el | 20 |
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." | |||
| 3454 | (setq cell (or cell (ses-get-cell row col)) | 3454 | (setq cell (or cell (ses-get-cell row col)) |
| 3455 | old-name (ses-cell-symbol cell) | 3455 | old-name (ses-cell-symbol cell) |
| 3456 | new-rowcol (ses-decode-cell-symbol (symbol-name new-name))) | 3456 | new-rowcol (ses-decode-cell-symbol (symbol-name new-name))) |
| 3457 | ;; when ses-rename-cell is called interactively, then 'sym' is the | ||
| 3458 | ;; 'cursor-intangible' property of text at cursor position, while | ||
| 3459 | ;; 'old-name' is the symbol stored in array cell at coordinate | ||
| 3460 | ;; 'rowcol' corresponding to 'ses-cell' property of symbol | ||
| 3461 | ;; 'sym'. Both must be the same. | ||
| 3462 | (unless (eq sym old-name) | ||
| 3463 | (error "Spreadsheet is broken, both symbols %S and %S refering to cell (%d,%d)" sym old-name row col)) | ||
| 3457 | (if new-rowcol | 3464 | (if new-rowcol |
| 3465 | ;; the new name is of A1 type, so we test that the coordinate | ||
| 3466 | ;; inferred from new name | ||
| 3458 | (if (equal new-rowcol rowcol) | 3467 | (if (equal new-rowcol rowcol) |
| 3459 | (put new-name 'ses-cell rowcol) | 3468 | (put new-name 'ses-cell rowcol) |
| 3460 | (error "Not a valid name for this cell location")) | 3469 | (error "Not a valid name for this cell location")) |
| 3461 | (setq ses--named-cell-hashmap | 3470 | (setq ses--named-cell-hashmap |
| 3462 | (or ses--named-cell-hashmap (make-hash-table :test 'eq))) | 3471 | (or ses--named-cell-hashmap (make-hash-table :test 'eq))) |
| @@ -3470,7 +3479,7 @@ highlighted range in the spreadsheet." | |||
| 3470 | (setf (ses-cell-formula xcell) | 3479 | (setf (ses-cell-formula xcell) |
| 3471 | (ses-replace-name-in-formula | 3480 | (ses-replace-name-in-formula |
| 3472 | (ses-cell-formula xcell) | 3481 | (ses-cell-formula xcell) |
| 3473 | sym | 3482 | old-name |
| 3474 | new-name)))) | 3483 | new-name)))) |
| 3475 | ;; Replace name by new name in reference list of cells to which renamed | 3484 | ;; Replace name by new name in reference list of cells to which renamed |
| 3476 | ;; cell refers to. | 3485 | ;; cell refers to. |
| @@ -3478,11 +3487,14 @@ highlighted range in the spreadsheet." | |||
| 3478 | (let* ((x (ses-sym-rowcol ref)) | 3487 | (let* ((x (ses-sym-rowcol ref)) |
| 3479 | (xcell (ses-get-cell (car x) (cdr x)))) | 3488 | (xcell (ses-get-cell (car x) (cdr x)))) |
| 3480 | (setf (ses-cell-references xcell) | 3489 | (setf (ses-cell-references xcell) |
| 3481 | (cons new-name (delq sym | 3490 | (cons new-name (delq old-name |
| 3482 | (ses-cell-references xcell)))))) | 3491 | (ses-cell-references xcell)))))) |
| 3483 | (set (make-local-variable new-name) (symbol-value sym)) | 3492 | (set (make-local-variable new-name) (symbol-value sym)) |
| 3484 | (setf (ses-cell--symbol cell) new-name) | 3493 | (setf (ses-cell--symbol cell) new-name) |
| 3485 | (makunbound sym) | 3494 | ;; Unbind old name |
| 3495 | (if (eq (get old-name 'ses-cell) :ses-named) | ||
| 3496 | (ses--unbind-cell-name old-name) | ||
| 3497 | (kill-local-variable old-name)) | ||
| 3486 | (and curcell (setq ses--curcell new-name)) | 3498 | (and curcell (setq ses--curcell new-name)) |
| 3487 | (save-excursion | 3499 | (save-excursion |
| 3488 | (or curcell (ses-goto-print row col)) | 3500 | (or curcell (ses-goto-print row col)) |