0

Question

I am live-coding. I would like to be able to change the major mode to and from org-mode without un-hiding any of the text that org-mode has hidden. I would switch to a code mode whenever I want that mode's syntax highlighting and smart indentation, and switch to org-mode whenever I want to fold, unfold and quickly jump between org headings.

Why org-edit-src-code is a poor solution when live-coding

In a live-coding setting, cursor navigation time and screen space are both at a premium. Therefore, cluttering the screen with #+begin_src / #+end_src brackets around each code snippet is problematic. It reduces the amount of code that can be visible, and it increases the time one must spend cursoring through "administrative" lines in order to get to the code.

Getting bounced to an auxiliary window to code the snippet is problematic, too, because it cuts the amount of context one can see by more than half (since the code being edited is duplicated in both windows, and because there's a line dedicated to separating the windows).

Another bad option: Simply switching major modes

I can switch modes easily enough, e.g. by typing M-x ha-mode <RET>. But when I do that, all the text that I had carefully collapsed pops back into view. Worse, if I then switch back to org-mode, everything but the top level collapses. I would like both transitions to have no effect on what text is visible.

My particular use case

I believe my question would be relevant to anyone live-coding. But about me:

I'm using https://tidalcycles.org. TidalCycles is a DSL for music written in Haskell. One can evaluate TidalCycles expressions interactively from within Emacs. I would like to keep my TidalCycles code in an org file, so that I can more easily hop around between stashed snippets.

I'm also visually impaired. There are only about 18 lines and 64 columns on my screen. Therefore wrapping a one-line code snippet in a heading and two _SRC brackets is very costly.

2
  • If the motivation is really just writing bracket lines would slow me down then use yasnippet or something. You can also beautify the brackets. See pank.eu/blog/pretty-babel-src-blocks.html and elsewhere.
    – mankoff
    Oct 13, 2023 at 14:41
  • @mankoff Thanks! You're right. Unfortunately that's not most of what bothers me about the brackets. Scattering brackets throughout the document eats up screen space and increases cursor navigation time, both of which are at a premium when live-coding (esp. if visually impaired, which I am). I've only got 15 lines on my screen. If a one-line code snippet is stashed under a heading and between two brackets, then that one-line snippet (when visible) occupies more than 25% of my screen. Oct 15, 2023 at 14:27

1 Answer 1

1

That’s built in to org mode. See chapter 16.10 Editing Source Code of the Org Mode manual. Basically, just go to a source block and type C-c ' to edit it in its native mode.

1
  • Thanks! Unfortunately that solution is problematic for two reasons: the #+BEGIN_SRC / #+END_SRC brackets, and the fact that it bounces you to an auxiliary window. Scattering brackets throughout the document eats up screen space and increases cursor navigation time, both of which are at a premium when live-coding (esp. if visually impaired, which I am). Similarly, the auxiliary window cuts half of the context I was able to see around the code I'm editing. More than half, actually, since the code to edit is duplicated in the two windows. Oct 15, 2023 at 14:22

Your Answer

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

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