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

Feature: include helper function for starting socket repls #209

Open
mikepjb opened this issue Mar 18, 2023 · 1 comment
Open

Feature: include helper function for starting socket repls #209

mikepjb opened this issue Mar 18, 2023 · 1 comment

Comments

@mikepjb
Copy link
Contributor

mikepjb commented Mar 18, 2023

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))
@bbatsov
Copy link
Member

bbatsov commented Mar 18, 2023

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

Nobody's perfect. 😉

I guess it'd be useful to add an option to start a socket REPL straight from Emacs, so feel free to convert this to a PR and we can discuss the code there in more details.

mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 18, 2023
inf-clojure-socket is a helper function to create
and connect to a socket REPL from within Emacs.
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 18, 2023
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 18, 2023
When multiple REPLs are running, it is hardly useful to evaluate
Clojurescript inside a Clojure REPL so there are two global
inf-clojure buffers now for each 'sub'-language cljs & clj. When
running inf-clojure functions, we take into account the major-mode
before deciding which REPL should perform evaluation.
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 18, 2023
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 19, 2023
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 19, 2023
The user gets asked if they want to close each buffer sequentially.
Or whatever their process-kill-query-function dictates.
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 20, 2023
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 24, 2023
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 24, 2023
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 24, 2023
More simplification, more consistent naming conventions and also
cleaning up bugs.
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 24, 2023
inf-clojure-socket is a helper function to create
and connect to a socket REPL from within Emacs.
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 24, 2023
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 24, 2023
When multiple REPLs are running, it is hardly useful to evaluate
Clojurescript inside a Clojure REPL so there are two global
inf-clojure buffers now for each 'sub'-language cljs & clj. When
running inf-clojure functions, we take into account the major-mode
before deciding which REPL should perform evaluation.
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 24, 2023
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 24, 2023
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 24, 2023
The user gets asked if they want to close each buffer sequentially.
Or whatever their process-kill-query-function dictates.
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 24, 2023
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 24, 2023
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 24, 2023
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 24, 2023
More simplification, more consistent naming conventions and also
cleaning up bugs.
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 24, 2023
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 24, 2023
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 26, 2023
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 26, 2023
inf-clojure-socket is a helper function to create
and connect to a socket REPL from within Emacs.

[clojure-emacs#209] pass :repl-type to inf-clojure-connect

[clojure-emacs#209] Automatic REPL selection by type

When multiple REPLs are running, it is hardly useful to evaluate
Clojurescript inside a Clojure REPL so there are two global
inf-clojure buffers now for each 'sub'-language cljs & clj. When
running inf-clojure functions, we take into account the major-mode
before deciding which REPL should perform evaluation.

[clojure-emacs#209] Correct changelog PR link

[clojure-emacs#209] fix modeline + better socket form support

[clojure-emacs#209] close socket buffer when REPL buffer closed

The user gets asked if they want to close each buffer sequentially.
Or whatever their process-kill-query-function dictates.

[clojure-emacs#209] ensure space for clojure cli args

[clojure-emacs#209] remove cljs/dual buffer & keep this PR simple

[clojure-emacs#209] clean up!

[clojure-emacs#209] implement PR feedback

More simplification, more consistent naming conventions and also
cleaning up bugs.

[clojure-emacs#209] linting fixes

[clojure-emacs#209] bug fix with manually set socket-repl cmd

[clojure-emacs#209] include node-babashka and fix PR remarks
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 26, 2023
inf-clojure-socket is a helper function to create
and connect to a socket REPL from within Emacs.

[clojure-emacs#209] pass :repl-type to inf-clojure-connect

[clojure-emacs#209] Automatic REPL selection by type

When multiple REPLs are running, it is hardly useful to evaluate
Clojurescript inside a Clojure REPL so there are two global
inf-clojure buffers now for each 'sub'-language cljs & clj. When
running inf-clojure functions, we take into account the major-mode
before deciding which REPL should perform evaluation.

[clojure-emacs#209] Correct changelog PR link

[clojure-emacs#209] fix modeline + better socket form support

[clojure-emacs#209] close socket buffer when REPL buffer closed

The user gets asked if they want to close each buffer sequentially.
Or whatever their process-kill-query-function dictates.

[clojure-emacs#209] ensure space for clojure cli args

[clojure-emacs#209] remove cljs/dual buffer & keep this PR simple

[clojure-emacs#209] clean up!

[clojure-emacs#209] implement PR feedback

More simplification, more consistent naming conventions and also
cleaning up bugs.

[clojure-emacs#209] linting fixes

[clojure-emacs#209] bug fix with manually set socket-repl cmd

[clojure-emacs#209] include node-babashka and fix PR remarks
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 26, 2023
inf-clojure-socket is a helper function to create
and connect to a socket REPL from within Emacs.

[clojure-emacs#209] pass :repl-type to inf-clojure-connect

[clojure-emacs#209] Automatic REPL selection by type

When multiple REPLs are running, it is hardly useful to evaluate
Clojurescript inside a Clojure REPL so there are two global
inf-clojure buffers now for each 'sub'-language cljs & clj. When
running inf-clojure functions, we take into account the major-mode
before deciding which REPL should perform evaluation.

[clojure-emacs#209] Correct changelog PR link

[clojure-emacs#209] fix modeline + better socket form support

[clojure-emacs#209] close socket buffer when REPL buffer closed

The user gets asked if they want to close each buffer sequentially.
Or whatever their process-kill-query-function dictates.

[clojure-emacs#209] ensure space for clojure cli args

[clojure-emacs#209] remove cljs/dual buffer & keep this PR simple

[clojure-emacs#209] clean up!

[clojure-emacs#209] implement PR feedback

More simplification, more consistent naming conventions and also
cleaning up bugs.

[clojure-emacs#209] linting fixes

[clojure-emacs#209] bug fix with manually set socket-repl cmd

[clojure-emacs#209] include node-babashka and fix PR remarks
mikepjb pushed a commit to mikepjb/inf-clojure that referenced this issue Mar 26, 2023
inf-clojure-socket is a helper function to create
and connect to a socket REPL from within Emacs.

[clojure-emacs#209] pass :repl-type to inf-clojure-connect

[clojure-emacs#209] Automatic REPL selection by type

When multiple REPLs are running, it is hardly useful to evaluate
Clojurescript inside a Clojure REPL so there are two global
inf-clojure buffers now for each 'sub'-language cljs & clj. When
running inf-clojure functions, we take into account the major-mode
before deciding which REPL should perform evaluation.

[clojure-emacs#209] Correct changelog PR link

[clojure-emacs#209] fix modeline + better socket form support

[clojure-emacs#209] close socket buffer when REPL buffer closed

The user gets asked if they want to close each buffer sequentially.
Or whatever their process-kill-query-function dictates.

[clojure-emacs#209] ensure space for clojure cli args

[clojure-emacs#209] remove cljs/dual buffer & keep this PR simple

[clojure-emacs#209] clean up!

[clojure-emacs#209] implement PR feedback

More simplification, more consistent naming conventions and also
cleaning up bugs.

[clojure-emacs#209] linting fixes

[clojure-emacs#209] bug fix with manually set socket-repl cmd

[clojure-emacs#209] include node-babashka and fix PR remarks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants