emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/pending r105053: The overall change is to a


From: Vincent Belaïche
Subject: [Emacs-diffs] /srv/bzr/emacs/pending r105053: The overall change is to add cell renaming, that is setting fancy names for cell symbols other than name matching "\\`[A-Z]+[0-9]+\\'" regexp . (ses-create-cell-variable): New defun. (ses-relocate-formula): Relocate formulas only for cells the symbols of which are not renamed, i.e. symbols whose names do not match regexp "\\`[A-Z]+[0-9]+\\'". (ses-relocate-all): Relocate values only for cells the symbols of which are not renamed. (ses-load): Create cells variables as the (ses-cell ...) are read, in order to check row col consistency with cell symbol name only for cells that are not renamed. (ses-replace-name-in-formula): New defun. (ses-rename-cell): New defun. (ses-call-printer-return, ses-cell-property-get) (ses-sym-rowcol, ses-printer-validate, ses-formula-record) (ses-create-cell-variable, ses-reset-header-string) (ses-cell-set-formula, ses-repair-cell-reference-all) (ses-self-reference-early-detection, ses-in-print-area, ses-set-curcell) (ses-check-curcell, ses-call-printer, ses-adjust-print-width) (ses-print-cell-new-width, ses-formula-references, ses-relocate-formula) (ses-aset-with-undo, ses-load, ses-truncate-cell) (ses-read-column-printer, ses-read-default-printer, ses-insert-row) (ses-delete-row, ses-delete-column, ses-append-row-jump-first-column) (ses-kill-override, ses-yank-pop, ses-yank-cells, ses-yank-tsf) (ses-yank-resize, ses-export-tab, ses-mark-row, ses-mark-column) (ses-renarrow-buffer, ses-insert-range, ses-insert-ses-range) (ses-safe-printer, ses-safe-formula, ses-warn-unsafe, ses--clean-!) (ses--clean-_, ses-range, ses-select, ses-center, ses-center-span) (ses-dashfill, ses-unsafe): Fix typos and reflow docstrings.
Date: Tue, 27 Dec 2011 20:30:39 +0100
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 105053
committer: Vincent Belaïche  <address@hidden>
branch nick: pending
timestamp: Tue 2011-12-27 20:30:39 +0100
message:
  The overall change is to add cell renaming, that is setting fancy names for 
cell symbols other than name matching "\\`[A-Z]+[0-9]+\\'" regexp . 
(ses-create-cell-variable): New defun. (ses-relocate-formula): Relocate 
formulas only for cells the symbols of which are not renamed, i.e. symbols 
whose names do not match regexp "\\`[A-Z]+[0-9]+\\'". (ses-relocate-all): 
Relocate values only for cells the symbols of which are not renamed. 
(ses-load): Create cells variables as the (ses-cell ...) are read, in order to 
check row col consistency with cell symbol name only for cells that are not 
renamed. (ses-replace-name-in-formula): New defun. (ses-rename-cell): New 
defun. (ses-call-printer-return, ses-cell-property-get) (ses-sym-rowcol, 
ses-printer-validate, ses-formula-record) (ses-create-cell-variable, 
ses-reset-header-string) (ses-cell-set-formula, ses-repair-cell-reference-all) 
(ses-self-reference-early-detection, ses-in-print-area, ses-set-curcell) 
(ses-check-curcell, ses-call-printer, ses-adjust-print-width) 
(ses-print-cell-new-width, ses-formula-references, ses-relocate-formula) 
(ses-aset-with-undo, ses-load, ses-truncate-cell) (ses-read-column-printer, 
ses-read-default-printer, ses-insert-row) (ses-delete-row, ses-delete-column, 
ses-append-row-jump-first-column) (ses-kill-override, ses-yank-pop, 
ses-yank-cells, ses-yank-tsf) (ses-yank-resize, ses-export-tab, ses-mark-row, 
ses-mark-column) (ses-renarrow-buffer, ses-insert-range, ses-insert-ses-range) 
(ses-safe-printer, ses-safe-formula, ses-warn-unsafe, ses--clean-!) 
(ses--clean-_, ses-range, ses-select, ses-center, ses-center-span) 
(ses-dashfill, ses-unsafe): Fix typos and reflow docstrings.
modified:
  lisp/ChangeLog
  lisp/ses.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2011-07-09 03:11:57 +0000
