[Top][All Lists]

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

Re: [O] [PATCH] [org-table] user-chosen separator in org-table-convert-r

From: francois
Subject: Re: [O] [PATCH] [org-table] user-chosen separator in org-table-convert-region
Date: Fri, 27 Sep 2013 11:39:20 +0200
User-agent: Roundcube Webmail/0.7.2

On Tue, 24 Sep 2013 15:08:10 +0200, Carsten Dominik <address@hidden> 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))
      (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)))

reply via email to

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