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: Mon, 03 Jul 2023 09:58:01 +0000

Sébastien Miquel <sebastien.miquel@posteo.eu> writes:

> On second thought, I don't think moving the LaTeX fragment logic away
> from `org-src--contents-for-write-back` makes sense. This part of the
> function does the opposite of `org-do-remove-indentation`, and the
> latter has a boolean argument `skip-fl`, so it makes sense to keep it
> the same here. It is simple enough.
>
> If you're worried about consistency with inline src blocks, I find it
> weird for them to have newlines, let alone newlines mixed with org's
> indentation. But if we do want to treat them the same, then we also
> need to modify `org-do-remove-indentation` to skip the first line for
> them as well.
>
> I've taken this part off the patch for now.

Ok.

I am not that much worried about consistency with inline src blocks.
Rather do not like the mix of org-src buffer local variables and
checking the block type. But we can leave this refactoring to another
day. It is not just about preserve-fl. (also indentation-offset)

> What happens is: in the org buffer, the line is not empty, because it
> has the org indentation (which was possibly just added by
> org-indent-line), but in the edit buffer, the line is empty, because
> the common org indentation was removed. In that case, we want to add
> back the org indentation.

May you please provide an example when it is necessary?
`org-indent-line' will run `org-babel-do-key-sequence-in-edit-buffer', so
it should still use `org-src--contents-for-write-back' and will not
modify the org buffer text directly.

> --- a/lisp/org-macs.el
> +++ b/lisp/org-macs.el
> @@ -483,9 +483,12 @@ line.  Return nil if it fails."
>          (when skip-fl (forward-line))
>       (while (not (eobp))
>         (let ((ind (progn (skip-chars-forward " \t") (current-column))))
> -         (cond ((eolp) (delete-region (line-beginning-position) (point)))
> -               ((< ind n) (throw :exit nil))
> -               (t (indent-line-to (- ind n))))
> +         (cond ((< ind n)
> +                   (if (eolp) (delete-region (line-beginning-position) 
> (point))
> +                     (throw :exit nil)))

This function is actually confusing both before and after the change.
According to the docstring:

    When optional argument N is a positive integer, remove exactly
    that much characters from indentation, if possible.

But the function can actually remove less than N characters.

Before your change, all the blank non-empty lines were unconditionally
removed. After your change, the first such line is removed and the
function returns nil without continuing.

> * lisp/org-macs.el (org-do-remove-indentation): Preserve
> indentation (spaces vs tabs) past the common indentation to remove.
> Do not empty blank lines.

Since not removing blank lines is intentional after the change, why
doing it on a single line that is indented less than N?

-- 
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]