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: Sébastien Miquel
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, 3 Jul 2023 12:49:17 +0000


Ihor Radchenko writes:
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.

You're at the end of a line, you press =org-return-and-indent=.
 1. It adds a newline character.
 2. =org-indent-line= adds the org indentation, _before_ calling
    =org-babel-do-key-sequence-in-edit-buffer=
 3. The native edit call removes the common indentation, before
    calling tab in the native buffer.
 4. Calling tab in the native buffer possibly does nothing.
 5. =org-src--contents-for-write-back= sees the current line is empty,
    but it should indent it (with org indentation) nonetheless.


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

I don't understand. With this change, the function only stops if it
finds a non blank line with less than n indentation (same as before).
When a blank line with less than n indentation is found, it is emptied
(same as before), and execution continues.

* 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?

Are you advocating for computing N using blank lines as well ?

 1. It isn't consistent with the previous behaviour.
 2. If I mistakenly add a space to an empty line in a src block, an
    edit-special round trip will add indentation to every line.

Is there any benefit ?

--
Sébastien Miquel



reply via email to

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