portal

lukasz 2023-09-27T15:18:23.872909Z

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

djblue 2023-09-27T16:50:28.124979Z

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) ")"))))

djblue 2023-09-27T16:50:53.517779Z

Just tested it, still works for me 🤔

lukasz 2023-09-27T16:52:23.844969Z

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.

djblue 2023-09-27T16:56:03.918689Z

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

lukasz 2023-09-27T17:10:39.716059Z

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

lukasz 2023-09-27T17:17:35.081249Z

@djblue 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.

djblue 2023-09-27T17:20:52.802999Z

Ohh, I think you want to do this then

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

djblue 2023-09-27T17:21:51.141269Z

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

lukasz 2023-09-27T17:22:38.218879Z

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

djblue 2023-09-27T17:25:26.687599Z

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 👌

lukasz 2023-09-27T17:25:57.298849Z

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

1
lukasz 2023-09-27T17:47:30.735769Z

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))))

lukasz 2023-09-27T18:03:31.400859Z

@djblue here you go! https://github.com/djblue/portal/pull/196

djblue 2023-09-27T18:05:02.102799Z

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

lukasz 2023-09-27T18:11:23.859249Z

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
djblue 2023-09-27T18:14:01.243049Z

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 🤔

lukasz 2023-09-27T18:15:17.495579Z

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