From 50a18201c7cf3ba069b031a2040d8266d4698844 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Thu, 8 Oct 2015 18:57:30 +0200 Subject: [PATCH] org-src: Preserve tab characters unrelated to indentation * lisp/org-src.el (org-edit-src-code): Always preserve tabs not related to indentation. * testing/lisp/test-org-src.el (test-org-src/preserve-tabs): New test. --- lisp/org-src.el | 11 +++++------ testing/lisp/test-org-src.el | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/lisp/org-src.el b/lisp/org-src.el index 9c205e1a1..390897748 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -851,13 +851,12 @@ name of the sub-editing buffer." `(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))))) + (while (not (eobp)) + (unless (looking-at "[ \t]*$") + (indent-line-to (+ (org-get-indentation) + org-edit-src-content-indentation))) + (forward-line)))) (org-escape-code-in-region (point-min) (point-max)))) (and code (org-unescape-code-in-string code))) ;; Finalize buffer. diff --git a/testing/lisp/test-org-src.el b/testing/lisp/test-org-src.el index e3910a703..7d3d08533 100644 --- a/testing/lisp/test-org-src.el +++ b/testing/lisp/test-org-src.el @@ -98,5 +98,40 @@ blah #+end_src "))))) +(ert-deftest test-org-src/preserve-tabs () + "Editing block preserve tab characters." + ;; With `org-src-preserve-indentation' set to nil. + (should + (equal " +#+begin_src emacs-lisp + This is a tab: . +#+end_src" + (org-test-with-temp-text + " +#+begin_src emacs-lisp +This is a tab: . +#+end_src" + (let ((org-edit-src-content-indentation 2) + (org-src-preserve-indentation nil)) + (org-edit-special) + (org-edit-src-exit) + (buffer-string))))) + ;; With `org-src-preserve-indentation' set to t. + (should + (equal " +#+begin_src emacs-lisp +This is a tab: . +#+end_src" + (org-test-with-temp-text + " +#+begin_src emacs-lisp +This is a tab: . +#+end_src" + (let ((org-edit-src-content-indentation 2) + (org-src-preserve-indentation t)) + (org-edit-special) + (org-edit-src-exit) + (buffer-string)))))) + (provide 'test-org-src) ;;; test-org-src.el ends here