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

Make --eval print values to the shell #1453

Open
aartaka opened this issue May 24, 2021 · 7 comments
Open

Make --eval print values to the shell #1453

aartaka opened this issue May 24, 2021 · 7 comments
Labels
bug good-first-issue Marks a good issue for first-time contributors. help-wanted

Comments

@aartaka
Copy link
Contributor

aartaka commented May 24, 2021

This would allow to create Nyxt front-ends (like the one discussed on IRC recently) and have better shell interaction in general.

@aartaka aartaka added feature Feature requests. good-first-issue Marks a good issue for first-time contributors. help-wanted labels May 24, 2021
@aartaka
Copy link
Contributor Author

aartaka commented May 24, 2021

Command that doesn't print anything, even though it should:
nyxt --remote --eval '(nyxt:current-buffer)'

@Ambrevar
Copy link
Member

Any idea how to do this?

For now all I have in mind is that the remote evaluator should open its own temporary socket and send 2 commands to the server: 1 with the remote socket information, 1 with the actual command.
Then when the server is done, it writes to the remote socket.
The remote evaluator listens to its socket and upon reception it closes it, outputs the result to stdout and exits.

There must be a simpler way though, no?
Any idea what emacsclient does?

@Ambrevar
Copy link
Member

Ambrevar commented Jun 14, 2023

Forget what I said: Unix sockets are bidrectional, this works:

(iolib:with-open-socket (s :address-family :local :remote-filename "foo.socket")
  (write-string "foo" s)
  (read-line s))

and on the Nyxt server side, write to the accepted connection.
Don't forget to flush.

@aadcg
Copy link
Member

aadcg commented Jun 30, 2023

I don't see any issues here. It does seem to print values to stdout.

$ nyxt --remote --quit --eval '4'

(process:31943): Gtk-WARNING **: 16:16:17.309: Locale not supported by C library.
	Using the fallback 'C' locale.
<INFO> [16:16:17] Probing remote instance listening to /run/user/1000/nyxt/nyxt.socket.
<INFO> [16:16:17] External evaluation request: "4"
4

$ nyxt --remote --quit --eval '(nyxt:current-buffer)'

(process:31964): Gtk-WARNING **: 16:16:35.845: Locale not supported by C library.
	Using the fallback 'C' locale.
<INFO> [16:16:35] Probing remote instance listening to /run/user/1000/nyxt/nyxt.socket.
<INFO> [16:16:35] External evaluation request: "(nyxt:current-buffer)"
#<WEB-BUFFER 1665 {1007EDB4C3}>

EDIT: The above works because nyxt and nyxt --remote were both issued under the same shell process. When that's not the case, the output is written to stout of the shell that started nyxt. Interesting!

Then this is a bug, not a feature request.

@aartaka aartaka added bug and removed feature Feature requests. labels Jun 30, 2023
@aartaka
Copy link
Contributor Author

aartaka commented Jun 30, 2023

Yes, that's a bug.

@aadcg
Copy link
Member

aadcg commented Jun 30, 2023

I'm not sure how to fix this bug since I don't know much about Unix sockets. My primitive understanding is that when we connect to the socket and send a sexp (nyxt --server --eval ...) we need to set the right output stream since, by default, it will pick the *standard-output* from the moment when nyxt (not the server) was started.

@Ambrevar
Copy link
Member

Ambrevar commented Jul 3, 2023

I don't think it's a bug: the nyxt server instance prints to its stdout, so if the remote instance is in the same shell, it's only normal that that result is printed in the same shell.

To fix this, we need to go as I mentioned in #1453 (comment), but sionescu/iolib#79 is kind of blocking here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good-first-issue Marks a good issue for first-time contributors. help-wanted
Development

No branches or pull requests

3 participants