emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] [PATCH] org-table: several cleanups


From: Achim Gratz
Subject: [O] [PATCH] org-table: several cleanups
Date: Sun, 12 May 2013 11:11:04 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

>From 5972eaf924c726c1791fe6968e5b5b5abf053431 Mon Sep 17 00:00:00 2001
From: Achim Gratz <address@hidden>
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 '("<" "&lt;")) :start)
-                                        ((member x '(">" "&gt;")) :end)
-                                        ((member x '("<>" "&lt;&gt;")) 
: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 '("<" "&lt;")) :start)
-                                    ((member x '(">" "&gt;")) :end)
-                                    ((member x '("<>" "&lt;&gt;")) :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

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]