Skip to content

Commit

Permalink
use correct buffer with project directory
Browse files Browse the repository at this point in the history
  • Loading branch information
bbuccianti committed Nov 28, 2019
1 parent 0cbf763 commit 38a1488
Showing 1 changed file with 33 additions and 22 deletions.
55 changes: 33 additions & 22 deletions monroe.el
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ be called when reply is received."
(message (append (list "id" id) request))
(bmessage (monroe-encode message)))
(puthash id callback monroe-requests)
(monroe-write-message "*monroe-connection*" bmessage)))
(monroe-write-message
(concat "*monroe-conn*" (monroe-get-directory)) bmessage)))

(defun monroe-clear-request-table ()
"Erases current request table."
Expand All @@ -215,7 +216,7 @@ be called when reply is received."

(defun monroe-current-session ()
"Returns current session id."
(with-current-buffer "*monroe-connection*"
(with-current-buffer (concat "*monroe-conn*" (monroe-get-directory))
monroe-session))

;;; nrepl messages we knows about
Expand Down Expand Up @@ -261,7 +262,8 @@ the operations supported by an nREPL endpoint."
(let ((output (concat err out
(if value
(concat value "\n"))))
(process (get-buffer-process monroe-repl-buffer)))
(process (get-buffer-process
(concat monroe-repl-buffer (monroe-get-directory)))))
;; update namespace if needed
(if ns (setq monroe-buffer-ns ns))
(comint-output-filter process output)
Expand Down Expand Up @@ -375,7 +377,11 @@ monroe-repl-buffer."
(port (string-to-number
(monroe-valid-host-string (second hp) "7888"))))
(message "Connecting to nREPL host on '%s:%d'..." host port)
(let ((process (open-network-stream "monroe" "*monroe-connection*" host port)))
(let ((process
(open-network-stream "monroe"
(concat "*monroe-conn*" (monroe-get-directory))
host
port)))
(set-process-filter process 'monroe-net-filter)
(set-process-sentinel process 'monroe-sentinel)
(set-process-coding-system process 'utf-8-unix 'utf-8-unix)
Expand All @@ -390,8 +396,10 @@ will force connection closing, which will as result call '(monroe-sentinel)'."
(when (and p (process-live-p p))
(delete-process p))))
;; 'monroe-repl-buffer' process is actually 'fake-proc'
(proc1 (get-buffer-process monroe-repl-buffer))
(proc2 (get-buffer-process "*monroe-connection*")))
(proc1 (get-buffer-process
(concat monroe-repl-buffer (monroe-get-directory))))
(proc2 (get-buffer-process
(concat "*monroe-conn*" (monroe-get-directory)))))
(funcall delete-process-safe proc1)
(funcall delete-process-safe proc2)))

Expand All @@ -400,7 +408,8 @@ will force connection closing, which will as result call '(monroe-sentinel)'."
(defun monroe-eval-region (start end &optional ns)
"Evaluate selected region."
(interactive "r")
(monroe-input-sender (get-buffer-process monroe-repl-buffer)
(monroe-input-sender (get-buffer-process
(concat monroe-repl-buffer (monroe-get-directory)))
(buffer-substring-no-properties start end)
ns))

Expand Down Expand Up @@ -498,6 +507,10 @@ inside a container.")
(fboundp 'clojure-find-ns)
(funcall 'clojure-find-ns)))

(defun monroe-get-directory ()
"Internal function to get project directory."
(locate-dominating-file default-directory monroe-nrepl-server-project-file))

(defun monroe-describe (symbol)
"Ask user about symbol and show symbol documentation if found."
(interactive
Expand Down Expand Up @@ -548,7 +561,7 @@ as path can be remote location. For remote paths, use absolute path."

(defun monroe-switch-to-repl ()
(interactive)
(pop-to-buffer monroe-repl-buffer))
(pop-to-buffer (concat monroe-repl-buffer (monroe-get-directory))))

(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"
Expand All @@ -558,12 +571,9 @@ as path can be remote location. For remote paths, use absolute path."
(if 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 "Starting nREPL server in %s" default-directory)
(async-shell-command (concat monroe-nrepl-server-cmd " " monroe-nrepl-server-cmd-args)
nrepl-buf-name))))))
(message "Starting nREPL server in %s" (monroe-get-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."
Expand Down Expand Up @@ -649,14 +659,15 @@ connection endpoint."
(list
(read-string (format "Host (default '%s'): " host)
nil nil host))))
(unless (ignore-errors
(with-current-buffer (get-buffer-create monroe-repl-buffer)
(prog1
(monroe-connect host-and-port)
(goto-char (point-max))
(monroe-mode)
(switch-to-buffer (current-buffer)))))
(message "Unable to connect to %s" host-and-port)))
(let ((monroe-buffer (concat monroe-repl-buffer (monroe-get-directory))))
(unless (ignore-errors
(with-current-buffer (get-buffer-create monroe-buffer)
(prog1
(monroe-connect host-and-port)
(goto-char (point-max))
(monroe-mode)
(switch-to-buffer (current-buffer)))))
(message "Unable to connect to %s" host-and-port))))

(provide 'monroe)

Expand Down

0 comments on commit 38a1488

Please sign in to comment.