emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ‘org-test-with-temp-text’ fails weirdly


From: Nicolas Goaziou
Subject: Re: ‘org-test-with-temp-text’ fails weirdly
Date: Thu, 14 May 2020 16:06:38 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)

Hello,

Göktuğ Kayaalp <address@hidden> writes:

> I was trying to have spurious indentation removed from Python source
> blocks before execution so that such blocks can be indented in Org mode
> buffers.

Removing indentation from Python blocks sounds like a bad idea. Do you
have an example demonstrating what you need?

> I think the cause is the modifications to the code blocks body (deletion
> of spurious indentation from an indented src block), but I’m not sure
> how exactly.
>
> This is weird because the in-buffer text doesn’t change.

Do you have a reproducer for this? Ideally, using Emacs Lisp instead of
Python.

> In any case I’m also proposing the attached patch as a new feature.
> Could start a new thread for it if necessary.

> +(defun org-babel-python--clean-spurious-indentation (body)
> +  (let* ((extra-indentation
> +       (save-match-data
> +         (string-match "\\`\\([ \t]+\\)" body)
> +         (match-string 1 body)))
> +      (xlen (length extra-indentation)))
> +    (if (zerop xlen)
> +     body
> +      (mapconcat
> +       (lambda (line) (if (<= (length line) xlen)
> +                       line
> +                     (if (string= extra-indentation
> +                                  (substring line 0 xlen))
> +                         (substring line xlen)
> +                       line)))
> +       (split-string body "\n")
> +       "\n"))))

I think `org-remove-indentation' does about the same. It does not
systematically use first line as reference, though.

Regards,

-- 
Nicolas Goaziou



reply via email to

[Prev in Thread] Current Thread [Next in Thread]