From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Boruch Baum Newsgroups: gmane.emacs.bugs Subject: bug#44133: org-table insert/delete multiple columns [PATCH INCLUDED] Date: Thu, 22 Oct 2020 03:27:09 -0400 Message-ID: <20201022072709.fuf2rcpxpmthlco7@E15-2016.optimum.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="rbxgyjtq6cxxflc2" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10230"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: NeoMutt/20180716 To: 44133@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 22 09:28:37 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kVV1Z-0002Zf-BF for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 22 Oct 2020 09:28:37 +0200 Original-Received: from localhost ([::1]:33544 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVV1X-0001xk-H2 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 22 Oct 2020 03:28:35 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60826) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVV11-0001wL-1p for bug-gnu-emacs@gnu.org; Thu, 22 Oct 2020 03:28:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:39753) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kVV10-0001ow-OV for bug-gnu-emacs@gnu.org; Thu, 22 Oct 2020 03:28:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kVV10-0004gG-LE for bug-gnu-emacs@gnu.org; Thu, 22 Oct 2020 03:28:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Boruch Baum Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 22 Oct 2020 07:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 44133 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: Emacs Bug Reporting Original-Received: via spool by submit@debbugs.gnu.org id=B.160335164217931 (code B ref -1); Thu, 22 Oct 2020 07:28:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 22 Oct 2020 07:27:22 +0000 Original-Received: from localhost ([127.0.0.1]:51299 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kVV0M-0004f9-Gk for submit@debbugs.gnu.org; Thu, 22 Oct 2020 03:27:22 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:50386) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kVV0K-0004f1-IC for submit@debbugs.gnu.org; Thu, 22 Oct 2020 03:27:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVV0K-0001pf-BU for bug-gnu-emacs@gnu.org; Thu, 22 Oct 2020 03:27:20 -0400 Original-Received: from mout.gmx.net ([212.227.15.15]:37581) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVV0I-0001ZC-2Y for bug-gnu-emacs@gnu.org; Thu, 22 Oct 2020 03:27:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1603351632; bh=hdkbSBLuoAW3bdK4/v25n0G4Ef9XIgAjAQOHG6omfJ0=; h=X-UI-Sender-Class:Date:From:To:Subject; b=V1lHLGF7eP1NhsUKR8+t3MqNo71FKrwGRdXzJodNociOw7xRKN/L/w+AIaPj1JLff 4U1yFHVOrmGjXsOzCGiAnvo1VxpApuu8nHpt88WTh3uhtYlYz62ZIQcma3q7yXQ8Ew nk7AX2LQSXdHA7hnKCmFpWw0B28OeslRnCBUyorc= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from E15-2016.optimum.net ([72.89.170.172]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1N49h5-1kMb8T1FmD-0101TK for ; Thu, 22 Oct 2020 09:27:12 +0200 Content-Disposition: inline X-Provags-ID: V03:K1:WPS69VXHe2oYqiKQDHpFnbt78HLWUSm6+F5fbAodI4Hz0Fp5ood Z9xXdGTVp0li4+wAdffH2cu5Zw+dHiVGWJzVHXE3T8GL0y4vhH5+L2t7C9or3Q0K9mTuueG SlvdBkNzJqMWdei+vRHovobfMEc6s2uWoT/dCvqyozFFRboWeWO3vVLQadG+7BRakF02u28 PNYm8WAf0CzIARAJLearg== X-UI-Out-Filterresults: notjunk:1;V03:K0:t+ViS91mLeg=:szvdbGX6bDGojU7WjPeYom cjV6VYvgeLG9kPi4jnptrmdrIBqwLAKB459mV3YoQiWg/bB6pJY2Dx93Xrv4378kPjH9EE9Ov zU+XgWDlDzLZM3wzg9UmLVRgwRfgYVKglVoavzhvNBpdp2lMSTthc31myvukxlMd49+/MUByM D1X5346FZQgI2Nm40ApB0VdDUdVt0JUfHjptO6lEVPPqF/vKp3v4B+AiAN3lSoaQsJhBuFyMb 9BFomg76obfK3+uoIh2tKKoegIDydBl0JAvufzTe0COhoU03eT+IOjGev5lY+iJCESMAfLQtR PlW7rYWl2lY0kA3O8ZFa/8eNa7WCwkd/mFv2MyI9q0y2veF7ahK1EK5zeEhl7m6ft4+NA5WoY lVWdbVjbOjCThFq6dvIJ9HxSA2+9DMEbPCb3D/OCyKHo4V71UuMG/OZY1duregWCP6+nidu5r bZjSK/aX4+ZDZvK1BZgWRe9L57A5/q80WliNFj0PjsEGVOVGw7aeK5edD4KP6xu3JBLHHh/uj RoOd/lmvrYu3xai/1e5ScMwFZkYziu27qhzqxSEbvrfK0kLmDQZ8v9+yM5Ic8NwOxZkV5Yz1n /y5/yIP80sGqDa7y808BUlEtpADqXxzdts7iEIjtXpvqx+ILro8b/b36UsiH+urqMzSk6H4tv 1GssyUeJw7F2qLSPj7VVN1W9eQYJsWdCBcEJ74LeTXA2w2s5TUteFs8fxfRJXqNfAr5dVERZc bWoHZvjlIqWFUcwAuzIHIsv+3rMjNOsvRpMWODQ5tM0QuzmDL0pSe3hQ1Ht9SDHZ3NAXRHYZ Received-SPF: pass client-ip=212.227.15.15; envelope-from=boruch_baum@gmx.com; helo=mout.gmx.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 03:27:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:191228 Archived-At: --rbxgyjtq6cxxflc2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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. =2D- hkp://keys.gnupg.net CA45 09B5 5351 7C11 A9D1 7286 0036 9E45 1595 8BC0 --rbxgyjtq6cxxflc2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="org-table-mult-ops.patch" Content-Transfer-Encoding: quoted-printable diff --git a/org-table.el b/org-table.el index dcf7430..23bb480 100644 =2D-- 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 comm= ands." @@ -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 co= l))) + (org-table-next-field)) + (org-table-previous-field)) ;;;###autoload (defun org-table-move-column-right () --rbxgyjtq6cxxflc2--