Function: ses-delete-column

ses-delete-column is an interactive and byte-compiled function defined in ses.el.gz.

Signature

(ses-delete-column COUNT)

Documentation

Delete the current column.

With prefix, deletes COUNT columns starting from the current one.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/ses.el.gz
(defun ses-delete-column (count)
  "Delete the current column.
With prefix, deletes COUNT columns starting from the current one."
  (interactive "*p")
  (ses-check-curcell)
  (or (> count 0) (signal 'args-out-of-range nil))
  (let ((inhibit-quit t)
	(inhibit-read-only t)
	(rowcol  (ses-sym-rowcol ses--curcell))
	(width 0)
	col origrow has-skip)
    (setq origrow (car rowcol)
	  col     (cdr rowcol)
	  count   (min count (- ses--numcols col)))
    (if (= count ses--numcols)
	(error "Can't delete all columns!"))
    ;;Determine width of column(s) being deleted
    (dotimes (x count)
      (setq width (+ width (ses-col-width (+ col x)) 1)))
    (ses-begin-change)
    (ses-set-parameter 'ses--numcols (- ses--numcols count))
    (ses-adjust-print-width col (- width))
    ;; Prepare collecting named cells in the deleted columns, in order
    ;; to clean the symbols out of the named cell hash map, once the
    ;; deletion is complete
    (unless (null ses--in-killing-named-cell-list)
      (warn "Internal error, `ses--in-killing-named-cell-list' should be nil, but is equal to %S"
      ses--in-killing-named-cell-list)
      (setq ses--in-killing-named-cell-list nil))
    (dotimes-with-progress-reporter (row ses--numrows) "Deleting column..."
      ;;Delete lines from cell data area
      (ses-goto-data row col)
      (ses-delete-line count)
      ;; Collect named cells in the deleted columns within this row
      (dotimes (ncol count)
	(let ((sym (ses-cell-symbol row (+ col ncol))))
	  (and (eq (get sym 'ses-cell) :ses-named)
	       (push sym ses--in-killing-named-cell-list))))
      ;;Delete cells.  Check if deletion area begins or ends with a skip.
      (if (or (eq (ses-cell-value row col) '*skip*)
	      (and (< col ses--numcols)
		   (eq (ses-cell-value row (+ col count)) '*skip*)))
	  (setq has-skip t))
      (ses-aset-with-undo ses--cells row
			  (ses-vector-delete (aref ses--cells row) col count)))
    ;;Update globals
    (ses-set-parameter 'ses--col-widths
		       (ses-vector-delete ses--col-widths col count))
    (ses-set-parameter 'ses--col-printers
		       (ses-vector-delete ses--col-printers col count))
    (ses-reset-header-string)
    ;;Relocate variables and formulas
    (ses-relocate-all 0 col 0 (- count))
    (ses-destroy-cell-variable-range 0            (1- ses--numrows)
				     ses--numcols (+ ses--numcols count -1))
    (if has-skip
	(ses-reprint-all t)
      (ses-setup))
    (if (>= col ses--numcols)
	(setq col (1- col)))
    (ses-goto-print origrow col)))