emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] [org-table] user-chosen separator in org-table-convert-region
@ 2013-09-03 10:20 francois
  2013-09-24 13:08 ` Carsten Dominik
  2013-09-29 10:28 ` Carsten Dominik
  0 siblings, 2 replies; 5+ messages in thread
From: francois @ 2013-09-03 10:20 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

I made this patch to make easier conversion to
org-table from csv-like text with arbitrary separator.

---
  lisp/org-table.el |    2 ++
  1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/lisp/org-table.el b/lisp/org-table.el
index c7e7eb8..c8c2462 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -575,6 +575,8 @@ nil      When nil, the command tries to be smart 
and figure out the
  		 (if (< separator 1)
  		     (user-error "Number of spaces in separator must be >= 1")
  		   (format "^ *\\| *\t *\\| \\{%d,\\}" separator)))
+		((stringp separator)
+		   (format "^ *\\|%s" separator))
  		(t (error "This should not happen"))))
        (while (re-search-forward re end t)
  	(replace-match "| " t t)))
-- 
1.7.9

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

* [PATCH] [org-table] user-chosen separator in org-table-convert-region
@ 2013-09-03 14:25 francois
  0 siblings, 0 replies; 5+ messages in thread
From: francois @ 2013-09-03 14:25 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

I made this patch to make easier conversion to
org-table from csv-like text with arbitrary separator.

---
  lisp/org-table.el |    2 ++
  1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/lisp/org-table.el b/lisp/org-table.el
index c7e7eb8..c8c2462 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -575,6 +575,8 @@ nil      When nil, the command tries to be smart 
and figure out the
  		 (if (< separator 1)
  		     (user-error "Number of spaces in separator must be >= 1")
  		   (format "^ *\\| *\t *\\| \\{%d,\\}" separator)))
+		((stringp separator)
+		   (format "^ *\\|%s" separator))
  		(t (error "This should not happen"))))
        (while (re-search-forward re end t)
  	(replace-match "| " t t)))
-- 
1.7.9

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

* Re: [PATCH] [org-table] user-chosen separator in org-table-convert-region
  2013-09-03 10:20 [PATCH] [org-table] user-chosen separator in org-table-convert-region francois
@ 2013-09-24 13:08 ` Carsten Dominik
  2013-09-27  9:39   ` francois
  2013-09-29 10:28 ` Carsten Dominik
  1 sibling, 1 reply; 5+ messages in thread
From: Carsten Dominik @ 2013-09-24 13:08 UTC (permalink / raw)
  To: francois; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1007 bytes --]

Hi Francois,

could you please explain what this does and show an example on how this should be used?

Thank you.

- Carsten

On 3.9.2013, at 12:20, francois@avalenn.eu wrote:

> Hello,
> 
> I made this patch to make easier conversion to
> org-table from csv-like text with arbitrary separator.
> 
> ---
> lisp/org-table.el |    2 ++
> 1 files changed, 2 insertions(+), 0 deletions(-)
> 
> diff --git a/lisp/org-table.el b/lisp/org-table.el
> index c7e7eb8..c8c2462 100644
> --- a/lisp/org-table.el
> +++ b/lisp/org-table.el
> @@ -575,6 +575,8 @@ nil      When nil, the command tries to be smart and figure out the
> 		 (if (< separator 1)
> 		     (user-error "Number of spaces in separator must be >= 1")
> 		   (format "^ *\\| *\t *\\| \\{%d,\\}" separator)))
> +		((stringp separator)
> +		   (format "^ *\\|%s" separator))
> 		(t (error "This should not happen"))))
>       (while (re-search-forward re end t)
> 	(replace-match "| " t t)))
> -- 
> 1.7.9
> 
> 
> 


[-- Attachment #2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

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

* Re: [PATCH] [org-table] user-chosen separator in org-table-convert-region
  2013-09-24 13:08 ` Carsten Dominik
