From: Rick Frankel <rick@rickster.com>
To: Jarmo Hurri <jarmo.hurri@syk.fi>
Cc: emacs-orgmode@gnu.org
Subject: Re: Babel: the disappearing hline
Date: Tue, 12 Nov 2013 10:45:52 -0500 [thread overview]
Message-ID: <ad4285b5535d33da3e4ddae69d4409e3@mail.rickster.com> (raw)
In-Reply-To: <87r4amb0vc.fsf@syk.fi>
[-- Attachment #1: Type: text/plain, Size: 2712 bytes --]
On 2013-11-12 01:16, Jarmo Hurri wrote:
> Eric Schulte <schulte.eric@gmail.com> writes:
>
> There are two paces to specify header arguments in a call line, the
> arguments in the [] are applied to the input-table function, *not* to
> the call line, so they change the inputs. The trailing header
> arguments are applied to the call line.
>
> So there is an implicit post-processing function that takes the result
> of the called block as input, and hline pruning is applied in this
> function?
>
> I put on the table a suggestion that the default behaviour of #+CALL
> w.r.t. the handling of hlines is changed from removing hlines in output
> to not removing them. I am suggesting this partly because I don't
> understand why the default behaviour is as it is now, and secondly
> because the current behavious differs from the way hlines are handled
> in
> other block evaluations:
This behavior is controlled globally by the value of
`org-babel-default-header-args'. This is overriden by the value of
`org-babel-default-header-args:{lang}' and of course, the setting on
individual source blocks and call lines. As you can see from the below
output, the default is =:hlines no=. Note that in versions of org-mode
prior to commit 6857d139 of 2013-09-28 (below), this was overridden in
the setting of `org-babel-default-header-args:emacs-lisp, so this may
be why you are seeing and "inconsistency" between the call line and
the emacs-lisp source block.
If you want hlines to be included by default, you can modify the value
of `org-babel-default-header-args'.
I have attached an org file i have been working on to see the results
of various settings of =colnames= and =hlines= on table evaluation in
various languages, you may find it useful.
rick
------
commit 6857d139e1b5ea5c235e3555dbe15aeab227aaef
Author: Eric Schulte <schulte.eric@gmail.com>
Date: Sat Sep 28 06:37:54 2013 -0600
set default emacs-lisp header args to nil
The difference between elisp and every other language was causing
confusion, so simpler just to set these to nil.
* lisp/ob-emacs-lisp.el (org-babel-default-header-args:emacs-lisp):
Set to nil.
1 file changed, 1 insertion(+), 2 deletions(-)
lisp/ob-emacs-lisp.el | 3 +--
Modified lisp/ob-emacs-lisp.el
diff --git a/lisp/ob-emacs-lisp.el b/lisp/ob-emacs-lisp.el
index 886645d..4505129 100644
--- a/lisp/ob-emacs-lisp.el
+++ b/lisp/ob-emacs-lisp.el
@@ -28,8 +28,7 @@
;;; Code:
(require 'ob)
-(defvar org-babel-default-header-args:emacs-lisp
- '((:hlines . "yes") (:colnames . "no"))
+(defvar org-babel-default-header-args:emacs-lisp nil
"Default arguments for evaluating an emacs-lisp source block.")
(declare-function orgtbl-to-generic "org-table" (table params))
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: colnames.org --]
[-- Type: text/x-lisp; name=colnames.org, Size: 5123 bytes --]
#+TITLE: Colnames handling
#+DATE: {{{modification-time(%Y-%m-%d)}}}
#+AUTHOR: Rick Frankel
#+EMAIL: ut0598@rtasdv12
#+OPTIONS: ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline
#+OPTIONS: author:t c:nil creator:comment d:(not LOGBOOK) date:t
#+OPTIONS: e:t email:nil f:t inline:t num:nil p:nil pri:nil stat:t
#+OPTIONS: tags:t tasks:t tex:t timestamp:nil toc:t todo:t |:t
#+DESCRIPTION:
#+EXCLUDE_TAGS: noexport
#+KEYWORDS:
#+LANGUAGE: en
#+SELECT_TAGS: export
Evaluate the subtree [[Test generator]] with =org-babel-execute-subtree= (=C-c C-v C-s=).
It will:
1. Run [[generate-colnames-and-hlines-tests]] to create the [[colnames and
hlines]] tests.
2. Run the tests.
Note that it will automatically require the file "ob-{lang}" for
each language block specified in [[Language functions]] below.
* Language functions
:PROPERTIES:
:results: silent
:exports: code
:var: table=table
:ID: LANGUAGES
:END:
This function should modify each cell of the input table by appending
/-o/ to the value of the cell and convert ='hline= rows in the
input to the literal /hline/, so it appears in the output table.
Create one for each babel language to be tested.
#+CAPTION: emacs-lisp
#+BEGIN_SRC emacs-lisp
(mapcar
(lambda (r)
(if (sequencep r)
(mapcar
(lambda (c)
(if (integerp c)
(format "%d-o" c)
(concat c "-o")))
r)
(list r)))
table)
#+END_SRC
#+CAPTION: perl
#+BEGIN_SRC perl :results value
return [map {
ref $_ ? [map { $_ . "-o" } @$_] : $_
} @$table];
#+END_SRC
#+CAPTION: python
#+name: python
#+BEGIN_SRC python
return [isinstance(r,list) and [str(c)+"-o" for c in r] or [r] for r in table]
#+END_SRC
#+CAPTION: ruby
#+BEGIN_SRC ruby
table.collect do |r|
r.instance_of?(Array) ? r.collect { |c| "#{c}-o" } : [r]
end
#+END_SRC
* Test generator
#+CAPTION: Input table
#+name: table
| a | b | c |
|---+---+---|
| 1 | 2 | 3 |
| 4 | 5 | 6 |
|---+---+---|
| 7 | 8 | 9 |
#+CAPTION: Function to list default header args by language
#+name: list-defaults
#+HEADER: :var val='org-babel-default-header-args :eval never :exports code
#+BEGIN_SRC emacs-lisp :colnames '(option value)
(or
(mapcar
(lambda (x) (list (car x) (cdr x))) (eval val)) '(("" "")))
#+END_SRC
#+name: generate-colnames-and-hlines-tests
#+BEGIN_SRC emacs-lisp :results raw :exports results
(condition-case nil
(progn
(widen)
(org-id-goto "COLNAMES-AND-HLINES")
(org-cut-subtree))
(error t))
(concat
"* Test results\n"
":PROPERTIES:\n"
":ID: COLNAMES-AND-HLINES\n"
":END:\n"
(let ((data ()) (defaults '("org-babel-default-header-args")))
(save-excursion
(save-restriction
(widen)
(org-id-goto "LANGUAGES")
(org-narrow-to-subtree)
(org-babel-map-executables nil
(let* ((info (org-babel-get-src-block-info 'light))
(lang (nth 0 info)))
(push (format "org-babel-default-header-args:%s" lang) defaults)
(require (intern (format "ob-%s" lang)))
(push
(concat
(format "#+name: %s-%%s\n" lang)
"#+HEADER: :results value :colnames %s :hlines %s\n"
(format "#+BEGIN_SRC %s :var table=table\n" lang)
(replace-regexp-in-string
"^" " "
(replace-regexp-in-string "%" "%%" (nth 1 info)))
"\n#+END_SRC\n"
"#+ATTR_LATEX: :placement [H]"
(format "\n#+CAPTION: %s" lang)
(format "\n#+RESULTS: %s-%%s\n" lang))
data)))))
(concat
"** Default header args\n"
":PROPERTIES:\n"
":colnames: yes\n"
":END:\n"
"#+LaTeX: \\begin{multicols}{3}\n"
(mapconcat
(lambda (arg)
(format "#+call: list-defaults[:eval yes]('%s)\n\n#+CAPTION: %s\n#+RESULTS:\n"
arg arg)) (reverse defaults) "\n")
"#+LaTeX: \\end{multicols}\n"
(mapconcat
'identity
(mapcar
(lambda (arg)
(let* ((colname (car arg))
(hlines (nth 1 arg))
(argname (format "%s-%s"
(if (symbolp colname)
(symbol-name colname)
(replace-regexp-in-string "[' ()]" "" colname))
hlines)))
(concat
(format "** colnames %s, hlines %s\n" colname hlines)
"#+LaTeX: \\begin{multicols}{3}\n"
(mapconcat
(lambda (block)
(format block argname colname hlines argname))
(reverse data) "\n")
"#+LaTeX: \\end{multicols}\n")))
(let ((l ()))
(mapc (lambda (hline)
(mapc
(lambda (colname) (setq l (cons (list colname hline) l)))
(list "'nil" 'yes 'no "'t" "'(d e f)")))
'(yes no))
(reverse l))) "\n"))))
#+END_SRC
#+RESULTS: generate-colnames-and-hlines-tests
next prev parent reply other threads:[~2013-11-12 15:46 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-11 14:35 Babel: the disappearing hline Jarmo Hurri
2013-11-11 14:53 ` Thorsten Jolitz
2013-11-11 15:11 ` Jarmo Hurri
2013-11-11 15:31 ` Thorsten Jolitz
2013-11-11 16:19 ` Eric Schulte
2013-11-11 17:26 ` Jarmo Hurri
2013-11-11 17:44 ` Eric Schulte
2013-11-12 6:16 ` Jarmo Hurri
2013-11-12 15:45 ` Rick Frankel [this message]
2013-11-12 16:09 ` Jarmo Hurri
2013-11-12 19:22 ` Rick Frankel
2013-11-13 6:19 ` Jarmo Hurri
2013-11-13 14:17 ` Eric Schulte
2013-11-13 18:52 ` Rick Frankel
2013-11-13 23:27 ` Eric Schulte
2013-11-15 6:50 ` Jarmo Hurri
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ad4285b5535d33da3e4ddae69d4409e3@mail.rickster.com \
--to=rick@rickster.com \
--cc=emacs-orgmode@gnu.org \
--cc=jarmo.hurri@syk.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.