Function: org-table-create

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

Signature

(org-table-create &optional SIZE)

Documentation

Query for a size and insert a table skeleton.

SIZE is a string Columns x Rows like for example "3x2".

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-table.el.gz
;;;###autoload
(defun org-table-create (&optional size)
  "Query for a size and insert a table skeleton.
SIZE is a string Columns x Rows like for example \"3x2\"."
  (interactive "P")
  (unless size
    (setq size (read-string
		(concat "Table size Columns x Rows [e.g. "
			org-table-default-size "]: ")
		"" nil org-table-default-size)))

  (let* ((pos (point))
	 (indent (make-string (current-column) ?\ ))
	 (split (org-split-string size " *x *"))
	 (rows (string-to-number (nth 1 split)))
	 (columns (string-to-number (car split)))
	 (line (concat (apply 'concat indent "|" (make-list columns "  |"))
		       "\n")))
    (if (string-match "^[ \t]*$" (buffer-substring-no-properties
				  (point-at-bol) (point)))
	(beginning-of-line 1)
      (newline))
    ;; (mapcar (lambda (x) (insert line)) (make-list rows t))
    (dotimes (_ rows) (insert line))
    (goto-char pos)
    (when (> rows 1)
      ;; Insert a hline after the first row.
      (end-of-line 1)
      (insert "\n|-")
      (goto-char pos))
    (org-table-align)))