Re: Import Reusable org-babel snippet using #+SETUPFILE

2020-06-18 Thread Douglas Perrin
Hi Salomon,
Babel definitions, in this case, lots of elsip blocks to add behaviors like
this example to clear bloc results on save to avoid polluting commits that
can be turned on and off per section with properties.

#+name: Clear-Results-On-Save
#+begin_src emacs-lisp :results none
;;; code to clean up org-file results on save
(defun CHAI-ClearResultsOnSave ()
  (when (eq major-mode 'org-mode)
(org-babel-map-executables nil
  (cond ((equal "true" (org-entry-get nil "ClearOnSave" t t))
 (org-babel-remove-result))
))
))

;;; interactive version that ignores PROPERTIES and clears all results
(defun CHAI-ClearResultsNow ()
  (interactive)
  (when (eq major-mode 'org-mode)
(org-babel-map-executables nil (org-babel-remove-result))
))

;;; add the hook before saving a file
(add-hook 'before-save-hook 'CHAI-ClearResultsOnSave nil t)
#+end_src

In this case, the init block in the template.org file would have an org-sbe
call to "Clear-Results-On-Save" after ingesting GeneralORGTools.org if I
wanted that behavior. By convention, I always have an init bloc but in this
case it is not very interesting:

#+name:GeneralORGTools_Init
#+BEGIN_SRC elisp
  ;; nice org-mode setting to remove newlines from the outline
  (setq org-cycle-separator-lines 0)
 #+end_src

**correction from my previous post**:
 (org-sbe "GeneralORGTools.org") '
should have been a call to the init
(org-sbe ":GeneralORGTools_Init")

Regards
Doug


Re: Import Reusable org-babel snippet using #+SETUPFILE

2020-06-17 Thread Salomon Turgman
Hey Doug,

What types of things are in GeneralORGTools.org? Are those babel
definitions? Or something else?

-s-

On Tue, Jun 16, 2020 at 11:21 AM Salomon Turgman  wrote:

> Thanks for the useful example. I will take a look. Didn't know about
> org-sbe!
>
> -s-
>
> On Mon, 15 Jun 2020 15:52:16 -0400
> Douglas Perrin  wrote:
>
> > Hi Salomon Turgman,
> > I do this a lot and have had success using a combination of #+SETUPFILE
> to
> > bring in names and configuration, and org-sbe to do initialization. I mix
> > emacs vars and org names in my source headers with back quoting.
> >
> > The following example has a template file containing user/local
> > information. This is brought into the example file, on load, through
> #:eval
> > calling org-babel-lob-ingest and org-sbe, in addition, parameters are
> > pulled in with #+SETUPFILE and the same template file name. The end
> result
> > for this example is a running docker image with access to local paths and
> > "remote" execution via tramp. More complex orchestration and actions in
> the
> > template are certainly possible using org-sbe calls in the init elisp
> > source blocks but hopefully, this shows the flavor of what can be done.
> >
> > In addition to avoiding code duplication, I have found this to be very
> > effective when my group is all working from the same org file (via git)
> but
> > everyone has their own template file with credentials, local paths, and
> org
> > more preferences (ie showstars).
> > Regards,
> > Doug
> >
> >
> -
> > TemplatingExample.org
> >
> -
> > #+SETUPFILE: Template-Loader.org
> >
> > * Init Code, run when file is opened
> > #+name: Execute-On-Load
> > #+begin_src elisp  :results output
> >;; for this the container and image have the same name
> > (setq *DockerName* "ContanerName")
> > #+end_src
> >
> > * Run Contaner
> > #+begin_src bash  :results raw drawer :var DockerName=`,*DockerName*
> > DockerHubUID=`,*DockerHubUID* containerName=`,*DockerContainer*
> > LocalWorkPath=`,*LocalWorkPath* LocalDataPath=`,*LocalDataPath*
> >docker run --rm -d \
> >   -v $LocalWorkPath:/root/Workdir \
> >   -v $LocalDataPath:/root/Data \
> >   --name $DockerName $DockerHubUID/$DockerName bash -c "tail -f
> > /dev/null"
> >   #+end_src
> >
> > * run IN contaner
> > #+begin_src bash  :results output :dir (concat "/docker:" `,*DockerName*
> > ":/root/Workdir/")
> > ls
> > #+end_src
> >
> > # Local Variables:
> > # eval: (org-babel-lob-ingest "Template-Loader.org")
> > # eval: (org-sbe "Init-Template")
> > # eval: (org-sbe "Execute-On-Load")
> > # End:
> >
> >
> -
> > Template-Loader.org
> >
> -
> > #+STARTUP: showstars
> > #+PROPERTY: header-args :mkdirp yes
> >
> > #+name: Init-Template
> > #+begin_src emacs-lisp :results none
> >   ;; This is called expecitly via org-sbe in the buffer that will uses
> the
> > templating
> > (setq *DockerHubUID* "MyUserName")
> > (setq *LocalWorkPath* "/run/desktop/mnt/host/c/Users/.")
> > (setq *LocalDataPath* "/run/desktop/mnt/host/d/devData/")
> >
> >   ;; ingest + SBE can be used to bring in a hierarchy of templates
> >   (org-babel-lob-ingest "./GroupTools/GeneralORGTools.org")
> >   (org-sbe "GeneralORGTools.org")
> >
> > #+end_src
>
>
> --
> Salomon Turgman 
>


Re: Import Reusable org-babel snippet using #+SETUPFILE

2020-06-16 Thread Salomon Turgman
Thanks for the useful example. I will take a look. Didn't know about org-sbe!

-s-

On Mon, 15 Jun 2020 15:52:16 -0400
Douglas Perrin  wrote:

> Hi Salomon Turgman,
> I do this a lot and have had success using a combination of #+SETUPFILE to
> bring in names and configuration, and org-sbe to do initialization. I mix
> emacs vars and org names in my source headers with back quoting.
> 
> The following example has a template file containing user/local
> information. This is brought into the example file, on load, through #:eval
> calling org-babel-lob-ingest and org-sbe, in addition, parameters are
> pulled in with #+SETUPFILE and the same template file name. The end result
> for this example is a running docker image with access to local paths and
> "remote" execution via tramp. More complex orchestration and actions in the
> template are certainly possible using org-sbe calls in the init elisp
> source blocks but hopefully, this shows the flavor of what can be done.
> 
> In addition to avoiding code duplication, I have found this to be very
> effective when my group is all working from the same org file (via git) but
> everyone has their own template file with credentials, local paths, and org
> more preferences (ie showstars).
> Regards,
> Doug
> 
> -
> TemplatingExample.org
> -
> #+SETUPFILE: Template-Loader.org
> 
> * Init Code, run when file is opened
> #+name: Execute-On-Load
> #+begin_src elisp  :results output
>;; for this the container and image have the same name
> (setq *DockerName* "ContanerName")
> #+end_src
> 
> * Run Contaner
> #+begin_src bash  :results raw drawer :var DockerName=`,*DockerName*
> DockerHubUID=`,*DockerHubUID* containerName=`,*DockerContainer*
> LocalWorkPath=`,*LocalWorkPath* LocalDataPath=`,*LocalDataPath*
>docker run --rm -d \
>   -v $LocalWorkPath:/root/Workdir \
>   -v $LocalDataPath:/root/Data \
>   --name $DockerName $DockerHubUID/$DockerName bash -c "tail -f
> /dev/null"
>   #+end_src
> 
> * run IN contaner
> #+begin_src bash  :results output :dir (concat "/docker:" `,*DockerName*
> ":/root/Workdir/")
> ls
> #+end_src
> 
> # Local Variables:
> # eval: (org-babel-lob-ingest "Template-Loader.org")
> # eval: (org-sbe "Init-Template")
> # eval: (org-sbe "Execute-On-Load")
> # End:
> 
> -
> Template-Loader.org
> -
> #+STARTUP: showstars
> #+PROPERTY: header-args :mkdirp yes
> 
> #+name: Init-Template
> #+begin_src emacs-lisp :results none
>   ;; This is called expecitly via org-sbe in the buffer that will uses the
> templating
> (setq *DockerHubUID* "MyUserName")
> (setq *LocalWorkPath* "/run/desktop/mnt/host/c/Users/.")
> (setq *LocalDataPath* "/run/desktop/mnt/host/d/devData/")
> 
>   ;; ingest + SBE can be used to bring in a hierarchy of templates
>   (org-babel-lob-ingest "./GroupTools/GeneralORGTools.org")
>   (org-sbe "GeneralORGTools.org")
> 
> #+end_src


