-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any way to get output back to emacs ? #6
Comments
Hi, Very good question! I have looked into this, but not implemented anything. It might be worthwile to look into the emamux package. I do not use it (yet), but this package might contain the functionality you need :) Moreover, there is a programmatic way to get the output from tmux using bash. From the tmux man page:
Could you explain how you would want to use this functionality? |
Thanks for responding.
I use tmux primarily for remote machines, and this way it won't break my flow when working within emacs for setup, run commands and document what I did. |
I have been thinking about this quite a bit for the past few days. I think I have a function that might begin to scratch your itch: (defun ob-tmux-get-output ()
(interactive)
(let ((info (org-babel-get-src-block-info 'light)))
(when (and info (string-equal "tmux" (nth 0 info)))
(with-help-window (help-buffer)
(let* ((lang (nth 0 info))
(block-content (nth 1 info))
(params (nth 2 info))
(org-session (cdr (assq :session params)))
(socket (cdr (assq :socket params)))
(socket (when socket (expand-file-name socket)))
(ob-session (ob-tmux--from-org-session org-session socket)))
(princ (ob-tmux--execute-string ob-session
"capture-pane" "-p"
"-t" (ob-tmux--session ob-session))))))))
If you execute this function with point in an ob-tmux source block, it will get the output of the tmux pane and put it in a help-buffer. This is not yet perfect, but at least it is a start. I can think of the following improvements:
To be honest, I am not sure when I will get around to implementing this soon. What do you think? |
This feature would be perfect! |
I agree ob-tmux shows what you executed, but not the result. @dkrm0: do you think the manual workflow I have described above would be a good fit for you?
I am trying to understand why people want this feature, so I do not implement something that people do not want. Moreover, I do not think I feel the need for this feature, although once implemented I will probably use it often ;) |
Thanks for taking the time to posting the function. It works very well, I can now get the state of the tmux pane from emacs! The improvements you suggested would be very useful if implimented. |
@ahendriksen This is an example for a couple of days ago: I've benchmarked my new build and documented the whole procedures. I've used This is just a simple example from the top of my head :) I don't keep a terminal session open next to emacs. |
I am noticing this is an often requested feature. That's great! It means that people are using this package and find it useful. Unfortunately, I have little time at the moment to work on this (even during Christmas ;-) ). I will try to get to this in February at the earliest. I will also have to improve my elisp skills, since I have never popped up buffers before and never written a minor mode before. Again, I appreciate all your input. I am going to implement this. Just not very soon :) |
Hi @ahendriksen, I just started using ob-tmux and I am happy to say that I got it to run after a bit of tweaking and it works wonderfully. I would still be interested in the feature of getting output back to emacs, and wanted to give this thread a little bump :) |
Hi, thanks for the kind words :) While looking for a good keybinding, I found out that org mode allows jumping to the result of a code block using Perhaps you could evaluate the following snippet (copy it to the scratch buffer, select the text and execute (defun ob-tmux--insert-result ()
(interactive)
(let ((info (org-babel-get-src-block-info 'light)))
(when (and info (string-equal "tmux" (nth 0 info)))
(let* ((params (nth 2 info))
(org-session (cdr (assq :session params)))
(socket (cdr (assq :socket params)))
(socket (when socket (expand-file-name socket)))
(ob-session (ob-tmux--from-org-session org-session socket)))
(org-babel-insert-result
(ob-tmux--execute-string ob-session
"capture-pane" "-p"
"-t" (ob-tmux--session ob-session))
'("replace"))))))
(defun ob-tmux--open-src-block-result (orig-fun &rest args)
(ob-tmux--insert-result)
(apply orig-fun args))
(advice-add 'org-babel-open-src-block-result
:around #'ob-tmux--open-src-block-result) This code should modify org-mode so that pressing This is still work in progress, and I would like to hold off adding this feature to ob-tmux until it is actually pleasant to use :) |
Thanks for this implementation, I just tried it out and for me it works the following way:
So for me this is quite good already. I could see the following improvements (but only from a user's perspective, since I do not really know elisp programming and emacs internals...):
|
Thanks for the feedback. I appreciate the time you put into testing this :)
I reckon that editing will be necessary, so for now I will stay on the track that a new buffer is opened.
I fixed this in the snippet below. There is an "-S" option to the tmux
This will be out of scope for ob-tmux.
Does this work for other kind of source blocks? I updated the snippet with the following improvements:
To test, please first execute this snippet a couple times to ensure the previous implementation is removed: (advice-remove 'org-babel-open-src-block-result
#'ob-tmux--open-src-block-result) This should (defun ob-tmux--insert-result ()
(interactive)
(let ((info (org-babel-get-src-block-info 'light)))
(when (and info (string-equal "tmux" (nth 0 info)))
(let* ((params (nth 2 info))
(org-session (cdr (assq :session params)))
(socket (cdr (assq :socket params)))
(socket (when socket (expand-file-name socket)))
(ob-session (ob-tmux--from-org-session org-session socket)))
(org-babel-insert-result
(ob-tmux--execute-string ob-session
"capture-pane"
"-p" ;; print to stdout
"-S" "-" ;; start at beginning of history
"-t" (ob-tmux--session ob-session))
'("replace"))))))
(defun ob-tmux--edit-result ()
(interactive)
(pcase (org-babel-get-src-block-info 'light)
(`(,_ ,_ ,arguments ,_ ,_ ,start ,_)
(save-excursion
;; Go to the results, if there aren't any then run the block.
(goto-char start)
(goto-char (or (org-babel-where-is-src-block-result)
(progn (org-babel-execute-src-block)
(org-babel-where-is-src-block-result))))
(end-of-line)
(skip-chars-forward " \r\t\n")
(org-edit-special)
(delete-trailing-whitespace)
(end-of-buffer)
t))
(_ nil)))
(defun ob-tmux--open-src-block-result (orig-fun &rest args)
(let ((info (org-babel-get-src-block-info 'light)))
(if (and info (string-equal "tmux" (nth 0 info)))
(progn
(ob-tmux--insert-result)
(ob-tmux--edit-result))
(apply orig-fun args))))
(advice-add 'org-babel-open-src-block-result
:around #'ob-tmux--open-src-block-result) |
I used the function now for some time and it works nicely. I noticed one shortcoming: After
According this you are right: this does not work with other source blocks as well. It aborts with |
Thank you very much for writing this very nice package.
Is there a way to get kind of screenshot of the latest state as seen in the tmux window back to org-mode ?
I could not find any such option in tmux manual, anyone knows ?, but it would be helpful to make this even more interactive.
The text was updated successfully, but these errors were encountered: