emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] [PATCH] Process hlines in imported tables


From: Eric Schulte
Subject: Re: [O] [PATCH] Process hlines in imported tables
Date: Fri, 29 Mar 2013 09:04:42 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Rick Frankel <address@hidden> writes:

> Currently, there is no way to include an hline in an imported or
> converted table. The `org-babel-import-elisp-from-file converts lines
> starting with '-' (or '|-') to an integer 0,

Oh, thanks for pointing this out, I've just pushed up a fix.  The single
"-" was tricking the number checker because it looks like a minus sign
about to be followed by numbers.  These characters are no longer
converted to 0s.

> because, even though `org-table-to-lisp' will correctly convert lines
> starting with "|-", because `org-table-convert-region' always puts "|
> " at the begining of each line.
>
> This patch solves that by not putting a space after the pipe symbol if
> the first character of the line is a dash ("-").
>

Users may want to insert a "-" in their tables, and I think it would be
surprising to magically replace floating "-" characters with hlines.
There are numerous existing options for inserting hlines into tables,
e.g., the :colnames header argument, using the raw, wrap and org result
types and printing literal Org-mode syntax from your block, additionally
any result could be passed through an elisp code block which may insert
hline symbols at will.

Is there a specific use case which isn't addressed by the existing
functionality?

Thanks,

>
> rick
>
> From 86ee5bfcaa7513769cc3e2939c5e0b1a1f3c7706 Mon Sep 17 00:00:00 2001
> From: Rick Frankel <address@hidden>
> Date: Thu, 28 Mar 2013 21:34:06 -0400
> Subject: [PATCH] When importing or converting table, convert rows starting
>  with "-" to horizontal (hlines).
>
> * lisp/ob-core.el (org-babel-import-elisp-from-file): Check if row in
>   an array or 'hline.
> * lisp/org-table.el (org-table-convert-region): Don't put space after
>   pipe symbol if line starts with '-', so `org-table-to-lisp' will
>   match the row against `org-table-hline-regexp'.
> ---
>  lisp/ob-core.el   | 3 ++-
>  lisp/org-table.el | 3 ++-
>  2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/lisp/ob-core.el b/lisp/ob-core.el
> index a63f77e..93b12b2 100644
> --- a/lisp/ob-core.el
> +++ b/lisp/ob-core.el
> @@ -2537,7 +2537,8 @@ If the table is trivial, then return it as a scalar."
>             (org-table-import file-name separator)
>             (delete-file file-name)
>             (setq result (mapcar (lambda (row)
> -                                  (mapcar #'org-babel-string-read row))
> +                                  (if (eq row 'hline) 'hline
> +                                    (mapcar #'org-babel-string-read row)))
>                                  (org-table-to-lisp))))
>         (error (message "Error reading results: %s" err) nil)))
>        (if (null (cdr result)) ;; if result is trivial vector, then scalarize 
> it
> diff --git a/lisp/org-table.el b/lisp/org-table.el
> index f087cf7..da923cc 100644
> --- a/lisp/org-table.el
> +++ b/lisp/org-table.el
> @@ -605,7 +605,8 @@ nil      When nil, the command tries to be smart and 
> figure out the
>                  (format "^ *\\| *\t *\\| \\{%d,\\}" separator)))
>               (t (error "This should not happen"))))
>        (while (re-search-forward re end t)
> -     (replace-match "| " t t)))
> +     (replace-match
> +      (if (= (char-after) ?-) "|" "| ") t t)))
>      (goto-char beg)
>      (org-table-align)))

-- 
Eric Schulte
http://cs.unm.edu/~eschulte



reply via email to

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