diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2015-10-08 18:57:30 +0200 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2015-10-08 18:57:30 +0200 |
commit | 50a18201c7cf3ba069b031a2040d8266d4698844 (patch) | |
tree | a7544a00eea598dca3988c4619034bb67e23c097 | |
parent | 348890f79befad7dce0913ff06c8e8cc09c1d15a (diff) | |
download | org-mode-50a18201c7cf3ba069b031a2040d8266d4698844.tar.gz |
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.
-rw-r--r-- | lisp/org-src.el | 11 | ||||
-rw-r--r-- | 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 9c205e1..3908977 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 e3910a7..7d3d085 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 +<point>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 +<point>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 |