-- 
Salomon Turgman 



Re: Import Reusable org-babel snippet using #+SETUPFILE

2020-06-15 Thread Douglas Perrin
Hi Salomon Turgman,
I do this a lot and have had success using a combination of #+SETUPFILE to
bring in names and configuration, and org-sbe to do initialization. I mix
emacs vars and org names in my source headers with back quoting.

The following example has a template file containing user/local
information. This is brought into the example file, on load, through #:eval
calling org-babel-lob-ingest and org-sbe, in addition, parameters are
pulled in with #+SETUPFILE and the same template file name. The end result
for this example is a running docker image with access to local paths and
"remote" execution via tramp. More complex orchestration and actions in the
template are certainly possible using org-sbe calls in the init elisp
source blocks but hopefully, this shows the flavor of what can be done.

In addition to avoiding code duplication, I have found this to be very
effective when my group is all working from the same org file (via git) but
everyone has their own template file with credentials, local paths, and org
more preferences (ie showstars).
Regards,
Doug

-
TemplatingExample.org
-
#+SETUPFILE: Template-Loader.org

* Init Code, run when file is opened
#+name: Execute-On-Load
#+begin_src elisp  :results output
   ;; for this the container and image have the same name
(setq *DockerName* "ContanerName")
#+end_src

* Run Contaner
#+begin_src bash  :results raw drawer :var DockerName=`,*DockerName*
DockerHubUID=`,*DockerHubUID* containerName=`,*DockerContainer*
LocalWorkPath=`,*LocalWorkPath* LocalDataPath=`,*LocalDataPath*
   docker run --rm -d \
  -v $LocalWorkPath:/root/Workdir \
  -v $LocalDataPath:/root/Data \
  --name $DockerName $DockerHubUID/$DockerName bash -c "tail -f
