Skip to content

Commit 518488c

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 518488c

File tree

3 files changed

+49
-23
lines changed

3 files changed

+49
-23
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: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,23 @@ 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 arg)
249+
"Return true if commands have to prompt.
250+
The behavior can altered with `inf-clojure-prompt-on-commands`.
251+
If ARG is \\[universal-argument] or `\\[universal-argument]
252+
\\[universal-argument]' the logic is flipped."
253+
(let ((narg (prefix-numeric-value arg)))
254+
(pcase narg
255+
(16 (not inf-clojure-prompt-on-commands)) ; inverting
256+
(4 (not inf-clojure-prompt-on-commands)) ; inverting
257+
(_ inf-clojure-prompt-on-commands))))
246258

247259
(defcustom inf-clojure-repl-use-same-window nil
248260
"Controls whether to display the REPL buffer in the current window or not."
@@ -725,19 +737,24 @@ The value is nil if it can't find one."
725737
(defun inf-clojure-show-var-documentation (var)
726738
"Send a form to the inferior Clojure to give documentation for VAR.
727739
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)))
740+
(interactive "P")
741+
(let ((var-at-pt (if (inf-clojure--prompt-on-commands-p var)
742+
(car (inf-clojure-symprompt "Var doc" (inf-clojure-var-at-pt)))
743+
(inf-clojure-var-at-pt))))
744+
(comint-proc-query (inf-clojure-proc) (format (inf-clojure-var-doc-form) var-at-pt))))
730745

731746
(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)))
747+
"Send a command to the inferior Clojure to give source for VAR.
748+
See variable `inf-clojure-var-source-command'."
749+
(interactive "P")
750+
(let ((var-at-pt (if (inf-clojure--prompt-on-commands-p var)
751+
(car (inf-clojure-symprompt "Var source" (inf-clojure-var-at-pt)))
752+
(inf-clojure-var-at-pt))))
753+
(comint-proc-query (inf-clojure-proc) (format inf-clojure-var-source-form var-at-pt))))
736754

737755
(defun inf-clojure-arglist (fn)
738756
"Send a query to the inferior Clojure for the arglist for function FN.
739757
See variable `inf-clojure-arglist-form'."
740-
(interactive (inf-clojure-symprompt "Arglist" (inf-clojure-fn-called-at-pt)))
741758
(let* ((proc (inf-clojure-proc))
742759
(comint-filt (process-filter proc))
743760
(kept "")
@@ -748,34 +765,40 @@ See variable `inf-clojure-arglist-form'."
748765
(process-send-string proc eldoc-snippet)
749766
(while (and (not (string-match inf-clojure-prompt kept))
750767
(accept-process-output proc 2)))
751-
(setq eldoc (and (string-match "(.+)" kept) (match-string 0 kept)))
752-
)
768+
(setq eldoc (and (string-match "(.+)" kept) (match-string 0 kept))))
753769
(set-process-filter proc comint-filt))
754770
eldoc))
755771

756772
(defun inf-clojure-show-arglist (fn)
757773
"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)))
774+
(interactive "P")
775+
(let* ((fn-at-pt (if (inf-clojure--prompt-on-commands-p fn)
776+
(car (inf-clojure-symprompt "Arglist" (inf-clojure-fn-called-at-pt)))
777+
(inf-clojure-fn-called-at-pt)))
778+
(eldoc (inf-clojure-arglist fn-at-pt)))
760779
(when eldoc
761-
(message "%s: %s" fn eldoc))))
780+
(message "%s: %s" fn-at-pt eldoc))))
762781

763782
(defun inf-clojure-show-ns-vars (ns)
764783
"Send a query to the inferior Clojure for the public vars in NS.
765784
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)))
785+
(interactive "P")
786+
(let ((ns-at-pt (if (inf-clojure--prompt-on-commands-p ns)
787+
(car (inf-clojure-symprompt "Ns vars" (clojure-find-ns)))
788+
(clojure-find-ns))))
789+
(comint-proc-query (inf-clojure-proc) (format inf-clojure-ns-vars-form ns-at-pt))))
768790

769791
(defun inf-clojure-set-ns (ns)
770792
"Set the ns of the inferior Clojure process to NS.
771793
Defaults to the ns of the current buffer, always prompting before
772794
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)))
795+
(interactive "P")
796+
(let ((ns-at-pt (if (inf-clojure--prompt-on-commands-p ns)
797+
(car (inf-clojure-symprompt "Set ns to" (clojure-find-ns)))
798+
(clojure-find-ns))))
799+
(when (or (not ns-at-pt) (equal ns-at-pt ""))
800+
(user-error "No namespace selected"))
801+
(comint-proc-query (inf-clojure-proc) (format inf-clojure-set-ns-form ns-at-pt))))
779802

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

0 commit comments

Comments
 (0)