]> code.delx.au - gnu-emacs/commitdiff
Changes suggested by Stefan Monnier to truncate decimal places if print format too...
authorJonathan Yavner <jyavner@member.fsf.org>
Fri, 30 Jan 2004 08:02:57 +0000 (08:02 +0000)
committerJonathan Yavner <jyavner@member.fsf.org>
Fri, 30 Jan 2004 08:02:57 +0000 (08:02 +0000)
lisp/ChangeLog
lisp/ses.el

index f76f875d5e8ee0279d3824b33bacd7ff45f0f784..d8f7fe3b08f23a3c2147202a1f57ef05f2e6e262 100644 (file)
@@ -1,3 +1,9 @@
+2004-01-30  Jonathan Yavner  <jyavner@member.fsf.org>
+
+       * ses.el (ses-print-cell): If print format too wide for column
+       width, truncate decimal places if that helps to avoid "#####" fill.
+       * ses.el (ses-initial-column-width): Revert previous change.
+
 2004-01-29  Stefan Monnier  <monnier@iro.umontreal.ca>
 
        * jit-lock.el (jit-lock-context-time, jit-lock-context-timer): New var.
index b50a441d261e1618444b28ef0d247daba2812f04..a56b1b5c87a56e3dcdac8ba95e9b00f9a625df39 100644 (file)
@@ -1,6 +1,6 @@
 ;;;; ses.el -- Simple Emacs Spreadsheet
 
-;; Copyright (C) 2002 Free Software Foundation, Inc.
+;; Copyright (C) 2002,03,04  Free Software Foundation, Inc.
 
 ;; Author: Jonathan Yavner <jyavner@member.fsf.org>
 ;; Maintainer: Jonathan Yavner <jyavner@member.fsf.org>
@@ -52,7 +52,7 @@
   :group 'ses
   :type '(cons (integer :tag "numrows") (integer :tag "numcols")))
 
-(defcustom ses-initial-column-width 14
+(defcustom ses-initial-column-width 7
   "Initial width of columns in a new spreadsheet."
   :group 'ses
   :type '(integer :match (lambda (widget value) (> value 0))))
@@ -720,11 +720,23 @@ preceding cell has spilled over."
                ;;Fill to complete width of all the fields spanned
                (setq text (concat text (make-string (- maxwidth len) ? )))
              ;;Not enough room to end of line or next non-nil field.  Truncate
-             ;;if string; otherwise fill with error indicator
+             ;;if string or decimal; otherwise fill with error indicator
              (setq sig `(error "Too wide" ,text))
-             (if (stringp value)
-                 (setq text (substring text 0 maxwidth))
-               (setq text (make-string maxwidth ?#))))))))
+             (cond
+              ((stringp value)
+               (setq text (substring text 0 maxwidth)))
+              ((and (numberp value)
+                    (string-match "\\.[0-9]+" text)
+                    (>= 0 (setq width
+                                (- len maxwidth
+                                   (- (match-end 0) (match-beginning 0))))))
+               ;; Turn 6.6666666666e+49 into 6.66e+49.  Rounding is too hard!
+               (setq text (concat (substring text
+                                             0
+                                             (- (match-beginning 0) width))
+                                  (substring text (match-end 0)))))
+              (t
+               (setq text (make-string maxwidth ?#)))))))))
       ;;Substitute question marks for tabs and newlines.  Newlines are
       ;;used as row-separators; tabs could confuse the reimport logic.
       (setq text (replace-regexp-in-string "[\t\n]" "?" text))