diff options
author | Carsten Dominik <carsten.dominik@gmail.com> | 2013-09-29 12:27:09 +0200 |
---|---|---|
committer | Carsten Dominik <carsten.dominik@gmail.com> | 2013-09-29 12:27:09 +0200 |
commit | 817cbca767b8716118a105552c44de3150667fe8 (patch) | |
tree | 999c092fc9a28f526d6e9add0905b4581ec52761 | |
parent | f485539d6365a0711129c28732e72bd75083105b (diff) | |
download | org-mode-817cbca767b8716118a105552c44de3150667fe8.tar.gz |
Allow regexp separator when converting the region to a table
* lisp/org-table.el (org-table-convert-region): Interpret string SEPARATOR
as regular expression. Triple `C-u' prefix arg will read a regexp
from the user.
* doc/org.texi: Document that `C-c |' can take a regexp as a separator.
Patch modified from a proposal by Francois.
-rw-r--r-- | doc/org.texi | 3 | ||||
-rw-r--r-- | lisp/org-table.el | 6 |
2 files changed, 8 insertions, 1 deletions
diff --git a/doc/org.texi b/doc/org.texi index 64c4fe3..9b056f7 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -2143,7 +2143,8 @@ TAB character, the function assumes that the material is tab separated. If every line contains a comma, comma-separated values (CSV) are assumed. If not, lines are split at whitespace into fields. You can use a prefix argument to force a specific separator: @kbd{C-u} forces CSV, @kbd{C-u -C-u} forces TAB, and a numeric argument N indicates that at least N +C-u} forces TAB, @kbd{C-u C-u C-u} will prompt for a regular expression to +match the separator, and a numeric argument N indicates that at least N consecutive spaces, or alternatively a TAB will be the separator. @* If there is no active region, this command creates an empty Org diff --git a/lisp/org-table.el b/lisp/org-table.el index 246cf8d..5bc754c 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -547,7 +547,9 @@ following values: '(4) Use the comma as a field separator '(16) Use a TAB as field separator +'(64) Prompt for a regular expression as field separator integer When a number, use that many spaces as field separator +regexp When a regular expression, use it to match the 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 @@ -557,6 +559,8 @@ nil When nil, the command tries to be smart and figure out the (let* ((beg (min beg0 end0)) (end (max beg0 end0)) re) + (if (equal separator '(64)) + (setq separator (read-regexp "Regexp for field separator"))) (goto-char beg) (beginning-of-line 1) (setq beg (point-marker)) @@ -591,6 +595,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))) |