浏览代码

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.
Carsten Dominik 11 年之前
父节点
当前提交
817cbca767
共有 2 个文件被更改,包括 8 次插入1 次删除
  1. 2 1
      doc/org.texi
  2. 6 0
      lisp/org-table.el

+ 2 - 1
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 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
 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
 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.
 consecutive spaces, or alternatively a TAB will be the separator.
 @*
 @*
 If there is no active region, this command creates an empty Org
 If there is no active region, this command creates an empty Org

+ 6 - 0
lisp/org-table.el

@@ -547,7 +547,9 @@ following values:
 
 
 '(4)     Use the comma as a field separator
 '(4)     Use the comma as a field separator
 '(16)    Use a TAB as 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
 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
 nil      When nil, the command tries to be smart and figure out the
          separator in the following way:
          separator in the following way:
          - when each line contains a TAB, assume TAB-separated material
          - 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))
   (let* ((beg (min beg0 end0))
 	 (end (max beg0 end0))
 	 (end (max beg0 end0))
 	 re)
 	 re)
+    (if (equal separator '(64))
+	(setq separator (read-regexp "Regexp for field separator")))
     (goto-char beg)
     (goto-char beg)
     (beginning-of-line 1)
     (beginning-of-line 1)
     (setq beg (point-marker))
     (setq beg (point-marker))
@@ -591,6 +595,8 @@ nil      When nil, the command tries to be smart and figure out the
 		 (if (< separator 1)
 		 (if (< separator 1)
 		     (user-error "Number of spaces in separator must be >= 1")
 		     (user-error "Number of spaces in separator must be >= 1")
 		   (format "^ *\\| *\t *\\| \\{%d,\\}" separator)))
 		   (format "^ *\\| *\t *\\| \\{%d,\\}" separator)))
+		((stringp separator)
+		 (format "^ *\\|%s" separator))
 		(t (error "This should not happen"))))
 		(t (error "This should not happen"))))
       (while (re-search-forward re end t)
       (while (re-search-forward re end t)
 	(replace-match "| " t t)))
 	(replace-match "| " t t)))