brightlystar · 2022-11-11 10:43
It takes a lot of typing to add code blocks in org-mode file. Example:
This is text.
#+begin_src
print('hello, this is code')
#+end_src
This is text again.
Even if we reduce typing with convenient key bindings, this way of writing code blocks also adds a lot of clutter to the org-mode file. Is there some way to use simpler syntax to make code blocks? I like how easy it is to make code blocks in Markdown with triple-backquotes. Someone knows something similar for org-mode?
arthurno1 · 2022-11-11 11:00
> It takes a lot of typing to add code blocks in org-mode file.
Have you tried [structure templates](https://orgmode.org/manual/Structure-Templates.html)?
You could also define your own abbrevs, or a small function to bind on a key to insert text for a src block.
> this way of writing code blocks also adds a lot of clutter to the org-mode file.
For the clutter, you can try [hiding src blocks](https://github.com/amno1/org-babel-hide-markers-mode) or if you prefer [hide all markup](https://github.com/amno1/org-view-mode).
> I like how easy it is to make code blocks in Markdown with triple-backquotes. Someone knows something similar for org-mode?
Org markup is much more powerful than Markup in Markdown mode. You can evaluate source blocks in org-mode, use return values in other source blocks and some other stuff which you can't do in Markdown mode, since Markdown is just for exporting to HTML. As a result, org markup is more complex, too.
hungry_m8 · 2022-11-11 11:49
there are abbrevs, skeletons, snippets, or write your own functions, or the built-in C-c C-, s
if you don't like having to use multiple lines for just a code block of 1 line, there are also inline code blocks (and you can further use abbrevs, skeletons, etc)
pathemata · 2022-11-11 13:12
`org-insert-structure-template` and `org-modern`.
xenodium · 2022-11-11 14:49
I wrote something for this https://github.com/xenodium/company-org-block
gonz808 · 2022-11-11 18:12
> or the built-in C-c C-, s
I do not have that binding. Wha tis it bound to?
hungry_m8 · 2022-11-11 18:20
`C-c C-,` is bound to `org-insert-structure-template`
then `s` to select the src block.
schmooser · 2022-11-11 20:13
After (require 'org-tempo), <s TAB expands into a source code block. <q and <e expand to quote and example, correspondingly.
nickanderson5308 · 2022-11-12 05:59
I use yasnippet for inserting code blocks.
fatfingerdeathcrunch · 2022-11-12 07:31
I use tempel for that, which inserts the boilerplate and after choosing mode, it opens the edit buffer C-c '. Comes in handy.
gonz808 · 2022-11-12 16:40
Thanks. I have to enable them via org-use-extra-keys