0

I want to do literate programming. Entering language after every code block is prone to errors and distracting. To make matters worse, I do not know how to verify if all my blocks were tangled. I can end up in a situation where my code does not work because I forgot language after #+begin_src

Is it possible to declare at the top of the file a default language for all code blocks? Is there an example available? I have spent a few hours in vain trying to digest contradicting advice possibly created for different versions of org-mode. I use org-mode 9.5.3

5
  • I am not sure what kind of contradicting advice you have 'digested', but I would advise you to either use org-babel-demarcate-block (using some handy shortcut), or create useful snippets with yasnippet (using either a shortcut, or maybe even handier keys + expansion). You might use snippets you find on the web, but it is easy enough to create custom snippets yourself. May 10 at 11:35
  • Your advice does not answer my question. If I understand you correctly you suggest something like typing scb and using emacs to expand it into a source code block with declared language. I can press a shortcut C-c , s to get a generated source code block. I want it to leave it as it is without adding any headers to the block. there seems to be a possibility to do what I need in the properties at the top of the org file. Doing it that way would be more flexible if I wanted different literate files for different langiages. May 10 at 11:46
  • emacsdocs.org/docs/org/Structure-of-Code-Blocks#language says the language is mandatory. So there must have been a change in the org mode. Please correct me if I am wrong. May 10 at 12:16
  • Indeed, therefore I did not post it as an answer. Can you tell me what C-c , s does? With yasnippet keys you can e.g. insert 'p' followed by your shortcut for yas-maybe-expand to insert a python code block, and 'r' + the shortcut, to enter a ruby code block. I am not sure why you think your approach is more flexible, but you should use the solution that you prefer of course. I just wasn't sure about the advice you had already digested. At least, now it is clear that this advice does not include a satisfactory solution. May 10 at 12:18
  • I have seen some vague document written years ago suggesting I could have the language argument defined once at the top of the file. May 10 at 12:23

1 Answer 1

2

It is not possible now. The documentation says the language argument is mandatory.

https://emacsdocs.org/docs/org/Structure-of-Code-Blocks#language

At the top of the file, I can have the property

#+PROPERTY: header-args :tangle "./some-file.el"

Then I can have some content and the block:

#+begin_src emacs-lisp
(provide 'some-file)
;;; some-file.el ends here
#+end_src

So I do not have to repeat that tangle in every code block, but the language, in this case, emacs-lisp is mandatory. The suggested way around the problem was using yasnippet. https://github.com/joaotavora/yasnippet

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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