From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Price Subject: Re: setting a custom flag for src blocks Date: Sun, 11 Dec 2016 06:46:25 -0500 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a114536387e1542054360897c Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55475) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cG2bg-0006Fd-3L for emacs-orgmode@gnu.org; Sun, 11 Dec 2016 06:47:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cG2bc-00059s-UV for emacs-orgmode@gnu.org; Sun, 11 Dec 2016 06:47:52 -0500 Received: from mail-io0-f171.google.com ([209.85.223.171]:36502) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cG2bc-00058c-Ne for emacs-orgmode@gnu.org; Sun, 11 Dec 2016 06:47:48 -0500 Received: by mail-io0-f171.google.com with SMTP id a81so121878252ioe.3 for ; Sun, 11 Dec 2016 03:47:27 -0800 (PST) In-Reply-To: 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" To: Org Mode --001a114536387e1542054360897c Content-Type: text/plain; charset=UTF-8 Huh. This is pretty cool, Charles. But I think it will be a little hard for me to implement for lectures, since I really need to quickly write up slides in the half-hour before class... So, instead, I rewrote org-reveal-src-block to do the work for me. I've just written a blog post -- for some reason my posts are no longer showing up on Planet Emacsen (maybe b/c I have soem non-Emas stuff o nthat blog now), but the blog is here: http://matt.hackinghistory.ca/2016/12/11/org-mode-run-code-live-in-a-reveal-slideshow-with-klipse/ I would really love to get feedback on this solution, or any other ones. Thanks as always to all readers and commentators! On Sun, Dec 11, 2016 at 12:19 AM, Charles C. Berry wrote: > On Sat, 10 Dec 2016, Matt Price wrote: > > On Sat, Dec 10, 2016 at 12:19 AM, Matt Price wrote: >> >> >>> >>> On Fri, Dec 9, 2016 at 12:19 PM, Eric S Fraga wrote: >>> >>> On Friday, 9 Dec 2016 at 16:42, Matt Price wrote: >>>> >>>>> I think I am getting closer, actually (details soon, when I have a >>>>> fully working solution)). >>>>> >>>> > [deleted] > > I *think* that I'm looking for an export filter. From what I can see, it >> has access to all the information that the initial export function does. >> > > It does not. :-( > > When `org-babel-exp-process-buffer' runs (under `org-export-as'), all the > header info is dropped. > > There might be a way to backtrack from the copy buffer to the original and > remap the src blocks, but it seems like the wrong way to go. It would be a > lot of work, I think. > > More below ... > > So now I'm wondering what the easiest way is to set a simple flag for a src >> block, and make that flag available to the export filter. For instance, >> if >> I want a particular block to be renderd in klipse on export, could I >> specify somehow: >> >> #+HEADER: klipsify t >> #+BEGIN_SRC: javascript >> console.log("success"); >> #+END_SRC >> >> or alternatively in a subtree: >> >> * Lots of Examples >> :PROPERTIES: >> #+PROPERTY: header-args:javascript :klipsify t >> :END: >> >> #+BEGIN_SRC: javascript >> console.log("success"); >> #+END_SRC >> >> > I think the better way to go is to do all the formatting in babel. That > is, make a babel src block handle the formatting for you and subvert the > normal mechanisms. > > To do this, write a src block that is given the name of another src > block, that grabs the body (and if you really need it the header > info), formats it as you need, and inserts it in final form wrapped > in an `export html' block. > > So if you had a src block named `codeA' and one named `klipsify' which > has the code needed to render the output you desire depending on the > value of > > : :var src-blk-name="my-codes" > > then a > > #+CALL:klipsify("codeA") > > line will put the output in the exported document. > > Something like this: > > #+NAME: codeA > #+BEGIN_SRC: javascript :eval never-export :exports none > console.log("success"); > #+END_SRC > > #+NAME: klipsify > #+header: :var src-blk-name="my-code" :exports none > #+header: :results raw :wrap export html > #+BEGIN_SRC emacs-lisp > (save-excursion > (org-babel-goto-named-src-block > src-block-name) > (let ((body-code > (org-babel-expand-src-block))) > (klipsify-my-code body-code))) > #+END_SRC > > Obviously, you need to defun `klipsify-my-code' or whatever. > > > All the code blocks would need to be named and have these headers: > > : :eval never-export :exports none > > or maybe > > : :exports results > > You would use the latter, if you want the results of evaluating the code > to appear in the exported document. Put the #+CALL line just before the > code block and then the code will appear first and the results next. > > HTH, > > Chuck > --001a114536387e1542054360897c Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Huh.=C2=A0 This is pretty cool, Charles. But I think = it will be a little hard for me to implement for lectures, since I really n= eed to quickly write up slides in the half-hour before class...=C2=A0 So, i= nstead, I rewrote org-reveal-src-block to do the work for me. I've just= written a blog post -- for some reason my posts are no longer showing up o= n Planet Emacsen (maybe b/c I have soem non-Emas stuff o nthat blog now), b= ut the blog is here:

