Skip to content

Commit ec99211

Browse files
arichiardibbatsov
authored andcommitted
Support loading directory locals in our buffers
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 715bd82 commit ec99211

File tree

2 files changed

+36
-25
lines changed

2 files changed

+36
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* [#122](https://github.com/clojure-emacs/inf-clojure/pull/122): Introduce `inf-clojure-completions-fn` defcustom.
1212
* [#128](https://github.com/clojure-emacs/inf-clojure/pull/128): Expose `inf-clojure-apropos` as `C-c C-S-a` in `inf-clojure-mode` (the REPL).
1313
* [#125](https://github.com/clojure-emacs/inf-clojure/pull/125): Avoid throwing an error for frequent operations like completion.
14+
* [#130](https://github.com/clojure-emacs/inf-clojure/pull/130): Support loading directory locals in our buffers.
1415

1516
### Bugs Fixed
1617

inf-clojure.el

Lines 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*")
@@ -1124,6 +1125,17 @@ are going to match those."
11241125
(length string))
11251126
(or (string-match prompt string) (length string))))
11261127

1128+
(defun inf-clojure--get-redirect-buffer ()
1129+
"Get the redirection buffer, creating it if necessary.
1130+
1131+
It is the buffer used for processing REPL responses, see variable
1132+
\\[inf-clojure--redirect-buffer-name]."
1133+
(or (get-buffer inf-clojure--redirect-buffer-name)
1134+
(let ((buffer (generate-new-buffer inf-clojure--redirect-buffer-name)))
1135+
(with-current-buffer buffer
1136+
(hack-dir-local-variables-non-file-buffer)
1137+
buffer))))
1138+
11271139
;; Originally from:
11281140
;; https://github.com/glycerine/lush2/blob/master/lush2/etc/lush.el#L287
11291141
(defun inf-clojure--process-response (command process &optional beg-regexp end-regexp)
@@ -1134,31 +1146,29 @@ If BEG-REGEXP is nil, the result string will start from (point)
11341146
in the results buffer. If END-REGEXP is nil, the result string
11351147
will end at (point-max) in the results buffer. It cuts out the
11361148
output from and including the `inf-clojure-prompt`."
1137-
(let ((work-buffer inf-clojure--redirect-buffer-name)
1149+
(let ((redirect-buffer-name inf-clojure--redirect-buffer-name)
11381150
(sanitized-command (inf-clojure--sanitize-command command)))
11391151
(when (not (string-empty-p sanitized-command))
11401152
(inf-clojure--log-string command "----CMD->")
1141-
(with-current-buffer (get-buffer-create work-buffer)
1142-
(erase-buffer)
1143-
(comint-redirect-send-command-to-process sanitized-command work-buffer process nil t)
1144-
;; Wait for the process to complete
1145-
(set-buffer (process-buffer process))
1146-
(while (and (null comint-redirect-completed)
1147-
(accept-process-output process 1 0 t))
1148-
(sleep-for 0.01))
1149-
;; Collect the output
1150-
(set-buffer work-buffer)
1151-
(goto-char (point-min))
1152-
(let* ((buffer-string (buffer-substring-no-properties (point-min) (point-max)))
1153-
(boundaries (inf-clojure--string-boundaries buffer-string inf-clojure-prompt beg-regexp end-regexp))
1154-
(beg-pos (car boundaries))
1155-
(end-pos (car (cdr boundaries)))
1156-
(prompt-pos (car (cdr (cdr boundaries))))
1157-
(response-string (substring buffer-string beg-pos (min end-pos prompt-pos))))
1158-
(inf-clojure--log-string buffer-string "<-BUF----")
1159-
(inf-clojure--log-string boundaries "<-BND----")
1160-
(inf-clojure--log-string response-string "<-RES----")
1161-
response-string)))))
1153+
(set-buffer (inf-clojure--get-redirect-buffer))
1154+
(erase-buffer)
1155+
(comint-redirect-send-command-to-process sanitized-command redirect-buffer-name process nil t)
1156+
;; Wait for the process to complete
1157+
(set-buffer (process-buffer process))
1158+
(while (and (null comint-redirect-completed)
1159+
(accept-process-output process 1 0 t))
1160+
(sleep-for 0.01))
1161+
;; Collect the output
1162+
(set-buffer redirect-buffer-name)
1163+
(goto-char (point-min))
1164+
(let* ((buffer-string (buffer-substring-no-properties (point-min) (point-max)))
1165+
(boundaries (inf-clojure--string-boundaries buffer-string inf-clojure-prompt beg-regexp end-regexp))
1166+
(beg-pos (car boundaries))
1167+
(end-pos (car (cdr boundaries)))
1168+
(prompt-pos (car (cdr (cdr boundaries))))
1169+
(response-string (substring buffer-string beg-pos (min end-pos prompt-pos))))
1170+
(inf-clojure--log-string buffer-string "<-RES----")
1171+
response-string))))
11621172

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

0 commit comments

Comments
 (0)