[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/inf-clojure 8fb1929 254/313: Set REPL type from startup fo
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/inf-clojure 8fb1929 254/313: Set REPL type from startup form, prompt, or defcustom at startup |
Date: |
Wed, 11 Aug 2021 10:00:28 -0400 (EDT) |
branch: elpa/inf-clojure
commit 8fb19294207e0a6fd294a4e9c85b9d1b58ab9c15
Author: dan sutton <dan@dpsutton.com>
Commit: Bozhidar Batsov <bozhidar.batsov@gmail.com>
Set REPL type from startup form, prompt, or defcustom at startup
also prevent these when `inf-clojure` is invoked with a prefix arg
---
CHANGELOG.md | 5 ++++
README.md | 21 ++++++++++++++
inf-clojure.el | 90 ++++++++++++++++++++++++++--------------------------------
todo.org | 18 ++++++------
4 files changed, 77 insertions(+), 57 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ffe24b9..3c5b3ed 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,11 @@
## master (unreleased)
+### New features
+
+* [#174](https://github.com/clojure-emacs/inf-clojure/pull/174): Set REPL type
from startup form or prompt at startup, introduce
`inf-clojure-custom-repl-type` defcustom
+* [#174](https://github.com/clojure-emacs/inf-clojure/pull/174): Prefix on
`inf-clojure` to prevent using `inf-clojure-custom-startup` and
`inf-clojure-custom-repl-type.
+
## 2.2.0 (2020-04-15)
### New features
diff --git a/README.md b/README.md
index 83fcbe1..d1ddc19 100644
--- a/README.md
+++ b/README.md
@@ -136,6 +136,27 @@ for the symbol you want to show the docstring for.
## Configuration
+## Most Common Configuration
+
+Most likely you will want to set the startup command and the repl
+type. This is most easily set with the follow dir-locals
+
+```emacs-lisp
+((nil
+ (inf-clojure-custom-startup . "clojure -A:compliment")
+ (inf-clojure-custom-repl-type . clojure)))
+```
+
+There are two important commands here:
+1. `inf-clojure-custom-startup`: Which startup command to use so
+ inf-clojure can run the inferior process and
+2. `inf-clojure-custom-repl-type`: Which repl type it is so
+ inf-clojure knows how to format commands to the repl
+
+If these are set and you wish to prevent inf-clojure from using them,
+use a prefix arg when invoking `inf-clojure`.
+
+### All Configuration
**Note:** The configuration options were changed massively in `inf-clojure`
3.0.
In the time-honoured Emacs tradition `inf-clojure`'s behaviour is extremely
diff --git a/inf-clojure.el b/inf-clojure.el
index 85146dd..7399cc0 100644
--- a/inf-clojure.el
+++ b/inf-clojure.el
@@ -71,14 +71,6 @@
(require 'subr-x)
(require 'seq)
-(defvar inf-clojure-recognize-alist '((lumo . "lumo.repl")
- (planck . "planck.repl")
- ;; cljs goes after the selfhosts
- (cljs . "cljs.repl")
- (joker . "joker.repl")
- (babashka . "babashka.classpath")
- (clojure . "clojure.core.server")))
-
(defvar inf-clojure-startup-forms '((lein . "lein repl")
(boot . "boot repl")
(clojure . "clojure")
@@ -217,37 +209,13 @@ either `setq-local` or an entry in `.dir-locals.el`." )
"Global lock for protecting against proc filter race conditions.
See
http://blog.jorgenschaefer.de/2014/05/race-conditions-in-emacs-process-filter.html")
-(defun inf-clojure--detect-repl-type (proc)
- "Identifies the current REPL type for PROC."
- (when (not inf-clojure--repl-type-lock)
- (let ((inf-clojure--repl-type-lock t))
- (or (seq-some (lambda (r)
- (when (inf-clojure--some-response-p
- proc (format "(find-ns '%s)" (cdr r)))
- (car r)))
- inf-clojure-recognize-alist)
- 'clojure))))
-
-(defun inf-clojure-set-repl-type ()
+(defun inf-clojure--prompt-repl-type ()
"Set the REPL type to one of the available implementations."
(interactive)
- (let* ((proc (inf-clojure-proc))
- (types (mapcar #'car inf-clojure-repl-features))
- (type-to-set (intern
- (completing-read "Set REPL type:"
- (sort (mapcar #'symbol-name types)
#'string-lessp)))))
- (with-current-buffer (process-buffer proc)
- (setq-local inf-clojure-repl-type type-to-set))))
-
-(defun inf-clojure--set-repl-type (proc)
- "Set the REPL type if has not already been set.
-It requires a REPL PROC for inspecting the correct type."
- ;; todo: don't like this happening so frequently
- (with-current-buffer (process-buffer proc)
- (if (not inf-clojure-repl-type)
- (let ((repl-type (inf-clojure--detect-repl-type proc)))
- (setq-local inf-clojure-repl-type repl-type))
- inf-clojure-repl-type)))
+ (let ((types (mapcar #'car inf-clojure-repl-features)))
+ (intern
+ (completing-read "Set REPL type:"
+ (sort (mapcar #'symbol-name types) #'string-lessp)))))
(defgroup inf-clojure nil
"Run an external Clojure process (REPL) in an Emacs buffer."
@@ -390,6 +358,19 @@ Can be a cons pair of (host . port) where host is a string
and
port is an integer, or a string to startup an interpreter like
\"planck\".")
+(defcustom inf-clojure-custom-repl-type
+ nil
+ "REPL type to use for inf-clojure process buffer.
+Should be a symbol that is a key in `inf-clojure-repl-features'."
+ :package-version '(inf-clojure . "3.0.0")
+ :type '(choice (const :tag "clojure" clojure)
+ (const :tag "cljs" cljs)
+ (const :tag "lumo" lumo)
+ (const :tag "planck" planck)
+ (const :tag "joker" joker)
+ (const :tag "babashka" babashka)
+ (const :tag "determine at startup" nil)))
+
(defun inf-clojure--whole-comment-line-p (string)
"Return non-nil iff STRING is a whole line semicolon comment."
(string-match-p "^\s*;" string))
@@ -424,7 +405,6 @@ always be preferred over `comint-send-string`. It
delegates to
`comint-simple-send` so it always appends a newline at the end of
the string for evaluation. Refer to `comint-simple-send` for
customizations."
- (inf-clojure--set-repl-type proc)
(let ((sanitized (inf-clojure--sanitize-command string)))
(inf-clojure--log-string sanitized "----CMD->")
(comint-send-string proc sanitized)))
@@ -449,7 +429,6 @@ Clojure to load that file."
"Return the form to query the Inf-Clojure PROC for reloading a namespace.
If you are using REPL types, it will pickup the most appropriate
`inf-clojure-reload-form` variant."
- (inf-clojure--set-repl-type proc)
inf-clojure-reload-form)
(defcustom inf-clojure-reload-all-form "(require '%s :reload-all)"
@@ -468,7 +447,6 @@ Clojure to load that file."
"Return the form to query the Inf-Clojure PROC for :reload-all of a
namespace.
If you are using REPL types, it will pickup the most appropriate
`inf-clojure-reload-all-form` variant."
- (inf-clojure--set-repl-type proc)
inf-clojure-reload-all-form)
(defcustom inf-clojure-prompt "^[^=> \n]+=> *"
@@ -681,14 +659,23 @@ to suppress the usage of the target buffer discovery
logic."
;;;###autoload
(defun inf-clojure (cmd)
"Run an inferior Clojure process, input and output via buffer
`*inf-clojure*'.
-If there is a process already running in `*inf-clojure*', just switch
-to that buffer.
-With argument, allows you to edit the CMD used to launch
-it (default is value of `inf-clojure-*-cmd'). Runs the hooks
-from `inf-clojure-mode-hook' (after the `comint-mode-hook' is
-run).
-\(Type \\[describe-mode] in the process buffer for a list of commands.)"
- (interactive (list (or inf-clojure-custom-startup
+If there is a process already running in `*inf-clojure*', just
+switch to that buffer.
+
+CMD is a string which serves as the startup command or a cons of
+host and port.
+
+ Prompts user for repl startup command and repl type if not
+inferrable from startup command. Uses
+`inf-clojure-custom-repl-type' and `inf-clojure-custom-startup'
+if those are set. Use a prefix to prevent using these when they
+are set.
+
+ Runs the hooks from `inf-clojure-mode-hook' (after the
+`comint-mode-hook' is run). \(Type \\[describe-mode] in the
+process buffer for a list of commands.)"
+ (interactive (list (or (unless current-prefix-arg
+ inf-clojure-custom-startup)
(completing-read "Select Clojure REPL startup
command: "
(mapcar #'cdr
inf-clojure-startup-forms)
nil
@@ -698,11 +685,16 @@ run).
(let ((default-directory (inf-clojure-project-root))
(cmdlist (if (consp cmd)
(list cmd)
- (split-string cmd))))
+ (split-string cmd)))
+ (repl-type (or (unless prefix-arg
+ inf-clojure-custom-repl-type)
+ (car (rassoc cmd inf-clojure-startup-forms))
+ (inf-clojure--prompt-repl-type))))
(message "Starting Clojure REPL via `%s'..." cmd)
(with-current-buffer (apply #'make-comint
"inf-clojure" (car cmdlist) nil (cdr
cmdlist))
(inf-clojure-mode)
+ (setq-local inf-clojure-repl-type repl-type)
(hack-dir-local-variables-non-file-buffer))))
(setq inf-clojure-buffer "*inf-clojure*")
(if inf-clojure-repl-use-same-window
diff --git a/todo.org b/todo.org
index 1495a54..811c287 100644
--- a/todo.org
+++ b/todo.org
@@ -1,6 +1,6 @@
* Core
-** TODO set repl type on connection not first command
+** DONE set repl type on connection not first command
For some reason ~inf-clojure--set-repl-type~ is called in:
1. inf-clojure--send-string
2. inf-clojure-reload-form
@@ -11,13 +11,6 @@ Seems better to do this on the two different connection
methods and then be done
** DONE do we need repl type in both source buffer and connection?
these can get out of sync and lead to confusing errors when closing a repl
and opening a new one. It seems like we keep the repl-type in the source buffer
to prevent a single ~(with-current-buffer (process-buffer proc)
inf-clojure-repl-type)~
-** TODO nice startup
-There's some project detection but that's becoming less and less useful as
time goes on. Shadow, lein, deps.edn can all easily be mixed in the same
project. And then lumo, planck, or bb scripts could live side by side. Rather
than trying to guess the project type, I think i'd like to mimic geiser's style
of handling multiple scheme backends. Perhaps ~m-x inf-clojure-run-planck~ and
similar could help out.
-
-Some considerations:
-- is this path aware? IE, don't show an option to run planck, lumo, etc, if
they aren't visible or installed?
-- should it have a rebuild function so that user registered implementations
can show up in the ~m-x~ menu as well?
-
** DONE Better dispatch for the implementations
Right now the functions are kinda clunky cond statements:
#+BEGIN_SRC emacs-lisp
@@ -65,6 +58,9 @@ The source primitive is quite nice but we most likely need a
way to navigate to
** TODO PREPL
Be nice to implement this now that we have parseedn in elisp to understand edn.
+
+** DONE inhibit custom repl-type and startup form
+its nice to have these in dir-locals to just start up. but if you normally
have ~clojure -m cljs.main -r~ as the startup command but you want to crank up
a clj repl there's no way without removing those dir locals.
* Nice-to-haves
** TODO Put repl type in modeline
Rather than just ~*inf-clojure*~ we could put the repl type. Make it easy to
follow and makes it easy to see when it gets it wrong.
@@ -81,3 +77,9 @@ Seems a bit heavy handed but its working for me so far.
** TODO is disabling color still required?
in the readme it mentions that color should be turned off. in my usage I
haven't run into this problem at all. perhaps no longer true?
+** TODO nice startup
+There's some project detection but that's becoming less and less useful as
time goes on. Shadow, lein, deps.edn can all easily be mixed in the same
project. And then lumo, planck, or bb scripts could live side by side. Rather
than trying to guess the project type, I think i'd like to mimic geiser's style
of handling multiple scheme backends. Perhaps ~m-x inf-clojure-run-planck~ and
similar could help out.
+
+Some considerations:
+- is this path aware? IE, don't show an option to run planck, lumo, etc, if
they aren't visible or installed?
+- should it have a rebuild function so that user registered implementations
can show up in the ~m-x~ menu as well?
- [nongnu] elpa/inf-clojure 715bd82 188/313: Add macroexpand forms for Lumo, (continued)
- [nongnu] elpa/inf-clojure 715bd82 188/313: Add macroexpand forms for Lumo, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure ec99211 189/313: Support loading directory locals in our buffers, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 803a419 193/313: Add test harness (finally?), ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 903dd73 196/313: Set explicitly inf-clojure-repl-type for REPL and source buffer, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure de59fce 206/313: Merge pull request #142 from austinhaas/master, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 9deb198 202/313: Use comint-send-string, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure b2224bc 211/313: Merge pull request #145 from austinhaas/master, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure cf53284 220/313: Fix for https://github.com/clojure-emacs/inf-clojure/issues/154 (#158), ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 1e93db8 237/313: Bump the development version, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure c590c65 240/313: Remove projects from inf-clojure except to serve as project root, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 8fb1929 254/313: Set REPL type from startup form, prompt, or defcustom at startup,
ELPA Syncer <=
- [nongnu] elpa/inf-clojure f298612 259/313: [Fix #173] Use clojure-mode project detection (#176), ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 380528f 078/313: Bump the clojure-mode dependency, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 24463b4 105/313: [Fix #26] Make switching to the REPL optional on, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure b357856 112/313: Rename defcustoms to `inf-clojure-*-form` where appropriate, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 64162aa 138/313: Fix a formatting issue in the README, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 9d2d143 144/313: Make sure tabs would never sneak in, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure c08d8bb 165/313: Split the only when-let for backward compatibility, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure 94f440e 192/313: Extract keyword words for completion, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure da88c8c 205/313: Require seq library. Fixes https://github.com/clojure-emacs/inf-clojure/issues/141, ELPA Syncer, 2021/08/11
- [nongnu] elpa/inf-clojure feca1cc 201/313: Send string even when empty, ELPA Syncer, 2021/08/11