From: Boruch Baum <boruch_baum@gmx.com>
To: 44133@debbugs.gnu.org
Subject: bug#44133: org-table insert/delete multiple columns [PATCH INCLUDED]
Date: Thu, 22 Oct 2020 03:27:09 -0400 [thread overview]
Message-ID: <20201022072709.fuf2rcpxpmthlco7@E15-2016.optimum.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 435 bytes --]
Currently, functions org-table-insert-column and
org-table-delete-column only perform the operation a single time. The
attached patch adds a feature to allow insertion and deletion of
multiple columns by specifying a numeric prefix argument.
A nice follow-up would be for someone else to add operations on a range,
but I'm not offering that here.
--
hkp://keys.gnupg.net
CA45 09B5 5351 7C11 A9D1 7286 0036 9E45 1595 8BC0
[-- Attachment #2: org-table-mult-ops.patch --]
[-- Type: text/x-diff, Size: 4789 bytes --]
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 ()
next reply other threads:[~2020-10-22 7:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-22 7:27 Boruch Baum [this message]
2021-05-13 10:56 ` bug#44133: org-table insert/delete multiple columns [PATCH INCLUDED] Lars Ingebrigtsen
2021-05-14 5:16 ` Bastien
2021-07-21 12:09 ` Lars Ingebrigtsen
2021-10-11 12:53 ` Stefan Kangas
2021-10-13 7:57 ` Bastien Guerry
2021-11-12 8:00 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201022072709.fuf2rcpxpmthlco7@E15-2016.optimum.net \
--to=boruch_baum@gmx.com \
--cc=44133@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.