wbolster / emacs-python-black

Emacs package to reformat Python using black-macchiato
BSD 3-Clause "New" or "Revised" License
95 stars 11 forks source link

`python-black-org-mode-block` doesn't respect `org-src-preserve-indentation` #20

Open nick4f42 opened 1 week ago

nick4f42 commented 1 week ago

If org-src-preserve-indentation is nil and org-edit-src-content-indentation is non-zero (both are by default), python-black-org-mode-block fails because of the indentation.

For example, with (setq-local org-src-preserve-indentation nil org-edit-src-content-indentation 2), this Org markup:

#+begin_src python
  x = 1
#+end_src

corresponds to this code:

x = 1

But, our function currently sees it with extra indentation:

  x = 1

org-edit-src-code is a user command for editing a source block in a different buffer, and it handles the indentation and de-indentation according to these settings. It also escapes certain characters, as #18 addressed. It does update the window configuration though, so we'd have to work around that if we were to use it.

wbolster commented 1 week ago

good catch. i do not use org myself. patches welcome 🙃