@ 2013-09-27  9:39   ` francois
  0 siblings, 0 replies; 5+ messages in thread
From: francois @ 2013-09-27  9:39 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: emacs-orgmode

On Tue, 24 Sep 2013 15:08:10 +0200, Carsten Dominik 
<carsten.dominik@gmail.com> wrote:
> could you please explain what this does and show an example on how 
> this should be used?

It adds the possibility of a string argument used as a regexp for
arbitrary field separator.

It can be used as following :
   (defun my-fjd/convert (beg0 end0 arg)
     (interactive "r\nsSeparator: ")
     (let* ((beg (min beg0 end0))
            (end (max beg0 end0))
            re)
       (org-table-convert-region beg0 end0 arg)
       ))
   (global-set-key (kbd "<f5>T") 'my-fjd/convert)

It permits for example to convert in place csv-like table with
semi-colon separator if I pass ";" as argument.

I modified the patch to add correct documentation in the function.

---
  lisp/org-table.el |    3 +++
  1 file changed, 3 insertions(+)

diff --git a/lisp/org-table.el b/lisp/org-table.el
index 246cf8d..4883fc6 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -548,6 +548,7 @@ (defun org-table-convert-region (beg0 end0 
&optional separator)
  '(4)     Use the comma as a field separator
  '(16)    Use a TAB as field separator
  integer  When a number, use that many spaces as field separator
+string   When a string, use it as a regexp for field separator
  nil      When nil, the command tries to be smart and figure out the
           separator in the following way:
           - when each line contains a TAB, assume TAB-separated 
material
@@ -591,6 +592,8 @@ (defun org-table-convert-region (beg0 end0 
&optional separator)
  		 (if (< separator 1)
  		     (user-error "Number of spaces in separator must be >= 1")
  		   (format "^ *\\| *\t *\\| \\{%d,\\}" separator)))
+		((stringp separator)
+		   (format "^ *\\|%s" separator))
  		(t (error "This should not happen"))))
        (while (re-search-forward re end t)
  	(replace-match "| " t t)))
-- 
1.7.10.4

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

* Re: [PATCH] [org-table] user-chosen separator in org-table-convert-region
  2013-09-03 10:20 [PATCH] [org-table] user-chosen separator in org-table-convert-region francois
  2013-09-24 13:08 ` Carsten Dominik
@ 2013-09-29 10:28 ` Carsten Dominik
  1 sibling, 0 replies; 5+ messages in thread
From: Carsten Dominik @ 2013-09-29 10:28 UTC (permalink / raw)
  To: francois; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1184 bytes --]

Hi Francois,

thanks for the explanation.  I have checked in a modified version which does
what you proposal and also allows the user to call `C-c |' with a triple prefix
arg.  In that case, the command will prompt the user for a regular expression
that will be used.

Useful, thank you!

- Carsten

On 3.9.2013, at 12:20, francois@avalenn.eu wrote:

> Hello,
> 
> I made this patch to make easier conversion to
> org-table from csv-like text with arbitrary separator.
> 
> ---
> lisp/org-table.el |    2 ++
> 1 files changed, 2 insertions(+), 0 deletions(-)
> 
> diff --git a/lisp/org-table.el b/lisp/org-table.el
> index c7e7eb8..c8c2462 100644
> --- a/lisp/org-table.el
> +++ b/lisp/org-table.el
> @@ -575,6 +575,8 @@ nil      When nil, the command tries to be smart and figure out the
> 		 (if (< separator 1)
> 		     (user-error "Number of spaces in separator must be >= 1")
> 		   (format "^ *\\| *\t *\\| \\{%d,\\}" separator)))
> +		((stringp separator)
> +		   (format "^ *\\|%s" separator))
> 		(t (error "This should not happen"))))
>       (while (re-search-forward re end t)
> 	(replace-match "| " t t)))
> -- 
> 1.7.9
> 
> 
> 


[-- Attachment #2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

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

end of thread, other threads:[~2013-09-29 10:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-03 10:20 [PATCH] [org-table] user-chosen separator in org-table-convert-region francois
2013-09-24 13:08 ` Carsten Dominik
2013-09-27  9:39   ` francois
2013-09-29 10:28 ` Carsten Dominik
  -- strict thread matches above, loose matches on Subject: below --
2013-09-03 14:25 francois

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

	https://git.savannah.gnu.org/cgit/emacs/org-mode.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).