Function: ses-yank-tsf

ses-yank-tsf is a byte-compiled function defined in ses.el.gz.

Signature

(ses-yank-tsf TEXT ARG)

Documentation

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.

Source Code

;; Defined in /usr/src/emacs/lisp/ses.el.gz
(defun ses-yank-tsf (text arg)
  "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))
	  (= (match-end 0) (length text)))
      ;;Not TSF format
      nil
    (if (/= (aref text (1- (length text))) ?\n)
	(setq text (concat text "\n")))
    (let ((pos      -1)
	  (spots    (list -1))
	  (cols     0)
	  (needrows 0)
	  needcols rowcol)
      ;;Find all the tabs and newlines
      (while (setq pos (string-match "[\t\n]" text (1+ pos)))
	(push pos spots)
	(setq cols (1+ cols))
	(when (eq (aref text pos) ?\n)
	  (if (not needcols)
	      (setq needcols cols)
	    (or (= needcols cols)
		(error "Inconsistent row lengths")))
	  (setq cols     0
		needrows (1+ needrows))))
      ;;Insert the formulas
      (setq rowcol (ses-yank-resize needrows needcols))
      (dotimes (row needrows)
	(dotimes (col needcols)
	  (ses-yank-one (cons (+ (car rowcol) needrows (- row) -1)
			      (+ (cdr rowcol) needcols (- col) -1))
			text (1+ (cadr spots)) (car spots) arg)
	  (setq spots (cdr spots))))
      (ses-goto-print (+ (car rowcol) needrows -1)
		      (+ (cdr rowcol) needcols -1))
      t)))