From a33acf61917d8c72369297289031d8745e08e320 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Fri, 29 May 2015 09:55:56 +0200 Subject: [PATCH] org-src: Fix indentation rampage when editing src blocks * lisp/org-src.el (org-edit-src-code): Do not add indentation at every edit when `org-src-preserve-indentation' is non-nil. Function taking care of indentation cannot check `org-src--preserve-indentation' since the variable is buffer-local and indentation happens in a temporary buffer. Reported-by: Rainer M Krug --- lisp/org-src.el | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lisp/org-src.el b/lisp/org-src.el index 47416ed63..b1ee56fcf 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -834,15 +834,17 @@ name of the sub-editing buffer." (org-src--construct-edit-buffer-name (buffer-name) lang)) lang-f (and (null code) - (lambda () - (unless org-src--preserve-indentation - (untabify (point-min) (point-max)) - (when (> org-edit-src-content-indentation 0) - (let ((ind (make-string org-edit-src-content-indentation ?\s))) - (while (not (eobp)) - (unless (looking-at "[ \t]*$") (insert ind)) - (forward-line))))) - (org-escape-code-in-region (point-min) (point-max)))) + `(lambda () + (unless ,(or org-src-preserve-indentation + (org-element-property :preserve-indent element)) + (untabify (point-min) (point-max)) + (when (> org-edit-src-content-indentation 0) + (let ((ind (make-string org-edit-src-content-indentation + ?\s))) + (while (not (eobp)) + (unless (looking-at "[ \t]*$") (insert ind)) + (forward-line))))) + (org-escape-code-in-region (point-min) (point-max)))) (and code (org-unescape-code-in-string code))) ;; Finalize buffer. (org-set-local 'org-coderef-label-format -- 2.11.4.GIT