comparison lisp/ses.el @ 53758:c503ef8bb300

Changes suggested by Stefan Monnier to truncate decimal places if print format too large for column width.
author Jonathan Yavner <jyavner@member.fsf.org>
date Fri, 30 Jan 2004 08:01:43 +0000
parents 6f8197877736
children e647f66db84b
comparison
equal deleted inserted replaced
53757:970795582ae9 53758:c503ef8bb300
1 ;;;; ses.el -- Simple Emacs Spreadsheet 1 ;;;; ses.el -- Simple Emacs Spreadsheet
2 2
3 ;; Copyright (C) 2002 Free Software Foundation, Inc. 3 ;; Copyright (C) 2002,03,04 Free Software Foundation, Inc.
4 4
5 ;; Author: Jonathan Yavner <jyavner@member.fsf.org> 5 ;; Author: Jonathan Yavner <jyavner@member.fsf.org>
6 ;; Maintainer: Jonathan Yavner <jyavner@member.fsf.org> 6 ;; Maintainer: Jonathan Yavner <jyavner@member.fsf.org>
7 ;; Keywords: spreadsheet 7 ;; Keywords: spreadsheet
8 8
50 (defcustom ses-initial-size '(1 . 1) 50 (defcustom ses-initial-size '(1 . 1)
51 "Initial size of a new spreadsheet, as a cons (NUMROWS . NUMCOLS)." 51 "Initial size of a new spreadsheet, as a cons (NUMROWS . NUMCOLS)."
52 :group 'ses 52 :group 'ses
53 :type '(cons (integer :tag "numrows") (integer :tag "numcols"))) 53 :type '(cons (integer :tag "numrows") (integer :tag "numcols")))
54 54
55 (defcustom ses-initial-column-width 14 55 (defcustom ses-initial-column-width 7
56 "Initial width of columns in a new spreadsheet." 56 "Initial width of columns in a new spreadsheet."
57 :group 'ses 57 :group 'ses
58 :type '(integer :match (lambda (widget value) (> value 0)))) 58 :type '(integer :match (lambda (widget value) (> value 0))))
59 59
60 (defcustom ses-initial-default-printer "%.7g" 60 (defcustom ses-initial-default-printer "%.7g"
718 maxcol (1+ maxcol))) 718 maxcol (1+ maxcol)))
719 (if (<= len maxwidth) 719 (if (<= len maxwidth)
720 ;;Fill to complete width of all the fields spanned 720 ;;Fill to complete width of all the fields spanned
721 (setq text (concat text (make-string (- maxwidth len) ? ))) 721 (setq text (concat text (make-string (- maxwidth len) ? )))
722 ;;Not enough room to end of line or next non-nil field. Truncate 722 ;;Not enough room to end of line or next non-nil field. Truncate
723 ;;if string; otherwise fill with error indicator 723 ;;if string or decimal; otherwise fill with error indicator
724 (setq sig `(error "Too wide" ,text)) 724 (setq sig `(error "Too wide" ,text))
725 (if (stringp value) 725 (cond
726 (setq text (substring text 0 maxwidth)) 726 ((stringp value)
727 (setq text (make-string maxwidth ?#)))))))) 727 (setq text (substring text 0 maxwidth)))
728 ((and (numberp value)
729 (string-match "\\.[0-9]+" text)
730 (>= 0 (setq width
731 (- len maxwidth
732 (- (match-end 0) (match-beginning 0))))))
733 ;; Turn 6.6666666666e+49 into 6.66e+49. Rounding is too hard!
734 (setq text (concat (substring text
735 0
736 (- (match-beginning 0) width))
737 (substring text (match-end 0)))))
738 (t
739 (setq text (make-string maxwidth ?#)))))))))
728 ;;Substitute question marks for tabs and newlines. Newlines are 740 ;;Substitute question marks for tabs and newlines. Newlines are
729 ;;used as row-separators; tabs could confuse the reimport logic. 741 ;;used as row-separators; tabs could confuse the reimport logic.
730 (setq text (replace-regexp-in-string "[\t\n]" "?" text)) 742 (setq text (replace-regexp-in-string "[\t\n]" "?" text))
731 (ses-goto-print row col) 743 (ses-goto-print row col)
732 (setq startpos (point)) 744 (setq startpos (point))