/dev/null"
  #+end_src

* run IN contaner
#+begin_src bash  :results output :dir (concat "/docker:" `,*DockerName*
":/root/Workdir/")
ls
#+end_src

# Local Variables:
# eval: (org-babel-lob-ingest "Template-Loader.org")
# eval: (org-sbe "Init-Template")
# eval: (org-sbe "Execute-On-Load")
# End:

-
Template-Loader.org
-
#+STARTUP: showstars
#+PROPERTY: header-args :mkdirp yes

#+name: Init-Template
#+begin_src emacs-lisp :results none
  ;; This is called expecitly via org-sbe in the buffer that will uses the
templating
(setq *DockerHubUID* "MyUserName")
(setq *LocalWorkPath* "/run/desktop/mnt/host/c/Users/.")
(setq *LocalDataPath* "/run/desktop/mnt/host/d/devData/")

  ;; ingest + SBE can be used to bring in a hierarchy of templates
  (org-babel-lob-ingest "./GroupTools/GeneralORGTools.org")
  (org-sbe "GeneralORGTools.org")

#+end_src


Re: Import Reusable org-babel snippet using #+SETUPFILE

2020-06-09 Thread Nicolas Goaziou
Hello,

Salomon Turgman  writes:

> Now, if I include the definition in every org file that I want to use it,
> everything works well. However, if I include the definition in a central
> org file that I import using #+SETUPFILE, things break and I don't get the
> proper output in my html exports.

SETUPFILE only imports keywords.

> Is there a way that I can "import" that snippet without rewriting it in
> every file I need it?

See (info "(org) Library of Babel")

Regards,

-- 
Nicolas Goaziou



Import Reusable org-babel snippet using #+SETUPFILE

2020-06-09 Thread Salomon Turgman
Hello all,

I have created what I hoped was a reusable org-babel snippet that looks
like this:

#+NAME: simulation
#+HEADER: :var cap="DEFAULTCAPTION" :cache yes :eval no-export :var
altimage="1_image.svg#img1"
#+BEGIN_SRC emacs-lisp :var divid="defid" :var num=1 :results html :exports
results
(format
"cool string that uses parameters %s %s ..."
num cap divid altimage (capitalize divid) divid)
#+END_SRC

I will use this snippet with something like:

#+CALL: simulation(cap="bam", num=1, divid="bamid"...)

Now, if I include the definition in every org file that I want to use it,
everything works well. However, if I include the definition in a central
org file that I import using #+SETUPFILE, things break and I don't get the
proper output in my html exports.

Is there a way that I can "import" that snippet without rewriting it in
every file I need it?

Thanks in advance!

-s-