From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: filter for src-block export question Date: Sun, 21 Sep 2014 17:11:38 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:50759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XVoQD-0003XL-3T for emacs-orgmode@gnu.org; Sun, 21 Sep 2014 17:11:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XVoQ8-0008EB-3N for emacs-orgmode@gnu.org; Sun, 21 Sep 2014 17:11:53 -0400 Received: from mail-qg0-x22a.google.com ([2607:f8b0:400d:c04::22a]:59161) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XVoQ7-0008Di-T4 for emacs-orgmode@gnu.org; Sun, 21 Sep 2014 17:11:48 -0400 Received: by mail-qg0-f42.google.com with SMTP id z60so793860qgd.29 for ; Sun, 21 Sep 2014 14:11:41 -0700 (PDT) Received: from Johns-MacBook-Air.local (c-24-3-17-30.hsd1.pa.comcast.net. [24.3.17.30]) by mx.google.com with ESMTPSA id b89sm1680407qgb.3.2014.09.21.14.11.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Sep 2014 14:11:40 -0700 (PDT) In-Reply-To: (John Kitchin's message of "Sat, 20 Sep 2014 19:33:59 -0400") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org To followup on this, I believe there is either a bug or an inconsistency in the export engine with regards to getting the parameters of a src-block. Below, I show why it appears there is a bug. * Bug report for org-mode Here is a named table #+tblname: tbl-data | x | y | |---+---| | 1 | 1 | | 2 | 4 | | 3 | 9 | Here is a named src-block with a defined var #+name: print-table #+BEGIN_SRC python :var data=tbl-data :results value return data #+END_SRC #+RESULTS: print-table | 1 | 1 | | 2 | 4 | | 3 | 9 | Now, we illustrate that the src-block does have :parameters. #+name: get-properties #+BEGIN_SRC emacs-lisp (save-excursion (re-search-backward "#\\+name: print-table") (org-element-property :parameters (org-element-at-point))) #+END_SRC #+RESULTS: get-properties : :var data=tbl-data :results value In the export machinery, though it appears the src-block does not. #+BEGIN_SRC emacs-lisp :results output (defun my-src-block (src-block contents info) (princ (concat (format "[language: %s]\n" (org-element-property :language src-block)) (format "name: %s\n" (org-element-property :name src-block)) (format "parameters: %s\n\n" (org-element-property :parameters src-block)))) (org-export-format-code-default src-block info)) (org-export-define-derived-backend 'my-html 'html :translate-alist '((src-block . my-src-block))) (org-export-to-file 'my-html "custom-src-table-export.html") #+END_SRC #+RESULTS: #+begin_example [language: python] name: print-table parameters: nil [language: emacs-lisp] name: get-properties parameters: nil [language: emacs-lisp] name: nil parameters: nil #+end_example You can see the parameters are nil in each case, even though we know the print-table block does have parameters. I do not know where the parameters get lost, so I am reporting the issue here. John Kitchin writes: > I have noticed that when code blocks have input variables, e.g. > > #+tblname: tbl-data > | x | y | > > |---+---| > | 1 | 1 | > | 2 | 4 | > | 3 | 9 | > > #+BEGIN_SRC python :var data=tbl-data > print data > #+END_SRC > > > #+RESULTS: > : [[1, 1], [2, 4], [3, 9]] > > When I export this, the codeblock shows no indication of what "data" is, > or where it came from. I had hoped to develop a filter that would allow > me to put something like: > >
language=python
> parameters: :var data=tbl-data
> > in front of the block for an html export. I tried following the example > here: http://orgmode.org/manual/Advanced-configuration.html at the end, > by defining a derived mode. However, it does not appear that the > information is kept in the parse tree. > > (src-block (:language python :switches nil :parameters nil :begin 536 > :end 578 :number-lines nil :preserve-indent t :retain-labels t > :use-labels t :label-fmt nil :hiddenp nil :value print data > :post-blank 2 :post-affiliated 536 :parent #4)) > > although if I look at the element at point, it seems to be there: > > (src-block (:language python :switches nil :parameters :var > data=tbl-data :begin 536 :end 629 :number-lines nil :preserve-indent t > :retain-labels t :use-labels t :label-fmt nil :hiddenp nil :value print > data (princ (org-element-at-point)) > > I am not sure why the :end values are not the same though. > > Here is what I was trying to use: > > #+BEGIN_SRC emacs-lisp > (defun my-src-block (src-block contents info) > (message "start-block\n\n%s\n\nend-block" info) > (concat "
"
>    (format "[language: %s]" (org-element-property :language src-block))
>    (format "\nparameters: %s" (org-element-property :parameters src-block))
>    "

" > (org-export-format-code-default src-block info))) > > (org-export-define-derived-backend 'my-html 'html > :translate-alist '((src-block . my-src-block))) > > (org-export-to-file 'my-html "custom-src-table-export.html") > (browse-url "custom-src-table-export.html") > #+END_SRC > > There are two issues with this block: > > 1. All parameters are listed as nil > 2. the code is not syntax highlighted in html at all. > > Any suggestions on how to achieve this? I also want to insert > tablenames, and if the src-block is named to put the name above the > block (for extra gravy, a hyperlink from :var to the source ;). > > thanks, -- ----------------------------------- John Kitchin Professor Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 http://kitchingroup.cheme.cmu.edu