emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Babel: Programmatically evaluate a heading and subtrees?
@ 2021-02-20 19:10 Nathan Neff
  2021-02-27 13:18 ` ian martins
  2021-03-01 23:26 ` Ken Mankoff
  0 siblings, 2 replies; 4+ messages in thread
From: Nathan Neff @ 2021-02-20 19:10 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 637 bytes --]

Hello all,

I have some code like this:

* Heading 1

# code block name:FOO

** Subheading 1

# code block

** Subheading 2

# code block

I find that I often want to evaluate the code in Heading 1 and its
subheadings.

Currently, I navigate to Heading 1 and then use org-babel-execute-subtree

I see that there's a function called org-babel-goto-named-src-block, so I
think
I could write a small function to jump to FOO in Heading 1 and then run
execute subtree
and then jump back to my previous location in Emacs.

Is there a more programmatic or built-in way?  For example:
org-babel-execute-block-and-subheadings FOO

Thanks,
--Nate

[-- Attachment #2: Type: text/html, Size: 996 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Babel: Programmatically evaluate a heading and subtrees?
  2021-02-20 19:10 Babel: Programmatically evaluate a heading and subtrees? Nathan Neff
@ 2021-02-27 13:18 ` ian martins
  2021-03-01  2:12   ` Nathan Neff
  2021-03-01 23:26 ` Ken Mankoff
  1 sibling, 1 reply; 4+ messages in thread
From: ian martins @ 2021-02-27 13:18 UTC (permalink / raw)
  To: Nathan Neff; +Cc: emacs-orgmode

Can you use noweb? In the example below, if you run the top code block
babel will run the two that follow.

A drawback is that you have to redefine variables, but it might be a
benefit, since the individual blocks could be set with test data and
the "main driver" could point to real data.
-------

#+begin_src elisp :results output :noweb yes :var data=data1
  <<fun1>>
  <<fun2>>
#+end_src

#+RESULTS:
: called fun1: some data
: called fun2

#+name: data1
some data

#+name: fun1
#+begin_src elisp :var data=data1
(princ (format "called fun1: %s" data))
#+end_src

#+name: fun2
#+begin_src elisp
(princ "called fun2")
#+end_src

On Sat, Feb 20, 2021 at 2:11 PM Nathan Neff <nathan.neff@gmail.com> wrote:
>
> Hello all,
>
> I have some code like this:
>
> * Heading 1
>
> # code block name:FOO
>
> ** Subheading 1
>
> # code block
>
> ** Subheading 2
>
> # code block
>
> I find that I often want to evaluate the code in Heading 1 and its subheadings.
>
> Currently, I navigate to Heading 1 and then use org-babel-execute-subtree
>
> I see that there's a function called org-babel-goto-named-src-block, so I think
> I could write a small function to jump to FOO in Heading 1 and then run execute subtree
> and then jump back to my previous location in Emacs.
>
> Is there a more programmatic or built-in way?  For example:
> org-babel-execute-block-and-subheadings FOO
>
> Thanks,
> --Nate


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Babel: Programmatically evaluate a heading and subtrees?
  2021-02-27 13:18 ` ian martins
@ 2021-03-01  2:12   ` Nathan Neff
  0 siblings, 0 replies; 4+ messages in thread
From: Nathan Neff @ 2021-03-01  2:12 UTC (permalink / raw)
  To: ian martins; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1910 bytes --]

On Sat, Feb 27, 2021 at 7:18 AM ian martins <ianxm@jhu.edu> wrote:

> Can you use noweb? In the example below, if you run the top code block
> babel will run the two that follow.
>

Hi Ian, yes, I can run the top code block *manually* by navigating to that
block and then evaluating it.  I would like to define a keyboard shortcut
that
will call the function and its subheadings' functions.


>
> A drawback is that you have to redefine variables, but it might be a
> benefit, since the individual blocks could be set with test data and
> the "main driver" could point to real data.
> -------
>
> #+begin_src elisp :results output :noweb yes :var data=data1
>   <<fun1>>
>   <<fun2>>
> #+end_src
>
> #+RESULTS:
> : called fun1: some data
> : called fun2
>
> #+name: data1
> some data
>
> #+name: fun1
> #+begin_src elisp :var data=data1
> (princ (format "called fun1: %s" data))
> #+end_src
>
> #+name: fun2
> #+begin_src elisp
> (princ "called fun2")
> #+end_src
>

I don't see an example of calling these blocks programmatically.
I will research the docs a bit more.  Thanks!


> On Sat, Feb 20, 2021 at 2:11 PM Nathan Neff <nathan.neff@gmail.com> wrote:
> >
> > Hello all,
> >
> > I have some code like this:
> >
> > * Heading 1
> >
> > # code block name:FOO
> >
> > ** Subheading 1
> >
> > # code block
> >
> > ** Subheading 2
> >
> > # code block
> >
> > I find that I often want to evaluate the code in Heading 1 and its
> subheadings.
> >
> > Currently, I navigate to Heading 1 and then use org-babel-execute-subtree
> >
> > I see that there's a function called org-babel-goto-named-src-block, so
> I think
> > I could write a small function to jump to FOO in Heading 1 and then run
> execute subtree
> > and then jump back to my previous location in Emacs.
> >
> > Is there a more programmatic or built-in way?  For example:
> > org-babel-execute-block-and-subheadings FOO
> >
> > Thanks,
> > --Nate
>

[-- Attachment #2: Type: text/html, Size: 3115 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Babel: Programmatically evaluate a heading and subtrees?
  2021-02-20 19:10 Babel: Programmatically evaluate a heading and subtrees? Nathan Neff
  2021-02-27 13:18 ` ian martins
@ 2021-03-01 23:26 ` Ken Mankoff
  1 sibling, 0 replies; 4+ messages in thread
From: Ken Mankoff @ 2021-03-01 23:26 UTC (permalink / raw)
  To: Nathan Neff; +Cc: emacs-orgmode

Hi Nathan,

On 2021-02-20 at 11:10 -08, Nathan Neff <nathan.neff@gmail.com> wrote...
> I have some code like this:
>
> * Heading 1
>
> # code block name:FOO
>
> ** Subheading 1
>
> # code block
>
> ** Subheading 2
>
> # code block
>
> I find that I often want to evaluate the code in Heading 1 and its
> subheadings.
>
> Currently, I navigate to Heading 1 and then use org-babel-execute-subtree
>
> I see that there's a function called org-babel-goto-named-src-block,
> so I think I could write a small function to jump to FOO in Heading 1
> and then run execute subtree and then jump back to my previous
> location in Emacs.
>
> Is there a more programmatic or built-in way? For example:
> org-babel-execute-block-and-subheadings FOO

What about,

(defun my/eval-parent-subtree()
  (save-excursion
    (outline-up-heading 1)
    (org-babel-execute-subtree)))

And then binding that to some key or something? Or (outline-up-heading 99) if you always want to go to "*". Or make that line a bit more dynamically controllable by use of 'prefix-arg' ?

  -k.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-01 23:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-20 19:10 Babel: Programmatically evaluate a heading and subtrees? Nathan Neff
2021-02-27 13:18 ` ian martins
2021-03-01  2:12   ` Nathan Neff
2021-03-01 23:26 ` Ken Mankoff

Code repositories for project(s) associated with this 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).