Skip to content

Commit b500f3e

Browse files
committed
Insert flavor check before project type check
1 parent a450a0b commit b500f3e

File tree

1 file changed

+39
-72
lines changed

1 file changed

+39
-72
lines changed

inf-clojure.el

Lines changed: 39 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,9 @@
4242
(require 'clojure-mode)
4343
(require 'eldoc)
4444
(require 'thingatpt)
45-
<<<<<<< variant A
4645
(require 'ansi-color)
4746
(require 'cl-lib)
48-
>>>>>>> variant B
4947
(require 'subr-x)
50-
####### Ancestor
51-
======= end
5248

5349

5450
(defgroup inf-clojure nil
@@ -189,6 +185,16 @@ often connecting to a remote REPL process."
189185
:type '(choice (string)
190186
(cons string integer)))
191187

188+
(defcustom inf-clojure-lumo-cmd "lumo -d"
189+
"The command used to start a Lumo REPL.
190+
191+
Alternative you can specify a TCP connection cons pair, instead
192+
of command, consisting of a host and port
193+
number (e.g. (\"localhost\" . 5555)). That's useful if you're
194+
often connecting to a remote REPL process."
195+
:type '(choice (string)
196+
(cons string integer)))
197+
192198
(defcustom inf-clojure-load-command "(clojure.core/load-file \"%s\")\n"
193199
"Format-string for building a Clojure expression to load a file.
194200
This format string should use `%s' to substitute a file name
@@ -261,12 +267,12 @@ whichever process buffer you want to use.")
261267

262268
(put 'inf-clojure-mode 'mode-class 'special)
263269

264-
(defcustom inf-clojure-repl-default-flavor 'clojure
270+
(defcustom inf-clojure-repl-default-flavor nil
265271
"Symbol to define your default REPL flavor.
266272
The default flavor is clojure, lumo is the other supported
267273
one."
268274
:type '(choice (const :tag "Lumo" lumo)
269-
(other :tag "Clojure" clojure))
275+
(other :tag "Project driven" nil))
270276
:group 'inf-clojure)
271277

272278
(defvar-local inf-clojure-repl-flavor inf-clojure-repl-default-flavor
@@ -275,13 +281,6 @@ Takes its root binding from inf-clojure-repl-default-flavor but
275281
can be further customized using either `setq-local` or an entry
276282
in `.dir-locals.el`." )
277283

278-
(defun inf-clojure--flavor-setup ()
279-
"Setup inf-clojure defcustoms depending on the choose flavor."
280-
(pcase inf-clojure-repl-flavor
281-
(lumo (inf-clojure--flavor-lumo-setup))
282-
(clojure nil)
283-
(_ (user-error "[inf-clojure] The specified flavor is not supported at the moment."))))
284-
285284
(define-derived-mode inf-clojure-mode comint-mode "Inferior Clojure"
286285
"Major mode for interacting with an inferior Clojure process.
287286
Runs a Clojure interpreter as a subprocess of Emacs, with Clojure
@@ -391,12 +390,21 @@ Fallback to `default-directory.' if not within a project."
391390
((file-exists-p "build.boot") "boot")
392391
(t nil))))
393392

393+
(defun inf-clojure-flavor-cmd ()
394+
"Determine the flavor of the project.
395+
Return nil if no flavor has been specified"
396+
(pcase inf-clojure-repl-flavor
397+
(lumo inf-clojure-lumo-cmd)
398+
(_ nil)))
399+
394400
(defun inf-clojure-cmd (project-type)
395401
"Determine the command `inf-clojure' needs to invoke for the PROJECT-TYPE."
396-
(pcase project-type
397-
("lein" inf-clojure-lein-cmd)
398-
("boot" inf-clojure-boot-cmd)
399-
(_ inf-clojure-generic-cmd)))
402+
(if-let ((flavor-command (inf-clojure-flavor-cmd)))
403+
flavor-command
404+
(pcase project-type
405+
("lein" inf-clojure-lein-cmd)
406+
("boot" inf-clojure-boot-cmd)
407+
(_ inf-clojure-generic-cmd))))
400408

401409
(defun inf-clojure-clear-repl-buffer ()
402410
"Clear the REPL buffer."
@@ -926,61 +934,20 @@ to suppress the usage of the target buffer discovery logic."
926934
;;;; Lumo
927935
;;;; ====
928936

929-
(defgroup lumo nil
930-
"Run an external Lumo process (REPL) in an Emacs buffer."
931-
:group 'inf-clojure)
932-
933-
(defcustom inf-clojure-lumo-command "lumo"
934-
"The command used to launch lumo."
935-
:type 'string
936-
:group 'lumo)
937-
938-
(defcustom inf-clojure-lumo-args "-d"
939-
"The command arguments used to launch lumo."
940-
:type 'string
941-
:group 'lumo)
942-
943-
;; AR - TODO Alternatively you can specify a command string that will be called,
944-
;; which should return a string.
945-
(defcustom inf-clojure-lumo-classpath-generator "cp"
946-
"The file used to create the classpath string.
947-
The classpath string has to be a \":\" separated list of dir and
948-
files."
949-
:type 'string
950-
:group 'lumo)
951-
952-
;; AR - not used but left here because it is a possible sanity check
953-
(defun inf-clojure--lumo-mode-p ()
954-
"Return true if the lumo is the target REPL."
955-
(comint-send-string (inf-clojure-proc) "(js/global.hasOwnProperty \"$$LUMO_GLOBALS\")"))
956-
957-
(defun inf-clojure--lumo-repl-command ()
958-
"Return inf-clojure-program for lumo."
959-
(concat inf-clojure-lumo-command
960-
" "
961-
(when (not (string-empty-p inf-clojure-lumo-classpath-generator))
962-
(concat inf-clojure-lumo-args " "))
963-
"-c " (inf-clojure--read-classpath inf-clojure-lumo-classpath-generator)))
964-
965-
(defun inf-clojure--flavor-lumo-setup ()
966-
"Setup defcustoms for the Lumo flavor."
967-
;; The defcustoms for the following are already ok:
968-
;; * inf-clojure-set-ns-command
969-
;; * inf-clojure-macroexpand-command
970-
;; * inf-clojure-macroexpand-1-command
971-
;;
972-
;; https://github.com/anmonteiro/lumo/issues/84
973-
;; (setq inf-clojure-var-source-command "(lumo.repl/source %s)")
974-
;; https://github.com/anmonteiro/lumo/issues/87
975-
;; (setq inf-clojure-ns-vars-command "(lumo.repl/dir %s)")
976-
;; https://github.com/anmonteiro/lumo/issues/86
977-
;; (setq inf-clojure-var-apropos-command "(lumo.repl/apropos %s)")
978-
979-
;; Uncomment after https://github.com/anmonteiro/lumo/pull/88
980-
;; (setq inf-clojure-arglist-command "(lumo.repl/get-arglists \"%s\")")
981-
(setq inf-clojure-var-doc-command "(lumo.repl/doc %s)")
982-
(setq inf-clojure-completion-command "(or (doall (map str (lumo.repl/get-completions \"%s\")) '())")
983-
(inf-clojure--maybe-set-program (inf-clojure--lumo-repl-command)))
937+
;; The defcustoms for the following are already ok:
938+
;; * inf-clojure-set-ns-command
939+
;; * inf-clojure-macroexpand-command
940+
;; * inf-clojure-macroexpand-1-command
941+
;;
942+
;; TODOs
943+
;; https://github.com/anmonteiro/lumo/issues/84
944+
;; (setq inf-clojure-var-source-command "(lumo.repl/source %s)")
945+
;; https://github.com/anmonteiro/lumo/issues/87
946+
;; (setq inf-clojure-ns-vars-command "(lumo.repl/dir %s)")
947+
;; https://github.com/anmonteiro/lumo/issues/86
948+
;; (setq inf-clojure-var-apropos-command "(lumo.repl/apropos %s)")
949+
;; https://github.com/anmonteiro/lumo/pull/88
950+
;; (setq inf-clojure-arglist-command "(lumo.repl/get-arglists \"%s\")")
984951

985952
(provide 'inf-clojure)
986953
;;; inf-clojure.el ends here

0 commit comments

Comments
 (0)