Skip to content
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

Grabbing multiple outputs in swank:eval-and-grab-output #554

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

akater
Copy link

@akater akater commented Apr 11, 2020

The suggestion had previously been discussed in PR #551 but I proposed an incompatible change then. Patches suggested here ensure everything is backwards-compatible.

swank:eval-and-grab-output now returns alist with many possible outputs, if they were requested in the call. (Return values are provided in that alist too.) Outputs are requested in an optional argument. If optional argument is not supplied, we infer that caller uses old interface and return standard output and values as they are returned now. It thus doesn't break anything.

The check for old interface can certainly be dropped when Emacs 27 is not supported anymore, and can very likely be dropped when Org-mode adopts new interface (Org-mode is likely the only user of swank:eval-and-grab-output in the present day Emacs; I did check). I have a corresponding patch ready for Org-mode but it's difficult to test until SLIME merges this.

My main motivation was to make traces and errors accessible to Org-Babel. I use the feature very often (mostly traces).

My Org-mode patch also ensures backwards compatibility with stable SLIME releases. I presume this feature can be used since SLIME 2.25. Please correct me on this if needed.

The only Elisp functions affected are slime-eval-print and slime-eval-save. They behave exactly as they do now.

@akater
Copy link
Author

akater commented Apr 11, 2020

One question from @luismbo I left unanswered concerns *debug-io*. I did not include support for bidirectional streams as there is no way that I know of to test this feature applied to such streams, in contrast to output streams. E.g. org-mode does not support any kind of interactive evaluation at the moment.

@akater akater force-pushed the grab-multiple-outputs branch 2 times, most recently from c94ea67 to fbd0679 Compare April 27, 2020 20:25
@akater akater force-pushed the grab-multiple-outputs branch 2 times, most recently from b823dc3 to a477508 Compare June 26, 2020 04:42
@akater akater force-pushed the grab-multiple-outputs branch 2 times, most recently from 3764e4e to 8520569 Compare July 6, 2020 21:43
@akater akater force-pushed the grab-multiple-outputs branch 4 times, most recently from 859ff65 to 4a0e1cb Compare November 25, 2020 06:26
@akater akater force-pushed the grab-multiple-outputs branch 2 times, most recently from ceb6ba7 to 7264b1d Compare May 8, 2021 21:15
@akater akater force-pushed the grab-multiple-outputs branch 2 times, most recently from 2186322 to d2a5d41 Compare June 30, 2021 08:26
@akater
Copy link
Author

akater commented Jun 30, 2021

Could we return to this please? Everything is backward-compatible now, and the feature needs to be merged into slime first, then into Org.

@luismbo
Copy link
Member

luismbo commented Jul 1, 2021

@akater I have some refactoring suggestions, but before getting to that, I'm wondering to you think about my question regarding interleaving output in #551 (comment)

@akater
Copy link
Author

akater commented Jul 1, 2021 via email

@luismbo
Copy link
Member

luismbo commented Jul 1, 2021

@akater but if eval-and-grab-output segregates output per stream and doesn't store the order then higher level interfaces won't be able to guess the order.

@akater
Copy link
Author

akater commented Jul 1, 2021 via email

@luismbo
Copy link
Member

luismbo commented Jul 1, 2021

@akater can you give me an example where's you'd prefer to see output segregated by stream rather than interleaved?

@akater
Copy link
Author

akater commented Jul 1, 2021 via email

@luismbo
Copy link
Member

luismbo commented Jul 1, 2021

That example only has trace output, it doesn't show output from other streams does it?

@akater
Copy link
Author

akater commented Jul 1, 2021 via email

@luismbo
Copy link
Member

luismbo commented Jul 1, 2021

@akater What I mean is, given

(defun foo (x)
  (print x))

(trace foo)

what output do you expect to grab with swank:eval-and-grab-output? And assuming you'd want to grab both standard output and trace output, what do you expect the result to look like?

@akater
Copy link
Author

akater commented Jul 2, 2021

given [...] what output do you expect to grab with swank:eval-and-grab-output?

All of it. swank:eval-and-grab-output should always grab all output.

what do you expect the result to look like?

It depends on :results header-arg in Org. Usually it'd be :results ‹kind›, and contents of the corresponding stream would be inserted into Org buffer as usual. So far I don't have any support for emitting multiple results, mostly because I'd like to take small steps and get feedback from practitioners. One variation I have in mind is

#+begin_src lisp :results output trace :wrap example
(f x)
#+end_src

#+RESULTS:
#+begin_example fundamental
this came from standard output
#+end_example
#+begin_example lisp
0: (F X)
  1: (G X Y)
  (G X Y) returned NIL
(F X) returned NIL
#+end_example

but it presumes some guessing by org-mode so I'm not certain. I'd rather discuss this in emacs-orgmode mailing list, and I'd rather do it when diverse multiple stream contents are actually available in org-mode to combine.

It is often desirable to get output from time and trace in Emacs,
particularly in org-babel.  This patch extends
swank:eval-and-grab-output to support emitting *trace-output*; it also
introduces *error-output*, for good measure.

We check whether eval-and-grab-output caller presumes older interface
to it and return a legacy list of two elements instead of alist in
those cases.

This check can very likely be dropped when either Emacs 27 or Org 9.4
become unsupported.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants