Re: custom function for org-babel src block export

2023-12-26 Thread David Bremner
Rudolf Adamkovič  writes:

> How about:
>
> (defvar stacker-base
>   "\href{https://www.example.com/stacker/?program=%s}{execute on stacker}")
>
> (defun org-babel-execute:stacker (body params)
>   (format stacker-base 
>   (org-link-encode body '(?? ?  ?( ?) ?\n
>

Thanks, that's a definite improvement on my version. I feel less like
I'm fighting org-mode now ;). It just needs the same ":results value
latex" to insert properly into the beamer export.



Re: custom function for org-babel src block export

2023-12-26 Thread Rudolf Adamkovič
How about:

(defvar stacker-base
  "\href{https://www.example.com/stacker/?program=%s}{execute on stacker}")

(defun org-babel-execute:stacker (body params)
  (format stacker-base 
  (org-link-encode body '(?? ?  ?( ?) ?\n

It works with noweb too:

#+NAME: last
#+BEGIN_SRC stacker :eval no
(f)
#+END_SRC

#+BEGIN_SRC stacker :noweb yes
(defvar x 1)
(deffun (f)
  (defvar y 2)
  (deffun (h)
(+ x y))
  (h))
<>
#+END_SRC

#+RESULTS:
: 
href{https://www.example.com/stacker/?program=%28defvar%20x%201%29%0A%28deffun%20%28f%29%0A%20%20%28defvar%20y%202%29%0A%20%20%28deffun%20%28h%29%0A%20%20%20%20%28+%20x%20y%29%29%0A%20%20%28h%29%29%0A%28f%29}{execute
 on stacker}

Rudy
-- 
"Genius is 1% inspiration and 99% perspiration."
--- Thomas Alva Edison, 1932

Rudolf Adamkovič  [he/him]
Studenohorská 25
84103 Bratislava
Slovakia



Re: custom function for org-babel src block export

2023-12-25 Thread David Bremner
David Bremner  writes:

> Ihor Radchenko  writes:
>
>> David Bremner  writes:
>>
>>> I am generating slides using org-beamer. I would like certain code
>>> blocks to export as links containing URL-encoded content of the
>>> block.
>>
>> Check out https://orgmode.org/manual/Advanced-Export-Configuration.html
>> You may use export filter or extend ox-beamer backend, creating a new
>> custom backend that will export your code blocks as desired.
>>
>
> Thanks for the suggestion(s).
>
> I tried defining org-export-filter-src-block-functions (see end)
> but I encountered two issues
>

My "good enough for now" solution is to use a second emacs-lisp code
block as below.  This requires a bit of care to keep the link in sync
with the exported code, but is otherwise workable.

#+name: smol-test
#+begin_src smol
  (deffun (f x) (+ x 1))
#+end_src

#+begin_src emacs-lisp :eval true :exports results :noweb yes :results value 
latex
  (db-stacker-link "<>")
#+end_src
#+results:
#+begin_export latex
\href{https://www.example.com/stacker/?program=%28deffun%20%28f%20x%29%20%28+%20x%201%29%29}{execute
 on stacker}
#+end_export



Re: custom function for org-babel src block export

2023-12-25 Thread David Bremner
Ihor Radchenko  writes:

> David Bremner  writes:
>
>> I am generating slides using org-beamer. I would like certain code
>> blocks to export as links containing URL-encoded content of the
>> block.
>
> Check out https://orgmode.org/manual/Advanced-Export-Configuration.html
> You may use export filter or extend ox-beamer backend, creating a new
> custom backend that will export your code blocks as desired.
>

Thanks for the suggestion(s).

I tried defining org-export-filter-src-block-functions (see end)
but I encountered two issues

1) The text already includes the latex environment (in my case
listings). This is solvable, but did make me wonder if I was using the
right filter.

2) I could not figure out how to cleanly access the source language
   (e.g. "stacker" in my example). It didn't seem to be in "info".  I
   guess I can recover it from the text using e.g. regex, but this seems 
fragile, since
   it would break when switching backends.

;;

(defun db-ox-src-filter (text backend info)
  (when (org-export-derived-backend-p backend 'latex)
(db-stacker-link text)))

(add-to-list 'org-export-filter-src-block-functions
 #'db-ox-src-filter)



Re: custom function for org-babel src block export

2023-12-25 Thread Ihor Radchenko
David Bremner  writes:

> I am generating slides using org-beamer. I would like certain code
> blocks to export as links containing URL-encoded content of the
> block.

Check out https://orgmode.org/manual/Advanced-Export-Configuration.html
You may use export filter or extend ox-beamer backend, creating a new
custom backend that will export your code blocks as desired.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at