]> code.delx.au - gnu-emacs/blobdiff - lisp/ses.el
(add-to-history): New function.
[gnu-emacs] / lisp / ses.el
index c2239327e1cbae0468bd53613cbcdfb09fbc4e89..debb22d84dbce39a720f806d841cea95b3dcfc51 100644 (file)
@@ -1,6 +1,6 @@
 ;;; ses.el -- Simple Emacs Spreadsheet  -*- coding: utf-8 -*-
 
-;; Copyright (C) 2002, 2003, 2004, 2005  Free Software Foundation, Inc.
+;; Copyright (C) 2002, 2003, 2004, 2005, 2006  Free Software Foundation, Inc.
 
 ;; Author: Jonathan Yavner <jyavner@member.fsf.org>
 ;; Maintainer: Jonathan Yavner <jyavner@member.fsf.org>
@@ -20,8 +20,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
@@ -49,7 +49,7 @@
 ;;----------------------------------------------------------------------------
 
 (defgroup ses nil
-  "Simple Emacs Spreadsheet"
+  "Simple Emacs Spreadsheet."
   :group  'applications
   :prefix "ses-"
   :version "21.1")
@@ -148,8 +148,7 @@ Each function is called with ARG=1."
        (newmap (make-sparse-keymap)))
     (set-keymap-parent newmap minibuffer-local-map)
     (while keys
-      (define-key newmap (car keys) (cadr keys))
-      (setq keys (cddr keys)))
+      (define-key newmap (pop keys) (pop keys)))
     newmap)
   "Local keymap for SES minibuffer cell-editing.")
 
@@ -376,7 +375,7 @@ macro to prevent propagate-on-load viruses."
   ;;print area (excluding the terminating newline)
   (setq ses--col-widths widths
        ses--linewidth  (apply '+ -1 (mapcar '1+ widths))
