emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: "Göktuğ Kayaalp" <self@gkayaalp.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: ‘org-test-with-temp-text’ fails weirdly
Date: Thu, 14 May 2020 16:06:38 +0200	[thread overview]
Message-ID: <87pnb68vbl.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <87h7wsjxgf.fsf@gkayaalp.com> ("Göktuğ Kayaalp"'s message of "Thu, 07 May 2020 05:22:24 +0300")

Hello,

Göktuğ Kayaalp <self@gkayaalp.com> 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	other threads:[~2020-05-14 14:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-07  2:22 ‘org-test-with-temp-text’ fails weirdly Göktuğ Kayaalp
2020-05-14 14:06 ` Nicolas Goaziou [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87pnb68vbl.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=self@gkayaalp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).