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

Indentation of some lines of transcluded python src block is modified #203

Open
sebmiq opened this issue Oct 22, 2023 · 2 comments
Open

Comments

@sebmiq
Copy link

sebmiq commented Oct 22, 2023

Hi,

I have an in.org file, whose content is

* Crible d’Ératosthène

#+BEGIN_SRC python
def crible(n):
    l = [True] * (n+1)
    l[0], l[1] = False, False
    i = 2
    while i*i <= n:
        if l[i]:
            k = 2
            while i*k <= n:
                l[i*k] = False
                k += 1
        i += 1
    return l
#+END_SRC

and an out.org file, whose content is

#+transclude: [[file:in.org::*Crible d’Ératosthène][Crible d’Ératosthène]]

When I activate the transclusion, it shows

* Crible d’Ératosthène

#+begin_src python 
def crible(n):
    l = [True] * (n+1)
    l[0], l[1] = False, False
    i = 2
    while i*i <= n:
        if l[i]:
            k = 2
            while i*k <= n:
                l[i*k] = False
                k += 1
                i += 1
    return l
#+end_src

Note that the i += 1 line had its indentation modified.

@sebmiq
Copy link
Author

sebmiq commented Oct 24, 2023

The issue is that org-transclusion-content-format-org calls org-indent-region, which, when org-src-tab-acts-natively is t, calls python-indent-region, which indents as shown.

I'm not sure what part is wrong, but this can be fixed in org-transclusion-content-format-org by setting org-src-tab-acts-natively to nil.

@nobiot
Copy link
Owner

nobiot commented Oct 24, 2023

Thank you for the report and the investigation. I am not sure what the best way to support this within the code base. The source code notes this:

;; Fix indentation when `org-adapt-indentation' is non-nil
org-transclusion-content-format-org

I don't think I can support every problem case, and this is my main reason to have the flexible mechanism to call org-transclusion-content-format-org as an abnormal hook.

(defvar org-transclusion-content-format-functions
  '(org-transclusion-content-format-org
    org-transclusion-content-format))

My immediate suggestion for you is to either override the function org-transclusion-content-format-org or define a custom function and set the variable org-transclusion-content-format-functions so that your custom function gets called.

I will be in a vacation from the end of this week for five weeks or so; I will not be able to provide an immmediate fix. I trust that with your skill you will be able to implement your own solution for now.

I will need to come back to the issue of indentation at a later stage -- at the moment, I don't see a good way to support the Org-src's indentation behavior in every case... I will be very happy if you or anyone can find a good solution.

Thank you.

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

2 participants