mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-09-29 22:07:49 +00:00
ob-core: Prevent spurious blanks lines when executing code
* lisp/ob-core.el (org-babel--insert-results-keyword): (org-babel-where-is-src-block-result): Control better the number of empty lines around results of a source block evaluation. * testing/lisp/test-ob.el (test-ob/blocks-with-spaces): Add tests. (test-ob/specific-colnames): Fix test.
This commit is contained in:
parent
91e26352c5
commit
2116162fe6
|
@ -1872,8 +1872,16 @@ the results hash, or nil. Leave point before the keyword."
|
|||
(t (format "[%s]" hash)))
|
||||
":"
|
||||
(when name (concat " " name))
|
||||
"\n\n"))
|
||||
(beginning-of-line -1)
|
||||
"\n"))
|
||||
;; Make sure results are going to be followed by at least one blank
|
||||
;; line so they do not get merged with the next element, e.g.,
|
||||
;;
|
||||
;; #+results:
|
||||
;; : 1
|
||||
;;
|
||||
;; : fixed-width area, unrelated to the above.
|
||||
(unless (looking-at "^[ \t]*$") (save-excursion (insert "\n")))
|
||||
(beginning-of-line 0)
|
||||
(when hash (org-babel-hide-hash)))
|
||||
|
||||
(defun org-babel--clear-results-maybe (hash)
|
||||
|
@ -1988,11 +1996,8 @@ to HASH."
|
|||
(goto-char (min (org-element-property :end context) (point-max)))
|
||||
(skip-chars-backward " \t\n")
|
||||
(forward-line)
|
||||
(cond ((not (bolp)) (insert "\n\n"))
|
||||
((or (eobp)
|
||||
(= (org-element-property :post-blank context) 0))
|
||||
(insert "\n"))
|
||||
(t (forward-line)))
|
||||
(unless (bolp) (insert "\n"))
|
||||
(insert "\n")
|
||||
(org-babel--insert-results-keyword
|
||||
(org-element-property :name context) hash)
|
||||
(point))))))
|
||||
|
|
|
@ -1107,6 +1107,7 @@ Line 3\"
|
|||
|
||||
(ert-deftest test-ob/blocks-with-spaces ()
|
||||
"Test expansion of blocks followed by blank lines."
|
||||
;; Preserve number of blank lines after block.
|
||||
(should
|
||||
(equal "#+BEGIN_SRC emacs-lisp
|
||||
\(+ 1 2)
|
||||
|
@ -1119,7 +1120,57 @@ Line 3\"
|
|||
#+END_SRC\n\n\n"
|
||||
(let ((org-babel-next-src-block "RESULTS"))
|
||||
(org-babel-execute-src-block))
|
||||
(buffer-string)))))
|
||||
(buffer-string))))
|
||||
;; Do not add spurious blank lines after results.
|
||||
(should
|
||||
(equal
|
||||
"
|
||||
- item 1
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
0
|
||||
#+end_src
|
||||
|
||||
#+RESULTS:
|
||||
: 0
|
||||
|
||||
- item 2"
|
||||
(org-test-with-temp-text "
|
||||
- item 1
|
||||
|
||||
#+begin_src emacs-lisp<point>
|
||||
0
|
||||
#+end_src
|
||||
|
||||
- item 2"
|
||||
(org-babel-execute-src-block)
|
||||
(buffer-string))))
|
||||
(should
|
||||
(equal
|
||||
"
|
||||
- item 1
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
1
|
||||
#+end_src
|
||||
|
||||
#+RESULTS:
|
||||
: 1
|
||||
|
||||
- item 2"
|
||||
(org-test-with-temp-text "
|
||||
- item 1
|
||||
|
||||
#+begin_src emacs-lisp<point>
|
||||
1
|
||||
#+end_src
|
||||
|
||||
#+RESULTS:
|
||||
: 1
|
||||
|
||||
- item 2"
|
||||
(org-babel-execute-src-block)
|
||||
(buffer-string)))))
|
||||
|
||||
(ert-deftest test-ob/results-in-narrowed-buffer ()
|
||||
"Test block execution in a narrowed buffer."
|
||||
|
@ -1203,7 +1254,6 @@ echo \"$data\"
|
|||
|-----+--------|
|
||||
| 1 | bar |
|
||||
| 2 | baz |
|
||||
|
||||
"
|
||||
(org-test-with-temp-text
|
||||
"#+name: input-table
|
||||
|
|
Loading…
Reference in a new issue