Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indenting Org Babel's Source Blocks #6

Open
beetleb opened this issue Feb 17, 2021 · 2 comments
Open

Indenting Org Babel's Source Blocks #6

beetleb opened this issue Feb 17, 2021 · 2 comments

Comments

@beetleb
Copy link

beetleb commented Feb 17, 2021

I've noticed in a lot of your videos you copy/paste code into an Emacs lisp source block and then manually fix the indent.

This is Emacs lisp - it's trivial to autoindent it! Below is a function that will do this for you:

(defun mn:indent-src-block ()
  (interactive)
  (org-edit-special)
  (indent-region (point-min) (point-max))
  (org-edit-src-exit))

Simply invoke it while the point is in a source block.

@daviwil
Copy link
Owner

daviwil commented Feb 17, 2021

Thanks! I'll give it a shot

@sexptherapy
Copy link

sexptherapy commented Jun 21, 2021

indent-region is already bound by default to C-M-\. The problem with just pressing that command at an org source code block without a region is that, ironically, sometimes it breaks the indentation of the block delimiters (#+end_src). A way around that is to bind C-M-\to org-indent-region when inside org (I don't know why it isn't by default). This way you can just press that command and it will do the right thing (at least in my tests, it does).

Still, I've got used to either use M-h to org-mark-element (or mark-paragraph elsewhere) and follow that with C-M-\ or, more often, just do a few C-M-u to backward-up-list until I reach the scope that needs indentation (usually one or two times) and then invoke C-M-\. I like that it is one workflow that fits every scenario, including editing source code blocks, and doesn't require any extra configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants