ob-core: Unify Org Babel related buffer names using constant variable

* lisp/ob-core.el (org-babel-results-buffer-name): Define constant
variable for buffer name.
(org-babel-open-src-block-result): Use the
`org-babel-results-buffer-name'.
* lisp/ob-eval.el (org-babel-error-buffer-name): Add docstring.
* testing/lisp/test-ob-octave.el (org-babel-error-buffer-name):
(ob-octave/graphics-file):
(ob-octave/graphics-file-session):
(ob-octave/graphics-file-space):
* testing/lisp/test-ob-shell.el (org-babel-error-buffer-name):
(test-ob-shell/dont-error-on-babel-error):
(test-ob-shell/standard-output-after-failure):
(test-ob-shell/error-output-after-success):
(test-ob-shell/error-output-after-failure):
(test-ob-shell/error-output-after-failure-multiple):
(test-ob-shell/exit-code):
(test-ob-shell/exit-code-multiple): Use variable for buffer names.
This commit is contained in:
stardiviner 2024-07-14 19:24:55 +08:00 committed by Ihor Radchenko
parent 240eb969e4
commit f2141541b4
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
4 changed files with 23 additions and 17 deletions

View File

@ -1238,6 +1238,9 @@ evaluation mechanisms."
(save-match-data (org-element-context))
'(babel-call inline-babel-call inline-src-block src-block)))
(defvar org-babel-results-buffer-name "*Org Babel Results*"
"The buffer name of Org Babel evaluate results.")
;;;###autoload
(defun org-babel-open-src-block-result (&optional re-run)
"Open results of source block at point.
@ -1261,7 +1264,7 @@ exist."
(if (looking-at org-link-bracket-re) (org-open-at-point)
(let ((r (org-babel-format-result (org-babel-read-result)
(cdr (assq :sep arguments)))))
(pop-to-buffer (get-buffer-create "*Org Babel Results*"))
(pop-to-buffer (get-buffer-create org-babel-results-buffer-name))
(erase-buffer)
(insert r)))
t))

View File

@ -33,7 +33,8 @@
(eval-when-compile (require 'subr-x)) ; For `string-empty-p', Emacs < 29
(defvar org-babel-error-buffer-name "*Org-Babel Error Output*")
(defvar org-babel-error-buffer-name "*Org-Babel Error Output*"
"The buffer name Org Babel evaluate error output.")
(declare-function org-babel-temp-file "ob-core" (prefix &optional suffix))
(defun org-babel-eval-error-notify (exit-code stderr)

View File

@ -18,6 +18,8 @@
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
(require 'ob-core)
(org-test-for-executable "octave")
(unless (featurep 'ob-octave)
(signal 'missing-test-dependency '("Support for Octave code blocks")))
@ -67,8 +69,8 @@
(ert-deftest ob-octave/graphics-file ()
"Graphics file. Test that link is correctly inserted and graphics file is created (and not empty). Clean-up side-effects."
;; In case a prior test left the Error Output buffer hanging around.
(when (get-buffer "*Org-Babel Error Output*")
(kill-buffer "*Org-Babel Error Output*"))
(when (get-buffer org-babel-error-buffer-name)
(kill-buffer org-babel-error-buffer-name))
(let ((file (make-temp-file "test-ob-octave-" nil ".png")))
(unwind-protect
(org-test-with-temp-text
@ -81,8 +83,8 @@ sombrero;
(should (file-readable-p file)))
;; clean-up
(delete-file file)
(when (get-buffer "*Org-Babel Error Output*")
(kill-buffer "*Org-Babel Error Output*")))))
(when (get-buffer org-babel-error-buffer-name)
(kill-buffer org-babel-error-buffer-name)))))
(ert-deftest ob-octave/graphics-file-session ()
"Graphics file in a session. Test that session is started in *Inferior Octave* buffer, link is correctly inserted and graphics file is created (and not empty). Clean-up side-effects."
@ -102,8 +104,8 @@ sombrero;
(delete-file file)
(let (kill-buffer-query-functions kill-buffer-hook)
(kill-buffer "*Inferior Octave*"))
(when (get-buffer "*Org-Babel Error Output*")
(kill-buffer "*Org-Babel Error Output*")))))
(when (get-buffer org-babel-error-buffer-name)
(kill-buffer org-babel-error-buffer-name)))))
(ert-deftest ob-octave/graphics-file-space ()
"Graphics file with a space in filename. Test that session is started in *Inferior Octave* buffer, link is correctly inserted and graphics file is created (and not empty). Clean-up side-effects."
@ -119,8 +121,8 @@ sombrero;
(should (file-readable-p file)))
;; clean-up
(delete-file file)
(when (get-buffer "*Org-Babel Error Output*")
(kill-buffer "*Org-Babel Error Output*")))))
(when (get-buffer org-babel-error-buffer-name)
(kill-buffer org-babel-error-buffer-name)))))
(ert-deftest ob-octave/session-multiline ()
"Test multiline session input."

View File

@ -51,7 +51,7 @@ the body of the tangled block does."
(ert-deftest test-ob-shell/dont-error-on-babel-error ()
"Errors within Babel execution should not cause Lisp errors."
(if (should (null (org-babel-execute:sh "ls NoSuchFileOrDirectory.txt" nil)))
(kill-buffer "*Org-Babel Error Output*")))
(kill-buffer org-babel-error-buffer-name)))
(ert-deftest test-ob-shell/session-single-return-returns-string ()
"Sessions with a single result should return a string."
@ -429,7 +429,7 @@ echo 3
(should (= 1
(org-babel-execute:sh
"echo 1; exit 2" nil)))
(kill-buffer "*Org-Babel Error Output*")))
(kill-buffer org-babel-error-buffer-name)))
;;; Standard error
@ -446,7 +446,7 @@ the exit code, after exiting with a zero code."
"echo 1 >&2" nil)
(with-current-buffer org-babel-error-buffer-name
(buffer-string)))))
(kill-buffer "*Org-Babel Error Output*")))
(kill-buffer org-babel-error-buffer-name)))
(ert-deftest test-ob-shell/error-output-after-failure ()
"Test that standard error shows in the error buffer, alongside
@ -460,7 +460,7 @@ the exit code, after exiting with a non-zero code."
"echo 1 >&2; exit 2" nil)
(with-current-buffer org-babel-error-buffer-name
(buffer-string)))))
(kill-buffer "*Org-Babel Error Output*")))
(kill-buffer org-babel-error-buffer-name)))
(ert-deftest test-ob-shell/error-output-after-failure-multiple ()
"Test that multiple standard error strings show in the error
@ -478,7 +478,7 @@ buffer, alongside multiple exit codes."
"echo 3 >&2; exit 4" nil)
(with-current-buffer org-babel-error-buffer-name
(buffer-string)))))
(kill-buffer "*Org-Babel Error Output*")))
(kill-buffer org-babel-error-buffer-name)))
;;; Exit codes
@ -494,7 +494,7 @@ with a non-zero return code."
"exit 1" nil)
(with-current-buffer org-babel-error-buffer-name
(buffer-string)))))
(kill-buffer "*Org-Babel Error Output*")))
(kill-buffer org-babel-error-buffer-name)))
(ert-deftest test-ob-shell/exit-code-multiple ()
"Test that multiple exit codes show in the error buffer after
@ -510,7 +510,7 @@ exiting with a non-zero return code multiple times."
"exit 2" nil)
(with-current-buffer org-babel-error-buffer-name
(buffer-string)))))
(kill-buffer "*Org-Babel Error Output*")))
(kill-buffer org-babel-error-buffer-name)))
(provide 'test-ob-shell)