-       ses--blank-line (concat (make-string ses--linewidth ? ) "\n"))
+       ses--blank-line (concat (make-string ses--linewidth ?\s) "\n"))
   t)
 
 (defmacro ses-column-printers (printers)
@@ -798,7 +797,7 @@ preceding cell has spilled over."
        (cond
         ((< len width)
          ;;Fill field to length with spaces
-         (setq len  (make-string (- width len) ? )
+         (setq len  (make-string (- width len) ?\s)
                text (if (eq ses-call-printer-return t)
                         (concat text len)
                       (concat len text))))
@@ -816,7 +815,7 @@ preceding cell has spilled over."
                    maxcol   (1+ maxcol)))
            (if (<= len maxwidth)
                ;;Fill to complete width of all the fields spanned
-               (setq text (concat text (make-string (- maxwidth len) ? )))
+               (setq text (concat text (make-string (- maxwidth len) ?\s)))
              ;;Not enough room to end of line or next non-nil field.  Truncate
              ;;if string or decimal; otherwise fill with error indicator
              (setq sig `(error "Too wide" ,text))
@@ -878,7 +877,7 @@ preceding cell has spilled over."
 lambda of one argument) on VALUE.  Result is the 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
-printer signalled one (and \"%s\" is used as the default printer), else nil."
+printer signaled one (and \"%s\" is used as the default printer), else nil."
   (setq ses-call-printer-return nil)
   (unless value
     (setq value ""))
@@ -906,12 +905,12 @@ printer signalled one (and \"%s\" is used as the default printer), else nil."
 COL=NUMCOLS.  Deletes characters if CHANGE < 0.  Caller should bind
 inhibit-quit to t."
   (let ((inhibit-read-only t)
-       (blank  (if (> change 0) (make-string change ? )))
+       (blank  (if (> change 0) (make-string change ?\s)))
        (at-end (= col ses--numcols)))
     (ses-set-with-undo 'ses--linewidth (+ ses--linewidth change))
     ;;ses-set-with-undo always returns t for strings.
     (1value (ses-set-with-undo 'ses--blank-line
-                              (concat (make-string ses--linewidth ? ) "\n")))
+                              (concat (make-string ses--linewidth ?\s) "\n")))
     (dotimes (row ses--numrows)
       (ses-goto-print row col)
       (when at-end
@@ -1281,34 +1280,20 @@ to each symbol."
 
 ;; This should be unnecessary, because the feature is now built in.
 
-;;; (defadvice undo-more (around ses-undo-more activate preactivate)
-;;;   "Define a meaning for conses in buffer-undo-list whose car is a symbol
-;;; other than t or nil.  To undo these, apply the car--a function--to the
-;;; cdr--its arglist."
-;;;   (let ((ses-count (ad-get-arg 0)))
-;;;     (catch 'undo
-;;;       (dolist (ses-x pending-undo-list)
-;;;    (unless ses-x
-;;;      ;;End of undo boundary
-;;;      (setq ses-count (1- ses-count))
-;;;      (if (<= ses-count 0)
-;;;          ;;We've seen enough boundaries - stop undoing
-;;;          (throw 'undo nil)))
-;;;    (and (consp ses-x) (symbolp (car ses-x)) (fboundp (car ses-x))
-;;;         ;;Undo using apply
-;;;         (apply (car ses-x) (cdr ses-x)))))
-;;;     (if (not (eq major-mode 'ses-mode))
-;;;    ad-do-it
-;;;       ;;Here is some extra code for SES mode.
-;;;       (setq ses--deferred-narrow
-;;;        (or ses--deferred-narrow (ses-narrowed-p)))
-;;;       (widen)
-;;;       (condition-case x
-;;;      ad-do-it
-;;;    (error
-;;;     ;;Restore narrow if appropriate
-;;;     (ses-command-hook)
-;;;     (signal (car x) (cdr x)))))))
+(defadvice undo-more (around ses-undo-more activate preactivate)
+  "For SES mode, allow undo outside of narrowed buffer range."
+  (if (not (eq major-mode 'ses-mode))
+      ad-do-it
+    ;;Here is some extra code for SES mode.
+    (setq ses--deferred-narrow
+         (or ses--deferred-narrow (ses-narrowed-p)))
+    (widen)
+    (condition-case x
+       ad-do-it
+      (error
+       ;;Restore narrow if appropriate
+       (ses-command-hook)
+       (signal (car x) (cdr x))))))
 
 (defun ses-begin-change ()
   "For undo, remember point before we start changing hidden stuff."
@@ -1375,7 +1360,7 @@ execute cell formulas or print functions."
        (ses-set-parameter 'ses--file-format 2)
        (message "Upgrading from SES-1 file format")))
     (or (= ses--file-format 2)
-       (error "This file needs a newer version of the SES library code."))
+       (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))
@@ -1566,7 +1551,7 @@ These are active only in the minibuffer, when entering or editing a formula:
     (setq ses--deferred-narrow 'ses-mode)
     (1value (add-hook 'post-command-hook 'ses-command-hook nil t))
     (run-with-idle-timer 0.01 nil 'ses-command-hook)
-    (run-hooks 'ses-mode-hook)))
+    (run-mode-hooks 'ses-mode-hook)))
 
 (put 'ses-mode 'mode-class 'special)
 
@@ -1626,7 +1611,7 @@ narrows the buffer now."
     (error
      (unless executing-kbd-macro
        (ding))
-     (message (error-message-string err))))
+     (message "%s" (error-message-string err))))
   nil) ;Make coverage-tester happy
 
 (defun ses-create-header-string ()
@@ -1753,7 +1738,7 @@ to are recalculated first."
        (error (setq sig hold))))
     (cond
      (sig
-      (message (error-message-string sig)))
+      (message "%s" (error-message-string sig)))
      ((consp ses--curcell)
       (message " "))
      (t
@@ -1879,20 +1864,20 @@ cell formula was unsafe and user declined confirmation."
 (defun ses-read-cell (row col newval)
   "Self-insert for initial character of cell function."
   (interactive
-   (let ((initial (this-command-keys))
-        (rowcol  (progn (ses-check-curcell) (ses-sym-rowcol ses--curcell))))
+   (let* ((initial (this-command-keys))
+          (rowcol  (progn (ses-check-curcell) (ses-sym-rowcol ses--curcell)))
+          (curval (ses-cell-formula (car rowcol) (cdr rowcol))))
      (barf-if-buffer-read-only)
-     (if (string= initial "\"")
-        (setq initial "\"\"") ;Enter a string
-       (if (string= initial "(")
-          (setq initial "()"))) ;Enter a formula list
      (list (car rowcol)
           (cdr rowcol)
-          (read-from-minibuffer (format "Cell %s: " ses--curcell)
-                                (cons initial 2)
-                                ses-mode-edit-map
-                                t ;Convert to Lisp object
-                                'ses-read-cell-history))))
+           (read-from-minibuffer
+            (format "Cell %s: " ses--curcell)
+            (cons (if (equal initial "\"") "\"\""
+                    (if (equal initial "(") "()" initial)) 2)
+            ses-mode-edit-map
+            t                         ;Convert to Lisp object
+            'ses-read-cell-history
+            (prin1-to-string curval)))))
   (when (ses-edit-cell row col newval)
     (ses-command-hook) ;Update cell widths before movement
     (dolist (x ses-after-entry-functions)
@@ -2574,7 +2559,7 @@ spot, or error signal if user requests cancel."
          colbool  (> needcols 0))
     (when (or rowbool colbool)
       ;;Need to insert.  Get confirm
-      (or (y-or-n-p (format "Yank will insert %s%s%s.  Continue "
+      (or (y-or-n-p (format "Yank will insert %s%s%s.  Continue? "
                            (if rowbool (format "%d rows" needrows) "")
                            (if (and rowbool colbool) " and " "")
                            (if colbool (format "%d columns" needcols) "")))
@@ -2915,7 +2900,7 @@ columns to include in width (default = 0)."
   (let ((printer (or (ses-col-printer col) ses--default-printer))
        (width   (ses-col-width col))
        half)
-    (or fill (setq fill ? ))
+    (or fill (setq fill ?\s))
     (or span (setq span 0))
     (setq value (ses-call-printer printer value))
     (dotimes (x span)