emacs-orgmode
[Top][All Lists]
Advanced

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

Re: begin_src Indentation in org 9.4.4, 9.4.5


From: Sébastien Miquel
Subject: Re: begin_src Indentation in org 9.4.4, 9.4.5
Date: Mon, 17 May 2021 09:02:47 +0000

Hi Bastien,

The commit `bfda3cc7df31fa79222efb4c190618c3c85a3d04` breaks automatic
(electric) indentation  in src blocks for all configurations.

Here's what happens with the original issue.

When you press `RET` after the first ~hello hi~, the result is that
the first line is indented by two spaces, and the second (where the
point is) isn't.
 - since ~electric-indent-mode~ is on, ~org-return~ is called with
   `indent` set to `t`.
 - Since ~org-src-tab-acts-natively~ is `t`, indentation is done by
   calling `tab` in a src edit buffer, which by itself, does nothing.
 - The observed indentation comes from ~org-src--contents-for-write-back~.
   Since ~org-src--content-indentation~ is 2 and ~org-src--preserve-indentation~
   is ~nil~, this functions further indents each *non blank* line by 2.

At this point, the first line is indented, cursor is at bol. Note
that you cannot indent your current empty line with `tab`. You can
either indent it manually, or call ~org-edit-special~.

When you write your second line, then press `RET`,
~org-src--contents-for-write-back~ will add an additional two spaces,
producing the reported result.

I think a reasonable fix is to have ~org-src--contents-for-write-back~
also indent blank lines. To do this, you need only remove following
line from its definition.

: (unless (eolp)        ;ignore blank lines

With this done and `bfda3cc7df31fa79222efb4c190618c3c85a3d04`
reverted, the original issue is fixed, and the behaviour is better:
when you press `RET` to enter a newline in a src block, it is
automatically indented.

The downside is that, unless ~org-src--preserve-indentation~ is `t`,
when editing a src block, every empty line will be indented with
spaces (according to ~org-edit-src-content-indentation~ + the
indentation of the #+begin_src line). I think this is reasonable, but
perhaps some might disagree.

Regards,

--
Sébastien Miquel




reply via email to

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