branch: externals/org commit 4750b37809b12c1266722b7024cd4037020f4af3 Author: Lukas Rudd Andersen <l...@phdk.org> Commit: Ihor Radchenko <yanta...@posteo.net>
org-indent-line: Fix undindented line with non-zero `org-edit-src-content-indentation' * org.el (org-indent-line): Indent to content before indenting with mode. Indent to content before the block contents are put in the edit buffer to indent according to mode, ensuring that the whole block is properly cleaned of content indentation, avoiding unintended over-indentation when the contents of the edit buffer are reinserted. * test-org.el (org-indent-line): Add test. TINYCHANGE Link: https://orgmode.org/list/omp_5ys--...@phdk.org --- lisp/org.el | 4 ++++ testing/lisp/test-org.el | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index e9f11db1e8..3fcc036970 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -19469,6 +19469,10 @@ Also align node properties according to `org-property-format'." (org-with-point-at (org-element-property :begin element) (+ (org-current-text-indentation) org-edit-src-content-indentation))))) + ;; Avoid over-indenting when beginning of a new line is not empty. + ;; https://list.orgmode.org/omcpuwz--...@phdk.org/ + (when block-content-ind + (save-excursion (indent-line-to block-content-ind))) (ignore-errors ; do not err when there is no proper major mode ;; It is important to call `indent-according-to-mode' ;; rather than `indent-line-function' here or we may diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 2487c9ace6..a55c4162ea 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -1220,8 +1220,9 @@ Otherwise, evaluate RESULT as an sexp and return its result." (org-indent-line) (org-get-indentation))))) ;; Within code part of a source block, use language major mode if - ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent - ;; according to line above. + ;; `org-src-tab-acts-natively' is non-nil, only add + ;; `org-edit-src-content-indentation' to lines with indentation that + ;; is lower. Otherwise, indent according to line above. (should (= 6 (org-test-with-temp-text @@ -1230,6 +1231,15 @@ Otherwise, evaluate RESULT as an sexp and return its result." (org-edit-src-content-indentation 0)) (org-indent-line)) (org-get-indentation)))) + (should + (= 2 + (org-test-with-temp-text + "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC" + (let ((org-src-tab-acts-natively t) + (org-edit-src-content-indentation 2)) + (org-indent-line)) + (forward-line -1) + (org-get-indentation)))) (should (= 1 (org-test-with-temp-text