+++ b/lisp/ChangeLog    2011-12-27 19:30:39 +0000
@@ -1,3 +1,37 @@
+2011-12-27  Vincent Belaïche  <address@hidden>
+
+       * ses.el: The overall change is to add cell renaming, that is
+       setting fancy names for cell symbols other than name matching
+       "\\`[A-Z]+[0-9]+\\'" regexp .
+       (ses-create-cell-variable): New defun.
+       (ses-relocate-formula): Relocate formulas only for cells the
+       symbols of which are not renamed, i.e. symbols whose names do not
+       match regexp "\\`[A-Z]+[0-9]+\\'".
+       (ses-relocate-all): Relocate values only for cells the symbols of
+       which are not renamed.
+       (ses-load): Create cells variables as the (ses-cell ...) are read,
+       in order to check row col consistency with cell symbol name only
+       for cells that are not renamed.
+       (ses-replace-name-in-formula): New defun.
+       (ses-rename-cell): New defun.
+       (ses-call-printer-return, ses-cell-property-get)
+       (ses-sym-rowcol, ses-printer-validate, ses-formula-record)
+       (ses-create-cell-variable, ses-reset-header-string)
+       (ses-cell-set-formula, ses-repair-cell-reference-all)
+       (ses-self-reference-early-detection, ses-in-print-area, ses-set-curcell)
+       (ses-check-curcell, ses-call-printer, ses-adjust-print-width)
+       (ses-print-cell-new-width, ses-formula-references, ses-relocate-formula)
+       (ses-aset-with-undo, ses-load, ses-truncate-cell)
+       (ses-read-column-printer, ses-read-default-printer, ses-insert-row)
+       (ses-delete-row, ses-delete-column, ses-append-row-jump-first-column)
+       (ses-kill-override, ses-yank-pop, ses-yank-cells, ses-yank-tsf)
+       (ses-yank-resize, ses-export-tab, ses-mark-row, ses-mark-column)
+       (ses-renarrow-buffer, ses-insert-range, ses-insert-ses-range)
+       (ses-safe-printer, ses-safe-formula, ses-warn-unsafe, ses--clean-!)
+       (ses--clean-_, ses-range, ses-select, ses-center, ses-center-span)
+       (ses-dashfill, ses-unsafe): Fix typos and reflow docstrings.
+
+
 2011-07-09  Leo Liu  <address@hidden>
 
        * register.el (insert-register): Restore accidental change on

=== modified file 'lisp/ses.el'
--- a/lisp/ses.el       2011-06-30 02:51:27 +0000
+++ b/lisp/ses.el       2011-12-27 19:30:39 +0000
@@ -43,7 +43,7 @@
 ;; working fine in most cases, however failed in some cases of several path
 ;; racing together.
 ;;
-;; The current algorithm is based on Dijksta algorithm.  The ``cycle length'' 
is
+;; The current algorithm is based on Dijkstra's algorithm.  The cycle length is
 ;; stored in some cell property. In order not to reset in all cells such
 ;; property at each update, the cycle length is stored in this property along
 ;; with some update attempt id that is incremented at each update. The current
@@ -282,6 +282,9 @@
       ses--numcols ses--numrows ses--symbolic-formulas
       ses--data-marker ses--params-marker (ses--Dijkstra-attempt-nb . 0)
       ses--Dijkstra-weight-bound
+      ;; This list is useful to speed-up clean-up of symbols when
+      ;; an area containing renamed cell is deleted.
+      ses--renamed-cell-symb-list
       ;; Global variables that we override
       mode-line-process next-line-add-newlines transient-mark-mode)
     "Buffer-local variables used by SES.")
