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

Commit 57c5556

Browse filesBrowse files
committed
Support loading directory locals in our buffers, simplify code
A couple of changes to the way the redirect buffer and the main REPL buffer are created was needed in order to have actual loading of .dir-locals.el. Additionally, code in inf-clojure--process-response has been simplified and corrected.
1 parent d3c0d4f commit 57c5556
Copy full SHA for 57c5556

File tree

1 file changed

+35
-25
lines changed
Filter options

1 file changed

+35
-25
lines changed

‎inf-clojure.el

Copy file name to clipboardExpand all lines: inf-clojure.el
+35-25Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,10 @@ run).
575575
(list cmd)
576576
(split-string cmd))))
577577
(message "Starting Clojure REPL via `%s'..." cmd)
578-
(set-buffer (apply #'make-comint
579-
"inf-clojure" (car cmdlist) nil (cdr cmdlist)))
580-
(inf-clojure-mode)))
578+
(with-current-buffer (apply #'make-comint
579+
"inf-clojure" (car cmdlist) nil (cdr cmdlist))
580+
(inf-clojure-mode)
581+
(hack-dir-local-variables-non-file-buffer))))
581582
(setq inf-clojure-buffer "*inf-clojure*")
582583
(if inf-clojure-repl-use-same-window
583584
(pop-to-buffer-same-window "*inf-clojure*")
@@ -1108,6 +1109,17 @@ are going to match those."
11081109
(length string))
11091110
(or (string-match prompt string) (length string))))
11101111

1112+
(defun inf-clojure--get-redirect-buffer ()
1113+
"Get the redirection buffer, creating it if necessary.
1114+
1115+
It is the buffer used for processing REPL responses, see variable
1116+
\\[inf-clojure--redirect-buffer-name]."
1117+
(or (get-buffer inf-clojure--redirect-buffer-name)
1118+
(let ((buffer (generate-new-buffer inf-clojure--redirect-buffer-name)))
1119+
(with-current-buffer buffer
1120+
(hack-dir-local-variables-non-file-buffer)
1121+
buffer))))
1122+
11111123
;; Originally from:
11121124
;; https://github.com/glycerine/lush2/blob/master/lush2/etc/lush.el#L287
11131125
(defun inf-clojure--process-response (command process &optional beg-regexp end-regexp)
@@ -1118,31 +1130,29 @@ If BEG-REGEXP is nil, the result string will start from (point)
11181130
in the results buffer. If END-REGEXP is nil, the result string
11191131
will end at (point-max) in the results buffer. It cuts out the
11201132
output from and including the `inf-clojure-prompt`."
1121-
(let ((work-buffer inf-clojure--redirect-buffer-name)
1133+
(let ((redirect-buffer-name inf-clojure--redirect-buffer-name)
11221134
(sanitized-command (inf-clojure--sanitize-command command)))
11231135
(when (not (string-empty-p sanitized-command))
11241136
(inf-clojure--log-string command "----CMD->")
1125-
(with-current-buffer (get-buffer-create work-buffer)
1126-
(erase-buffer)
1127-
(comint-redirect-send-command-to-process sanitized-command work-buffer process nil t)
1128-
;; Wait for the process to complete
1129-
(set-buffer (process-buffer process))
1130-
(while (and (null comint-redirect-completed)
1131-
(accept-process-output process 1 0 t))
1132-
(sleep-for 0.01))
1133-
;; Collect the output
1134-
(set-buffer work-buffer)
1135-
(goto-char (point-min))
1136-
(let* ((buffer-string (buffer-substring-no-properties (point-min) (point-max)))
1137-
(boundaries (inf-clojure--string-boundaries buffer-string inf-clojure-prompt beg-regexp end-regexp))
1138-
(beg-pos (car boundaries))
1139-
(end-pos (car (cdr boundaries)))
1140-
(prompt-pos (car (cdr (cdr boundaries))))
1141-
(response-string (substring buffer-string beg-pos (min end-pos prompt-pos))))
1142-
(inf-clojure--log-string buffer-string "<-BUF----")
1143-
(inf-clojure--log-string boundaries "<-BND----")
1144-
(inf-clojure--log-string response-string "<-RES----")
1145-
response-string)))))
1137+
(set-buffer (inf-clojure--get-redirect-buffer))
1138+
(erase-buffer)
1139+
(comint-redirect-send-command-to-process sanitized-command redirect-buffer-name process nil t)
1140+
;; Wait for the process to complete
1141+
(set-buffer (process-buffer process))
1142+
(while (and (null comint-redirect-completed)
1143+
(accept-process-output process 1 0 t))
1144+
(sleep-for 0.01))
1145+
;; Collect the output
1146+
(set-buffer redirect-buffer-name)
1147+
(goto-char (point-min))
1148+
(let* ((buffer-string (buffer-substring-no-properties (point-min) (point-max)))
1149+
(boundaries (inf-clojure--string-boundaries buffer-string inf-clojure-prompt beg-regexp end-regexp))
1150+
(beg-pos (car boundaries))
1151+
(end-pos (car (cdr boundaries)))
1152+
(prompt-pos (car (cdr (cdr boundaries))))
1153+
(response-string (substring buffer-string beg-pos (min end-pos prompt-pos))))
1154+
(inf-clojure--log-string response-string "<-RES----")
1155+
response-string))))
11461156

11471157
(defun inf-clojure--nil-string-match-p (string)
11481158
"Return true iff STRING is not nil.

0 commit comments

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