summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2015-08-23 23:38:36 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2015-08-23 23:41:56 +0200
commit6626dfb30bea8fa7bcb760f0265dc3c7422cc1e4 (patch)
tree101233052bfeb6d63ae65a3fb7abf0f661c30a47
parent9c5588377f2b954e389f0da70c1dcc5afffdb96a (diff)
downloadorg-mode-6626dfb30bea8fa7bcb760f0265dc3c7422cc1e4.tar.gz
ob: Fix RESULTS indentation
* lisp/ob-core.el (org-babel-parse-src-block-match): Compute indentation taking into consideration tab width. (org-babel-where-is-src-block-result): Do not assume indentation consists of white space characters only. * testing/lisp/test-ob.el (test-ob/preserve-results-indentation): Add test. Reported-by: Jarmo Hurri <jarmo.hurri@iki.fi> <http://permalink.gmane.org/gmane.emacs.orgmode/100403>
-rw-r--r--lisp/ob-core.el21
-rw-r--r--testing/lisp/test-ob.el37
2 files changed, 37 insertions, 21 deletions
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index e3abe97..f642b18 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -1438,17 +1438,16 @@ specified in the properties of the current outline entry."
(defvar org-src-preserve-indentation) ;; declare defcustom from org-src
(defun org-babel-parse-src-block-match ()
"Parse the results from a match of the `org-babel-src-block-regexp'."
- (let* ((block-indentation (length (match-string 1)))
- (lang (org-no-properties (match-string 2)))
+ (let* ((block-indentation (string-width (match-string 1)))
+ (lang (org-match-string-no-properties 2))
(lang-headers (intern (concat "org-babel-default-header-args:" lang)))
(switches (match-string 3))
- (body (org-no-properties
- (let* ((body (match-string 5))
- (sub-length (- (length body) 1)))
- (if (and (> sub-length 0)
- (string= "\n" (substring body sub-length)))
- (substring body 0 sub-length)
- (or body "")))))
+ (body (let* ((body (org-match-string-no-properties 5))
+ (sub-length (- (length body) 1)))
+ (if (and (> sub-length 0)
+ (string= "\n" (substring body sub-length)))
+ (substring body 0 sub-length)
+ (or body ""))))
(preserve-indentation (or org-src-preserve-indentation
(save-match-data
(string-match "-i\\>" switches)))))
@@ -1972,8 +1971,8 @@ following the source block."
(goto-char end)
(unless beg
(if (looking-at "[\n\r]") (forward-char 1) (insert "\n")))
+ (when (wholenump indent) (indent-to indent))
(insert (concat
- (when (wholenump indent) (make-string indent ? ))
"#+" org-babel-results-keyword
(when hash
(if org-babel-hash-show-time
@@ -1984,7 +1983,7 @@ following the source block."
(when name (concat " " name)) "\n"))
(unless beg (insert "\n") (backward-char))
(beginning-of-line 0)
- (if hash (org-babel-hide-hash))
+ (when hash (org-babel-hide-hash))
(point)))))
(defvar org-block-regexp)
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index 2a929cd..508a3ed 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -1289,16 +1289,33 @@ echo \"$data\"
(ert-deftest test-ob/preserve-results-indentation ()
"Preserve indentation when executing a src block."
(should
- (equal '(2 2)
- (org-test-with-temp-text
- " #+begin_src emacs-lisp\n (+ 1 1)\n #+end_src"
- (org-babel-execute-src-block)
- (buffer-string)
- (let ((case-fold-search t)) (search-forward "#+results:"))
- ;; Check if both #+RESULTS: keyword and actual results are
- ;; indented by 2 columns.
- (list (org-get-indentation)
- (progn (forward-line) (org-get-indentation)))))))
+ (equal
+ '(2 2)
+ (org-test-with-temp-text " #+begin_src emacs-lisp\n(+ 1 1)\n #+end_src"
+ (org-babel-execute-src-block)
+ (let ((case-fold-search t)) (search-forward "RESULTS"))
+ (list (org-get-indentation)
+ (progn (forward-line) (org-get-indentation))))))
+ (should
+ (equal
+ '(2 2)
+ (org-test-with-temp-text
+ " #+name: block\n #+begin_src emacs-lisp\n(+ 1 1)\n #+end_src"
+ (org-babel-execute-src-block)
+ (let ((case-fold-search t)) (search-forward "RESULTS"))
+ (list (org-get-indentation)
+ (progn (forward-line) (org-get-indentation))))))
+ ;; Don't get fooled by TAB-based indentation.
+ (should
+ (equal
+ '(6 6)
+ (org-test-with-temp-text
+ "\t #+begin_src emacs-lisp\n\t (+ 1 1)\n\t #+end_src"
+ (setq tab-width 4)
+ (org-babel-execute-src-block)
+ (let ((case-fold-search t)) (search-forward "RESULTS"))
+ (list (org-get-indentation)
+ (progn (forward-line) (org-get-indentation)))))))
(ert-deftest test-ob/safe-header-args ()
"Detect safe and unsafe header args."