Function: table-delete-row

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

Signature

(table-delete-row N)

Documentation

Delete N row(s) of cells.

Delete N rows of cells from current row. The current row is the row contains the current cell where point is located. Each row must consists from cells of same height.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/table.el.gz
;;;###autoload
(defun table-delete-row (n)
  "Delete N row(s) of cells.
Delete N rows of cells from current row.  The current row is the row
contains the current cell where point is located.  Each row must
consists from cells of same height."
  (interactive "*p")
  (let ((orig-coord (table--get-coordinate))
	(bt-coord (table--get-coordinate (cdr (table--vertical-cell-list nil 'first-only))))
	lu-coord rb-coord rect)
    ;; determine the area to delete while testing row height uniformity
    (while (> n 0)
      (setq n (1- n))
      (unless (table--probe-cell)
	(error "Table not found"))
      (let ((cell-list (table--horizontal-cell-list 'left-to-right)))
	(unless
	    (and (table--uniform-list-p
		  (mapcar (lambda (cell) (cdr (table--get-coordinate (car cell)))) cell-list))
		 (table--uniform-list-p
		  (mapcar (lambda (cell) (cdr (table--get-coordinate (cdr cell)))) cell-list)))
	  (error "Cells in this row are not in uniform height"))
	(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 (car orig-coord) (+ 2 (cdr rb-coord))))))
    ;; copy the remaining area (below the deleting area)
    (setq rect (extract-rectangle
		(table--goto-coordinate (cons (1- (car lu-coord)) (1+ (cdr rb-coord))))
		(table--goto-coordinate (cons (1+ (car rb-coord)) (1+ (cdr bt-coord))))))
    ;; delete the deleting area and below together
    (delete-rectangle
     (table--goto-coordinate (cons (1- (car lu-coord)) (1- (cdr lu-coord))))
     (table--goto-coordinate (cons (1+ (car rb-coord)) (1+ (cdr bt-coord)))))
    (table--goto-coordinate (cons (1- (car lu-coord)) (1- (cdr lu-coord))))
    ;; insert the remaining area while appending blank lines below it
    (table--insert-rectangle
     (append rect (make-list (+ 2 (- (cdr rb-coord) (cdr lu-coord)))
			     (make-string (+ 2 (- (car rb-coord) (car lu-coord))) ?\s))))
    ;; remove the appended blank lines below the table if they are unnecessary
    (table--goto-coordinate (cons 0 (- (cdr bt-coord) (- (cdr rb-coord) (cdr lu-coord)))))
    (table--remove-blank-lines (+ 2 (- (cdr rb-coord) (cdr lu-coord))))
    ;; fix up intersections
    (let ((coord (cons (car lu-coord) (1- (cdr lu-coord))))
	  (n (1+ (- (car rb-coord) (car lu-coord)))))
      (while (> n 0)
	(table--goto-coordinate coord)
	(if (save-excursion
	      (or (and (table--goto-coordinate (cons (car coord) (1- (cdr coord))) 'no-extension)
		       (looking-at (regexp-quote (char-to-string table-cell-vertical-char))))
		  (and (table--goto-coordinate (cons (car coord) (1+ (cdr coord))) 'no-extension)
		       (looking-at (regexp-quote (char-to-string table-cell-vertical-char))))))
	    (progn
	      (delete-char 1)
	      (insert table-cell-intersection-char))
	  (delete-char 1)
	  (insert (string-to-char table-cell-horizontal-chars)))
	(setq n (1- n))
	(setcar coord (1+ (car coord)))))
    ;; goto appropriate end point
    (table--goto-coordinate (cons (car orig-coord) (cdr lu-coord)))))