Function: table-delete-column

table-delete-column is an autoloaded, interactive and byte-compiled function defined in table.el.gz.

Signature

(table-delete-column N)

Documentation

Delete N column(s) of cells.

Delete N columns of cells from current column. The current column is the column contains the current cell where point is located. Each column must consists from cells of same width.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/table.el.gz
;;;###autoload
(defun table-delete-column (n)
  "Delete N column(s) of cells.
Delete N columns of cells from current column.  The current column is
the column contains the current cell where point is located.  Each
column must consists from cells of same width."
  (interactive "*p")
  (let ((orig-coord (table--get-coordinate))
	lu-coord rb-coord)
    ;; determine the area to delete while testing column width uniformity
    (while (> n 0)
      (setq n (1- n))
      (unless (table--probe-cell)
	(error "Table not found"))
      (let ((cell-list (table--vertical-cell-list 'top-to-bottom)))
	(unless
	    (and (table--uniform-list-p
                  (mapcar (lambda (cell) (car (table--get-coordinate (car cell)))) cell-list))
		 (table--uniform-list-p
                  (mapcar (lambda (cell) (car (table--get-coordinate (cdr cell)))) cell-list)))
	  (error "Cells in this column are not in uniform width"))
	(unless lu-coord
	  (setq lu-coord (table--get-coordinate (caar cell-list))))
	(setq rb-coord (table--get-coordinate (cdar (last cell-list))))
	(table--goto-coordinate (cons (1+ (car rb-coord)) (cdr orig-coord)))))
    ;; delete the area
    (delete-rectangle
     (table--goto-coordinate (cons (car lu-coord) (1- (cdr lu-coord))))
     (table--goto-coordinate (cons (1+ (car rb-coord)) (1+ (cdr rb-coord)))))
    ;; fix up the intersections
    (let ((coord (cons (1- (car lu-coord)) (cdr lu-coord)))
	  (n (1+ (- (cdr rb-coord) (cdr lu-coord)))))
      (while (> n 0)
	(table--goto-coordinate coord)
	(if (save-excursion
	      (or (and (table--goto-coordinate (cons (1- (car coord)) (cdr coord)) 'no-extension)
		       (looking-at (regexp-opt-charset
				    (string-to-list table-cell-horizontal-chars))))
		  (and (table--goto-coordinate (cons (1+ (car coord)) (cdr coord)) 'no-extension)
		       (looking-at (regexp-opt-charset
				    (string-to-list table-cell-horizontal-chars))))))
	    (progn
	      (delete-char 1)
	      (insert table-cell-intersection-char))
	  (delete-char 1)
	  (insert table-cell-vertical-char))
	(setq n (1- n))
	(setcdr coord (1+ (cdr coord)))))
    ;; goto appropriate end point
    (table--goto-coordinate (cons (car lu-coord) (cdr orig-coord)))))