changeset 95021:5c3aee83b8fa

* ses.el (ses-goto-print): Use move-to-column rather than forward-char. (ses-print-cell): Use string-width, truncate-string-to-width, delete-region rather than length, substring, delete-char. (ses-setup): Set inhibit-point-motion-hooks to t. Calculate position by actually moving point rather than just using unibyte character length. (ses-mode): Set indent-tabs-mode to nil. (ses-center): Use string-width rather than length.
author Jonathan Yavner <jyavner@member.fsf.org>
date Thu, 15 May 2008 19:24:27 +0000
parents 4da572dc4992
children ab3669590909
files lisp/ses.el
diffstat 1 files changed, 31 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ses.el	Thu May 15 17:38:50 2008 +0000
+++ b/lisp/ses.el	Thu May 15 19:24:27 2008 +0000
@@ -726,11 +726,18 @@
 ;;ses-goto-print is called during a recursive ses-print-cell).
 (defun ses-goto-print (row col)
   "Move point to print area for cell (ROW,COL)."
-  (let ((inhibit-point-motion-hooks t))
+  (let ((inhibit-point-motion-hooks t)
+	(n 0))
     (goto-char (point-min))
     (forward-line row)
+    ;; calculate column position
     (dotimes (c col)
-      (forward-char (1+ (ses-col-width c))))))
+      (setq n (+ n (ses-col-width c) 1)))
+    ;; move to the position
+    (and (> n (move-to-column n))
+	 (eolp)
+	 ;; move point to the bol of next line (for TAB at the last cell)
+	 (forward-char))))
 
 (defun ses-set-curcell ()
   "Sets `ses--curcell' to the current cell symbol, or a cons (BEG,END) for a
@@ -806,7 +813,7 @@
 	    (setq sig ses-call-printer-return))))
       ;;Adjust print width to match column width
       (let ((width (ses-col-width col))
-	    (len   (length text)))
+	    (len   (string-width text)))
 	(cond
 	 ((< len width)
 	  ;;Fill field to length with spaces
@@ -834,7 +841,7 @@
 	      (setq sig `(error "Too wide" ,text))
 	      (cond
 	       ((stringp value)
-		(setq text (substring text 0 maxwidth)))
+		(setq text (truncate-string-to-width text maxwidth 0 ?\s)))
 	       ((and (numberp value)
 		     (string-match "\\.[0-9]+" text)
 		     (>= 0 (setq width
@@ -855,7 +862,11 @@
       ;;Install the printed result.  This is not interruptible.
       (let ((inhibit-read-only t)
 	    (inhibit-quit      t))
-	(delete-char (1+ (length text)))
+	(let ((inhibit-point-motion-hooks t))
+	  (delete-region (point) (progn
+				   (move-to-column (+ (current-column)
+						      (string-width text)))
+				   (1+ (point)))))
 	;;We use concat instead of inserting separate strings in order to
 	;;reduce the number of cells in the undo list.
 	(setq x (concat text (if (< maxcol ses--numcols) " " "\n")))
@@ -1443,6 +1454,7 @@
   (interactive)
   (let ((end (point-min))
 	(inhibit-read-only t)
+	(inhibit-point-motion-hooks t)
 	(was-modified (buffer-modified-p))
 	pos sym)
     (ses-goto-data 0 0) ;;Include marker between print-area and data-area
@@ -1466,7 +1478,14 @@
 		    (eq (ses-cell-value row (1+ col)) '*skip*))
 	  (setq end (+ end (ses-col-width col) 1)
 		col (1+ col)))
-	(setq end (+ end (ses-col-width col) 1))
+	(setq end (save-excursion
+		    (goto-char pos)
+		    (move-to-column (+ (current-column) (- end pos)
+				       (ses-col-width col)))
+		    (if (eolp)
+			(+ end (ses-col-width col) 1)
+		      (forward-char)
+		      (point))))
 	(put-text-property pos end 'intangible sym)))
     ;;Adding these properties did not actually alter the text
     (unless was-modified
@@ -1519,7 +1538,10 @@
 	  ;;SES deliberately puts lots of trailing whitespace in its buffer
 	  show-trailing-whitespace nil
 	  ;;Cell ranges do not work reasonably without this
-	  transient-mark-mode    t)
+	  transient-mark-mode    t
+	  ;;not to use tab characters for safe
+	  ;;(tabs may do bad for column calculation)
+	  indent-tabs-mode	 nil)
     (1value (add-hook 'change-major-mode-hook 'ses-cleanup nil t))
     (1value (add-hook 'before-revert-hook 'ses-cleanup nil t))
     (setq ses--curcell         nil
@@ -2938,7 +2960,8 @@
     (setq value (ses-call-printer printer value))
     (dotimes (x span)
       (setq width (+ width 1 (ses-col-width (+ col span (- x))))))
-    (setq width (- width (length value)))
+    ;; set column width
+    (setq width (- width (string-width value)))
     (if (<= width 0)
 	value ;Too large for field, anyway
       (setq half (make-string (/ width 2) fill))