Fork me on GitHub
#portal
<
2023-09-27
>
lukasz15:09:23

I have Emacs 29.1 compiled with xwidgets support - but launching portal with (portal/open {:launcher :emacs}) doesn't seem to do anything - any idea how to debug this? Nothing in *Messages* buffer as far as I can see

djblue16:09:28

The implementation looks like

(defmethod browser/-open :emacs [{:keys [portal server]}]
  (let [url (str "http://" (:host server) ":" (:port server) "?" (:session-id portal))]
    (sh "emacsclient" "--no-wait" "--eval"
        (str "(xwidget-webkit-browse-url " (pr-str url) ")"))))

djblue16:09:53

Just tested it, still works for me :thinking_face:

lukasz16:09:23

Interesting - let me dig through it. Does portal have some sort of debug-level logging? I noticed yesterday when I was trying it out for the first time - it wouldn't launch in Chrome because... I never use Chrome, so the profiles were not setup there, so the browser would crash with no feedback sent back to Portal.

djblue16:09:03

No, unfortunately no debug logging, although shell calls should print out stuff if there are errors https://github.com/djblue/portal/blob/master/src/portal/runtime/shell.cljc#L8-L12

lukasz17:09:39

Ah, I see what's up - I don't run emacs server. I suppose I can hack around it and start the webserver on a known port and then pass that to xwdigets-browse-url somehow

lukasz17:09:35

@U1G869VNV last question (for now 😉 ) - any reason why host and port are not included in the data returned by (portal.api/sessions)? Or is there a way to find host + port for session ID? With that it would be easy to do something like: • (portal/open {:some :opt}) #> {:session-id ... :host ... :port ... } • write the URL to a file • make Emacs read it and launch the browser I use Monroe nREPL client so it's all nicely doable from there.

djblue17:09:52

Ohh, I think you want to do this then

(portal.api/url (portal.api/open {:launcher false}))

djblue17:09:51

I think the main reason a host + port aren't included is that they can change independently of a session

lukasz17:09:38

Gotcha. Let me see if I can make it work, and share what I came up with 👍

djblue17:09:26

https://cljdoc.org/d/djblue/portal/0.48.0/doc/editors/emacs would be a good place to add any discoveries if you would like 👌

lukasz17:09:57

I'll be more than happy to, let's see how it goes

awesome 1
lukasz17:09:30

Was easier than expected, at least the quick and dirty version:

(defun lk/monroe-portal ()
  (interactive)
  ;; initiate portal session
  (let* ((project-root (projectile-acquire-root))
         (default-directory project-root)
         (portal-url-file (format "%s.portal-url" project-root)))
    (monroe-input-sender
     (get-buffer-process (monroe-repl-buffer))
     (format "(require 'portal.api) (spit \"%s\" (portal.api/url (portal.api/open {:launcher false})))"
             portal-url-file))
    (sleep-for 1) ;; uh... this is a hack
    (let ((url (with-temp-buffer
                 (insert-file-contents portal-url-file)
                 (buffer-string))))
      (xwidget-webkit-browse-url url))))

djblue18:09:02

I'm curious if the nrepl client can return the value directly, is there a reason a file is required?

lukasz18:09:23

Good point, I'll dig into that when I have some more time later this week - if I find a way, I'll update the docs pull request. I remember looking into this a while back (for different reasons) and I think Monroe can only print back to the REPL buffer - unless I drop down to the nrepl protocol and do it there I suppose.

👍 1
djblue18:09:01

I wonder if https://github.com/sanel/monroe/blob/master/monroe.el#L247C8-L254 might work better. I assume the callback is called after a value is returned :thinking_face:

lukasz18:09:17

Yeah, that could be it - I contributed to Monroe a while back so I'm a bit rusty with the internals, that's a good pointer though!

👍 1