-
Notifications
You must be signed in to change notification settings - Fork 54
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
Embed swank-js within existing node.js server #65
Conversation
By default swank-js starts a server as soon as it is required. Instead export functions to start the servers, and remove the default behavior of relying on argv.
…mand * Remove custom quit_lisp handler * Add built-in quit-lisp handler * Provide self and response object to custom methods so they can accomplish more * Deal with quit message from handler * Note: if the client reconnects, they will have the same context as previous client
… to where the repl call ends
Better is to rewrite these calls to use some other function that conditionally does logging.
Thanks for contributing! What's the difference to using |
The difference is that require("swank-js/client/node").setupNodeJSClient(); is a client for an existing server. Not a server in itself. So it didn't seem like it was capable of evaluating code within the global context of my app from SLIME. |
Another related thing I noticed was that in order to prevent SLIME from trying to launch the entire node.js process (instead of just connecting to it via TCP), I had to do this to make C-c C-z from a newly-opened .js file Just Work. Would be nice if there was a better way. ;; Node REPL using SLIME
(add-to-list 'load-path (concat my-emacs-path "/elisp/slime"))
(add-to-list 'load-path (concat my-emacs-path "/elisp/slime/contrib"))
(require 'slime)
(autoload 'slime-js-minor-mode "slime-js" nil t)
(add-hook 'js2-mode-hook
(lambda ()
(slime-js-minor-mode 1)))
(slime-setup '(slime-repl slime-js))
(setq slime-auto-connect 'always)
(setq slime-kill-without-query-p t)
(setq slime-protocol-version 'ignore)
(defun slime ()
(interactive)
(let ((process (slime-connect "localhost" 4005)))
;; Use "NODE" instead of nil in the REPL buffer name
(setf (slime-connection-name process) "NODE"))) |
+1! |
Looks great! Thanks! can you update the wiki with some instructions? Cheers! |
Embed swank-js within existing node.js server
One thing to be aware of is that require() currently does not work with my patches, so may want to fix that before the next release. I'm thinking about plugging this into the built-in node.js REPL as a way of solving that. Possibly by taking a particular version of repl.js from node source and making small changes, possibly by just opening a socket to the one that comes with node.js. |
I updated the wiki with some instructions on how I used it, hope this helps. |
Here are some changes I've made to support embedding swank-js within an existing node.js server, with the goal being to inspect and modify state within that server.
I'm looking for comments to see whether honing these changes is worth it. They're not usable as-is for the main repo, but if some of it were made configurable, it might be useful.
One change that could be taken by itself (with some modification) is limiting stacktrace output in errors so that it doesn't overwhelm Emacs REPL buffers.
Example for integrating into another server: