Skip to content

Commit

Permalink
Abandon automagical envrc-mode-hook; instead recommend dir-locals
Browse files Browse the repository at this point in the history
Although a neat idea it can't reliably run soon enough.

Effectively this commit reverts a chunk of the previous commit
concerning that hook. However it preserves the change where we make
sure REPLs are per-back-end.
  • Loading branch information
greghendershott committed Apr 11, 2024
1 parent 2d5207e commit 6970ee7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 30 deletions.
16 changes: 14 additions & 2 deletions doc/racket-mode.texi
Original file line number Diff line number Diff line change
Expand Up @@ -3092,6 +3092,9 @@ The following values will @emph{not} work:

Function to call to browse a URL@.

Defaults to @ref{racket-browse-url-using-temporary-file} on macOS and
@code{browse-url} on other platforms.

@node racket-xp-after-change-refresh-delay
@subsection racket-xp-after-change-refresh-delay

Expand Down Expand Up @@ -3713,7 +3716,7 @@ A value for the variable @ref{racket-show-functions}.
@code{(racket-repl-buffer-name-shared)}


All @ref{racket-mode} edit buffers share one @ref{racket-repl-mode} buffer per back end.
Share one @ref{racket-repl-mode} buffer per back end.

A value for the variable @ref{racket-repl-buffer-name-function}.

Expand All @@ -3733,7 +3736,7 @@ A value for the variable @ref{racket-repl-buffer-name-function}.
@code{(racket-repl-buffer-name-project)}


All @ref{racket-mode} buffers in a project share a @ref{racket-repl-mode} buffer.
Share a @ref{racket-repl-mode} buffer per back end and per project.

A value for the variable @ref{racket-repl-buffer-name-function}.

Expand Down Expand Up @@ -3932,6 +3935,15 @@ are a few examples.
:racket-program "xvfb-run racket")
@end lisp

Tip: If you use various versions of Racket via .envrc files and
@code{envrc-global-mode}, then in each such directory with a .envrc
file you should have a .dir-locals.el file to force the use of a
distinct back end:

@lisp
((nil . ((eval . (racket-add-back-end default-directory)))))
@end lisp

@node Running racket and raco commands in a shell or terminal (1)
@section Running racket and raco commands in a shell or terminal

Expand Down
39 changes: 11 additions & 28 deletions racket-back-end.el
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ are a few examples.
(racket-add-back-end \"/ssh:headless:~/gui-project/\"
:racket-program \"xvfb-run racket\")
#+END_SRC
Tip: If you use various versions of Racket via .envrc files and
`envrc-global-mode', then in each such directory with a .envrc
file you should have a .dir-locals.el file to force the use of a
distinct back end:
#+BEGIN_SRC lisp
((nil . ((eval . (racket-add-back-end default-directory)))))
#+END_SRC
"
(unless (and (stringp directory) (file-name-absolute-p directory))
(error "racket-add-back-end: directory must be file-name-absolute-p"))
Expand Down Expand Up @@ -257,32 +266,6 @@ are a few examples.
(unless no-refresh-watches-p
(racket--back-end-refresh-watches)))

;; Avoid user needing to use dir-locals.el to manually create a
;; distinct back end for each envrc directory; see issue #706.
(eval-after-load 'envrc
'(progn
(defvar envrc--status)
(declare-function envrc--find-env-dir "ext:envrc" ())
(defun racket-back-end-envrc-mode-hook ()
"A value for `envrc-mode-hook'.
Automatically configures a distinct back end for the directory of
the dominating envrc file, if any. As a result, each such back
end uses appropriate `exec-path' and `process-environment'
values."
(when-let ((env-dir (and (eq 'on envrc--status)
(envrc--find-env-dir))))
(unless (cl-find env-dir
racket-back-end-configurations
:test
(lambda (dir back-end)
(equal dir (plist-get back-end :directory))))
(when-let ((path-to-racket (executable-find (if racket--winp "Racket.exe" "racket"))))
(message "racket-back-end-envrc-mode-hook configuring back end for %S to use %S"
env-dir path-to-racket)
(racket-add-back-end env-dir :racket-program path-to-racket)))))
(add-hook 'envrc-mode-hook 'racket-back-end-envrc-mode-hook)))

(defun racket-back-end-name (&optional back-end)
"Return the \"name\" of a back end.
Expand Down Expand Up @@ -471,8 +454,8 @@ a possibly slow remote connection."
(if (racket--back-end-local-p back-end)
(cons (or (executable-find (or (plist-get back-end :racket-program)
racket-program))
(user-error
"Cannot find Racket executable\nracket-program: %S\nexec-path: %S"
(error
"Cannot executable-find Racket:\n racket-program: %S\n exec-path: %S"
racket-program
exec-path))
racket-command-args)
Expand Down

0 comments on commit 6970ee7

Please sign in to comment.