by skookumchuck · 7y ago · 0 comments
: Simple pre-formatted text such as for source code.
: This also respects the line breaks. *bold* is not bold here.
The trouble with that is you cannot easily copy/paste code to/from it, because you'll need to manually add/subtract the : prefix. Delineating the section with: ```
Simple pre-formatted text such as for source code.
This also respects the line breaks. *bold* is not bold here.
```
is much more practical. #+BEGIN_SRC lisp
(format t "Hello world!~&")
#+END_SRC
but it has two things going for it.One, it's consistent with other blocks, like BEGIN_QUOTE, BEGIN_EXAMPLE, BEGIN_VERSE, etc. (n.b. all four have a default shorthand that gets tab-expanded; <s. <q, <e and <v, respectively) , and with arbitrary user-defined blocks like BEGIN_whatever.
Two, while #+BEGIN_SRC may seem only an unnecessarily verbose way of writing ```, things change when the block starts to look like this:
#+NAME: advanced-block
#+BEGIN_SRC lisp :package my-package :var foo=123 :var bar=asdf :noweb yes :exports both :eval never-export
<<preamble>>
(format t "Hello ~A!~&" <<some-other-block(param=3.14)>> )
#+END_SRC
AKA. a named source block (so I can reference it elsewhere) of Lisp executing in selected Lisp package, with org mode variables injected into it, using noweb syntax (literate programming) for injecting other code blocks[0], which when exporting the document to a different format (say, PDF) will export both code and results of its evaluation, but will not automatically evaluate the code.This feature makes Org Mode essentially a kind of better Jupyter, with automatic support for any and all possible language that you can plug into Emacs, simultaneously.
--
[0] -- here, it'll paste the literal contents of #+BEGIN_SRC block with #+NAME: preamble at the beginning, and then paste the results of executing a block with #+NAME: some-other-block, with value 3.14 for its :var param, at the end
#+NAME: advanced-block
#+HEADER: :noweb yes :exports both :eval never-export
#+HEADER: :package my-package :var foo=123 :var bar=asdf
#+BEGIN_SRC lisp
<<preamble>>
(format t "Hello ~A!~&" <<some-other-block(param=3.14)>> )
#+END_SRC
(Just wanted to point out that the header format has even more flexibility than what you've shown!) #+BEGIN_SRC sh
#!/bin/sh
echo "foobar"
#+END_SRC
That also works in org-mode, and then you get syntax highlighting for the language etc. It can even open that block to edit in a separate buffer with the right major mode loaded for that language.At that point, adding or removing a ':' is not a repetitive task. Then the ':' notation gains an advantage because selected lines can be copied and automatically keep their formatted status.
The very first line after the disclaimer even reads "Please do note that this is not about Emacs".