emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [BUG] Source block indentation does not work properly for yaml-mode


From: Ihor Radchenko
Subject: Re: [BUG] Source block indentation does not work properly for yaml-mode [9.6.6 ( @ /home/user/.emacs.d/elpa/org-9.6.6/)]
Date: Wed, 14 Jun 2023 12:16:58 +0000

wolf <wolf@wolfsden.cz> writes:

> Reproduction steps:
> 1. Have org-mode and yaml-mode installed.
> 2. C-x C-f /tmp/x.org RET
> 3. Type in:
>
> #+begin_src yaml
>   a:
>     b:
>       c:
>       d:
> #+end_src
>
> After each line, press RET to go to the next one.  RET is bound to org-return.
> Notice that when you press RET after `c:', emacs will insert a TAB character,
> instead of expected 8 spaces.

Confirmed.
This is caused by `org-src--contents-for-write-back' not adjusting
blank line indentation in some cases.

The attached diff will fix the issue, but git log reveals that the whole
thing is fragile - we adjusted code in this area multiple times with
a number of tricky special cases:

https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=e1c49af76
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=70e65a202
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=ee0fd1ec3
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=70e65a202
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=857ae366b
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=91236a3db

https://orgmode.org/list/0f961d3b-a4ef-fbbf-ab16-7ff1af8b2070@gmail.com
https://orgmode.org/list/5DCBAF63-0E88-44AC-B892-1260F37E7E00@manicmind.earth

CCing Bastien and Sébastien, the authors of the previous commits in this
area.

I feel that the whole approach we use now with preserve-fl, use-tabs?,
and preserve-blank-line is overcomplicated. Maybe someone can explain
why we need all these special cases? The code does not reveal a whole lot.

diff --git a/lisp/org-src.el b/lisp/org-src.el
index 317682844..876310867 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -499,12 +499,9 @@ (defun org-src--contents-for-write-back (write-back-buf)
        (when preserve-fl (forward-line))
         (while (not (eobp))
          (skip-chars-forward " \t")
-          (when (or (not (eolp))                               ; not a blank 
line
-                    (and (eq (point) (marker-position marker)) ; current line
-                         preserve-blank-line))
-           (let ((i (current-column)))
-             (delete-region (line-beginning-position) (point))
-             (indent-to (+ i indentation-offset))))
+         (let ((i (current-column)))
+           (delete-region (line-beginning-position) (point))
+           (indent-to (+ i indentation-offset)))
          (forward-line)))
       (set-marker marker nil))))
 
-- 
Ihor Radchenko // yantar92,
Org mode contributor,
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

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