10

I use org-babel to generate some reports which can't be automatically processed, and since org is a good outline format, I print the results in org to represent them as trees.

I've noticed that nesting org markup into #+begin_example block makes emacs really slow (and the formatting of the results is off, too).

It would be really cool to have babel place the output of certain code blocks to a separate buffer (and open a window for it too), the same way as it handles errors.

I've looked through documentation but it seems like there's no such option.

Am I wrong? If I'm not, maybe someone has such a snippet around?

Also, the slowness might be caused by some other options in my configuration, how's your experience with org formatted text nested into example? Maybe I'm barking under the wrong tree here.

Thanks

2
  • 1
    I should add that these are not huge or complicated reports. It's several hundred lines, two-three levels deep, under a hundred nodes overall. My actual org files are way bigger. Once I remove #+begin_example they work just fine Jun 10, 2016 at 17:07
  • 1
    I was able to create this new feature without too much trouble, but org-mode is always evolving and org-babel-insert-result is already rather quite long, and it will be even longer with this modification. Step #1: Decide on a new RESULT-PARAMS like the word separate. The source-code block can contain something like :results output separate Step #2: Turn the if/then statement that contains the condition (and result-params (member "silent" result-params)) into three conditions with the new one being (and result-params (member "separate" result-params)) and set new buf.
    – lawlist
    Apr 9, 2017 at 2:08

2 Answers 2

9

I've looked through documentation but it seems like there's no such option.

Surprising that org does not offer :output buffer option. Maybe this is in the works for future org versions.

... place the output of certain code blocks to a separate buffer...

Here's one way to simulate that functionality: take the output of one source block and stream it into a new buffer:

#+NAME: mycontent
#+BEGIN_SRC emacs-lisp :results value :results raw :exports results
(print "this content is streamed to a new buffer")
#+END_SRC

#+NAME: mystream
#+BEGIN_SRC emacs-lisp :var c=mycontent :results none
(prin1 c (generate-new-buffer "new"))
#+END_SRC

Because mycontent source block feeds the content to mystream, you will have to execute only the mystream src block. That is, C-c C-c on mystream block.

If you C-c C-c on the mycontent src block, then the results will be inserted in the same buffer.

Although mycontent is shown as an emacs-lisp src block, this can be any valid org src block. You may have to adjust the :results options based on the language.

The :results none for the mystream src block is counter-intuitive, but the magic that gets your content into a new buffer.

0
5

Since I've accepted the answer I've been living with that 'have elisp snippet for each report I want' setup for a while.

But then I've came up with the following trick:

There is a way to open org-babel outpupt in a separate buffer with C-o - org-open-at-point is fancy like that. The problem is, the result block is created. But there is also a command org-babel-remove-result. Combining the two, I made a little dirty hack

(defun my-babel-to-buffer ()
  "A function to efficiently feed babel code block result to a separate buffer"
  (interactive)
  (org-open-at-point)
  (org-babel-remove-result)
)

(defun my-org-mode-config ()
  "To use with `org-mode-hook'"
  (local-set-key (kbd "C-`") 'my-babel-to-buffer)
)

(add-hook 'org-mode-hook 'my-org-mode-config)

The codeblocks I use like that have properties :results output :format raw :exports results

My file with tips and howtos is no longer cluttered with large outputs and the buffer is reused (which suits my workflow).

2
  • If you want this behavior all the time, you can use your custom command as a hook: (add-hook 'org-babel-after-execute-hook 'my-bable-to-buffer))).
    – glucas
    Feb 19, 2018 at 14:52
  • No, just in some cases, to grab a report of puppet failures or something like that. Feb 20, 2018 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.