emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/org 35690cd 36/85: org-src.el (org-src--contents-for-wr


From: ELPA Syncer
Subject: [elpa] externals/org 35690cd 36/85: org-src.el (org-src--contents-for-write-back): Do not indent blank lines
Date: Mon, 27 Sep 2021 15:57:45 -0400 (EDT)

branch: externals/org
commit 35690cd04fa39489cab7afe0d518955d4541f269
Author: Sébastien Miquel <sebastien.miquel@posteo.eu>
Commit: Bastien <bzg@gnu.org>

    org-src.el (org-src--contents-for-write-back): Do not indent blank lines
    
    * lisp/org-src.el (org-src--contents-for-write-back): Do not indent
    blank lines, except for the current line.
    
    This was the original behaviour for all blank lines, before `857ae366b3`.
---
 lisp/org-src.el | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/lisp/org-src.el b/lisp/org-src.el
index 743e9e1..e331276 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -443,14 +443,20 @@ Assume point is in the corresponding edit buffer."
                0))))
        (use-tabs? (and (> org-src--tab-width 0) t))
        (source-tab-width org-src--tab-width)
-       (contents (org-with-wide-buffer (buffer-string)))
-       (write-back org-src--allow-write-back))
+       (contents (org-with-wide-buffer
+                   (let ((eol (progn (end-of-line) (point))))
+                     (list (buffer-substring (point-min) eol)
+                           (buffer-substring eol (point-max))))))
+       (write-back org-src--allow-write-back)
+        marker)
     (with-current-buffer write-back-buf
       ;; Reproduce indentation parameters from source buffer.
       (setq indent-tabs-mode use-tabs?)
       (when (> source-tab-width 0) (setq tab-width source-tab-width))
       ;; Apply WRITE-BACK function on edit buffer contents.
-      (insert (org-no-properties contents))
+      (insert (org-no-properties (car contents)))
+      (setq marker (point-marker))
+      (insert (org-no-properties (car (cdr contents))))
       (goto-char (point-min))
       (when (functionp write-back) (save-excursion (funcall write-back)))
       ;; Add INDENTATION-OFFSET to every line in buffer,
@@ -458,10 +464,13 @@ Assume point is in the corresponding edit buffer."
       (when (> indentation-offset 0)
        (while (not (eobp))
          (skip-chars-forward " \t")
-         (let ((i (current-column)))
-           (delete-region (line-beginning-position) (point))
-           (indent-to (+ i indentation-offset)))
-         (forward-line))))))
+          (when (or (not (eolp)) ; ignore blank lines
+                    (eq (point) (marker-position marker)))
+           (let ((i (current-column)))
+             (delete-region (line-beginning-position) (point))
+             (indent-to (+ i indentation-offset))))
+         (forward-line)))
+      (set-marker marker nil))))
 
 (defun org-src--edit-element
     (datum name &optional initialize write-back contents remote)



reply via email to

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