diff --git a/org-table.el b/org-table.el index dcf7430..23bb480 100644 --- a/org-table.el +++ b/org-table.el @@ -1386,27 +1386,29 @@ However, when FORCE is non-nil, create new columns if necessary." (if (looking-at " ") (forward-char 1))))) ;;;###autoload -(defun org-table-insert-column () - "Insert a new column into the table." - (interactive) +(defun org-table-insert-column (&optional arg) + "Insert a new column into the table. +With optional prefix ARG, perform the operation that many times." + (interactive "p") (unless (org-at-table-p) (user-error "Not at a table")) - (org-table-find-dataline) - (let* ((col (max 1 (org-table-current-column))) - (beg (org-table-begin)) - (end (copy-marker (org-table-end)))) - (org-table-save-field - (goto-char beg) - (while (< (point) end) - (unless (org-at-table-hline-p) - (org-table-goto-column col t) - (insert "| ")) - (forward-line))) - (set-marker end nil) - (org-table-align) - (when (or (not org-table-fix-formulas-confirm) - (funcall org-table-fix-formulas-confirm "Fix formulas? ")) - (org-table-fix-formulas "$" nil (1- col) 1) - (org-table-fix-formulas "$LR" nil (1- col) 1)))) + (dotimes (n (max arg 0)) + (org-table-find-dataline) + (let* ((col (max 1 (org-table-current-column))) + (beg (org-table-begin)) + (end (copy-marker (org-table-end)))) + (org-table-save-field + (goto-char beg) + (while (< (point) end) + (unless (org-at-table-hline-p) + (org-table-goto-column col t) + (insert "| ")) + (forward-line))) + (set-marker end nil) + (org-table-align) + (when (or (not org-table-fix-formulas-confirm) + (funcall org-table-fix-formulas-confirm "Fix formulas? ")) + (org-table-fix-formulas "$" nil (1- col) 1) + (org-table-fix-formulas "$LR" nil (1- col) 1))))) (defun org-table-find-dataline () "Find a data line in the current table, which is needed for column commands." @@ -1451,33 +1453,44 @@ non-nil, the one above is used." (if above min max)))))) ;;;###autoload -(defun org-table-delete-column () - "Delete a column from the table." - (interactive) +(defun org-table-delete-column (&optional arg) + "Delete a column from the table. +With optional prefix ARG, perform the operation that many times." + (interactive "p") (unless (org-at-table-p) (user-error "Not at a table")) - (org-table-find-dataline) - (org-table-check-inside-data-field) - (let ((col (org-table-current-column)) - (beg (org-table-begin)) - (end (copy-marker (org-table-end)))) - (org-table-save-field - (goto-char beg) - (while (< (point) end) - (if (org-at-table-hline-p) - nil - (org-table-goto-column col t) - (and (looking-at "|[^|\n]+|") - (replace-match "|"))) - (forward-line))) - (set-marker end nil) - (org-table-goto-column (max 1 (1- col))) - (org-table-align) - (when (or (not org-table-fix-formulas-confirm) - (funcall org-table-fix-formulas-confirm "Fix formulas? ")) - (org-table-fix-formulas - "$" (list (cons (number-to-string col) "INVALID")) col -1 col) - (org-table-fix-formulas - "$LR" (list (cons (number-to-string col) "INVALID")) col -1 col)))) + (org-table-find-dataline) + (org-table-check-inside-data-field) + (dotimes (n (min (max arg 0) + (let ((p (point)) + (c1 (org-table-current-column)) + c2) + (end-of-line) + (setq c2 (org-table-current-column)) + (goto-char p) + (- c2 c1)))) + (let ((col (org-table-current-column)) + (beg (org-table-begin)) + (end (copy-marker (org-table-end)))) + (org-table-save-field + (goto-char beg) + (while (< (point) end) + (if (org-at-table-hline-p) + nil + (org-table-goto-column col t) + (and (looking-at "|[^|\n]+|") + (replace-match "|"))) + (forward-line))) + (set-marker end nil) + (org-table-goto-column (max 1 (1- col))) + (org-table-align) + (when (or (not org-table-fix-formulas-confirm) + (funcall org-table-fix-formulas-confirm "Fix formulas? ")) + (org-table-fix-formulas + "$" (list (cons (number-to-string col) "INVALID")) col -1 col) + (org-table-fix-formulas + "$LR" (list (cons (number-to-string col) "INVALID")) col -1 col))) + (org-table-next-field)) + (org-table-previous-field)) ;;;###autoload (defun org-table-move-column-right ()