# Tag Info

108

As @kaushalmodi mentions in the comments you can use (org) Structure Templates to speed up insertion of different types of blocks. The general procedure is to insert < followed by a template selector (usually a single letter) on an otherwise empty line and press TAB. The template selector for a generic source block template is s, so typing <s ...

47

Yes, you certainly can, you can use org-babel-load-file to do this. In your init.el, put the following: (require 'org) (org-babel-load-file (expand-file-name "settings.org" user-emacs-directory)) (I'm using ~/.emacs.d/settings.org but that is personal preference). In the settings.org file you can arrange it however you would like, ...

44

I think this problem is caused by the change of org-babel-check-confirm-evaluate from a macro to a function. If you have org-mode (and thus the old macro) loaded when you compile the new code, it sees the old macro instead of the new function. As others have pointed out uninstalling org-mode restarting Emacs (without loading org-mode) and reinstalling will ...

38

To elaborate on @erikstokes: rm ~/.emacs.d/elpa/ORGDIRNAME/*.elc where ORGDIRNAME is the name of the core ogrmode directory. Restart emacs and you can now run org-babel code blocks.

29

You should have every header argument in one line: #+PROPERTY: header-args :session *my_python_session* :results silent :tangle yes Having several #+PROPERTY lines is accepted, but not in the way you're trying to do it. From the Org manual (7.1 Property syntax): If you want to add to the value of an existing property, append a ‘+’ to the property ...

28

You really only need this bit in your init file: (org-babel-do-load-languages 'org-babel-load-languages '((C . t))) Note it's a capital C. This enables Babel to process C, C++ and D source blocks.

22

If all you want is selective showing of sections and navigation between headings, you don't need Org mode. All you need is Outline mode. Outline mode is basically the header level and section visibility management of Org mode. In fact, Org mode was originally the author's extensions to Outline mode, and grew, and grew, and grew… Even today, org-mode is ...

19

This is a peculiarity of how babel handles some languages. This gives some detail on python, and a complete list of options is available here. There are quite a few useful ones. Basically, depending on the language, there are several options for output. Sometimes it makes sense to use the standard output (what print does), for other languages (eg octave), ...

18

You should not repeat such things, but define them in one place. For example you can define output file in a drawer as header args for whole tree and subtrees: * Header :PROPERTIES: :tangle: ~/dir/my/testfile.el :END: or for :dir * Header :PROPERTIES: :header-args: :dir ~/dir/my/dir/ :END: As described in docs you can have: System-wide header arguments ...

17

In a very simple case like this one, there's a hack I tend to use, replace print with return: #+BEGIN_SRC python return "hello" #+END_SRC #+RESULTS: : hello But in general the better solution will be to use :results output, as mentioned by user2699. #+BEGIN_SRC python :results output print("hello") #+END_SRC #+RESULTS: : hello

16

Figured it out: #BEGIN_SRC python :exports both :results output code :wrap "SRC c++"

15

You can do this most easily using org-babel's noweb reference syntax for literate programming. Here is an example: * Initialization block containing function definition #+NAME: init_block #+BEGIN_SRC python constant=19 def some_function(x): return constant * x #+END_SRC * Call the function on an integer #+BEGIN_SRC python :noweb yes <<...

15

Why not write it yourself? (defun org-insert-source-block (name language switches header) "Asks name, language, switches, header. Inserts org-mode source code snippet" (interactive "sname? slanguage? sswitches? sheader? ") (insert (if (string= name "") "" (concat "#+NAME: " name) ) (format " #+BEGIN_SRC %s %s %s #+END_SRC" ...

15

You can use something like: emacs --batch --eval "(require 'org)" --eval '(org-babel-tangle-file "file-to-tangle.org")' (That shell quoting is meant for Bash, adjust if you use a different shell.) EDIT: Thanks to @SkydiveMike for pointing out I had mistakenly written org-babel-tangle instead of org-babel-tangle-file.

14

Literate programming takes you the most way there, org-mode supports it via org-babel. Two possible solutions are explained on @malabarba's blog: The simplest way is loading org-mode, then using its untangling feature to load a literate Emacs configuration: (require 'org) (org-babel-load-file (expand-file-name "emacs-init.org" user-...

14

tl;dr Disable the checker emacs-lisp-checkdoc with the org-src-mode-hook. (defun disable-fylcheck-in-org-src-block () (setq-local flycheck-disabled-checkers '(emacs-lisp-checkdoc))) (add-hook 'org-src-mode-hook 'disable-fylcheck-in-org-src-block) Detailed walkthrough how to find this information First search for possible variables which change the ...

12

You can add advice to org-latex--inline-image: (advice-add 'org-latex--inline-image :around (lambda (orig link info) (concat "\\begin{center}" (funcall orig link info) "\\end{center}"))) Note that this puts every inline image in \begin{center} ... \end{center}, even ones that are ...

12

#+begin_src sql :engine postgresql :cmdline "-U wvxvw -W secret -d personal" select * from phonebook; #+end_src #+RESULTS: | name | phone | |------+----------------| | Dad | XXX-XX-XXXXXXX | | Mom | YYY-YY-YYYYYYY | #+header: :var pn="phone" #+begin_src sql :engine postgresql :cmdline "-U wvxvw -W secret -d personal" select $pn from phonebook; #+... 12 I'm not sure how you could extract these to custom headers, but you can put raw ELISP in your header arguments. So, to conditionally tangle, you can simply put a check in your :tangle argument like so: #+BEGIN_SRC emacs-lisp :tangle (when (eq system-type 'gnu/linux) "yes") (princ "I DO THINGS! (But only on Linux.)") #+END_SRC When the file gets tangled ... 12 A solution that doesn't depend on org-export-filter-src-block-functions and gives you more flexibility is using the :exports header argument (see (info "(org) Exporting code blocks")). Setting the argument to :exports none results in neither the code block nor its results being exported. If you prefer a backend specific rule, you may use a conditional as ... 11 This answer provides a workable workaround. The easiest way to do this would be using easy templates. Add your templates to the org-structure-template-alist: (add-to-list 'org-structure-template-alist '("py" "#+BEGIN_SRC python :results output\n?\n#+END_SRC" "")) The question mark indicates the cursor position. Insert the code block with <py ... 11 org-confirm-babel-evaluate can be set to nil to disable confirmation. From the documentation: Source code blocks Source code blocks can be evaluated during export, or when pressing ‘C-c C-c’ in the block. The most important thing to realize here is that Org mode files which contain code snippets are, in a certain sense, like ... 11 You need to use the :exports both header argument. By default, org only exports R code, not the results. From the org manual: 14.8.2.8 :exports The :exports header argument is to specify if that part of the Org file is exported to, say, HTML or LaTeX formats. Note that :exports affects only ‘src’ code blocks and not inline code. code The default.... 11 Try doing the following: cd .emacs.d/elpa/ # I suggest to run this without "delete" first. find org* -name "*.elc" -delete This will delete all compiled elisp files from org. The problem is likely to be caused by conflicts between Org Mode that ships with Emacs and Org 9. Restart Emacs afterwards and everything should work fine. 11 Org-mode files get exported to PDF with the document preparation system LaTeX. Code blocks by default get exported into verbatim environment which does not have line wrapping. You can see this by visiting the .tex file created in the same folder when you export; your code blocks should look like this: \begin{verbatim} import socket # etc \end{verbatim} ... 10 The original question has been modified to concern running multiple versions of an executable, and not simply independent interpreters. Using find-library I inspected the source of ob-ruby, which includes this code: (defvar org-babel-ruby-command "ruby" "Name of command to use for executing ruby code.") I have seen references elsewhere for python using ... 10 You can achieve that by naming your results table. Then, the code block will update the same table it used as input. #+begin_src emacs-lisp :var table=mytable (append table '((1 2 3))) #+end_src #+name: mytable #+RESULTS: | 0 | 0 | 0 | | 0 | 0 | 0 | | 1 | 2 | 3 | To have the greater flexibility that the OP had in mind: it isn't necessary to have the ... 10 While I personally don't use babel much, going from the example, this should simply be: (defun my-org-confirm-babel-evaluate (lang body) (not (member lang '("C" "clojure" "sh")))) (setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate) Where C, clojure and sh should be replaced by the languages you don't want the confirmation for. 10 Here's a simple way to fix your code by naming the src block instead of results: #+name: piped #+header: :exports code #+header: :results output #+begin_src sh echo "That goes to the next" #+end_src #+RESULTS: : That goes to the next #+header: :exports results #+header: :stdin piped #+header: :results output #+begin_src sh VALUE=$(cat) echo "I got:" echo ...

10

I'm seeing he same issue. In a little digging, I think I've identified the problem. However, not sure who this should be reported to. The problem is in the org-babel-execute:clojure function. This function has the following bit of code (setq result (nrepl-dict-get (nrepl-sync-request:eval expanded (cider-current-connection) (cider-current-...

Only top voted, non community-wiki answers of a minimum length are eligible