* [PATCH] org-table: several cleanups
@ 2013-05-12 9:11 Achim Gratz
2013-05-12 13:55 ` Carsten Dominik
0 siblings, 1 reply; 3+ messages in thread
From: Achim Gratz @ 2013-05-12 9:11 UTC (permalink / raw)
To: emacs-orgmode
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: 0001-org-table-several-cleanups.patch --]
[-- Type: text/x-patch, Size: 4927 bytes --]
From 5972eaf924c726c1791fe6968e5b5b5abf053431 Mon Sep 17 00:00:00 2001
From: Achim Gratz <Stromeko@Stromeko.DE>
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
[-- Attachment #2: Type: text/plain, Size: 198 bytes --]
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] org-table: several cleanups
2013-05-12 9:11 [PATCH] org-table: several cleanups Achim Gratz
@ 2013-05-12 13:55 ` Carsten Dominik
2013-05-12 19:19 ` Achim Gratz
0 siblings, 1 reply; 3+ messages in thread
From: Carsten Dominik @ 2013-05-12 13:55 UTC (permalink / raw)
To: Achim Gratz; +Cc: emacs-orgmode
Hi Achim,
this looks allright for me. Please go ahead and apply when you have tested it.
- Carsten
On 12.5.2013, at 11:11, Achim Gratz <Stromeko@nexgo.de> wrote:
> From 5972eaf924c726c1791fe6968e5b5b5abf053431 Mon Sep 17 00:00:00 2001
> From: Achim Gratz <Stromeko@Stromeko.DE>
> 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
>
>
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] org-table: several cleanups
2013-05-12 13:55 ` Carsten Dominik
@ 2013-05-12 19:19 ` Achim Gratz
0 siblings, 0 replies; 3+ messages in thread
From: Achim Gratz @ 2013-05-12 19:19 UTC (permalink / raw)
To: emacs-orgmode
Carsten Dominik writes:
> this looks allright for me. Please go ahead and apply when you have
> tested it.
I've reworked it a bit. There are no automated tests for this
functionality, but I hope to have covered everything in my manual
testing. Installed on master.
Regards,
Achim.
--
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+
SD adaptation for Waldorf microQ V2.22R2:
http://Synth.Stromeko.net/Downloads.html#WaldorfSDada
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-05-12 19:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-12 9:11 [PATCH] org-table: several cleanups Achim Gratz
2013-05-12 13:55 ` Carsten Dominik
2013-05-12 19:19 ` Achim Gratz
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.