From d5deb537519b6cd2d20d74918e2595739da50756 Mon Sep 17 00:00:00 2001 From: Allard Hendriksen Date: Fri, 5 Jan 2018 15:01:27 +0100 Subject: [PATCH] Implement org-babel-tmux-test Tests the tmux functionality. Also solves some problems in the original implementation where the temp file would be read directly after creation, i.e. before the random string could be written to the file. --- ob-tmux.el | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/ob-tmux.el b/ob-tmux.el index f0339aa..19bca93 100644 --- a/ob-tmux.el +++ b/ob-tmux.el @@ -119,27 +119,30 @@ In case you want to use a different tmux than one selected by your $PATH") sockets))))) (when match-socket (car (split-string match-socket ":"))))) -;; (defun org-babel-screen-test () -;; "Test if the default setup works. -;; The terminal should shortly flicker." -;; (interactive) -;; (let* ((random-string (format "%s" (random 99999))) -;; (tmpfile (org-babel-temp-file "ob-screen-test-")) -;; (body (concat "echo '" random-string "' > " tmpfile "\nexit\n")) -;; tmp-string) -;; (org-babel-execute:screen body org-babel-default-header-args:screen) -;; ;; XXX: need to find a better way to do the following -;; (while (not (file-readable-p tmpfile)) -;; ;; do something, otherwise this will be optimized away -;; (format "org-babel-screen: File not readable yet.")) -;; (setq tmp-string (with-temp-buffer -;; (insert-file-contents-literally tmpfile) -;; (buffer-substring (point-min) (point-max)))) -;; (delete-file tmpfile) -;; (message (concat "org-babel-screen: Setup " -;; (if (string-match random-string tmp-string) -;; "WORKS." -;; "DOESN'T work."))))) +(defun org-babel-tmux-open-file (path) + (with-temp-buffer + (insert-file-contents-literally path) + (buffer-substring (point-min) (point-max)))) + +(defun org-babel-tmux-test () + "Test if the default setup works. The terminal should shortly flicker." + (interactive) + (let* ((random-string (format "%s" (random 99999))) + (tmpfile (org-babel-temp-file "ob-screen-test-")) + (body (concat "echo '" random-string "' > " tmpfile " ; exit")) + tmp-string) + (org-babel-execute:tmux body org-babel-default-header-args:tmux) + ;; XXX: need to find a better way to do the following + (while (or (not (file-readable-p tmpfile)) + (= 0 (length (org-babel-tmux-open-file tmpfile)))) + ;; do something, otherwise this will be optimized away + (format "org-babel-screen: File not readable yet.")) + (setq tmp-string (org-babel-tmux-open-file tmpfile)) + (delete-file tmpfile) + (message (concat "org-babel-screen: Setup " + (if (string-match random-string tmp-string) + "WORKS." + "DOESN'T work."))))) (provide 'ob-tmux)