http://mat= t.hackinghistory.ca/2016/12/11/org-mode-run-code-live-in-a-reveal-slideshow= -with-klipse/

I would really love to get feedback on this = solution, or any other ones.=C2=A0 Thanks as always to all readers and comm= entators!

On Sun, Dec 11, 2016 at 12:19 AM, Charles C. Berry <= ccberry@ucsd.edu&= gt; wrote:
On Sat= , 10 Dec 2016, Matt Price wrote:

On Sat, Dec 10, 2016 at 12:19 AM, Matt Price <moptop99@gmail.com> wrote:



On Fri, Dec 9, 2016 at 12:19 PM, Eric S Fraga <e.fraga@ucl.ac.uk> wrote:

On Friday,=C2=A0 9 Dec 2016 at 16:42, Matt Price wrote:
I think I am getting closer, actually (details soon, when I have a
fully working=C2=A0 solution)).

[deleted]

I *think* that I'm looking for an export filter. From what I can see, i= t
has access to all the information that=C2=A0 the=C2=A0 initial export funct= ion does.

It does not. :-(

When `org-babel-exp-process-buffer' runs (under `org-export-as'), a= ll the header info is dropped.

There might be a way to backtrack from the copy buffer to the original and = remap the src blocks, but it seems like the wrong way to go. It would be a = lot of work, I think.

More below ...

So now I'm wondering what the easiest way is to set a simple flag for a= src
block, and make that flag available to the export filter.=C2=A0 For instanc= e, if
I want a particular block to be renderd in klipse on export, could I
specify somehow:

#+HEADER: klipsify t
#+BEGIN_SRC: javascript
console.log("success");
#+END_SRC

or alternatively in a subtree:

* Lots of Examples
:PROPERTIES:
#+PROPERTY: header-args:javascript=C2=A0 :klipsify t
:END:

#+BEGIN_SRC: javascript
console.log("success");
#+END_SRC


I think the better way to go is to do all the formatting in babel. That is,= make a babel src block handle the formatting for you and subvert the norma= l mechanisms.

To do this, write a src block that is given the name of another src
block, that grabs the body (and if you really need it the header
info), formats it as you need, and inserts it in final form wrapped
in an `export html' block.

So if you had a src block named `codeA' and one named `klipsify' wh= ich
has the code needed to render the output you desire depending on the
value of

: :var src-blk-name=3D"my-codes"

then a

#+CALL:klipsify("codeA")

line will put the output in the exported document.

Something like this:

#+NAME: codeA
#+BEGIN_SRC: javascript :eval never-export :exports none
console.log("success");
#+END_SRC

#+NAME: klipsify
#+header: :var src-blk-name=3D"my-code" :exports none
#+header: :results raw :wrap export html
#+BEGIN_SRC emacs-lisp
=C2=A0 (save-excursion
=C2=A0 =C2=A0 (org-babel-goto-named-src-block
=C2=A0 =C2=A0 =C2=A0src-block-name)
=C2=A0 =C2=A0 (let ((body-code
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(org-babel-expand-src-block))= )
=C2=A0 =C2=A0 =C2=A0 (klipsify-my-code body-code)))
#+END_SRC

Obviously, you need to defun `klipsify-my-code' or whatever.


All the code blocks would need to be named and have these headers:

:=C2=A0 :eval never-export :exports none

or maybe

:=C2=A0 :exports results

You would use the latter, if you want the results of evaluating the code to= appear in the exported document. Put the #+CALL line just before the code = block and then the code will appear first and the results next.

HTH,

Chuck

--001a114536387e1542054360897c--