Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Feature: include helper function for starting socket repls #209

Copy link
Copy link
Open
@mikepjb

Description

@mikepjb
Issue body actions

Hi guys,

Just started using inf-clojure and it's great as a simple tool.

I wrote a helper function for my personal use that I think may be useful to include in inf-clojure - let me know what you think, I'd like to improve & contribute this myself if you think it's worth including.

The code itself is loosely based on how cider does it's jack-in/spawning processes, I used the code there as a reference.

(also please excuse the elisp, I'm a long time vim user 😉)

  ;; used to transfer state between the connection fns and
  ;; socket-filter.
  (defvar-local repl-setup-callback nil)

  (defun config/socket-filter (process output)
    (let ((server-buffer (process-buffer process)))
      (when (buffer-live-p server-buffer)
	(with-current-buffer server-buffer
          (insert output)))
      (let ((prompt-displayed (string-match "=>" output)))
	(when prompt-displayed
	  (message (format "REPL prompt found for %s" (process-name process)))
	  (with-current-buffer server-buffer
	    (when repl-setup-callback
	      (funcall repl-setup-callback)))))))

  (defun config/create-repl-setup (port repl-type)
    (lambda ()
      (setq-default inf-clojure-repl-type (intern repl-type)) ;; doesn't work, still getting repl selection prompt!
      (inf-clojure-connect "localhost" port)))

  (defun config/start-repl (repl-type port)
    (let* ((socket-process-name "socket-server")
	   (socket-buffer-name "*test-socket-buffer*")
	   (socket-buffer (get-buffer-create socket-buffer-name))
	   (sock (start-file-process-shell-command
		  socket-process-name socket-buffer
		  (concat "clojure"
			  " -J-Dclojure.server.repl=\"{:port "
			  (number-to-string port)
			  " :accept clojure.core.server/repl}\" -Mdev"))))
      (with-current-buffer socket-buffer
	(setq-local repl-setup-callback (config/create-repl-setup port repl-type)))
      (set-process-filter sock #'config/socket-filter)
      (message (format "Socket server started on port: %s" port))
      sock))

  (defun config/clj-repl ()
    (interactive)
    (config/start-repl "clojure" 5555))

  (defun config/cljs-repl ()
    (interactive)
    (config/start-repl "cljs" 5556))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.