emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Charles Berry <ccberry@ucsd.edu>
To: emacs-orgmode@gnu.org
Subject: Re: accessing source block header arguments from exporters
Date: Fri, 10 Apr 2015 22:17:42 +0000 (UTC)	[thread overview]
Message-ID: <loom.20150410T231613-470@post.gmane.org> (raw)
In-Reply-To: 55282A05.8040203@roklein.de

Robert Klein <roklein <at> roklein.de> writes:

> 
> Hi,
> 
> is there a way, to read header arguments to source blocks in the
> exporters org-<exporter>-src-block funktions?

Not directly. org-babel-exp-code has no provision for headers. 
They get dropped.

>
> E.g. is there a way to access :firstline in the example below?
> 

Not exactly, but ...

If you precede the code block with

#+attr_firstline: 23 

then with point in the src block

(org-element-property :attr_firstline (org-element-context))

will return ("23"). And org-*-src-block functions can use it.

If you really want to use the :firstline idiom, you can add a hook in 
`org-export-before-processing-hook' to find :firstline headers and 
insert #+attr_firstline lines in the buffer copy that the exporter is using.

> #+begin_src c++ -n :firstline 23
>    static struct
>   {
>       char                        *entity;
>       unsigned char       equiv;
>   } entities[] =
>     {
>       { "lt",           '<' } ,
>       { "gt",           '>' } ,
>       { "amp",          '&' } ,
>       { "quot",         '"' } ,
>       { "trade",        153 } , /* trade mark */
> #+end_src
> 
> I didn't find it in the `element' structure.
> 
> However, if I use
> 
> #+begin_src c++ firstline=23
>   // random C++
> #+end_src
> 
> I could access :parameters from `element' and parse the string.
> However I'm not sure if I'd break some babel stuff or not.
>

C-c C-v C-i on that src block shows that 'firstline=23' is treated as 
a switch by babel. So if there is any language that tries to use that 
as a switch (or has a regexp that matches it), there could be trouble.  
 
But in C it looks innocuous.

> If I'm trying to implement a firstline feature -- source blocks with
> new line numbering (-n) beginning at a given line number -- I'd prefer
> to use :firstline, but I didn't find anything to suggest `:XXX ZZ'
> header arguments to source blocks are available to the exporters.
> 

HTH,

Chuck

  reply	other threads:[~2015-04-10 22:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-10 19:52 accessing source block header arguments from exporters Robert Klein
2015-04-10 22:17 ` Charles Berry [this message]
2015-04-11 10:57   ` John Kitchin

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

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=loom.20150410T231613-470@post.gmane.org \
    --to=ccberry@ucsd.edu \
    --cc=emacs-orgmode@gnu.org \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).