From mboxrd@z Thu Jan 1 00:00:00 1970 From: Achim Gratz Subject: [PATCH] org-table: several cleanups Date: Sun, 12 May 2013 11:11:04 +0200 Message-ID: <87li7k5zrr.fsf@Rainer.invalid> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:53156) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UbSJK-0007df-J4 for emacs-orgmode@gnu.org; Sun, 12 May 2013 05:11:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UbSJJ-00072b-3G for emacs-orgmode@gnu.org; Sun, 12 May 2013 05:11:18 -0400 Received: from plane.gmane.org ([80.91.229.3]:42075) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UbSJI-00072P-Oz for emacs-orgmode@gnu.org; Sun, 12 May 2013 05:11:17 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UbSJH-0008Vw-F4 for emacs-orgmode@gnu.org; Sun, 12 May 2013 11:11:15 +0200 Received: from pd9eb0df7.dip0.t-ipconnect.de ([217.235.13.247]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 12 May 2013 11:11:15 +0200 Received: from Stromeko by pd9eb0df7.dip0.t-ipconnect.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 12 May 2013 11:11:15 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-table-several-cleanups.patch >From 5972eaf924c726c1791fe6968e5b5b5abf053431 Mon Sep 17 00:00:00 2001 From: Achim Gratz Date: Sun, 12 May 2013 11:09:31 +0200 Subject: [PATCH] org-table: several cleanups * lisp/org.el (org-table-clean-did-remove-column), lisp/org-table.el (org-table-clean-did-remove-column): Move defvar, this dynamic variable is only used in org-table. * lisp/org-table.el (org-table-colgroup-info): Remove unused defvar for `org-table-colgroup-info'. (org-table-clean-before-export): Let-bind regular expression strings and remove unused matching group. Let-bind `remove-column-p' and use in cond statement rather than branching via if (also remove code duplication across the two branches). Remove the code associated with the unused `org-table-colgroup-info'. (orgtbl-export): Remove unused internal function. --- lisp/org-table.el | 82 ++++++++++++++++++------------------------------------- lisp/org.el | 1 - 2 files changed, 27 insertions(+), 56 deletions(-) diff --git a/lisp/org-table.el b/lisp/org-table.el index 8e461c8..fd58187 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -419,69 +419,41 @@ (defun org-table-cookie-line-p (line) (org-split-string (match-string 1 line) "[ \t]*|[ \t]*"))))))) -(defvar org-table-colgroup-info nil) ; Dynamically scoped. +(defvar org-table-clean-did-remove-column nil) ; dynamically scoped (defun org-table-clean-before-export (lines &optional maybe-quoted) "Check if the table has a marking column. If yes remove the column and the special lines." - (setq org-table-colgroup-info nil) - (if (memq nil - (mapcar - (lambda (x) (or (string-match "^[ \t]*|-" x) - (string-match - (if maybe-quoted - "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|" - "^[ \t]*| *\\([\#!$*_^ /]\\) *|") - x))) - lines)) - ;; No special marking column - (progn - (setq org-table-clean-did-remove-column nil) - (delq nil - (mapcar - (lambda (x) - (cond - ((org-table-colgroup-line-p x) - ;; This line contains colgroup info, extract it - ;; and then discard the line - (setq org-table-colgroup-info - (mapcar (lambda (x) - (cond ((member x '("<" "<")) :start) - ((member x '(">" ">")) :end) - ((member x '("<>" "<>")) :startend))) - (org-split-string x "[ \t]*|[ \t]*"))) - nil) - ((org-table-cookie-line-p x) - ;; This line contains formatting cookies, discard it - nil) - (t x))) - lines))) - ;; there is a special marking column - (setq org-table-clean-did-remove-column t) + (let* + ((special (if maybe-quoted + "^[ \t]*| *\\\\?[\#!$*_^/ ] *|" + "^[ \t]*| *[\#!$*_^/ ] *|")) + (ignore (if maybe-quoted + "^[ \t]*| *\\\\?[!$_^/] *|" + "^[ \t]*| *[!$_^/] *|")) + (remove-column-p + (not (memq nil + (mapcar + (lambda (line) + (or (string-match "^[ \t]*|-" line) + (string-match special line))) + lines))))) (delq nil (mapcar - (lambda (x) + (lambda (line) (cond - ((org-table-colgroup-line-p x) - ;; This line contains colgroup info, extract it - ;; and then discard the line - (setq org-table-colgroup-info - (mapcar (lambda (x) - (cond ((member x '("<" "<")) :start) - ((member x '(">" ">")) :end) - ((member x '("<>" "<>")) :startend))) - (cdr (org-split-string x "[ \t]*|[ \t]*")))) + ((or (org-table-colgroup-line-p line) ;; colgroup info + (org-table-cookie-line-p line) ;; formatting cookies + (and remove-column-p + (string-match ignore line))) ;; non-exportable data nil) - ((org-table-cookie-line-p x) - ;; This line contains formatting cookies, discard it - nil) - ((string-match "^[ \t]*| *\\([!_^/$]\\|\\\\\\$\\) *|" x) - ;; ignore this line - nil) - ((or (string-match "^\\([ \t]*\\)|-+\\+" x) - (string-match "^\\([ \t]*\\)|[^|]*|" x)) + ((and remove-column-p + (or (string-match "^\\([ \t]*\\)|-+\\+" line) + (string-match "^\\([ \t]*\\)|[^|]*|" line))) ;; remove the first column - (replace-match "\\1|" t nil x)))) - lines)))) + (replace-match "\\1|" t nil line)) + (t line))) + lines)) + (setq org-table-clean-did-remove-column remove-column-p))) (defconst org-table-translate-regexp (concat "\\(" "@[-0-9I$]+" "\\|" "[a-zA-Z]\\{1,2\\}\\([0-9]+\\|&\\)" "\\)") diff --git a/lisp/org.el b/lisp/org.el index b9d3894..6e4a6b4 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -4292,7 +4292,6 @@ (defun org-at-table-hline-p () (looking-at org-table-hline-regexp)) nil)) -(defvar org-table-clean-did-remove-column nil) (defun org-table-map-tables (function &optional quietly) "Apply FUNCTION to the start of all tables in the buffer." (save-excursion -- 1.8.2.2 --=-=-= Content-Type: text/plain Regards, Achim. -- +<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+ SD adaptations for Waldorf Q V3.00R3 and Q+ V3.54R2: http://Synth.Stromeko.net/Downloads.html#WaldorfSDada --=-=-=--