Skip to content

Commit 5250f74

Browse files
committed
Add inf-clojure-prompt-on-commands and closes #48
The patch introduces a way to globally disable prompting. It deletes `inf-clojure-prompt-when-set-ns`. Only apropos always prompts.
1 parent 204e5b7 commit 5250f74

File tree

3 files changed

+42
-22
lines changed

3 files changed

+42
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
### New Features
66

7+
* [#51](https://github.com/clojure-emacs/inf-clojure/pull/51): Add `Add inf-clojure-prompt-on-commands` to globally disable prompting on commands.
78
* [#44](https://github.com/clojure-emacs/inf-clojure/pull/44): Add REPL types and Lumo support.
89
* [#50](https://github.com/clojure-emacs/inf-clojure/pull/50): Rename defcustoms to `inf-clojure-*-form` where appropriate.
910
* [#34](https://github.com/clojure-emacs/inf-clojure/pull/34): Add support for socket REPL connections.
10-
* [#46](https://github.com/clojure-emacs/inf-clojure/pull/46): Make it possible to disable prompt on `inf-clojure-set-ns`.
1111
* New interactive command `inf-clojure-display-version`.
1212
* [#42](https://github.com/clojure-emacs/inf-clojure/issues/42): Add a defcustom controlling the window in which the REPL buffer is displayed (`inf-clojure-repl-use-same-window`).
1313
* Font-lock the code in the REPL.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ the default specified in `inf-clojure-program`.
7070
You can set custom values to `inf-clojure` variables on a per-project basis using [directory
7171
variables](https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html).
7272

73+
Every REPL command prompts by default, but with a prefix arg you can disable prompting (for instance: `C-u C-c C-v` will show the docstring of the var at point.
74+
This behavior is flipped when `inf-clojure-prompt-on-commands` is set to `nil`.
75+
7376
## REPL Type
7477

7578
An `inf-clojure` REPL can be of different types: Clojure, ClojureScript, Lumo and Planck are all potentially valid options.

inf-clojure.el

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,17 @@ This should usually be a combination of `inf-clojure-prompt' and
238238
`inf-clojure-subprompt'."
239239
:type 'regexp)
240240

241-
(defcustom inf-clojure-prompt-on-set-ns t
241+
(defcustom inf-clojure-prompt-on-commands t
242242
"Controls whether to prompt when switching namespace."
243243
:type '(choice (const :tag "always" t)
244244
(const :tag "never" nil))
245-
:package-version '(inf-clojure . "2.0.0"))
245+
:package-version '(inf-clojure . "2.0.0")
246+
:safe 'booleanp)
247+
248+
(defun inf-clojure--prompt-on-commands-p (&optional invert)
249+
"Return the value of the variable `inf-clojure-prompt-on-commands'.
250+
Optionally invert the value, if INVERT is truthy."
251+
(if invert (not inf-clojure-prompt-on-commands) inf-clojure-prompt-on-commands))
246252

247253
(defcustom inf-clojure-repl-use-same-window nil
248254
"Controls whether to display the REPL buffer in the current window or not."
@@ -725,19 +731,24 @@ The value is nil if it can't find one."
725731
(defun inf-clojure-show-var-documentation (var)
726732
"Send a form to the inferior Clojure to give documentation for VAR.
727733
See function `inf-clojure-var-doc-form'."
728-
(interactive (inf-clojure-symprompt "Var doc" (inf-clojure-var-at-pt)))
729-
(comint-proc-query (inf-clojure-proc) (format (inf-clojure-var-doc-form) var)))
734+
(interactive "P")
735+
(let ((var (if (inf-clojure--prompt-on-commands-p var)
736+
(car (inf-clojure-symprompt "Var doc" (inf-clojure-var-at-pt)))
737+
(inf-clojure-var-at-pt))))
738+
(comint-proc-query (inf-clojure-proc) (format (inf-clojure-var-doc-form) var))))
730739

731740
(defun inf-clojure-show-var-source (var)
732-
"Send a form to the inferior Clojure to give source for VAR.
733-
See variable `inf-clojure-var-source-form'."
734-
(interactive (inf-clojure-symprompt "Var source" (inf-clojure-var-at-pt)))
735-
(comint-proc-query (inf-clojure-proc) (format inf-clojure-var-source-form var)))
741+
"Send a command to the inferior Clojure to give source for VAR.
742+
See variable `inf-clojure-var-source-command'."
743+
(interactive "P")
744+
(let ((var (if (inf-clojure--prompt-on-commands-p var)
745+
(car (inf-clojure-symprompt "Var source" (inf-clojure-var-at-pt)))
746+
(inf-clojure-var-at-pt))))
747+
(comint-proc-query (inf-clojure-proc) (format inf-clojure-var-source-form var))))
736748

737749
(defun inf-clojure-arglist (fn)
738750
"Send a query to the inferior Clojure for the arglist for function FN.
739751
See variable `inf-clojure-arglist-form'."
740-
(interactive (inf-clojure-symprompt "Arglist" (inf-clojure-fn-called-at-pt)))
741752
(let* ((proc (inf-clojure-proc))
742753
(comint-filt (process-filter proc))
743754
(kept "")
@@ -748,34 +759,40 @@ See variable `inf-clojure-arglist-form'."
748759
(process-send-string proc eldoc-snippet)
749760
(while (and (not (string-match inf-clojure-prompt kept))
750761
(accept-process-output proc 2)))
751-
(setq eldoc (and (string-match "(.+)" kept) (match-string 0 kept)))
752-
)
762+
(setq eldoc (and (string-match "(.+)" kept) (match-string 0 kept))))
753763
(set-process-filter proc comint-filt))
754764
eldoc))
755765

756766
(defun inf-clojure-show-arglist (fn)
757767
"Show the arglist for function FN in the mini-buffer."
758-
(interactive (inf-clojure-symprompt "Arglist" (inf-clojure-fn-called-at-pt)))
759-
(let ((eldoc (inf-clojure-arglist fn)))
768+
(interactive "P")
769+
(let* ((fn (if (inf-clojure--prompt-on-commands-p fn)
770+
(car (inf-clojure-symprompt "Arglist" (inf-clojure-fn-called-at-pt)))
771+
(inf-clojure-fn-called-at-pt)))
772+
(eldoc (inf-clojure-arglist fn)))
760773
(when eldoc
761774
(message "%s: %s" fn eldoc))))
762775

763776
(defun inf-clojure-show-ns-vars (ns)
764777
"Send a query to the inferior Clojure for the public vars in NS.
765778
See variable `inf-clojure-ns-vars-form'."
766-
(interactive (inf-clojure-symprompt "Ns vars" (clojure-find-ns)))
767-
(comint-proc-query (inf-clojure-proc) (format inf-clojure-ns-vars-form ns)))
779+
(interactive "P")
780+
(let ((ns (if (inf-clojure--prompt-on-commands-p ns)
781+
(car (inf-clojure-symprompt "Ns vars" (clojure-find-ns)))
782+
(clojure-find-ns))))
783+
(comint-proc-query (inf-clojure-proc) (format inf-clojure-ns-vars-form ns))))
768784

769785
(defun inf-clojure-set-ns (ns)
770786
"Set the ns of the inferior Clojure process to NS.
771787
Defaults to the ns of the current buffer, always prompting before
772788
setting, unless `inf-clojure-prompt-on-set-ns` is nil."
773-
(interactive (list (if inf-clojure-prompt-on-set-ns
774-
(inf-clojure-symprompt "Set ns to" (clojure-find-ns))
775-
(clojure-find-ns))))
776-
(when (or (not ns) (equal ns ""))
777-
(user-error "No namespace selected"))
778-
(comint-proc-query (inf-clojure-proc) (format inf-clojure-set-ns-form ns)))
789+
(interactive "P")
790+
(let ((ns (if (inf-clojure--prompt-on-commands-p ns)
791+
(car (inf-clojure-symprompt "Set ns to" (clojure-find-ns)))
792+
(clojure-find-ns))))
793+
(when (or (not ns) (equal ns ""))
794+
(user-error "No namespace selected"))
795+
(comint-proc-query (inf-clojure-proc) (format inf-clojure-set-ns-form ns))))
779796

780797
(defun inf-clojure-apropos (var)
781798
"Send a form to the inferior Clojure to give apropos for VAR.

0 commit comments

Comments
 (0)