Closed lukaszkorecki closed 6 years ago
Good idea!
Can you please rename function to monroe-nrepl-server-start
and put cmd
as global variable, like monroe-nrepl-server-cmd
and monroe-nrepl-server-args
?
This way it will not be dependable on leiningen and can be easily replaced with boot
or other language implementations
What if this knew how to tell when the server launched (by calling monroe-locate-running-nrepl-host
) and could actually make the connection?
@sanel Will do!
@technomancy I like that 👍 - and locate-dominating-file
can be used to set the workdir of terminal buffer.
Using a terminal buffer here when the server is running headlessly actually struck me as a bit odd; usually that's for situations when you're interacting over stdio. Using async-shell-command
might be simpler?
Ah, that's a leftover from the original version of the function when it didn't use the :headless
option. I'll have a look at the async command 👍
@sanel @technomancy Pushed the following updates:
.nrepl-port
fileasync-start-process
rather than using make-term
Looks very good. Thanks @lukaszkorecki !
🙌
@lukaszkorecki sorry for re-opening this, from where you used async-start-process
? My emacs version 25.3.1 doesn't have it... Did you mean to use async-shell-command
instead?
@sanel I'm running Emacs 26 and have 25 laying around as well. Let me check if 25 has an equivalent function
Here is implementation with async-shell-command
:
diff --git a/monroe.el b/monroe.el
index 9135f00..0d655d3 100644
--- a/monroe.el
+++ b/monroe.el
@@ -544,24 +544,17 @@ as path can be remote location. For remote paths, use absolute path."
(defun monroe-nrepl-server-start ()
"Starts nrepl server. Uses monroe-nrepl-server-cmd + monroe-nrepl-server-cmd-args as the command. Finds project root by locatin monroe-nrepl-server-project-file"
(interactive)
- (let* ((cmd monroe-nrepl-server-cmd)
- (switches (split-string-and-unquote monroe-nrepl-server-cmd-args))
- (nrepl-buf-name (concat "*" monroe-nrepl-server-buffer-name "*"))
+ (let* ((nrepl-buf-name (concat "*" monroe-nrepl-server-buffer-name "*"))
(repl-started-dir (monroe-locate-port-file)))
(if repl-started-dir
- (message (concat "Monroe: nREPL server already running in " repl-started-dir))
+ (message "nREPL server already running in %s" repl-started-dir)
(progn
(lexical-let ((default-directory
(locate-dominating-file default-directory
monroe-nrepl-server-project-file)))
- (message (concat
- "Monroe: Starting nREPL server in " default-directory))
- (apply 'async-start-process
- monroe-nrepl-server-buffer-name
- cmd
- nil
- switches))
- (switch-to-buffer nrepl-buf-name)))))
+ (message "Starting nREPL server in %s" default-directory)
+ (async-shell-command (concat monroe-nrepl-server-cmd " " monroe-nrepl-server-cmd-args)
+ nrepl-buf-name))))))
(defun monroe-extract-keys (htable)
"Get all keys from hashtable."
Will this work for you? (Emacs 26 and 25)
@sanel checking 👍
@sanel yep confirmed working in Emacs 26.1 and Emacs 25.3.1 (both OSX)
@sanel Sorry for that - I didn't realize that async-start-process
is not a built-in (it comes with async.el
, which is probably pulled in by something else in my config)
No worry @lukaszkorecki :) I guess you have https://github.com/jwiegley/emacs-async package automatically loaded.
I had this function in my Emacs config for a while now and I thought I'll share it. It's quite naive in the implementation, it offers no help in finding the project's root path so my usual flow is:
project.clj
M-x monroe-start-lein-nrepl
M-x monroe
Now, it's probably not a good idea for Monroe to become CIDER's equivalent, but even simpler Clojure integration modes like
inf-clojure
have some way of launching the REPL server in the background.Let me know what you think!