@@ -327,7 +330,7 @@
 
 (defvar ses-call-printer-return nil
   "Set to t if last cell printer invoked by `ses-call-printer' requested
-left-justification of the result.  Set to error-signal if ses-call-printer
+left-justification of the result.  Set to error-signal if `ses-call-printer'
 encountered an error during printing.  Otherwise nil.")
 
 (defvar ses-start-time nil
@@ -394,7 +397,7 @@
            val)))))
 
 (defmacro ses-cell-property-get (property-name row &optional col)
-   "Get property named PROPERTY-NAME From a CELL or a pair (ROW,COL).
+   "Get property named PROPERTY-NAME from a CELL or a pair (ROW,COL).
 
 When COL is omitted, CELL=ROW is a cell object.  When COL is
 present ROW and COL are the integer coordinates of the cell of
@@ -490,8 +493,8 @@
   `(aref ses--col-printers ,col))
 
 (defmacro ses-sym-rowcol (sym)
-  "From a cell-symbol SYM, gets the cons (row . col).  A1 => (0 . 0).  Result
-is nil if SYM is not a symbol that names a cell."
+  "From a cell-symbol SYM, gets the cons (row . col).  A1 => (0 . 0).
+Result is nil if SYM is not a symbol that names a cell."
   `(and (symbolp ,sym) (get ,sym 'ses-cell)))
 
 (defmacro ses-cell (sym value formula printer references)
@@ -625,7 +628,7 @@
     (delete-region pos (point))))
 
 (defun ses-printer-validate (printer)
-  "Signals an error if PRINTER is not a valid SES cell printer."
+  "Signal an error if PRINTER is not a valid SES cell printer."
   (or (not printer)
       (stringp printer)
       (functionp printer)
@@ -642,7 +645,7 @@
       (add-to-list 'ses-read-printer-history (prin1-to-string printer))))
 
 (defun ses-formula-record (formula)
-  "If FORMULA is of the form 'symbol, adds it to the list of symbolic formulas
+  "If FORMULA is of the form 'symbol, add it to the list of symbolic formulas
 for this spreadsheet."
   (when (and (eq (car-safe formula) 'quote)
             (symbolp (cadr formula)))
@@ -674,6 +677,17 @@
        (put sym 'ses-cell (cons xrow xcol))
        (make-local-variable sym)))))
 
+(defun ses-create-cell-variable (sym row col)
+  "Create a buffer-local variable `SYM' for cell at position (ROW, COL).
+
+SYM is the symbol for that variable, ROW and COL are integers for
+row and column of the cell, with numbering starting from 0.
+
+Return nil in case of failure."
+  (unless (local-variable-p sym)
+    (make-local-variable  sym)
+    (put sym 'ses-cell (cons row col))))
+
 ;; We do not delete the ses-cell properties for the cell-variables, in
 ;; case a formula that refers to this cell is in the kill-ring and is
 ;; later pasted back in.
@@ -682,7 +696,10 @@
   (let (sym)
     (dotimes (row (1+ (- maxrow minrow)))
       (dotimes (col (1+ (- maxcol mincol)))
-       (setq sym (ses-create-cell-symbol (+ row minrow) (+ col mincol)))
+       (let ((xrow  (+ row minrow)) (xcol (+ col mincol)))
+         (setq sym (if (and (< xrow ses--numrows) (< xcol ses--numcols))
+                       (ses-cell-symbol xrow xcol)
+                       (ses-create-cell-symbol xrow xcol))))
        (if (boundp sym)
            (push `(apply ses-set-with-undo ,sym ,(symbol-value sym))
                  buffer-undo-list))
@@ -691,7 +708,7 @@
        buffer-undo-list))
 
 (defun ses-reset-header-string ()
-  "Flags the header string for update.  Upon undo, the header string will be
+  "Flag the header string for update.  Upon undo, the header string will be
 updated again."
   (push '(apply ses-reset-header-string) buffer-undo-list)
   (setq ses--header-hscroll -1))
@@ -727,7 +744,7 @@
   nil) ; Make coverage-tester happy.
 
 (defun ses-cell-set-formula (row col formula)
-  "Store a new formula for (ROW . COL) and enqueues the cell for
+  "Store a new formula for (ROW . COL) and enqueue the cell for
 recalculation via `post-command-hook'.  Updates the reference lists for the
 cells that this cell refers to.  Does not update cell value or reprint the
 cell.  To avoid inconsistencies, this function is not interruptible, which
@@ -812,9 +829,9 @@
                  errors)))))
     (if errors
       (warn "----------------------------------------------------------------
-Some reference where corrupted.
+Some references were corrupted.
 
-The following is a list of where each element ELT is such
+The following is a list where each element ELT is such
 that (car ELT) is the reference of cell CELL with corruption,
 and (cdr ELT) is a property list where
 
@@ -922,8 +939,7 @@
   (ses-cell-set-formula row col nil))
 
 (defcustom ses-self-reference-early-detection nil
-  "True if cycle detection is early for cells that refer to
-themselves."
+  "True if cycle detection is early for cells that refer to themselves."
   :type 'boolean
   :group 'ses)
 
@@ -980,7 +996,7 @@
        (error "Circular references: %s" ses--deferred-recalc))
       (message " "))
     ;; Can't use save-excursion here: if the cell under point is updated,
-    ;; save-excusion's marker will move past the cell.
+    ;; save-excursion's marker will move past the cell.
     (goto-char pos)))
 
 
@@ -989,7 +1005,7 @@
 ;;----------------------------------------------------------------------------
 
 (defun ses-in-print-area ()
-  "Returns t if point is in print area of spreadsheet."
+  "Return t if point is in print area of spreadsheet."
   (<= (point) ses--data-marker))
 
 ;; We turn off point-motion-hooks and explicitly position the cursor, in case
@@ -1011,7 +1027,7 @@
         (forward-char))))
 
 (defun ses-set-curcell ()
-  "Sets `ses--curcell' to the current cell symbol, or a cons (BEG,END) for a
+  "Set `ses--curcell' to the current cell symbol, or a cons (BEG,END) for a
 region, or nil if cursor is not at a cell."
   (if (or (not mark-active)
          deactivate-mark
@@ -1030,10 +1046,10 @@
   nil)
 
 (defun ses-check-curcell (&rest args)
-  "Signal an error if ses--curcell is inappropriate.  The end marker is
-appropriate if some argument is 'end.  A range is appropriate if some
-argument is 'range.  A single cell is appropriate unless some argument is
-'needrange."
+  "Signal an error if `ses--curcell' is inappropriate.
+The end marker is appropriate if some argument is 'end.
+A range is appropriate if some argument is 'range.
+A single cell is appropriate unless some argument is 'needrange."
   (if (eq ses--curcell t)
       ;; curcell recalculation was postponed, but user typed ahead.
       (ses-set-curcell))
@@ -1143,7 +1159,7 @@
        (setq x (concat text (if (< maxcol ses--numcols) " " "\n")))
        ;; We use set-text-properties to prevent a wacky print function from
        ;; inserting rogue properties, and to ensure that the keymap property is
-       ;; inherited (is it a bug that only unpropertied strings actually
+       ;; inherited (is it a bug that only unpropertized strings actually
        ;; inherit from surrounding text?)
        (set-text-properties 0 (length x) nil x)
        (insert-and-inherit x)
@@ -1168,7 +1184,7 @@
       sig)))
 
 (defun ses-call-printer (printer &optional value)
-  "Invokes PRINTER (a string or parenthesized string or function-symbol or
+  "Invoke PRINTER (a string or parenthesized string or function-symbol or
 lambda of one argument) on VALUE.  Result is the printed cell as a string.
 The variable `ses-call-printer-return' is set to t if the printer used
 parenthesis to request left-justification, or the error-signal if the
@@ -1200,7 +1216,7 @@
 (defun ses-adjust-print-width (col change)
   "Insert CHANGE spaces in front of column COL, or at end of line if
 COL=NUMCOLS.  Deletes characters if CHANGE < 0.  Caller should bind
-inhibit-quit to t."
+`inhibit-quit' to t."
   (let ((inhibit-read-only t)
        (blank  (if (> change 0) (make-string change ?\s)))
        (at-end (= col ses--numcols)))
@@ -1219,9 +1235,9 @@
        (delete-char (- change))))))
 
 (defun ses-print-cell-new-width (row col)
-  "Same as ses-print-cell, except if the cell's value is *skip*, the preceding
-nonskipped cell is reprinted.  This function is used when the width of
-cell (ROW,COL) has changed."
+  "Same as `ses-print-cell', except if the cell's value is *skip*,
+the preceding nonskipped cell is reprinted.  This function is used
+when the width of cell (ROW,COL) has changed."
   (if (not (eq (ses-cell-value row col) '*skip*))
       (ses-print-cell row col)
     ;;Cell was skipped over - reprint previous
@@ -1315,7 +1331,7 @@
              (setq formula (cadr formula)))
          (if (eq (car-safe printer) 'ses-safe-printer)
              (setq printer (cadr printer)))
-         ;; This is noticably faster than (format "%S %S %S %S %S")
+         ;; This is noticeably faster than (format "%S %S %S %S %S")
          (setq text    (concat "(ses-cell "
                                (symbol-name sym)
                                " "
@@ -1344,7 +1360,7 @@
 ;;----------------------------------------------------------------------------
 
 (defun ses-formula-references (formula &optional result-so-far)
-  "Produce a list of symbols for cells that this formula's value
+  "Produce a list of symbols for cells that this FORMULA's value
 refers to.  For recursive calls, RESULT-SO-FAR is the list being
 constructed, or t to get a wrong-type-argument error when the
 first reference is found."
@@ -1371,7 +1387,7 @@
     result-so-far)
 
 (defsubst ses-relocate-symbol (sym rowcol startrow startcol rowincr colincr)
-  "Relocate one symbol SYM, whichs corresponds to ROWCOL (a cons of ROW and
+  "Relocate one symbol SYM, which corresponds to ROWCOL (a cons of ROW and
 COL).  Cells starting at (STARTROW,STARTCOL) are being shifted
 by (ROWINCR,COLINCR)."
   (let ((row (car rowcol))
@@ -1389,8 +1405,8 @@
 
 (defun ses-relocate-formula (formula startrow startcol rowincr colincr)
   "Produce a copy of FORMULA where all symbols that refer to cells in row
-STARTROW or above and col STARTCOL or above are altered by adding ROWINCR
-and COLINCR.  STARTROW and STARTCOL are 0-based. Example:
+STARTROW or above, and col STARTCOL or above, are altered by adding ROWINCR
+and COLINCR.  STARTROW and STARTCOL are 0-based.  Example:
        (ses-relocate-formula '(+ A1 B2 D3) 1 2 1 -1)
        => (+ A1 B2 C4)
 If ROWINCR or COLINCR is negative, references to cells being deleted are
@@ -1400,7 +1416,8 @@
 Sets `ses-relocate-return' to 'delete if cell-references were removed."
   (let (rowcol result)
     (if (or (atom formula) (eq (car formula) 'quote))
-       (if (setq rowcol (ses-sym-rowcol formula))
+       (if (and (setq rowcol (ses-sym-rowcol formula))
+                (string-match "\\`[A-Z]+[0-9]+\\'" (symbol-name formula)))
            (ses-relocate-symbol formula rowcol
                                 startrow startcol rowincr colincr)
          formula) ; Pass through as-is.
@@ -1508,14 +1525,15 @@
 the rectangle (MINROW,MINCOL)..(NUMROWS,NUMCOLS) by adding ROWINCR and COLINCR
 to each symbol."
   (let (reform)
-    (let (mycell newval)
+    (let (mycell newval xrow)
       (dotimes-with-progress-reporter
          (row ses--numrows) "Relocating formulas..."
        (dotimes (col ses--numcols)
          (setq ses-relocate-return nil
                mycell (ses-get-cell row col)
                newval (ses-relocate-formula (ses-cell-formula mycell)
-                                            minrow mincol rowincr colincr))
+                                            minrow mincol rowincr colincr)
+               xrow  (- row rowincr))
          (ses-set-cell row col 'formula newval)
          (if (eq ses-relocate-return 'range)
              ;; This cell contains a (ses-range X Y) where a cell has been
@@ -1531,8 +1549,22 @@
                                             minrow mincol rowincr colincr))
          (ses-set-cell row col 'references newval)
          (and (>= row minrow) (>= col mincol)
-              (ses-set-cell row col 'symbol
-                            (ses-create-cell-symbol row col))))))
+              (let ((sym (ses-cell-symbol row col))
+                    (xcol (- col colincr)))
+                (if (and
+                     sym
+                     (>= xrow 0)
+                     (>= xcol 0)
+                     (null (eq sym
+                               (ses-create-cell-symbol xrow xcol))))
+                    ;; This is a renamed cell, do not update the cell
+                    ;; name, but just update the coordinate property.
+                    (put sym 'ses-cell (cons row col))
+                  (ses-set-cell row col 'symbol
+                                (setq sym (ses-create-cell-symbol row col)))
+                  (unless (and (boundp sym) (local-variable-p sym))
+                    (set (make-local-variable sym) nil)
+                    (put sym 'ses-cell (cons row col)))))) )))
     ;; Relocate the cell values.
     (let (oldval myrow mycol xrow xcol)
       (cond
@@ -1545,11 +1577,17 @@
            (setq mycol  (+ col mincol)
                  xrow   (- myrow rowincr)
                  xcol   (- mycol colincr))
-           (if (and (< xrow ses--numrows) (< xcol ses--numcols))
-               (setq oldval (ses-cell-value xrow xcol))
-             ;; Cell is off the end of the array.
-             (setq oldval (symbol-value (ses-create-cell-symbol xrow xcol))))
-           (ses-set-cell myrow mycol 'value oldval))))
+           (let ((sym (ses-cell-symbol myrow mycol))
+                 (xsym (ses-create-cell-symbol xrow xcol)))
+             ;; Make the value relocation only when if the cell is not
+             ;; a renamed cell.  Otherwise this is not needed.
+             (and (eq sym xsym)
+                 (ses-set-cell myrow mycol 'value
+                   (if (and (< xrow ses--numrows) (< xcol ses--numcols))
+                       (ses-cell-value xrow xcol)
+                     ;;Cell is off the end of the array
+                     (symbol-value xsym))))))))
+
        ((and (wholenump rowincr) (wholenump colincr))
        ;; Insertion of rows and/or columns.  Run the loop backwards.
        (let ((disty (1- ses--numrows))
@@ -1618,7 +1656,8 @@
     (makunbound sym)))
 
 (defun ses-aset-with-undo (array idx newval)
-  "Like aset, but undoable.  Result is t if element has changed"
+  "Like `aset', but undoable.
+Result is t if element has changed."
   (unless (equal (aref array idx) newval)
     (push `(apply ses-aset-with-undo ,array ,idx
                  ,(aref array idx)) buffer-undo-list)
@@ -1631,8 +1670,8 @@
 ;;----------------------------------------------------------------------------
 
 (defun ses-load ()
-  "Parse the current buffer and sets up buffer-local variables.  Does not
-execute cell formulas or print functions."
+  "Parse the current buffer and set up buffer-local variables.
+Does not execute cell formulas or print functions."
   (widen)
   ;; Read our global parameters, which should be a 3-element list.
   (goto-char (point-max))
@@ -1658,7 +1697,6 @@
        (message "Upgrading from SES-1 file format")))
     (or (= ses--file-format 2)
        (error "This file needs a newer version of the SES library code"))
-    (ses-create-cell-variable-range 0 (1- ses--numrows) 0 (1- ses--numcols))
     ;; Initialize cell array.
     (setq ses--cells (make-vector ses--numrows nil))
     (dotimes (row ses--numrows)
@@ -1678,11 +1716,10 @@
   (dotimes (row ses--numrows)
     (dotimes (col ses--numcols)
       (let* ((x      (read (current-buffer)))
-            (rowcol (ses-sym-rowcol (car-safe (cdr-safe x)))))
+            (sym  (car-safe (cdr-safe x))))
        (or (and (looking-at "\n")
                 (eq (car-safe x) 'ses-cell)
-                (eq row (car rowcol))
-                (eq col (cdr rowcol)))
+                (ses-create-cell-variable sym row col))
            (error "Cell-def error"))
        (eval x)))
     (or (looking-at "\n\n")
@@ -2082,8 +2119,7 @@
     (ses-jump-safe startcell)))
 
 (defun ses-truncate-cell ()
-  "Reprint current cell, but without spillover into any following blank
-cells."
+  "Reprint current cell, but without spillover into any following blank cells."
   (interactive "*")
   (ses-check-curcell)
   (let* ((rowcol (ses-sym-rowcol ses--curcell))
@@ -2273,7 +2309,7 @@
 
 (defun ses-read-printer (prompt default)
   "Common code for `ses-read-cell-printer', `ses-read-column-printer', and 
`ses-read-default-printer'.
-PROMPT should end with \": \".  Result is t if operation was cancelled."
+PROMPT should end with \": \".  Result is t if operation was canceled."
   (barf-if-buffer-read-only)
   (if (eq default t)
       (setq default "")
@@ -2331,8 +2367,8 @@
       (ses-print-cell row col))))
 
 (defun ses-read-column-printer (col newval)
-  "Set the printer function for the current column.  See
-`ses-read-cell-printer' for input forms."
+  "Set the printer function for the current column.
+See `ses-read-cell-printer' for input forms."
   (interactive
    (let ((col (cdr (ses-sym-rowcol ses--curcell))))
      (ses-check-curcell)
@@ -2348,8 +2384,8 @@
        (ses-print-cell row col)))))
 
 (defun ses-read-default-printer (newval)
-  "Set the default printer function for cells that have no other.  See
-`ses-read-cell-printer' for input forms."
+  "Set the default printer function for cells that have no other.
+See `ses-read-cell-printer' for input forms."
   (interactive
    (list (ses-read-printer "Default printer: " ses--default-printer)))
   (unless (eq newval t)
@@ -2363,8 +2399,8 @@
 ;;----------------------------------------------------------------------------
 
 (defun ses-insert-row (count)
-  "Insert a new row before the current one.  With prefix, insert COUNT rows
-before current one."
+  "Insert a new row before the current one.
+With prefix, insert COUNT rows before current one."
   (interactive "*p")
   (ses-check-curcell 'end)
   (or (> count 0) (signal 'args-out-of-range nil))
@@ -2416,8 +2452,8 @@
     (ses-goto-print (1- ses--numrows) 0)))
 
 (defun ses-delete-row (count)
-  "Delete the current row.  With prefix, Deletes COUNT rows starting from the
-current one."
+  "Delete the current row.
+With prefix, deletes COUNT rows starting from the current one."
   (interactive "*p")
   (ses-check-curcell)
   (or (> count 0) (signal 'args-out-of-range nil))
@@ -2509,8 +2545,8 @@
   (ses-jump-safe ses--curcell))
 
 (defun ses-delete-column (count)
-  "Delete the current column.  With prefix, Deletes COUNT columns starting
-from the current one."
+  "Delete the current column.
+With prefix, deletes COUNT columns starting from the current one."
   (interactive "*p")
   (ses-check-curcell)
   (or (> count 0) (signal 'args-out-of-range nil))
@@ -2584,7 +2620,7 @@
     (forward-char)))
 
 (defun ses-append-row-jump-first-column ()
-  "Insert a new row after current one and jumps to its first column."
+  "Insert a new row after current one and jump to its first column."
   (interactive "*")
   (ses-check-curcell)
   (ses-begin-change)
@@ -2687,8 +2723,8 @@
   line)
 
 (defun ses-kill-override (beg end)
-  "Generic override for any commands that kill text.  We clear the killed
-cells instead of deleting them."
+  "Generic override for any commands that kill text.
+We clear the killed cells instead of deleting them."
   (interactive "r")
   (ses-check-curcell 'needrange)
   ;; For some reason, the text-read-only error is not caught by 
`delete-region',
@@ -2720,7 +2756,7 @@
 relative references to neighboring cells.  This is best if the formulas
 generally refer to other cells within the yanked text.  You can use the C-u
 prefix to specify insertion without relocation, which is best when the
-formulas refer to cells outsite the yanked text.
+formulas refer to cells outside the yanked text.
 
 When inserting formulas, the text is treated as a string constant if it doesn't
 make sense as a sexp or would otherwise be considered a symbol.  Use 'sym to
@@ -2749,9 +2785,9 @@
 
 (defun ses-yank-pop (arg)
   "Replace just-yanked stretch of killed text with a different stretch.
-This command is allowed only immediately after a `yank' or a `yank-pop', when
-the region contains a stretch of reinserted previously-killed text.  We
-replace it with a different stretch of killed text.
+This command is allowed only immediately after a `yank' or a `yank-pop',
+when the region contains a stretch of reinserted previously-killed text.
+We replace it with a different stretch of killed text.
   Unlike standard `yank-pop', this function uses `undo' to delete the
 previous insertion."
   (interactive "*p")
@@ -2765,7 +2801,7 @@
   (setq this-command 'yank))
 
 (defun ses-yank-cells (text arg)
-  "If the TEXT has a proper set of 'ses attributes, inserts the text as
+  "If the TEXT has a proper set of 'ses attributes, insert the text as
 cells, else return nil.  The cells are reprinted--the supplied text is
 ignored because the column widths, default printer, etc. at yank time might
 be different from those at kill-time.  ARG is a list to indicate that
@@ -2848,8 +2884,8 @@
       (ses-cell-set-formula row col val))))
 
 (defun ses-yank-tsf (text arg)
-  "If TEXT contains tabs and/or newlines, treats the tabs as
-column-separators and the newlines as row-separators and inserts the text as
+  "If TEXT contains tabs and/or newlines, treat the tabs as
+column-separators and the newlines as row-separators and insert the text as
 cell formulas--else return nil.  Treat plain symbols as strings unless ARG
 is a list.  Ignore a final newline."
   (if (or (not (string-match "[\t\n]" text))
@@ -2887,8 +2923,8 @@
       t)))
 
 (defun ses-yank-resize (needrows needcols)
-  "If this yank will require inserting rows and/or columns, asks for
-confirmation and then inserts them.  Result is (row,col) for top left of yank
+  "If this yank will require inserting rows and/or columns, ask for
+confirmation and then insert them.  Result is (row,col) for top left of yank
 spot, or error signal if user requests cancel."
   (ses-begin-change)
   (let ((rowcol (if ses--curcell
@@ -2931,9 +2967,9 @@
   (ses-export-tab t))
 
 (defun ses-export-tab (want-formulas)
-  "Export the current range with tabs between columns and newlines between
-rows.  Result is placed in kill ring.  The export is values unless
-WANT-FORMULAS is non-nil.  Newlines and tabs in the export text are escaped."
+  "Export the current range with tabs between columns and newlines between 
rows.
+Result is placed in kill ring.  The export is values unless WANT-FORMULAS
+is non-nil.  Newlines and tabs in the export text are escaped."
   (ses-check-curcell 'needrange)
   (let ((print-escape-newlines t)
        result item)
@@ -2992,7 +3028,7 @@
   (ses-reset-header-string))
 
 (defun ses-mark-row ()
-  "Marks the entirety of current row as a range."
+  "Mark the entirety of current row as a range."
   (interactive)
   (ses-check-curcell 'range)
   (let ((row (car (ses-sym-rowcol (or (car-safe ses--curcell) ses--curcell)))))
@@ -3002,7 +3038,7 @@
     (ses-goto-print row 0)))
 
 (defun ses-mark-column ()
-  "Marks the entirety of current column as a range."
+  "Mark the entirety of current column as a range."
   (interactive)
   (ses-check-curcell 'range)
   (let ((col (cdr (ses-sym-rowcol (or (car-safe ses--curcell) ses--curcell))))
@@ -3046,13 +3082,14 @@
        (ses-goto-print row col)))))
 
 (defun ses-renarrow-buffer ()
-  "Narrow the buffer so only the print area is visible.  Use after \\[widen]."
+  "Narrow the buffer so only the print area is visible.
+Use after \\[widen]."
   (interactive)
   (setq ses--deferred-narrow t))
 
 (defun ses-sort-column (sorter &optional reverse)
-  "Sorts the range by a specified column.  With prefix, sorts in
-REVERSE order."
+  "Sort the range by a specified column.
+With prefix, sorts in REVERSE order."
   (interactive "*sSort column: \nP")
   (ses-check-curcell 'needrange)
   (let ((min (ses-sym-rowcol (car ses--curcell)))
@@ -3103,7 +3140,7 @@
       (ses-sort-column (ses-column-letter col) reverse))))
 
 (defun ses-insert-range ()
-  "Inserts into minibuffer the list of cells currently highlighted in the
+  "Insert into minibuffer the list of cells currently highlighted in the
 spreadsheet."
   (interactive "*")
   (let (x)
@@ -3115,7 +3152,7 @@
     (insert (substring (prin1-to-string (nreverse x)) 1 -1))))
 
 (defun ses-insert-ses-range ()
-  "Inserts \"(ses-range x y)\" in the minibuffer to represent the currently
+  "Insert \"(ses-range x y)\" in the minibuffer to represent the currently
 highlighted range in the spreadsheet."
   (interactive "*")
   (let (x)
@@ -3139,13 +3176,70 @@
   (mouse-set-point event)
   (ses-insert-ses-range))
 
+(defun ses-replace-name-in-formula (formula old-name new-name)
+  (let ((new-formula formula))
+    (unless (and (consp formula)
+                (eq (car-safe formula) 'quote))
+      (while formula
+       (let ((elt (car-safe formula)))
+         (cond
+          ((consp elt)
+           (setcar formula (ses-replace-name-in-formula elt old-name 
new-name)))
+          ((and (symbolp elt)
+                (eq (car-safe formula) old-name))
+           (setcar formula new-name))))
+       (setq formula (cdr formula))))
+    new-formula))
+
+(defun ses-rename-cell (new-name)
+  "Rename current cell."
+  (interactive "*SEnter new name: ")
+  (ses-check-curcell)
+  (or
+   (and  (local-variable-p new-name)
+        (ses-sym-rowcol new-name)
+        ;; this test is needed because ses-cell property of deleted cells
+        ;; is not deleted in case of subsequent undo
+        (memq new-name ses--renamed-cell-symb-list)
+        (error "Already a cell name"))
+   (and (boundp new-name)
+       (null (yes-or-no-p (format "`%S' is already bound outside this buffer, 
continue? "
+                                  new-name)))
+       (error "Already a bound cell name")))
+  (let* ((rowcol (ses-sym-rowcol ses--curcell))
+        (cell (ses-get-cell (car rowcol) (cdr rowcol))))
+    (put new-name 'ses-cell rowcol)
+    (dolist (reference (ses-cell-references (car rowcol) (cdr rowcol)))
+      (let* ((rowcol (ses-sym-rowcol reference))
+            (cell  (ses-get-cell (car rowcol) (cdr rowcol))))
+       (ses-cell-set-formula (car rowcol)
+                             (cdr rowcol)
+                             (ses-replace-name-in-formula
+                              (ses-cell-formula cell)
+                              ses--curcell
+                              new-name))))
+    (push new-name ses--renamed-cell-symb-list)
+    (set new-name (symbol-value ses--curcell))
+    (aset cell 0 new-name)
+    (put ses--curcell 'ses-cell nil)
+    (makunbound ses--curcell)
+    (setq ses--curcell new-name)
+    (let* ((pos (point))
+          (inhibit-read-only t)
+          (col (current-column))
+          (end (save-excursion
+                 (move-to-column (1+ col))
+                 (if (eolp)
+                     (+ pos (ses-col-width col) 1)
+                   (point)))))
+      (put-text-property pos end 'intangible new-name))) )
 
 ;;----------------------------------------------------------------------------
 ;; Checking formulas for safety
 ;;----------------------------------------------------------------------------
 
 (defun ses-safe-printer (printer)
-  "Returns PRINTER if safe, or the substitute printer `ses-unsafe' otherwise."
+  "Return PRINTER if safe, or the substitute printer `ses-unsafe' otherwise."
   (if (or (stringp printer)
          (stringp (car-safe printer))
          (not printer)
@@ -3154,16 +3248,16 @@
     'ses-unsafe))
 
 (defun ses-safe-formula (formula)
-  "Returns FORMULA if safe, or the substitute formula *unsafe* otherwise."
+  "Return FORMULA if safe, or the substitute formula *unsafe* otherwise."
   (if (ses-warn-unsafe formula 'unsafep)
       formula
     `(ses-unsafe ',formula)))
 
 (defun ses-warn-unsafe (formula checker)
-  "Applies CHECKER to FORMULA.  If result is non-nil, asks user for
-confirmation about FORMULA, which might be unsafe.  Returns t if formula
-is safe or user allows execution anyway.  Always returns t if
-`safe-functions' is t."
+  "Apply CHECKER to FORMULA.
+If result is non-nil, asks user for confirmation about FORMULA,
+which might be unsafe.  Returns t if formula is safe or user allows
+execution anyway.  Always returns t if `safe-functions' is t."
   (if (eq safe-functions t)
       t
     (setq checker (funcall checker formula))
@@ -3178,13 +3272,13 @@
 ;;----------------------------------------------------------------------------
 
 (defun ses--clean-! (&rest x)
-  "Clean by delq list X from any occurrence of `nil' or `*skip*'."
+  "Clean by `delq' list X from any occurrence of `nil' or `*skip*'."
   (delq nil (delq '*skip* x)))
 
 (defun ses--clean-_ (x y)
   "Clean list X  by replacing by Y any occurrence of `nil' or `*skip*'.
 
-This will change X by making setcar on its cons cells."
+This will change X by making `setcar' on its cons cells."
   (let ((ret x) ret-elt)
     (while ret
       (setq ret-elt (car ret))
@@ -3194,7 +3288,7 @@
   x)
 
 (defmacro ses-range (from to &rest rest)
-  "Expands to a list of cell-symbols for the range going from
+  "Expand to a list of cell-symbols for the range going from
 FROM up to TO.  The range automatically expands to include any
 new row or column inserted into its middle.  The SES library code
 specifically looks for the symbol `ses-range', so don't create an
@@ -3204,11 +3298,11 @@
 is read and how it is formatted.
 
 In the sequel we assume that cells A1, B1, A2 B2 have respective values
-1 2 3 and 4 for examplication.
+1 2 3 and 4.
 
 Readout direction is specified by a `>v', '`>^', `<v', `<^',
-`v>', `v<', `^>', `^<' flag. For historical reasons, in absence
-of such a flag, a default direction of `^<' is assumed. This
+`v>', `v<', `^>', `^<' flag.  For historical reasons, in absence
+of such a flag, a default direction of `^<' is assumed.  This
 way `(ses-range A1 B2 ^>)' will evaluate to `(1 3 2 4)',
 while `(ses-range A1 B2 >^)' will evaluate to (3 4 1 2).
 
@@ -3221,18 +3315,18 @@
 A `!' flag will remove all cells whose value is nil or `*skip*'.
 
 A `_' flag will replace nil or `*skip*' by the value following
-the `_' flag. If the `_' flag is the last argument, then they are
+the `_' flag.  If the `_' flag is the last argument, then they are
 replaced by integer 0.
 
 A `*', `*1' or `*2' flag will vectorize the range in the sense of
-Calc. See info node `(Calc) Top'. Flag `*' will output either a
+Calc.  See info node `(Calc) Top'.  Flag `*' will output either a
 vector or a matrix depending on the number of rows, `*1' will
 flatten the result to a one row vector, and `*2' will make a
 matrix whatever the number of rows.
 
-Warning: interaction with Calc is expermimental and may produce
-confusing results if you are not aware of Calc data format. Use
-`math-format-value' as a printer for Calc objects."
+Warning: interaction with Calc is experimental and may produce
+confusing results if you are not aware of Calc data format.
+Use `math-format-value' as a printer for Calc objects."
   (let (result-row
        result
        (prev-row -1)
@@ -3319,10 +3413,10 @@
   (/ (float (apply '+ list)) (length list)))
 
 (defmacro ses-select (fromrange test torange)
-  "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."
+  "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))
@@ -3352,9 +3446,10 @@
 (defvar col)
 
 (defun ses-center (value &optional span fill)
-  "Print VALUE, centered within column.  FILL is the fill character for
-centering (default = space).  SPAN indicates how many additional rightward
-columns to include in width (default = 0)."
+  "Print VALUE, centered within column.
+FILL is the fill character for centering (default = space).
+SPAN indicates how many additional rightward columns to include
+in width (default = 0)."
   (let ((printer (or (ses-col-printer col) ses--default-printer))
        (width   (ses-col-width col))
        half)
@@ -3373,8 +3468,8 @@
 
 (defun ses-center-span (value &optional fill)
   "Print VALUE, centered within the span that starts in the current column
-and continues until the next nonblank column.  FILL specifies the fill
-character (default = space)."
+and continues until the next nonblank column.
+FILL specifies the fill character (default = space)."
   (let ((end (1+ col)))
     (while (and (< end ses--numcols)
                (memq (ses-cell-value row end) '(nil *skip*)))
@@ -3382,8 +3477,8 @@
     (ses-center value (- end col 1) fill)))
 
 (defun ses-dashfill (value &optional span)
-  "Print VALUE centered using dashes.  SPAN indicates how many rightward
-columns to include in width (default = 0)."
+  "Print VALUE centered using dashes.
+SPAN indicates how many rightward columns to include in width (default = 0)."
   (ses-center value span ?-))
 
 (defun ses-dashfill-span (value)
@@ -3397,7 +3492,7 @@
   (ses-center-span value ?~))
 
 (defun ses-unsafe (value)
-  "Substitute for an unsafe formula or printer"
+  "Substitute for an unsafe formula or printer."
   (error "Unsafe formula or printer"))
 
 ;;All standard printers are safe, including ses-unsafe!


reply via email to

[Prev in Thread] Current Thread [Next in Thread]