Function: table-widen-cell

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

Signature

(table-widen-cell N &optional NO-COPY NO-UPDATE)

Documentation

Widen the current cell by N columns and expand the cell horizontally.

Some other cells in the same table are widen as well to keep the table's rectangle structure.

View in manual

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/table.el.gz
;;;###autoload
(defun table-widen-cell (n &optional no-copy no-update)
  "Widen the current cell by N columns and expand the cell horizontally.
Some other cells in the same table are widen as well to keep the
table's rectangle structure."
  (interactive "*p")
  (if (< n 0) (setq n 1))
  (let* ((coord-list (table--cell-list-to-coord-list (table--vertical-cell-list)))
	 (below-list nil)
	 (this-list coord-list)
	 (above-list (cdr coord-list)))
    (save-excursion
      ;; push back the affected area above and below this table
      (table--horizontally-shift-above-and-below n (reverse coord-list))
      ;; now widen vertically for each cell
      (while this-list
	(let* ((below (prog1 (car below-list) (setq below-list (if below-list (cdr below-list) coord-list))))
	       (this (prog1 (car this-list) (setq this-list (cdr this-list))))
	       (above (prog1 (car above-list) (setq above-list (cdr above-list))))
	       (beg (table--goto-coordinate
		     (cons (car (cdr this))
			   (if (or (null above) (<= (car (cdr this)) (car (cdr above))))
			       (1- (cdr (car this)))
			     (cdr (car this))))))
	       (end (table--goto-coordinate
		     (cons (1+ (car (cdr this)))
			   (if (or (null below) (< (car (cdr this)) (car (cdr below))))
			       (1+ (cdr (cdr this)))
			     (cdr (cdr this))))))
	       (tmp (extract-rectangle (1- beg) end))
	       (border (format "[%s%c]\\%c"
			       table-cell-horizontal-chars
			       table-cell-intersection-char
			       table-cell-intersection-char))
	       (blank (table--cell-blank-str))
	       rectangle)
	  ;; create a single wide vertical bar of empty cell fragment
	  (while tmp
;        (message "tmp is %s" tmp)
	    (setq rectangle (cons
                         (if (string-match border (car tmp))
				      (substring (car tmp) 0 1)
				    blank)
				  rectangle))
;        (message "rectangle is %s" rectangle)
	    (setq tmp (cdr tmp)))
	  (setq rectangle (nreverse rectangle))
	  ;; untabify the area right of the bar that is about to be inserted
	  (let ((coord (table--get-coordinate beg))
		(i 0)
		(len (length rectangle)))
	    (while (< i len)
	      (if (table--goto-coordinate coord 'no-extension)
		  (table--untabify-line (point)))
	      (setcdr coord (1+ (cdr coord)))
	      (setq i (1+ i))))
	  ;; insert the bar n times
	  (goto-char beg)
	  (let ((i 0))
	    (while (< i n)
	      (save-excursion
		(table--insert-rectangle rectangle))
	      (setq i (1+ i)))))))
    (table-recognize-cell 'force no-copy)
    (unless no-update
      (table--update-cell-widened))))