l...@phdk.org writes:

> When adding a newline to an org-src block with
> `org-src-tab-acts-natively' set to t, if there's a non-whitespace
> character following the pointer at insertion, all other lines are
> indented by an additional `org-edit-src-content-indentation'
> regardless of their original indentation.
>
> MRE with -Q on the current dev branch:
> Put the pointer between foo and bar in the following src block and
> press enter repeatedly.
>
> #+begin_src fundamental
>   foobar
> #+end_src

Confirmed.
The first indent is valid - Org ensures that previously unindented line
is indented to `org-edit-src-content-indentation'. However, the
following indents are indeed not right.

> What's happening is that before indenting, `org-remove-indentation'
> removes indentation equal to the least indented line in the block,
> which in this case is 0. It then inserts it in the src-edit buffer,
> runs the modes indentation, and adds the org-src content indentation
> again before reinserting it in the org buffer.
>
> I've attached the monkeypatch that I cooked up for myself. It passes
> tests and hasn't caused any issues for me yet, but Ihor's answers to a
> similar sounding report [1] makes me a bit uncertain on what the
> intended behavior is. I'm not really sure if might somehow be a
> breaking change. If the behavior is unintended but this patch is
> breaking, an alternative could be making `org-src-tab-acts-natively'
> always reindent the entire block, but that seems overkill to me.

Note that in the previous report I was only talking about the first
indent. I did not anticipate that repeated <RET> will cause such
breakage.

>                   ;; rather than `indent-line-function' here or we may
>                   ;; sometimes break `electric-indent-mode'
>                   ;; 
> https://orgmode.org/list/5O9VMGb6WRaqeHR5_NXTb832Z2Lek_5L40YPDA52-S3kPwGYJspI8kLWaGtuq3DXyhtHpj1J7jTIXb39RX9BtCa2ecrWHjijZqI8QAD742U=@proton.me
> +                 (save-excursion
> +                   (beginning-of-line)
> +                   (insert-char #x20 block-content-ind))

This looks about right.
May you please:
1. Use `insert' rather than `insert-char' that is for interactive use.
2. Use more readable ?\t notation
3. Add a comment linking to this report and explaining why we need it
4. Write a simple test so that we avoid future regressions

-- 
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

Reply via email to