unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#44133: org-table insert/delete multiple columns [PATCH INCLUDED]
@ 2020-10-22  7:27 Boruch Baum
  2021-05-13 10:56 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 7+ messages in thread
From: Boruch Baum @ 2020-10-22  7:27 UTC (permalink / raw)
  To: 44133

[-- 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 ()

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-11-12  8:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-22  7:27 bug#44133: org-table insert/delete multiple columns [PATCH INCLUDED] Boruch Baum
2021-05-13 10:56 ` 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

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).